PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.1
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.1
6.5.1 6.5.0 6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 All 154 releases
poll-maker / public / js / poll-maker-public-ajax.js

poll-maker-public-ajax.js in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.4.1, at public/js/poll-maker-public-ajax.js

1,346 lines 77.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 // String.prototype.stripSlashes = function () {
3 // return this.replace(/\\(.)/mg, "$1");
4 // }
5 function stripSlashes(str) {
6 return str.replace(/\\(.)/mg, "$1");
7 }
8 $.fn.serializeFormJSON = function () {
9 var o = {},
10 a = this.serializeArray();
11 $.each(a, function () {
12 if (o[this.name]) {
13 if (!o[this.name].push) {
14 o[this.name] = [o[this.name]];
15 }
16 o[this.name].push(this.value || '');
17 } else {
18 o[this.name] = this.value || '';
19 }
20 });
21 return o;
22 };
23
24 $.fn.goToPoll = function(enabelAnimation, scroll) {
25 var pollAnimationTop = (scroll && scroll != 0) ? parseInt(scroll) : 100;
26
27 if( enabelAnimation ){
28 $('html, body').animate({
29 scrollTop: $(this).offset().top - scroll + 'px'
30 }, 'slow');
31 }
32 return this; // for chaining...
33 }
34
35 $.fn.aysModal = function(action){
36 var $this = $(this);
37 switch(action){
38 case 'hide':
39 $(this).find('.ays-poll-avatars-modal-content').css('animation-name', 'zoomOut');
40 setTimeout(function(){
41 $(document.body).removeClass('modal-open');
42 $(document).find('.ays-modal-backdrop').remove();
43 $this.hide();
44 }, 250);
45 break;
46 case 'show':
47 default:
48 $this.show();
49 $(this).find('.ays-poll-avatars-modal-content').css('animation-name', 'zoomIn');
50 $(document).find('.modal-backdrop').remove();
51 $(document.body).append('<div class="ays-modal-backdrop"></div>');
52 $(document.body).addClass('modal-open');
53 break;
54 }
55 }
56
57 $(document).find(".ays-poll-main .apm-info-form").each(function(e){
58 var infoForm = $(this);
59 var mainContainer = infoForm.parents('.ays-poll-main');
60 var id = mainContainer.attr('id').match(/\d+$/)[0];
61 var pollBox = mainContainer.find('div[data-id="' + id + '"]');
62 var uniqueId = pollBox.attr('id');
63 var pollOptions = JSON.parse(window.atob(window.aysPollOptions[uniqueId]));
64
65 if (pollOptions.autofill_user_data && pollOptions.autofill_user_data == "on") {
66 var userData = {};
67 userData.action = 'ays_poll_get_user_information';
68 userData._ajax_nonce = poll_maker_ajax_public.nonce;
69 $.ajax({
70 url: poll_maker_ajax_public.ajax_url,
71 method: 'post',
72 dataType: 'json',
73 data: userData,
74 success: function (response) {
75 if(response !== null){
76 infoForm.find("input[name='apm_name']").val(response.data.display_name);
77 infoForm.find("input[name='apm_email']").val(response.data.user_email);
78 }
79 }
80 });
81 }
82 })
83
84 function socialBtnAdd(formId, buttons) {
85 var socialDiv = $("<div class='apm-social-btn'></div>");
86 if(buttons.heading != ""){
87 socialDiv.append("<div class='ays-survey-social-shares-heading'>"+
88 buttons.heading
89 +"</div>");
90 }
91 if(buttons.faceBook){
92 socialDiv.append("<a class='fb-share-button ays-share-btn ays-share-btn-branded ays-share-btn-facebook'"+
93 "title='Share on Facebook'>"+
94 "<span class='ays-share-btn-text'>Facebook</span>"+
95 "</a>");
96 }
97 if(buttons.twitter){
98 socialDiv.append("<a class='twt-share-button ays-share-btn ays-share-btn-branded ays-share-btn-twitter'"+
99 "title='Share on Twitter'>"+
100 "<span class='ays-share-btn-text'>Twitter</span>"+
101 "</a>");
102 }
103 if(buttons.linkedIn){
104 socialDiv.append("<a class='linkedin-share-button ays-share-btn ays-share-btn-branded ays-share-btn-linkedin'"+
105 "title='Share on LinkedIn'>"+
106 "<span class='ays-share-btn-text'>LinkedIn</span>"+
107 "</a>");
108 }
109 if(buttons.vkontakte){
110 socialDiv.append("<a class='vkontakte-share-button ays-share-btn ays-share-btn-branded ays-share-btn-vkontakte'"+
111 "title='Share on VKontakte'>"+
112 "<span class='ays-survey-share-btn-icon'></span>"+
113 "<span class='ays-share-btn-text'>VKontakte</span>"+
114 "</a>");
115 }
116 $("#"+formId).append(socialDiv);
117 $(document).on('click', '.fb-share-button', function (e) {
118 window.open('https://www.facebook.com/sharer/sharer.php?u=' + window.location.href,
119 'facebook-share-dialog',
120 'width=650,height=450'
121 );
122 return false;
123 })
124 $(document).on('click', '.twt-share-button', function (e) {
125 window.open('https://twitter.com/intent/tweet?url=' + window.location.href,
126 'twitter-share-dialog',
127 'width=650,height=450'
128 );
129 return false;
130 })
131 $(document).on('click', '.linkedin-share-button', function (e) {
132 window.open('https://www.linkedin.com/shareArticle?mini=true&url=' + window.location.href,
133 'linkedin-share-dialog',
134 'width=650,height=450'
135 );
136 return false;
137 })
138 $(document).on('click', '.vkontakte-share-button', function (e) {
139 window.open('https://vk.com/share.php?url=' + window.location.href,
140 'vkontakte-share-dialog',
141 'width=650,height=450'
142 );
143 return false;
144 })
145 setTimeout(function() {
146 $("#"+formId+" .apm-social-btn").css('opacity', '1');
147 }, 1000);
148 }
149
150 function socialLinksAdd(formId, buttons) {
151 var socialLinksDiv = $("<div class='apm-social-btn'></div>");
152 if(buttons.heading != ""){
153 socialLinksDiv.append("<div class='ays-survey-social-shares-heading'>"+
154 buttons.heading
155 +"</div>");
156 }
157 if(buttons.faceBookLink != ''){
158 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-facebook'"+
159 "title='Facebook Link' target='_blank' href=" + buttons.faceBookLink + ">"+
160 "<div class='ays-poll-link-icon'><?xml version='1.0'?><svg fill='#fff' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='48px' height='48px'><path d='M19,3H5C3.895,3,3,3.895,3,5v14c0,1.105,0.895,2,2,2h7.621v-6.961h-2.343v-2.725h2.343V9.309 c0-2.324,1.421-3.591,3.495-3.591c0.699-0.002,1.397,0.034,2.092,0.105v2.43h-1.428c-1.13,0-1.35,0.534-1.35,1.322v1.735h2.7 l-0.351,2.725h-2.365V21H19c1.105,0,2-0.895,2-2V5C21,3.895,20.105,3,19,3z'/></svg></div>"+
161 "</a>");
162 }
163 if(buttons.twitterLink != ''){
164 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-x'"+
165 "title='Twitter Link' target='_blank' href=" + buttons.twitterLink + ">"+
166 "<div class='ays-poll-link-icon'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='48px' height='48px' fill='currentColor'><path d='M18.244 2H21.552L14.325 10.26L22.8 22H16.17L10.96 14.82L4.7 22H1.39L9.14 13.14L1 2H7.8L12.52 8.46L18.244 2ZM17.1 20H18.95L6.8 4H4.82L17.1 20Z'/></svg></div>"+
167 "</a>");
168 }
169 if(buttons.linkedInLink != ''){
170 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-linkedin'"+
171 "title='LinkedIn Link' target='_blank' href=" + buttons.linkedInLink + ">"+
172 "<div class='ays-poll-link-icon'><?xml version='1.0'?><svg fill='#fff' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='48px' height='48px'> <path d='M21,3H3v18h18V3z M9,17H6.477v-7H9V17z M7.694,8.717c-0.771,0-1.286-0.514-1.286-1.2s0.514-1.2,1.371-1.2 c0.771,0,1.286,0.514,1.286,1.2S8.551,8.717,7.694,8.717z M18,17h-2.442v-3.826c0-1.058-0.651-1.302-0.895-1.302 s-1.058,0.163-1.058,1.302c0,0.163,0,3.826,0,3.826h-2.523v-7h2.523v0.977C13.93,10.407,14.581,10,15.802,10 C17.023,10,18,10.977,18,13.174V17z'/></svg></div>"+
173 "</a>");
174 }
175 if(buttons.vkontakteLink != ''){
176 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-vkontakte'"+
177 "title='VKontakte Link' target='_blank' href=" + buttons.vkontakteLink + ">"+
178 "<div class='ays-poll-link-icon'><svg fill='#fff' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48' width='48px' height='48px'><path d='M45.763,35.202c-1.797-3.234-6.426-7.12-8.337-8.811c-0.523-0.463-0.579-1.264-0.103-1.776 c3.647-3.919,6.564-8.422,7.568-11.143C45.334,12.27,44.417,11,43.125,11l-3.753,0c-1.237,0-1.961,0.444-2.306,1.151 c-3.031,6.211-5.631,8.899-7.451,10.47c-1.019,0.88-2.608,0.151-2.608-1.188c0-2.58,0-5.915,0-8.28 c0-1.147-0.938-2.075-2.095-2.075L18.056,11c-0.863,0-1.356,0.977-0.838,1.662l1.132,1.625c0.426,0.563,0.656,1.248,0.656,1.951 L19,23.556c0,1.273-1.543,1.895-2.459,1.003c-3.099-3.018-5.788-9.181-6.756-12.128C9.505,11.578,8.706,11.002,7.8,11l-3.697-0.009 c-1.387,0-2.401,1.315-2.024,2.639c3.378,11.857,10.309,23.137,22.661,24.36c1.217,0.12,2.267-0.86,2.267-2.073l0-3.846 c0-1.103,0.865-2.051,1.977-2.079c0.039-0.001,0.078-0.001,0.117-0.001c3.267,0,6.926,4.755,8.206,6.979 c0.368,0.64,1.056,1.03,1.8,1.03l4.973,0C45.531,38,46.462,36.461,45.763,35.202z'/></svg></div>"+
179 "</a>");
180 }
181 if(buttons.youtubeLink != ''){
182 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-poll-share-btn-youtube'"+
183 "title='Youtube Link' target='_blank' href=" + buttons.youtubeLink + ">"+
184 "<div class='ays-poll-link-icon'><svg xmlns='http://www.w3.org/2000/svg' fill='#FF0000' viewBox='0 0 28 28' width='48px' height='48px'> <path d='M 15 4 C 10.814 4 5.3808594 5.0488281 5.3808594 5.0488281 L 5.3671875 5.0644531 C 3.4606632 5.3693645 2 7.0076245 2 9 L 2 15 L 2 15.001953 L 2 21 L 2 21.001953 A 4 4 0 0 0 5.3769531 24.945312 L 5.3808594 24.951172 C 5.3808594 24.951172 10.814 26.001953 15 26.001953 C 19.186 26.001953 24.619141 24.951172 24.619141 24.951172 L 24.621094 24.949219 A 4 4 0 0 0 28 21.001953 L 28 21 L 28 15.001953 L 28 15 L 28 9 A 4 4 0 0 0 24.623047 5.0546875 L 24.619141 5.0488281 C 24.619141 5.0488281 19.186 4 15 4 z M 12 10.398438 L 20 15 L 12 19.601562 L 12 10.398438 z'/></svg></div>"+
185 "</a>");
186 }
187 if(buttons.tiktokLink != ''){
188 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-poll-share-btn-tiktok'"+
189 "title='Tiktok Link' target='_blank' href=" + buttons.tiktokLink + ">"+
190 "<div class='ays-poll-link-icon'><svg fill='none' viewBox='0 0 32 32' height='24px' width='24px' xmlns='http://www.w3.org/2000/svg'><path d='M8.45095 19.7926C8.60723 18.4987 9.1379 17.7743 10.1379 17.0317C11.5688 16.0259 13.3561 16.5948 13.3561 16.5948V13.2197C13.7907 13.2085 14.2254 13.2343 14.6551 13.2966V17.6401C14.6551 17.6401 12.8683 17.0712 11.4375 18.0775C10.438 18.8196 9.90623 19.5446 9.7505 20.8385C9.74562 21.5411 9.87747 22.4595 10.4847 23.2536C10.3345 23.1766 10.1815 23.0889 10.0256 22.9905C8.68807 22.0923 8.44444 20.7449 8.45095 19.7926ZM22.0352 6.97898C21.0509 5.90039 20.6786 4.81139 20.5441 4.04639H21.7823C21.7823 4.04639 21.5354 6.05224 23.3347 8.02482L23.3597 8.05134C22.8747 7.7463 22.43 7.38624 22.0352 6.97898ZM28 10.0369V14.293C28 14.293 26.42 14.2312 25.2507 13.9337C23.6179 13.5176 22.5685 12.8795 22.5685 12.8795C22.5685 12.8795 21.8436 12.4245 21.785 12.3928V21.1817C21.785 21.6711 21.651 22.8932 21.2424 23.9125C20.709 25.246 19.8859 26.1212 19.7345 26.3001C19.7345 26.3001 18.7334 27.4832 16.9672 28.28C15.3752 28.9987 13.9774 28.9805 13.5596 28.9987C13.5596 28.9987 11.1434 29.0944 8.96915 27.6814C8.49898 27.3699 8.06011 27.0172 7.6582 26.6277L7.66906 26.6355C9.84383 28.0485 12.2595 27.9528 12.2595 27.9528C12.6779 27.9346 14.0756 27.9528 15.6671 27.2341C17.4317 26.4374 18.4344 25.2543 18.4344 25.2543C18.5842 25.0754 19.4111 24.2001 19.9423 22.8662C20.3498 21.8474 20.4849 20.6247 20.4849 20.1354V11.3475C20.5435 11.3797 21.2679 11.8347 21.2679 11.8347C21.2679 11.8347 22.3179 12.4734 23.9506 12.8889C25.1204 13.1864 26.7 13.2483 26.7 13.2483V9.91314C27.2404 10.0343 27.7011 10.0671 28 10.0369Z' fill='#EE1D52'/><path d='M26.7009 9.91314V13.2472C26.7009 13.2472 25.1213 13.1853 23.9515 12.8879C22.3188 12.4718 21.2688 11.8337 21.2688 11.8337C21.2688 11.8337 20.5444 11.3787 20.4858 11.3464V20.1364C20.4858 20.6258 20.3518 21.8484 19.9432 22.8672C19.4098 24.2012 18.5867 25.0764 18.4353 25.2553C18.4353 25.2553 17.4337 26.4384 15.668 27.2352C14.0765 27.9539 12.6788 27.9357 12.2604 27.9539C12.2604 27.9539 9.84473 28.0496 7.66995 26.6366L7.6591 26.6288C7.42949 26.4064 7.21336 26.1717 7.01177 25.9257C6.31777 25.0795 5.89237 24.0789 5.78547 23.7934C5.78529 23.7922 5.78529 23.791 5.78547 23.7898C5.61347 23.2937 5.25209 22.1022 5.30147 20.9482C5.38883 18.9122 6.10507 17.6625 6.29444 17.3494C6.79597 16.4957 7.44828 15.7318 8.22233 15.0919C8.90538 14.5396 9.6796 14.1002 10.5132 13.7917C11.4144 13.4295 12.3794 13.2353 13.3565 13.2197V16.5948C13.3565 16.5948 11.5691 16.028 10.1388 17.0317C9.13879 17.7743 8.60812 18.4987 8.45185 19.7926C8.44534 20.7449 8.68897 22.0923 10.0254 22.991C10.1813 23.0898 10.3343 23.1775 10.4845 23.2541C10.7179 23.5576 11.0021 23.8221 11.3255 24.0368C12.631 24.8632 13.7249 24.9209 15.1238 24.3842C16.0565 24.0254 16.7586 23.2167 17.0842 22.3206C17.2888 21.7611 17.2861 21.1978 17.2861 20.6154V4.04639H20.5417C20.6763 4.81139 21.0485 5.90039 22.0328 6.97898C22.4276 7.38624 22.8724 7.7463 23.3573 8.05134C23.5006 8.19955 24.2331 8.93231 25.1734 9.38216C25.6596 9.61469 26.1722 9.79285 26.7009 9.91314Z' fill='#000000'/><path d='M4.48926 22.7568V22.7594L4.57004 22.9784C4.56076 22.9529 4.53074 22.8754 4.48926 22.7568Z' fill='#69C9D0'/><path d='M10.5128 13.7916C9.67919 14.1002 8.90498 14.5396 8.22192 15.0918C7.44763 15.7332 6.79548 16.4987 6.29458 17.354C6.10521 17.6661 5.38897 18.9168 5.30161 20.9528C5.25223 22.1068 5.61361 23.2983 5.78561 23.7944C5.78543 23.7956 5.78543 23.7968 5.78561 23.798C5.89413 24.081 6.31791 25.0815 7.01191 25.9303C7.2135 26.1763 7.42963 26.4111 7.65924 26.6334C6.92357 26.1457 6.26746 25.5562 5.71236 24.8839C5.02433 24.0451 4.60001 23.0549 4.48932 22.7626C4.48919 22.7605 4.48919 22.7584 4.48932 22.7564V22.7527C4.31677 22.2571 3.95431 21.0651 4.00477 19.9096C4.09213 17.8736 4.80838 16.6239 4.99775 16.3108C5.4985 15.4553 6.15067 14.6898 6.92509 14.0486C7.608 13.4961 8.38225 13.0567 9.21598 12.7484C9.73602 12.5416 10.2778 12.3891 10.8319 12.2934C11.6669 12.1537 12.5198 12.1415 13.3588 12.2575V13.2196C12.3808 13.2349 11.4148 13.4291 10.5128 13.7916Z' fill='#69C9D0'/><path d='M20.5438 4.04635H17.2881V20.6159C17.2881 21.1983 17.2881 21.76 17.0863 22.3211C16.7575 23.2167 16.058 24.0253 15.1258 24.3842C13.7265 24.923 12.6326 24.8632 11.3276 24.0368C11.0036 23.823 10.7187 23.5594 10.4844 23.2567C11.5962 23.8251 12.5913 23.8152 13.8241 23.341C14.7558 22.9821 15.4563 22.1734 15.784 21.2774C15.9891 20.7178 15.9864 20.1546 15.9864 19.5726V3H20.4819C20.4819 3 20.4315 3.41188 20.5438 4.04635ZM26.7002 8.99104V9.9131C26.1725 9.79263 25.6609 9.61447 25.1755 9.38213C24.2352 8.93228 23.5026 8.19952 23.3594 8.0513C23.5256 8.1559 23.6981 8.25106 23.8759 8.33629C25.0192 8.88339 26.1451 9.04669 26.7002 8.99104Z' fill='#69C9D0'/></svg></div>"+
191 "</a>");
192 }
193 $("#"+formId).append(socialLinksDiv);
194
195 setTimeout(function() {
196 $("#"+formId+" .apm-social-btn").css('opacity', '1');
197 }, 1000);
198 }
199
200 function loadEffect(formId, onOff , fontSize,message) {
201 var loadFontSize = fontSize.length > 0 ? fontSize+"px" : '100%';
202 var form = $("#"+formId),
203 effect = form.attr('data-loading');
204 switch (effect) {
205 case 'blur':
206 form.css({
207 WebkitFilter: onOff ? 'blur(5px)' : 'unset',
208 filter: onOff ? 'blur(5px)' : 'unset',
209 })
210 break;
211 case 'load_gif':
212 if (onOff) {
213 var loadSvg = '';
214 switch (form.attr('data-load-gif')) {
215 case 'plg_1':
216 loadSvg = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 24 30" style="enable-background:new 0 0 50 50;" xml:space="preserve">'+
217 '<rect x="0" y="0" width="4" height="10" fill="#333">'+
218 '<animateTransform attributeType="xml"'+
219 'attributeName="transform" type="translate"'+
220 'values="0 0; 0 20; 0 0"'+
221 'begin="0" dur="0.8s" repeatCount="indefinite" />'+
222 '</rect>'+
223 '<rect x="10" y="0" width="4" height="10" fill="#333">'+
224 '<animateTransform attributeType="xml"'+
225 'attributeName="transform" type="translate"'+
226 'values="0 0; 0 20; 0 0"'+
227 'begin="0.2s" dur="0.8s" repeatCount="indefinite" />'+
228 '</rect>'+
229 '<rect x="20" y="0" width="4" height="10" fill="#333">'+
230 '<animateTransform attributeType="xml"'+
231 'attributeName="transform" type="translate"'+
232 'values="0 0; 0 20; 0 0"'+
233 'begin="0.4s" dur="0.8s" repeatCount="indefinite" />'+
234 '</rect>'+
235 '</svg>';
236 break;
237 case 'plg_2':
238 loadSvg = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 24 30" style="enable-background:new 0 0 50 50;" xml:space="preserve">'+
239 '<rect x="0" y="10" width="4" height="10" fill="#333" opacity="0.2">'+
240 '<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0s" dur="0.7s" repeatCount="indefinite" />'+
241 '<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0s" dur="0.7s" repeatCount="indefinite" />'+
242 '<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0s" dur="0.7s" repeatCount="indefinite" />'+
243 '</rect>'+
244 '<rect x="8" y="10" width="4" height="10" fill="#333" opacity="0.2">'+
245 '<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+
246 '<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+
247 '<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+
248 '</rect>'+
249 '<rect x="16" y="10" width="4" height="10" fill="#333" opacity="0.2">'+
250 '<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+
251 '<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+
252 '<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+
253 '</rect>'+
254 '</svg>';
255 break;
256 case 'plg_3':
257 loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 105 105" xmlns="http://www.w3.org/2000/svg" fill="#000">'+
258 '<circle cx="12.5" cy="12.5" r="12.5">'+
259 '<animate attributeName="fill-opacity"'+
260 'begin="0s" dur="0.9s"'+
261 'values="1;.2;1" calcMode="linear"'+
262 'repeatCount="indefinite" />'+
263 '</circle>'+
264 '<circle cx="12.5" cy="52.5" r="12.5" fill-opacity=".5">'+
265 '<animate attributeName="fill-opacity"'+
266 'begin="100ms" dur="0.9s"'+
267 'values="1;.2;1" calcMode="linear"'+
268 'repeatCount="indefinite" />'+
269 '</circle>'+
270 '<circle cx="52.5" cy="12.5" r="12.5">'+
271 '<animate attributeName="fill-opacity"'+
272 'begin="300ms" dur="0.9s"'+
273 'values="1;.2;1" calcMode="linear"'+
274 'repeatCount="indefinite" />'+
275 '</circle>'+
276 '<circle cx="52.5" cy="52.5" r="12.5">'+
277 '<animate attributeName="fill-opacity"'+
278 'begin="600ms" dur="0.9s"'+
279 'values="1;.2;1" calcMode="linear"'+
280 'repeatCount="indefinite" />'+
281 '</circle>'+
282 '<circle cx="92.5" cy="12.5" r="12.5">'+
283 '<animate attributeName="fill-opacity"'+
284 'begin="800ms" dur="0.9s"'+
285 'values="1;.2;1" calcMode="linear"'+
286 'repeatCount="indefinite" />'+
287 '</circle>'+
288 '<circle cx="92.5" cy="52.5" r="12.5">'+
289 '<animate attributeName="fill-opacity"'+
290 'begin="400ms" dur="0.9s"'+
291 'values="1;.2;1" calcMode="linear"'+
292 'repeatCount="indefinite" />'+
293 '</circle>'+
294 '<circle cx="12.5" cy="92.5" r="12.5">'+
295 '<animate attributeName="fill-opacity"'+
296 'begin="700ms" dur="0.9s"'+
297 'values="1;.2;1" calcMode="linear"'+
298 'repeatCount="indefinite" />'+
299 '</circle>'+
300 '<circle cx="52.5" cy="92.5" r="12.5">'+
301 '<animate attributeName="fill-opacity"'+
302 'begin="500ms" dur="0.9s"'+
303 'values="1;.2;1" calcMode="linear"'+
304 'repeatCount="indefinite" />'+
305 '</circle>'+
306 '<circle cx="92.5" cy="92.5" r="12.5">'+
307 '<animate attributeName="fill-opacity"'+
308 'begin="200ms" dur="0.9s"'+
309 'values="1;.2;1" calcMode="linear"'+
310 'repeatCount="indefinite" />'+
311 '</circle>'+
312 '</svg>';
313 break;
314 case 'plg_4':
315 loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 57 57" xmlns="http://www.w3.org/2000/svg" stroke="#000">'+
316 '<g fill="none" fill-rule="evenodd">'+
317 '<g transform="translate(1 1)" stroke-width="2">'+
318 '<circle cx="5" cy="50" r="5">'+
319 '<animate attributeName="cy"'+
320 'begin="0s" dur="2.2s"'+
321 'values="50;5;50;50"'+
322 'calcMode="linear"'+
323 'repeatCount="indefinite" />'+
324 '<animate attributeName="cx"'+
325 'begin="0s" dur="2.2s"'+
326 'values="5;27;49;5"'+
327 'calcMode="linear"'+
328 'repeatCount="indefinite" />'+
329 '</circle>'+
330 '<circle cx="27" cy="5" r="5">'+
331 '<animate attributeName="cy"'+
332 'begin="0s" dur="2.2s"'+
333 'from="5" to="5"'+
334 'values="5;50;50;5"'+
335 'calcMode="linear"'+
336 'repeatCount="indefinite" />'+
337 '<animate attributeName="cx"'+
338 'begin="0s" dur="2.2s"'+
339 'from="27" to="27"'+
340 'values="27;49;5;27"'+
341 'calcMode="linear"'+
342 'repeatCount="indefinite" />'+
343 '</circle>'+
344 '<circle cx="49" cy="50" r="5">'+
345 '<animate attributeName="cy"'+
346 'begin="0s" dur="2.2s"'+
347 'values="50;50;5;50"'+
348 'calcMode="linear"'+
349 'repeatCount="indefinite" />'+
350 '<animate attributeName="cx"'+
351 'from="49" to="49"'+
352 'begin="0s" dur="2.2s"'+
353 'values="49;5;27;49"'+
354 'calcMode="linear"'+
355 'repeatCount="indefinite" />'+
356 '</circle>'+
357 '</g>'+
358 '</g>'+
359 '</svg>';
360 break;
361 case 'plg_5':
362 loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 135 140" xmlns="http://www.w3.org/2000/svg" stroke="#000">'+
363 '<rect y="10" width="15" height="120" rx="6">'+
364 '<animate attributeName="height" begin="0.5s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite" />'+
365 '<animate attributeName="y" begin="0.5s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite" />'+
366 '</rect>'+
367 '<rect x="30" y="10" width="15" height="120" rx="6">'+
368 '<animate attributeName="height" begin="0.25s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+
369 '<animate attributeName="y" begin="0.25s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+
370 '</rect>'+
371 ' <rect x="60" width="15" height="140" rx="6">'+
372 '<animate attributeName="height" begin="0s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+
373 '<animate attributeName="y" begin="0s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+
374 '</rect>'+
375 '<rect x="90" y="10" width="15" height="120" rx="6">'+
376 '<animate attributeName="height" begin="0.25s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+
377 '<animate attributeName="y" begin="0.25s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+
378 '</rect>'+
379 '<rect x="120" y="10" width="15" height="120" rx="6">'+
380 '<animate attributeName="height" begin="0.5s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+
381 '<animate attributeName="y" begin="0.5s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+
382 '</rect>'+
383 '</svg>';
384 break;
385 default:
386 loadSvg = '<svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"'+
387 'width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">'+
388 '<path fill="#000" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318, 0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0, 14.615, 6.543,14.615,14.615H43.935z">'+
389 '<animateTransform attributeType="xml"'+
390 'attributeName="transform"'+
391 'type="rotate"'+
392 'from="0 25 25"'+
393 'to="360 25 25"'+
394 'dur="0.6s"'+
395 'repeatCount="indefinite"/>'+
396 '</path>'+
397 '</svg>';
398 }
399 var layer = $('<div class="apm-opacity-layer-light" style="margin-top: 0">'+
400 '<div class="apm-loading-gif">'+
401 '<div class="apm-loader loader--style3">'+
402 loadSvg+
403 '</div>'+
404 '</div>'+
405 '</div>');
406 form.css({
407 position: 'relative'
408 });
409 form.append(layer);
410 layer.css('opacity', 1);
411 } else {
412 $('.apm-opacity-layer-light').css('opacity', 0).empty();
413 setTimeout(function() {
414 $('.apm-opacity-layer-light').remove();
415 }, 500);
416 }
417 break;
418 case 'message':
419 if (onOff) {
420 var layer = $('<div class="apm-opacity-layer-light apm-load-message-container"><span>'+message+'</span></div>');
421 form.css({
422 position: 'relative'
423 });
424 form.append(layer);
425 layer.css('opacity', 1);
426 setTimeout(function() {
427 $('.apm-load-message-container').remove();
428 }, 500);
429 }
430 else{
431 $('.apm-opacity-layer-light').css('opacity', 0).empty();
432 setTimeout(function() {
433 $('.apm-opacity-layer-dark').remove();
434 }, 500);
435 }
436 break;
437 default:
438 if (onOff) {
439 var layer = $('<div class="apm-opacity-layer-dark"></div>');
440 form.css({
441 position: 'relative'
442 });
443 form.append(layer);
444 layer.css('opacity', 1);
445 } else {
446 $('.apm-opacity-layer-dark').css('opacity', 0);
447 setTimeout(function() {
448 $('.apm-opacity-layer-dark').remove();
449 }, 500);
450 }
451 break;
452 }
453 }
454
455 function sortDate(rateCount, votesSum, answers, formId) {
456 var form = $("#"+formId),
457 sortable = form.attr('data-res-sort'),
458 widths = [];
459 for (var i = 0; i < rateCount; i++) {
460 var answer = answers[i];
461 widths[i] = {};
462 var width = (answer.votes * 100 / votesSum).toFixed(0);
463 widths[i].width = width;
464 widths[i].index = i;
465 }
466 if (sortable === "ASC") {
467 for (var i = 0; i < rateCount; i++) {
468 for (var j = (i + 1); j < rateCount; j++) {
469 if (Number(widths[i].width) > Number(widths[j].width)) {
470 var temp = widths[i].width;
471 widths[i].width = widths[j].width;
472 widths[j].width = temp;
473 temp = widths[i].index;
474 widths[i].index = widths[j].index;
475 widths[j].index = temp;
476 }
477 }
478 }
479 } else if (sortable === "DESC") {
480 for (var i = 0; i < rateCount; i++) {
481 for (var j = (i + 1); j < rateCount; j++) {
482 if (Number(widths[i].width) < Number(widths[j].width)) {
483 var temp = widths[i].width;
484 widths[i].width = widths[j].width;
485 widths[j].width = temp;
486 temp = widths[i].index;
487 widths[i].index = widths[j].index;
488 widths[j].index = temp;
489 }
490 }
491 }
492 }
493 return widths;
494 }
495
496 var apmIcons = {
497 star: "<i class='ays_poll_far ays_poll_fa-star'></i>",
498 star1: "<i class='ays_poll_fas ays_poll_fa-star'></i>",
499 emoji: [
500 "<i class='ays_poll_far ays_poll_fa-dizzy'></i>",
501 "<i class='ays_poll_far ays_poll_fa-smile'></i>",
502 "<i class='ays_poll_far ays_poll_fa-meh'></i>",
503 "<i class='ays_poll_far ays_poll_fa-frown'></i>",
504 "<i class='ays_poll_far ays_poll_fa-tired'></i>",
505 ],
506 emoji1: [
507 "<i class='ays_poll_fas ays_poll_fa-dizzy'></i>",
508 "<i class='ays_poll_fas ays_poll_fa-smile'></i>",
509 "<i class='ays_poll_fas ays_poll_fa-meh'></i>",
510 "<i class='ays_poll_fas ays_poll_fa-frown'></i>",
511 "<i class='ays_poll_fas ays_poll_fa-tired'></i>",
512 ],
513 hand: [
514 "<i class='ays_poll_far ays_poll_fa-thumbs-up'></i>",
515 "<i class='ays_poll_far ays_poll_fa-thumbs-down'></i>"
516 ],
517 hand1: [
518 "<i class='ays_poll_fas ays_poll_fa-thumbs-up'></i>",
519 "<i class='ays_poll_fas ays_poll_fa-thumbs-down'></i>"
520 ],
521 };
522
523 function showInfoForm($form) {
524 $form.find('.ays_question, .apm-answers').fadeOut(0);
525 $infoForm = $form.find('.apm-info-form');
526 $infoForm.fadeIn();
527 $form.find('.ays_finish_poll').val($infoForm.attr('data-text'));
528 $form.find('.ays_finish_poll').attr('style', 'display:initial !important');
529 $form.find('.ays-see-res-button-show').attr('style', 'display:none');
530 $form.attr('data-info-form', '');
531 }
532
533 var emailValivatePattern = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.\w{2,}$/;
534
535 function voting(btnId , type) {
536 if (typeof btnId == "undefined"){
537 btnId = 0;
538 }
539 var btn;
540 if( btnId === 0 ){
541 btn = $(this);
542 }else{
543 btn = btnId;
544 }
545 var seeRes = btn.attr('data-seeRes'),
546 isLimitation = btn.attr('data-limitation') == 'true';
547 formId = btn.attr('data-form'),
548 form = $("#"+formId),
549 pollId = form.attr('data-id'),
550 isRestart = form.attr('data-restart'),
551 voteURLRedirection = form.attr('data-redirect-check'),
552 voteRedirection = form.attr('data-redirection'),
553 infoForm = form.attr('data-info-form'),
554 resultColorsRgba = form.attr('data-res-rgba'),
555 hideBgImage = form.attr('data-hide-bg-image'),
556 hideBgImageDefColor = form.data('hide-bg-image-def-color'),
557 backgroundGradientCheck = form.data('gradient-check'),
558 backgroundGradientC1 = form.data('gradient-c1'),
559 backgroundGradientC2 = form.data('gradient-c2'),
560 backgroundGradientDir = form.data('gradient-dir'),
561 loadEffectFontSize = form.attr('data-load-gif-font-size');
562 enableTopAnimation = form.attr('data-enable-top-animation');
563 topAnimationScroll = form.attr('data-top-animation-scroll');
564 loadEffectMessage = typeof form.data('loadMessage') != "undefined" ? form.data('loadMessage') : "";
565
566 var pollOptions = JSON.parse(window.atob(window.aysPollOptions[formId]));
567 var pollEnableLn = typeof pollOptions.poll_show_social_ln != "undefined" && pollOptions.poll_show_social_ln.length > 0 && pollOptions.poll_show_social_ln == "on" ? true : false;
568 var pollEnableFb = typeof pollOptions.poll_show_social_fb != "undefined" && pollOptions.poll_show_social_fb.length > 0 && pollOptions.poll_show_social_fb == "on" ? true : false;
569 var pollEnableTr = typeof pollOptions.poll_show_social_tr != "undefined" && pollOptions.poll_show_social_tr.length > 0 && pollOptions.poll_show_social_tr == "on" ? true : false;
570 var pollEnableVk = typeof pollOptions.poll_show_social_vk != "undefined" && pollOptions.poll_show_social_vk.length > 0 && pollOptions.poll_show_social_vk == "on" ? true : false;
571 var pollSocialButtons = {
572 linkedIn : pollEnableLn,
573 faceBook : pollEnableFb,
574 twitter : pollEnableTr,
575 vkontakte : pollEnableVk,
576 };
577
578 if( typeof pollOptions.social_links != "undefined" ) {
579 var pollLinkedInLink = pollOptions.social_links.linkedin_link != "" ? pollOptions.social_links.linkedin_link : "";
580 var pollFacebookInLink = pollOptions.social_links.facebook_link != "" ? pollOptions.social_links.facebook_link : "";
581 var pollTwitterLink = pollOptions.social_links.twitter_link != "" ? pollOptions.social_links.twitter_link : "";
582 var pollVkontakteLink = pollOptions.social_links.vkontakte_link != "" ? pollOptions.social_links.vkontakte_link : "";
583 var pollYoutubeLink = pollOptions.social_links.youtube_link != "" ? pollOptions.social_links.youtube_link : "";
584 var pollTiktokLink = pollOptions.social_links.tiktok_link != "" ? pollOptions.social_links.tiktok_link : "";
585 }
586 var pollSocialLinks = {
587 linkedInLink : pollLinkedInLink,
588 faceBookLink : pollFacebookInLink,
589 twitterLink : pollTwitterLink,
590 vkontakteLink : pollVkontakteLink,
591 youtubeLink : pollYoutubeLink,
592 tiktokLink : pollTiktokLink,
593 }
594
595 var data = form.parent().serializeFormJSON();
596
597 if(form.hasClass('choosing-poll') && !seeRes){
598 var allowMultivoteCheck = $('#'+formId).find('input#ays_poll_multivote_min_count').data("allow");
599 if(allowMultivoteCheck){
600 var numberCheckedAnswers = $('#'+formId).find('input:checkbox:checked').length;
601 var numberAllAnswers = $('#'+formId).find('input:checkbox').length;
602 var minimumVotesCount = $('#'+formId).find('input#ays_poll_multivote_min_count').val();
603 var otherAnswer = $('#'+formId).find('input.ays-poll-new-answer-apply-text');
604 var otherAnswerVal = otherAnswer.val();
605 if(otherAnswer.length > 0 && otherAnswerVal != ""){
606 numberCheckedAnswers++;
607 }
608 if( numberAllAnswers < minimumVotesCount){
609 minimumVotesCount = numberAllAnswers;
610 form.find('.ays-poll-multivote-message').html("Minimum votes count shoulde be "+minimumVotesCount);
611 }
612 if(minimumVotesCount > numberCheckedAnswers){
613 form.find('.ays-poll-multivote-message').show();
614 return false;
615 }
616 }
617 }
618
619 if (infoForm) {
620 if (type == "text" && data.answer == ""){
621 return;
622 }
623
624 if ('answer' in data && !seeRes || (('ays_poll_new_answer' in data) && data.ays_poll_new_answer != '')) {
625 return showInfoForm(form);
626 } else if(!seeRes) {
627 return false;
628 }
629 }
630
631 var valid = true;
632 form.find('.apm-info-form input[name]').each(function () {
633 $(this).removeClass('ays_poll_shake');
634 if ($(this).attr('data-required') == 'true' && $(this).val() == "" && !seeRes) {
635 $(this).addClass('apm-invalid');
636 $(this).addClass('ays_red_border');
637 $(this).addClass('ays_poll_shake');
638 valid = false;
639 }
640 });
641
642 var email_val = $('[check_id="'+formId+'"]');
643 if (email_val.attr('type') !== 'hidden' && email_val.attr('check_id') == formId) {
644 if(email_val.val() != ''){
645 if (!(emailValivatePattern.test(email_val.val())) && !seeRes) {
646 email_val.addClass('ays_red_border');
647 email_val.addClass('ays_poll_shake');
648 valid = false;
649 }else{
650 email_val.addClass('ays_green_border');
651 }
652 }
653 }
654
655 var phoneInput = $(document).find("#"+formId).find('input[name="apm_phone"]');
656 var phoneInputVal = phoneInput.val();
657 if(phoneInputVal != '' && typeof phoneInputVal !== 'undefined'){
658 phoneInput.removeClass('ays_red_border');
659 phoneInput.removeClass('ays_green_border');
660 if (!validatePhoneNumber(phoneInput.get(0))) {
661 if (phoneInput.attr('type') !== 'hidden') {
662 phoneInput.addClass('ays_red_border');
663 phoneInput.addClass('ays_poll_shake');
664 valid = false;
665 }
666 }else{
667 phoneInput.addClass('ays_green_border');
668 }
669 }
670
671 if (!valid && !seeRes) {
672 return false;
673 }
674
675 if ((!('answer' in data) && !seeRes) && (!('ays_poll_new_answer' in data) || (('ays_poll_new_answer' in data) && data.ays_poll_new_answer == ''))) return;
676 var userAnswerValue;
677 if (data.answer) {
678 var userAnswerId = data.answer;
679
680 if ($.isArray(userAnswerId)) {
681 var userEachAnswerValue = [];
682
683 for (var i = 0; i < userAnswerId.length; i++) {
684 var userEachAnswer = form.find('input[name="answer"][value="'+userAnswerId[i]+'"]');
685 var userEachAnswerBox = userEachAnswer.parent();
686 userEachAnswerValue.push(userEachAnswerBox.find('span.ays-poll-each-answer-grid').text());
687 }
688
689 userAnswerValue = userEachAnswerValue;
690
691 if (data.ays_poll_new_answer) {
692 userAnswerValue.push(data.ays_poll_new_answer);
693 }
694 } else {
695 var userAnsweInput = form.find('input[name="answer"][value="'+userAnswerId+'"]');
696 var userAnswerBox = userAnsweInput.parent();
697 userAnswerValue = userAnswerBox.find('span.ays-poll-each-answer-grid').text();
698 }
699 } else if(data.ays_poll_new_answer) {
700 userAnswerValue = data.ays_poll_new_answer;
701 }
702 if (seeRes && ('answer' in data)) delete data['answer'];
703 loadEffect(formId, true , loadEffectFontSize,loadEffectMessage);
704 btn.off();
705 data.action = 'ays_finish_poll';
706 data.poll_id = pollId;
707
708 var endDate = GetFullDateTime();
709 data.end_date = endDate;
710
711 // Mute answer sound button
712 var $this = $(document).find('.ays_finish_poll').data("form");
713 var currentContainer = $(document).find("#"+$this);
714 var soundEls = currentContainer.find('.ays_music_sound');
715 if(soundEls.hasClass("ays_music_sound")){
716 soundEls.removeClass("ays_sound_active");
717 soundEls.addClass("ays_poll_display_none");
718 }
719 if($(document).scrollTop() >= form.offset().top){
720 form.goToPoll(enableTopAnimation,topAnimationScroll);
721 }
722
723 $.ajax({
724 url: poll_maker_ajax_public.ajax_url,
725 dataType: 'json',
726 method:'post',
727 data: data,
728 success: function(res) {
729 form.find(".ays-poll-vote-reason").hide();
730 var answers_sounds = $("#"+formId).parent().find('.ays_poll_ans_sound').get(0);
731 if(answers_sounds){
732 setTimeout(function() {
733 resetPlaying(answers_sounds);
734 }, 1000);
735 }
736 if(hideBgImage == 'true'){
737 if(!backgroundGradientCheck){
738 $(document).find("#"+formId).css("background-image", "none");
739 $(document).find("#"+formId).css("background-color", hideBgImageDefColor);
740 }
741 else{
742 $(document).find("#"+formId).css("background-image", "linear-gradient("+backgroundGradientDir+", "+backgroundGradientC1+", "+backgroundGradientC2+")");
743 }
744 }
745 $("#"+formId+" .ays_poll_cb_and_a").hide();
746 $("#"+formId+" .ays_poll_show_timer").hide();
747 var delay = $('.ays-poll-main').find('div.box-apm[data-delay]').attr('data-delay');
748 delayCountDown(delay);
749 loadEffect(formId, false , loadEffectFontSize,loadEffectMessage);
750 form.parent().next().prop('disabled', false);
751 $('.answer-' + formId).parent().remove(); //for removing apm-answer
752 form.find('.ays_poll_passed_count').remove();
753 form.find('.apm-info-form').remove();
754 var redirectMessage = voteRedirection ? form.find('.redirectionAfterVote').clone(true) : '';
755 $("#"+formId+" .apm-button-box").remove();
756 var hideRes = form.attr('data-res');
757 var resultContainer = $("#"+formId).parent().find('.box-apm');
758
759 var hideResOption = false;
760 var pollSocialLinksHeading = "";
761 var pollSocialButtonsHeading = "";
762 if(typeof res.styles != "undefined"){
763
764 if(typeof res.styles['hide_results'] != "undefined"){
765 hideResOption = res.styles['hide_results'].length > 0 && res.styles['hide_results'] != 1 ? true : false;
766 }
767
768 if(typeof res.styles['poll_social_links_heading'] != "undefined"){
769 pollSocialLinksHeading = typeof res.styles['poll_social_links_heading'] != "undefined" && res.styles['poll_social_links_heading'].length > 0 && res.styles['poll_social_links_heading'] != "" ? res.styles['poll_social_links_heading'] : "";
770 }
771
772 if(typeof res.styles['poll_social_buttons_heading'] != "undefined"){
773 pollSocialButtonsHeading = typeof res.styles['poll_social_buttons_heading'] != "undefined" && res.styles['poll_social_buttons_heading'].length > 0 && res.styles['poll_social_buttons_heading'] != "" ? res.styles['poll_social_buttons_heading'] : "";
774 }
775
776 var result_message = typeof res.styles['result_message'] != "undefined" && res.styles['result_message'] != "" ? res.styles['result_message'] : "";
777
778 if (!isLimitation) {
779 form.find('.apm-title-box.ays_res_mess').html(result_message);
780 }
781
782 var hide_results_text = typeof res.styles['hide_results_text'] != "undefined" && res.styles['hide_results_text'] != "" ? res.styles['hide_results_text'] : "";
783 form.find('.ays-poll-hide-result-box').html(hide_results_text);
784
785 }
786 pollSocialLinks.heading = pollSocialLinksHeading;
787 pollSocialButtons.heading = pollSocialButtonsHeading;
788
789 if( !res.voted_status && !seeRes && hideResOption){
790 var content = '';
791 var limitation_message = (res.styles['limitation_message'] && res.styles['limitation_message'] != '') ? res.styles['limitation_message'] : poll_maker_ajax_public.alreadyVoted;
792 limitation_message = limitation_message.replace(/\\/g, '');
793
794 content += '<div class="ays-poll-vote-message">';
795 content += '<p>'+ limitation_message +'</p>';
796 content += '</div>';
797
798 resultContainer.append(content);
799 }
800
801 if (hideRes != 0) {
802 $("#"+formId+" .ays_question").remove();
803 $("#"+formId+" .hideResults").css("display", "block");
804 }
805 else if ( type == "text" ) {
806 $("#"+formId+" .ays_question").remove();
807 $("#"+formId+" .hideResults").css("display", "block");
808 $("#"+formId+" .ays_res_mess").fadeIn();
809 }
810 else if ( !res.voted_status ) {
811 $("#"+formId+" .hideResults").css("display", "block");
812 }
813 else {
814 form.append('<div class="results-apm" id="pollResultId' +data.poll_id+ '">' + '</div>');
815 var votesSum = 0;
816 var votesMax = 0;
817 var answer;
818 for ( answer in res.answers) {
819 votesSum = Math.abs(res.answers[answer].votes) + votesSum;
820 if (+res.answers[answer].votes > votesMax) {
821 votesMax = +res.answers[answer].votes;
822 }
823 }
824 var answer2 = res.answers;
825
826 // Answer Numbering
827
828 var widths = sortDate(res.answers.length, votesSum, answer2, formId );
829 //show votes count
830 var showvotescounts = true;
831 if (res.styles.show_votes_count == 0) {
832 showvotescounts = false;
833 }
834
835 //show result percent
836 var showrespercent = true;
837 if (res.styles.show_res_percent == 0) {
838 showrespercent = false;
839 }
840
841 var barChartType = typeof res.styles['show_chart_type'] != "undefined" && res.styles['show_chart_type'].length > 0 && res.styles['show_chart_type'] != "" ? res.styles['show_chart_type'] : "default_bar_chart";
842
843 if(barChartType == "google_bar_chart") {
844 var chartHeight = typeof res.styles['show_chart_type_google_height'] != "undefined" && res.styles['show_chart_type_google_height'] != "" ? res.styles['show_chart_type_google_height'] : 400;
845 var aysBarChartData = new Array(['', '']);
846 $("#"+formId+" .ays_res_mess").fadeIn();
847 for (var tox in widths) {
848 var chartRealVotes = +answer2[widths[tox].index].votes;
849 var answerTextVal = answer2[widths[tox].index].answer;
850 //var finalAnswerText = ays_poll_restriction_string( 'words', answerTextVal, 2 );
851 answerTextVal = answerTextVal.replace(/\\/g, '');
852 aysBarChartData.push([
853 answerTextVal,
854 parseInt(chartRealVotes)
855 ]);
856 }
857
858 google.charts.load('current', {packages: ['corechart', 'bar']});
859 google.charts.setOnLoadCallback(drawBasic);
860
861 function drawBasic() {
862 var data = google.visualization.arrayToDataTable(aysBarChartData);
863
864 var groupData = google.visualization.data.group(
865 data,
866 [{column: 0, modifier: function () {return 'total'}, type:'string'}],
867 [{column: 1, aggregation: google.visualization.data.sum, type: 'number'}]
868 );
869
870 var formatPercent = new google.visualization.NumberFormat({
871 pattern: '#%'
872 });
873
874 var formatShort = new google.visualization.NumberFormat({
875 pattern: 'short'
876 });
877
878 var view = new google.visualization.DataView(data);
879 view.setColumns([0, 1, {
880 calc: function (dt, row) {
881 if( groupData.getValue(0, 1) == 0 ){
882 return amount;
883 }
884 var amount = formatShort.formatValue(dt.getValue(row, 1));
885 var percent = formatPercent.formatValue(dt.getValue(row, 1) / groupData.getValue(0, 1));
886 return amount + ' (' + percent + ')';
887 },
888 type: 'string',
889 role: 'annotation'
890 }]);
891 var options = {
892 maxWidth: '100%',
893 height: chartHeight,
894 legend: { position: 'none' },
895 axes: {
896 x: {
897 0: { side: 'bottom'}
898 }
899 },
900 bars: 'horizontal',
901 bar: { groupWidth: "90%" },
902 };
903
904 var chart = new google.visualization.BarChart(document.getElementById('pollResultId' + pollId));
905 google.visualization.events.addListener(chart, 'ready', function () {
906 $.each($('text[text-anchor="end"]'), function (index, label) {
907 var labelText = $(label).text();
908 if ($.isArray(userAnswerValue)) {
909 for (var i = 0; i < userAnswerValue.length; i++) {
910 if (labelText == userAnswerValue[i]) {
911 $(this).css('font-weight', '600');
912 }
913 }
914 } else {
915 if (labelText == userAnswerValue) {
916 $(this).css('font-weight', '600');
917 }
918 }
919 });
920 });
921 chart.draw(view,options);
922 }
923 } else if (barChartType == "default_bar_chart") {
924 if(typeof data.answer == "string") {
925 var dataAnswerArr = data.answer.split(",")
926 }
927 else {
928 dataAnswerArr = data.answer;
929 }
930
931 for (var i = 0; i < res.answers.length; i++) {
932 var rightAnswerCheck = (jQuery.inArray(res.answers[widths[i].index].id, dataAnswerArr) !== -1) ? 'ays_check' : '';
933 var starAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.star1 : apmIcons.star;
934 var emojiAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.emoji1 : apmIcons.emoji;
935 var handAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.hand1 : apmIcons.hand;
936 var answer = res.answers;
937 var percentColor = form.attr('data-percent-color');
938
939 var answerDiv = $('<div class="answer-title flex-apm"></div>'),
940 answerBar = $('<div class="answer-percent" data-percent="'+widths[i].width+'"></div>');
941 if( answerDiv.find('.ayspoll-answers-votes-count-before-voting-width').css('display') == 'none'){
942 answerDiv.find('.ayspoll-answers-votes-count-before-voting-width > span').css('width', '0%');
943 answerDiv.find('.ayspoll-answers-votes-count-before-voting').css('display', 'flex');
944 answerDiv.find('.ayspoll-answers-votes-count-before-voting-width').css('display', 'flex');
945 }
946 answerDiv.find('.ayspoll-answers-votes-count-before-voting').text(res_count);
947 answerDiv.css({
948 'pointer-events': 'none'
949 });
950 setTimeout(function(){
951 answerDiv.find('.ayspoll-answers-votes-count-before-voting-width > span').css('width', notLeloadingRes[answerID].width + '%');
952 }, 300);
953 var userMoreImage;
954 if(res.check_user_pic && res.answers[i].avatar){
955 var userpicsMore = res.answers[widths[i].index].avatar;
956 var userPicsCount = res.check_user_pic_count;
957 var addedMoreImage = "<div class='ays-users-profile-pics'><img src="+res.check_user_pic_url+" width='24' height='24' class='ays-user-image-more' data-answer-id="+res.answers[widths[i].index].id+"></div>";
958 if(userpicsMore.length != 0){
959 userpicsMore = userpicsMore.splice(0 , userPicsCount);
960 userpicsMore.push(addedMoreImage);
961 }
962 userMoreImage = $('<div class="ays-user-count">'+userpicsMore.join(' ')+'</div>');
963 }
964
965 if (resultColorsRgba) {
966 answerBar.attr('style', 'background-color:'+hexToRgba(percentColor, widths[i].width/100)+' !important; border: 1px solid ' + percentColor +' !important;');
967 }
968 else{
969 answerBar.attr('style', 'background-color:'+percentColor);
970 }
971
972 answerBar.css({
973 width: '1%'
974 });
975
976 var answerText = '';
977 var pollShowAnswerImage = false;
978 switch (type) {
979 case 'choose':
980 pollShowAnswerImage = (res.styles.poll_enable_answer_image_after_voting == "on") ? true : false;
981 if(pollShowAnswerImage){
982 var answerImage = typeof answer[widths[i].index].answer_img != "undefined" || typeof (answer[widths[i].index].answer_img) != "" ? answer[widths[i].index].answer_img : "";
983 var answerImageBox = $("<div class='ays-poll-answers-image-box-empty-image'></div>");
984 var answerImageIsEmptyClass = "ays-poll-answers-box-no-image";
985 if(answerImage != ""){
986 answerImageIsEmptyClass = "ays-poll-answers-box";
987 answerImageBox = $("<div class='ays-poll-answers-image-box'><img src="+answerImage+" class='ays-poll-answers-current-image'></div>");
988 }
989 var answerTextAndPercent = $("<div class='ays-poll-answer-text-and-percent-box'></div>");
990 var answerMainDiv = $('<div class='+answerImageIsEmptyClass+'></div>');
991 }
992
993 answerText = $('<span class="answer-text '+rightAnswerCheck+'"></span>');
994 var htmlstr = stripSlashes(answer[widths[i].index].answer);
995
996 answerText.html(htmlstr);
997 break;
998 case 'rate':
999 switch (res.view_type) {
1000 case 'emoji':
1001 answerText = emojiAnswerCheck[res.answers.length / 2 + 1.5 - widths[i].index];
1002 break;
1003
1004 case 'star':
1005 for (var j = 0; j <= widths[i].index; j++) {
1006 answerText += starAnswerCheck;
1007 }
1008 break;
1009 }
1010 answerText = $('<span class="answer-text">'+answerText+'</span>');
1011 break;
1012 case 'vote':
1013 switch (res.view_type) {
1014 case 'hand':
1015 answerText = handAnswerCheck[widths[i].index];
1016 break;
1017
1018 case 'emoji':
1019 answerText = emojiAnswerCheck[2 * widths[i].index + 1];
1020 break;
1021 }
1022 answerText = $('<span class="answer-text">'+answerText+'</span>');
1023 break;
1024 }
1025
1026 var answerVotes = $('<span class="answer-votes"></span>');
1027 if(showvotescounts){
1028 answerVotes.text(answer[widths[i].index].votes);
1029 }
1030 if(res.check_admin_approval){
1031 if(type == 'choose'){
1032 answerDiv.append("<span class='ays_grid_answer_span' >"+poll_maker_ajax_public.thank_message+"</span>").appendTo("#"+formId+" .results-apm");
1033 break;
1034 }
1035 }
1036
1037 if(!pollShowAnswerImage){
1038 answerDiv.append(answerText).append(answerVotes).appendTo("#"+formId+" .results-apm");
1039 $("#"+formId+" .results-apm").append(userMoreImage).append(answerBar);
1040 }
1041 else{
1042 answerMainDiv.appendTo("#"+formId+" .results-apm");
1043 answerImageBox.appendTo(answerMainDiv);
1044 answerTextAndPercent.appendTo(answerMainDiv);
1045 answerDiv.append(answerText).append(answerVotes).appendTo(answerTextAndPercent);
1046
1047 if(typeof userMoreImage != "undefined"){
1048 answerTextAndPercent.append(userMoreImage);
1049 }
1050
1051 answerBar.appendTo(answerTextAndPercent);
1052 }
1053
1054 $("#"+formId+" .ays_res_mess").fadeIn();
1055 $('.redirectionAfterVote').show();
1056
1057 }
1058
1059 setTimeout(function() {
1060 form.find('.answer-percent').each(function () {
1061 var percent = $(this).attr('data-percent');
1062
1063 $(this).css({
1064 width: (percent || 1) + '%'
1065 });
1066
1067 if (showrespercent) {
1068 var aaa = $(this);
1069 setTimeout(function() {
1070 aaa.text(percent > 5 ? percent + '%' : '');
1071 }, 200);
1072 }
1073 });
1074 }, 100);
1075 }
1076 }
1077
1078 // Remove disable from next button for category polls start
1079 form.parents('.ays_poll_category-container').find('.ays-poll-next-btn').prop('disabled', false);
1080 var vvv = form.parents('.ays_poll_category-container').attr("data-var");
1081 window['showNext' + vvv] = true;
1082 if (typeof(window['catIndex' + vvv]) != 'undefined') {
1083 if (typeof(window['pollsGlobalPool'+vvv]) != 'undefined') {
1084 if (window['catIndex' + vvv] == window['pollsGlobalPool' + vvv].length - 1) {
1085 form.parents('.ays_poll_category-container').find('.ays-poll-next-btn').prop('disabled', true);
1086 }
1087 }
1088
1089 if (window['catIndex' + vvv] == 0 && form.parents('.ays_poll_category-container').find('.results-apm').length > 0) {
1090 form.parents('.ays_poll_category-container').find('.ays-poll-previous-btn').prop('disabled', true);
1091 }
1092 }
1093 // Remove disable from next button for category polls end
1094
1095 if (form.attr('data-show-social') == 1) {
1096 socialBtnAdd(formId, pollSocialButtons);
1097 }
1098 if (form.attr('data-enable-social-links') == 1) {
1099 socialLinksAdd(formId, pollSocialLinks);
1100 }
1101 if (voteURLRedirection == 1) {
1102 var url = form.attr('data-url-href');
1103 var answerRedirectDelay = +form.attr('data-delay');
1104 form.append(redirectMessage);
1105 if (url !== '') {
1106 setTimeout(function() {
1107 location.href = url;
1108 } , answerRedirectDelay * 1000);
1109 }else{
1110 $('.redirectionAfterVote').hide();
1111 }
1112 }else{
1113 voteURLRedirection = false;
1114 }
1115 if (voteRedirection == 1 && voteURLRedirection == false) {
1116 var url = form.attr('data-href');
1117 var delay = +form.attr('data-delay');
1118 form.append(redirectMessage);
1119 setTimeout(function() {
1120 location.href = url;
1121 }, delay * 1000);
1122 }
1123 if (isRestart == 'true') {
1124 showRestart(formId);
1125 }
1126
1127 if(res.check_user_pic){
1128 var checkModal = $(document).find(".ays-poll-avatars-modal-main");
1129 if(checkModal.length < 1){
1130 var avatarsModal = "<div class='ays-poll-avatars-modal-main'>" +
1131 "<div class='ays-poll-avatars-modal-content'>" +
1132 "<div class='ays-poll-avatars-preloader'>" +
1133 "<img class='ays-poll-avatar-pic-loader' src="+res.check_user_pic_loader+">" +
1134 "</div>" +
1135 "<div class='ays-poll-avatars-modal-header'>" +
1136 "<span class='ays-close' id='ays-poll-close-avatars-modal'>&times;</span>" +
1137 "<span style='font-weight: bold;'></span>" +
1138 "</div>" +
1139 "<div class='ays-poll-modal-body' id='ays-poll-avatars-body'></div>" +
1140 "</div>" +
1141 "</div>";
1142 $(document.body).append(avatarsModal);
1143 }
1144 }
1145 },
1146 error: function () {
1147 loadEffect(formId, false , loadEffectFontSize,loadEffectMessage);
1148 $(".user-form-"+formId).fadeOut();
1149 form.parent().next().prop('disabled', false);
1150 $('.answer-' + formId).parent().parent().find('.apm-button-box').remove();
1151 $('.answer-' + formId).remove();
1152 btn.remove();
1153 $("#"+formId+" .ays_question").text("Something went wrong. Please reload page.");
1154 }
1155 });
1156
1157 }
1158
1159 function showRestart(formId) {
1160 var restartBtn = $('<div class="apm-button-box"><input type="button" class="btn ays-poll-btn btn-restart" onclick="location.reload()" value="' + poll_maker_ajax_public.restart + '"></div>');
1161 $("#"+formId).append(restartBtn);
1162 }
1163
1164 if ($(document).find('#ays_res_without_see').length > 0) {
1165
1166 let btn = $(document).find('#ays_res_without_see'),
1167 type = $(document).find('#ays_res_without_see').attr('data-polltype');
1168
1169 voting( btn, type );
1170 }
1171
1172 $(document).on('click', '.ays-poll-btn.choosing-btn', function () {
1173 voting( $(this), 'choose' );
1174 });
1175 $(document).on('click', '.ays-poll-btn.rating-btn', function () {
1176 voting( $(this), 'rate' );
1177 });
1178 $(document).on('click', '.ays-poll-btn.voting-btn', function () {
1179 voting( $(this), 'vote' );
1180 });
1181 $(document).on('click', '.ays-poll-btn.text-btn', function () {
1182 voting( $(this), 'text' );
1183 });
1184
1185 $(document).on('change', '.apm-answers-without-submit input', function () {
1186 if ($(this).parent().hasClass('apm-rating')) {
1187 voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'rate');
1188 } else if ($(this).parent().hasClass('apm-voting')) {
1189 voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'vote');
1190 } else if ($(this).parent().hasClass('apm-choosing')) {
1191 voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'choose');
1192 }
1193 })
1194
1195 function delayCountDown(sec) {
1196 delaySec = parseInt(sec);
1197 var intervalSec = setInterval(function() {
1198 if (delaySec > 0) {
1199 delaySec--;
1200 $('.ays-poll-main').find('p.redirectionAfterVote span').text(delaySec);
1201 } else {
1202 clearInterval(intervalSec);
1203 }
1204 }, 1000);
1205 }
1206
1207 function resetPlaying(audelems) {
1208 audelems.pause();
1209 audelems.currentTime = 0;
1210 }
1211
1212 function validatePhoneNumber(input) {
1213 var phoneno = /^[+ 0-9-]+$/;
1214 if (typeof input !== 'undefined') {
1215 if (input.value.match(phoneno)) {
1216 return true;
1217 } else {
1218 return false;
1219 }
1220
1221 }
1222 }
1223
1224 /**
1225 * @return {string}
1226 */
1227 function GetFullDateTime(){
1228 var now = new Date();
1229 return [[now.getFullYear(), AddZero(now.getMonth() + 1), AddZero(now.getDate())].join("-"), [AddZero(now.getHours()), AddZero(now.getMinutes()), AddZero(now.getSeconds())].join(":")].join(" ");
1230 }
1231
1232 /**
1233 * @return {string}
1234 */
1235 function AddZero(num) {
1236 return (num >= 0 && num < 10) ? "0" + num : num + "";
1237 }
1238
1239 function hexToRgba(hex, alfa) {
1240 var c;
1241 if (alfa == null) {
1242 alfa = 1;
1243 }
1244 if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
1245 c= hex.substring(1).split('');
1246 if(c.length== 3){
1247 c= [c[0], c[0], c[1], c[1], c[2], c[2]];
1248 }
1249 c= '0x'+c.join('');
1250 return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+alfa+')';
1251 }
1252 }
1253
1254 function ays_poll_restriction_string( type, x, length ){
1255 var tval = '';
1256 if( x.length > 0 && x != null){
1257 tval = x.trim();
1258 }
1259 switch ( type ) {
1260 case 'characters':
1261 break;
1262 case 'words':
1263 if(tval.length > 0 && tval != null && tval.length != ''){
1264 var wordsLength = tval.match(/\S+/g).length;
1265 if (wordsLength > length) {
1266 var trimmed = tval.split(/\s+/, length).join(" ");
1267 x = trimmed + '...';
1268 }
1269 }
1270 break;
1271 default:
1272 break;
1273 }
1274 return x;
1275 }
1276
1277 // Avatars modal start
1278
1279 // Open users avatars modal
1280 $(document).on('click', '.ays-user-image-more', function(e){
1281 $(document).find('div.ays-poll-avatars-preloader').css('display', 'flex');
1282 $(document).find('.ays-poll-avatars-modal-main').aysModal('show');
1283 var $this = $(this);
1284 var answer_id = $(this).data('answerId');
1285 var action = 'ays_poll_get_current_answer_users_pics';
1286 data = {};
1287 data.action = action;
1288 data.answer_id = answer_id;
1289 $.ajax({
1290 url: poll_maker_ajax_public.ajax_url,
1291 dataType: 'json',
1292 method:'post',
1293 data: data,
1294 success: function(response){
1295 for(var avatars of response){
1296 $('div#ays-poll-avatars-body').append(avatars);
1297
1298 }
1299 var answerTitle = $this.parents(".ays-user-count").prev().find(".answer-text").html();
1300 $(document).find('div.ays-poll-avatars-preloader').css('display', 'none');
1301 $(document).find('div.ays-poll-avatars-modal-header span:nth-child(2)').append(answerTitle);
1302 }
1303 });
1304 });
1305
1306 // Close users avatars modal
1307 $(document).on('click', '.ays-close', function () {
1308 $(document).find('.ays-poll-avatars-modal-main').aysModal('hide');
1309 setTimeout(function(){
1310 $(document).find('div#ays-poll-avatars-body').html('');
1311 $(document).find('div.ays-poll-avatars-modal-header span:nth-child(2)').html('');
1312 }, 250);
1313 });
1314
1315 // Cldoe users avatars modal with ESC button
1316 $(document).on("keydown", function(e){
1317 if(e.keyCode === 27){
1318 $(document).find('.ays-close').trigger('click');
1319 return false;
1320 }
1321 });
1322
1323 if(typeof idChecker !== 'undefined'){
1324 var checkResShow = $(document).find("#"+idChecker);
1325 if(checkResShow.data("loadMethod")){
1326 var checkModal = $(document).find(".ays-poll-avatars-modal-main");
1327 if(checkModal.length < 1){
1328 var avatarsModal = "<div class='ays-poll-avatars-modal-main'>" +
1329 "<div class='ays-poll-avatars-modal-content'>" +
1330 "<div class='ays-poll-avatars-preloader'>" +
1331 "<img class='ays-poll-avatar-pic-loader' src="+resLoader+">" +
1332 "</div>" +
1333 "<div class='ays-poll-avatars-modal-header'>" +
1334 "<span class='ays-close' id='ays-poll-close-avatars-modal'>&times;</span>" +
1335 "<span style='font-weight: bold;'></span>" +
1336 "</div>" +
1337 "<div class='ays-poll-modal-body' id='ays-poll-avatars-body'></div>" +
1338 "</div>" +
1339 "</div>";
1340 $(document.body).append(avatarsModal);
1341 }
1342 }
1343 }
1344 // Avatars modal end
1345
1346 })(jQuery);