Нема описа

polldaddy-shortcode.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ( function ( $ ) {
  2. window.polldaddyshortcode = {
  3. render: function () {
  4. var ratings = $( 'div.pd-rating[data-settings]' );
  5. var polls = $( 'div.PDS_Poll[data-settings]' );
  6. if ( polls ) {
  7. $.each( polls, function () {
  8. var poll = $( this ).data( 'settings' );
  9. if ( poll ) {
  10. var poll_url = document.createElement( 'a' );
  11. poll_url.href = poll[ 'url' ];
  12. if (
  13. poll_url.hostname != 'secure.polldaddy.com' &&
  14. poll_url.hostname != 'static.polldaddy.com'
  15. ) {
  16. return false;
  17. }
  18. var pathname = poll_url.pathname;
  19. if ( ! /\/?p\/\d+\.js/.test( pathname ) ) {
  20. return false;
  21. }
  22. var wp_pd_js = document.createElement( 'script' );
  23. wp_pd_js.type = 'text/javascript';
  24. wp_pd_js.src = poll[ 'url' ];
  25. wp_pd_js.charset = 'utf-8';
  26. wp_pd_js.async = true;
  27. document.getElementsByTagName( 'head' )[ 0 ].appendChild( wp_pd_js );
  28. }
  29. } );
  30. }
  31. if ( ratings ) {
  32. var script = '';
  33. $.each( ratings, function () {
  34. var rating = $( this ).data( 'settings' );
  35. if ( rating ) {
  36. script +=
  37. 'PDRTJS_settings_' +
  38. rating[ 'id' ] +
  39. rating[ 'item_id' ] +
  40. '=' +
  41. rating[ 'settings' ] +
  42. "; if ( typeof PDRTJS_RATING !== 'undefined' ){ if ( typeof PDRTJS_" +
  43. rating[ 'id' ] +
  44. rating[ 'item_id' ] +
  45. "=='undefined' ){PDRTJS_" +
  46. rating[ 'id' ] +
  47. rating[ 'item_id' ] +
  48. '= new PDRTJS_RATING( PDRTJS_settings_' +
  49. rating[ 'id' ] +
  50. rating[ 'item_id' ] +
  51. ' );}}';
  52. }
  53. } );
  54. if ( script.length > 0 )
  55. $( '#polldaddyRatings' ).after(
  56. "<script type='text/javascript' charset='utf-8' id='polldaddyDynamicRatings'>" +
  57. script +
  58. '</script>'
  59. );
  60. }
  61. },
  62. };
  63. $( 'body' ).on( 'post-load pd-script-load', function () {
  64. window.polldaddyshortcode.render();
  65. } );
  66. $( 'body' ).trigger( 'pd-script-load' );
  67. } )( jQuery );