PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | _inc/polldaddy-shortcode.js +92 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,92 @@
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 ( poll_url.protocol !== 'https:' ) {
31 + return false;
32 + }
33 + if (
34 + poll_url.hostname !== 'secure.polldaddy.com' &&
35 + poll_url.hostname !== 'static.polldaddy.com'
36 + ) {
37 + return false;
38 + }
39 + const pathname = poll_url.pathname;
40 + if ( ! /^\/p\/\d+\.js$/.test( pathname ) ) {
41 + return false;
42 + }
43 + const wp_pd_js = d.createElement( 'script' );
44 + wp_pd_js.src = poll_url.href;
45 + wp_pd_js.async = true;
46 + d.head.appendChild( wp_pd_js );
47 + }
48 + } );
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 + return;
61 + }
62 +
63 + const settings = parseJSON( rating.settings );
64 +
65 + if ( settings === null ) {
66 + return;
67 + }
68 +
69 + const key = `${ rating.id }${ rating.item_id }`;
70 + w[ `PDRTJS_settings_${ key }` ] = settings;
71 +
72 + if (
73 + typeof w.PDRTJS_RATING !== 'undefined' &&
74 + typeof w[ `PDRTJS_${ key }` ] === 'undefined'
75 + ) {
76 + w[ `PDRTJS_${ key }` ] = new w.PDRTJS_RATING( w[ `PDRTJS_settings_${ key }` ] );
77 + }
78 + } );
79 + },
80 + };
81 +
82 + d.body.addEventListener( 'is.post-load', () => w.polldaddyshortcode.render() );
83 +
84 + // In environments where jQuery is present, listen and dispatch with jQuery.
85 + if ( typeof w.jQuery !== 'undefined' ) {
86 + w.jQuery( d.body ).on( 'pd-script-load', () => w.polldaddyshortcode.render() );
87 + w.jQuery( d.body ).trigger( 'pd-script-load' );
88 + } else {
89 + d.body.addEventListener( 'pd-script-load', () => w.polldaddyshortcode.render() );
90 + d.body.dispatchEvent( new Event( 'pd-script-load' ) );
91 + }
92 +} )( window, document );