blocks
2 days ago
build
2 days ago
content-guidelines-ai
2 days ago
fonts
1 year ago
genericons
4 months ago
lib
2 days ago
accessible-focus.js
5 years ago
blogging-prompts.php
1 week ago
class.jetpack-provision.php
7 months ago
content-guidelines-ai.js
1 week ago
content-guidelines-ai.php
1 week ago
crowdsignal-shortcode.js
1 year ago
crowdsignal-survey.js
5 years ago
deprecate.js
7 months ago
facebook-embed.js
4 years ago
gallery-settings.js
5 years ago
genericons.php
1 year ago
jetpack-admin.js
3 years ago
jetpack-deactivate-dialog.js
1 year ago
jetpack-modules.js
1 year ago
jetpack-modules.models.js
7 months ago
jetpack-modules.views.js
7 months ago
polldaddy-shortcode.js
3 months ago
site-switcher-endpoint.php
5 months ago
site-switcher.js
5 months ago
site-switcher.php
5 months ago
social-logos.php
3 months ago
twitter-timeline.js
1 month ago
polldaddy-shortcode.js
97 lines
| 1 | ( function ( w, d ) { |
| 2 | function parseJSON( str ) { |
| 3 | try { |
| 4 | return str ? w.JSON.parse( str ) : null; |
| 5 | } catch { |
| 6 | return null; |
| 7 | } |
| 8 | } |
| 9 | |
| 10 | w.polldaddyshortcode = { |
| 11 | render: function () { |
| 12 | const ratings = d.querySelectorAll( 'div.pd-rating[data-settings]' ); |
| 13 | const polls = d.querySelectorAll( 'div.PDS_Poll[data-settings]' ); |
| 14 | |
| 15 | polls.forEach( pollEl => { |
| 16 | if ( pollEl.hasAttribute( 'data-pd-init-done' ) ) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | pollEl.setAttribute( 'data-pd-init-done', '1' ); |
| 21 | const poll = parseJSON( pollEl.getAttribute( 'data-settings' ) ); |
| 22 | |
| 23 | if ( poll ) { |
| 24 | let poll_url; |
| 25 | try { |
| 26 | poll_url = new w.URL( poll.url, 'https://invalid.tld' ); |
| 27 | } catch { |
| 28 | return false; |
| 29 | } |
| 30 | if ( |
| 31 | poll_url.hostname !== 'secure.polldaddy.com' && |
| 32 | poll_url.hostname !== 'static.polldaddy.com' |
| 33 | ) { |
| 34 | return false; |
| 35 | } |
| 36 | const pathname = poll_url.pathname; |
| 37 | if ( ! /\/?p\/\d+\.js/.test( pathname ) ) { |
| 38 | return false; |
| 39 | } |
| 40 | const wp_pd_js = d.createElement( 'script' ); |
| 41 | wp_pd_js.src = poll_url.href; |
| 42 | wp_pd_js.async = true; |
| 43 | d.head.appendChild( wp_pd_js ); |
| 44 | } |
| 45 | } ); |
| 46 | |
| 47 | if ( ratings.length ) { |
| 48 | let scriptContents = ''; |
| 49 | |
| 50 | ratings.forEach( ratingEl => { |
| 51 | if ( ratingEl.hasAttribute( 'data-pd-init-done' ) ) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | ratingEl.setAttribute( 'data-pd-init-done', '1' ); |
| 56 | |
| 57 | const rating = parseJSON( ratingEl.getAttribute( 'data-settings' ) ); |
| 58 | |
| 59 | if ( rating ) { |
| 60 | scriptContents += ` |
| 61 | PDRTJS_settings_${ rating.id }${ rating.item_id } = ${ rating.settings }; |
| 62 | if ( typeof PDRTJS_RATING !== 'undefined' ) { |
| 63 | if ( typeof PDRTJS_${ rating.id }${ rating.item_id } === 'undefined' ) { |
| 64 | PDRTJS_${ rating.id }${ rating.item_id } = |
| 65 | new PDRTJS_RATING( PDRTJS_settings_${ rating.id }${ rating.item_id } ); |
| 66 | } |
| 67 | } |
| 68 | `; |
| 69 | } |
| 70 | } ); |
| 71 | |
| 72 | if ( scriptContents ) { |
| 73 | const anchorEl = d.querySelector( '#polldaddyRatings' ); |
| 74 | if ( anchorEl ) { |
| 75 | const script = d.createElement( 'script' ); |
| 76 | script.id = 'polldaddyDynamicRatings'; |
| 77 | script.text = scriptContents; |
| 78 | |
| 79 | anchorEl.after( script ); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | }, |
| 84 | }; |
| 85 | |
| 86 | d.body.addEventListener( 'is.post-load', () => w.polldaddyshortcode.render() ); |
| 87 | |
| 88 | // In environments where jQuery is present, listen and dispatch with jQuery. |
| 89 | if ( typeof w.jQuery !== 'undefined' ) { |
| 90 | w.jQuery( d.body ).on( 'pd-script-load', () => w.polldaddyshortcode.render() ); |
| 91 | w.jQuery( d.body ).trigger( 'pd-script-load' ); |
| 92 | } else { |
| 93 | d.body.addEventListener( 'pd-script-load', () => w.polldaddyshortcode.render() ); |
| 94 | d.body.dispatchEvent( new Event( 'pd-script-load' ) ); |
| 95 | } |
| 96 | } )( window, document ); |
| 97 |