1jQuery(function ($) { 2 $('.totalpoll-poll-container').addClass('dom-ready'); 3 4 /** 5 * AJAX 6 */ 7 $(document).delegate('.totalpoll-poll-container [name^="totalpoll[action]"]', 'click', function (e) { 8 e.preventDefault(); 9 var $this = $(this); 10 var $container = $this.closest('.totalpoll-poll-container'); 11 12 var fields = $container.find('form').serializeArray(); 13 fields.push({name: $this.attr('name'), value: $this.val()}); 14 fields.push({name: 'action', value: TotalPoll.AJAX_ACTION || 'tp_action'}); 15 16 var transitionType = $container.data('transition-type') || 'fade'; 17 18 if (transitionType == 'none') { 19 $container.hide(); 20 } else if (transitionType == 'fade') { 21 $container.fadeTo('slow', 0.5).css( 22 { 23 'pointer-events': 'none', 24 'min-height': $container.outerHeight() 25 } 26 ); 27 } else if (transitionType == 'slide') { 28 $container.slideUp(); 29 } 30 31 32 $.ajax({
33 url: TotalPoll.AJAX || this.action, 34 type: 'POST', 35 data: fields, 36 success: function (content) { 37 var $content = $(content).hide(); 38 var scrollToTop = $container.offset().top; 39 $container.after($content).fadeOut(function () { 40 41 if (transitionType == 'none') { 42 $content.show(); 43 } else if (transitionType == 'fade') { 44 $content.fadeIn(); 45 } else if (transitionType == 'slide') { 46 $content.slideDown(); 47 } 48 49 $content.addClass('dom-ready'); 50 $(this).remove(); 51 52 if ($container.is('[data-scroll-back]')) { 53 $(document.body).animate({scrollTop: scrollToTop - 64}); 54 } 55 56 $(document).trigger('totalpoll.after.ajax', [ 57 { 58 button: $this, 59 container: $content, 60 }, 61 fields 62 ]); 63 }); 64 } 65 }); 66 67 }); 68 69 /** 70 * One-click vote 71 */ 72 $(document).delegate('.totalpoll-poll-container[data-oneclick-vote] [name="totalpoll[choices][]"]', 'click change', function (e) { 73 var $this = $(this); 74 var $container = $this.closest('.totalpoll-poll-container'); 75 $container.find('[name^="totalpoll[action]"][value="vote"]').click(); 76 }); 77 78 /** 79 * Maximum selection 80 */ 81 $(document).delegate('.totalpoll-poll-container input[name="totalpoll[choices][]"]', 'change', function (e) { 82 e.preventDefault(); 83 var $this = $(this); 84 var $poll = $this.closest('.totalpoll-poll-container'); 85 var $checkboxes = $poll.find('input[name="totalpoll[choices][]"]'); 86 var $checked = $checkboxes.filter(':checked'); 87 var $unchecked = $checkboxes.not(':checked'); 88 var maxSelection = $poll.attr('data-max-selection'); 89 90 if (maxSelection > 1 && $checked.length >= maxSelection) { 91 $unchecked.attr('disabled', ''); 92 } else { 93 $checkboxes.removeAttr('disabled'); 94 } 95 96 $checkboxes.each(function () { 97 $(this).closest('[data-tp-choice]').toggleClass('checked', this.checked); 98 }); 99 100 }); 101 102 /** 103 * reCaptcha 104 */ 105 window.reCaptchaReady = function () { 106 $('[data-tp-captcha]').each(function () { 107 grecaptcha.render(this, { 108 sitekey: TotalPoll.settings.limitations.captcha.sitekey, 109 }); 110 }); 111 }; 112 113 if (TotalPoll.settings.limitations.captcha.enabled) { 114 $(document).on('totalpoll.after.ajax', function () { 115 window.reCaptchaReady(); 116 }); 117 } 118 119 /** 120 * Sharing 121 */ 122 if (TotalPoll.settings.sharing.enabled) { 123 var shareConfig = { 124 description: TotalPoll.settings.sharing.expression, 125 networks: {} 126 }; 127 128 var shareNetworks = ['googlePlus', 'twitter', 'facebook', 'pinterest', 'reddit', 'linkedin', 'whatsapp', 'email']; 129 $.each(shareNetworks, function (index, network) { 130 shareConfig.networks[network] = { 131 enabled: TotalPoll.settings.sharing.networks.indexOf(network) != -1 132 } 133 }); 134 135 // Initialization helper 136 var shareInit = function () { 137 if (window.ShareButton) { 138 new ShareButton(shareConfig); 139 } 140 }; 141 142 // Event listener: Reinitialize share after receiving ajax response 143 $(document).on('totalpoll.after.ajax', shareInit); 144 145 // Initialize 146 shareInit(); 147 } 148 149 /** 150 * Asynchronous loading 151 */ 152 if (window['TotalPollAsync']) { 153 $.each(TotalPollAsync, function (key, poll) { 154 var $container = $('#' + poll.container); 155 $container.load( 156 TotalPoll.AJAX, 157 { 158 action: TotalPoll.AJAX_ACTION || 'tp_action', 159 totalpoll: { 160 id: poll.id, 161 action: 'load' 162 } 163 }, 164 function () { 165 $(document).trigger('totalpoll.after.ajax', [ 166 { 167 button: $(), 168 container: $container.find('.totalpoll-poll-container'), 169 } 170 ]); 171 } 172 ); 173 }); 174 } 175 176});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.