PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 5.6.3
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v5.6.3
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 5.6.6 All 153 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 5.6.3, at public/js/poll-maker-public-ajax.js

1,324 lines 72.1 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 $.ajax({
69 url: poll_maker_ajax_public.ajax_url,
70 method: 'post',
71 dataType: 'json',
72 data: userData,
73 success: function (response) {
74 if(response !== null){
75 infoForm.find("input[name='apm_name']").val(response.data.display_name);
76 infoForm.find("input[name='apm_email']").val(response.data.user_email);
77 }
78 }
79 });
80 }
81 })
82
83 function socialBtnAdd(formId, buttons) {
84 var socialDiv = $("<div class='apm-social-btn'></div>");
85 if(buttons.heading != ""){
86 socialDiv.append("<div class='ays-survey-social-shares-heading'>"+
87 buttons.heading
88 +"</div>");
89 }
90 if(buttons.faceBook){
91 socialDiv.append("<a class='fb-share-button ays-share-btn ays-share-btn-branded ays-share-btn-facebook'"+
92 "title='Share on Facebook'>"+
93 "<span class='ays-share-btn-text'>Facebook</span>"+
94 "</a>");
95 }
96 if(buttons.twitter){
97 socialDiv.append("<a class='twt-share-button ays-share-btn ays-share-btn-branded ays-share-btn-twitter'"+
98 "title='Share on Twitter'>"+
99 "<span class='ays-share-btn-text'>Twitter</span>"+
100 "</a>");
101 }
102 if(buttons.linkedIn){
103 socialDiv.append("<a class='linkedin-share-button ays-share-btn ays-share-btn-branded ays-share-btn-linkedin'"+
104 "title='Share on LinkedIn'>"+
105 "<span class='ays-share-btn-text'>LinkedIn</span>"+
106 "</a>");
107 }
108 if(buttons.vkontakte){
109 socialDiv.append("<a class='vkontakte-share-button ays-share-btn ays-share-btn-branded ays-share-btn-vkontakte'"+
110 "title='Share on VKontakte'>"+
111 "<span class='ays-survey-share-btn-icon'></span>"+
112 "<span class='ays-share-btn-text'>VKontakte</span>"+
113 "</a>");
114 }
115 $("#"+formId).append(socialDiv);
116 $(document).on('click', '.fb-share-button', function (e) {
117 window.open('https://www.facebook.com/sharer/sharer.php?u=' + window.location.href,
118 'facebook-share-dialog',
119 'width=650,height=450'
120 );
121 return false;
122 })
123 $(document).on('click', '.twt-share-button', function (e) {
124 window.open('https://twitter.com/intent/tweet?url=' + window.location.href,
125 'twitter-share-dialog',
126 'width=650,height=450'
127 );
128 return false;
129 })
130 $(document).on('click', '.linkedin-share-button', function (e) {
131 window.open('https://www.linkedin.com/shareArticle?mini=true&url=' + window.location.href,
132 'linkedin-share-dialog',
133 'width=650,height=450'
134 );
135 return false;
136 })
137 $(document).on('click', '.vkontakte-share-button', function (e) {
138 window.open('https://vk.com/share.php?url=' + window.location.href,
139 'vkontakte-share-dialog',
140 'width=650,height=450'
141 );
142 return false;
143 })
144 setTimeout(function() {
145 $("#"+formId+" .apm-social-btn").css('opacity', '1');
146 }, 1000);
147 }
148
149 function socialLinksAdd(formId, buttons) {
150 var socialLinksDiv = $("<div class='apm-social-btn'></div>");
151 if(buttons.heading != ""){
152 socialLinksDiv.append("<div class='ays-survey-social-shares-heading'>"+
153 buttons.heading
154 +"</div>");
155 }
156 if(buttons.faceBookLink != ''){
157 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-facebook'"+
158 "title='Facebook Link' target='_blank' href=" + buttons.faceBookLink + ">"+
159 "<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>"+
160 "</a>");
161 }
162 if(buttons.twitterLink != ''){
163 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-twitter'"+
164 "title='Twitter Link' target='_blank' href=" + buttons.twitterLink + ">"+
165 "<div class='ays-poll-link-icon'><svg fill='#fff' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48' width='16px' height='16px'><path d='M44.719,10.305C44.424,10,43.97,9.913,43.583,10.091l-0.164,0.075c-0.139,0.064-0.278,0.128-0.418,0.191 c0.407-0.649,0.73-1.343,0.953-2.061c0.124-0.396-0.011-0.829-0.339-1.085c-0.328-0.256-0.78-0.283-1.135-0.066 c-1.141,0.693-2.237,1.192-3.37,1.54C37.4,7.026,35.071,6,32.5,6c-5.247,0-9.5,4.253-9.5,9.5c0,0.005,0,0.203,0,0.5l-0.999-0.08 c-9.723-1.15-12.491-7.69-12.606-7.972c-0.186-0.47-0.596-0.813-1.091-0.916C7.81,6.927,7.297,7.082,6.939,7.439 C6.741,7.638,5,9.48,5,13c0,2.508,1.118,4.542,2.565,6.124c-0.674-0.411-1.067-0.744-1.077-0.753 c-0.461-0.402-1.121-0.486-1.669-0.208c-0.546,0.279-0.868,0.862-0.813,1.473c0.019,0.211,0.445,4.213,5.068,7.235l-0.843,0.153 c-0.511,0.093-0.938,0.444-1.128,0.928C6.914,28.437,6.988,28.984,7.3,29.4c0.105,0.141,2.058,2.68,6.299,4.14 C11.334,34.295,8.222,35,4.5,35c-0.588,0-1.123,0.344-1.366,0.88c-0.244,0.536-0.151,1.165,0.237,1.607 C3.532,37.672,7.435,42,17.5,42C34.213,42,42,26.485,42,16v-0.5c0-0.148-0.016-0.293-0.022-0.439 c2.092-2.022,2.879-3.539,2.917-3.614C45.084,11.067,45.014,10.609,44.719,10.305z'/></svg></div>"+
166 "</a>");
167 }
168 if(buttons.linkedInLink != ''){
169 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-linkedin'"+
170 "title='LinkedIn Link' target='_blank' href=" + buttons.linkedInLink + ">"+
171 "<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>"+
172 "</a>");
173 }
174 if(buttons.vkontakteLink != ''){
175 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-share-btn-vkontakte'"+
176 "title='VKontakte Link' target='_blank' href=" + buttons.vkontakteLink + ">"+
177 "<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>"+
178 "</a>");
179 }
180 if(buttons.youtubeLink != ''){
181 socialLinksDiv.append("<a class='ays-share-btn ays-share-btn-branded ays-poll-share-btn-youtube'"+
182 "title='Youtube Link' target='_blank' href=" + buttons.youtubeLink + ">"+
183 "<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>"+
184 "</a>");
185 }
186 $("#"+formId).append(socialLinksDiv);
187
188 setTimeout(function() {
189 $("#"+formId+" .apm-social-btn").css('opacity', '1');
190 }, 1000);
191 }
192
193 function loadEffect(formId, onOff , fontSize,message) {
194 var loadFontSize = fontSize.length > 0 ? fontSize+"px" : '100%';
195 var form = $("#"+formId),
196 effect = form.attr('data-loading');
197 switch (effect) {
198 case 'blur':
199 form.css({
200 WebkitFilter: onOff ? 'blur(5px)' : 'unset',
201 filter: onOff ? 'blur(5px)' : 'unset',
202 })
203 break;
204 case 'load_gif':
205 if (onOff) {
206 var loadSvg = '';
207 switch (form.attr('data-load-gif')) {
208 case 'plg_1':
209 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">'+
210 '<rect x="0" y="0" width="4" height="10" fill="#333">'+
211 '<animateTransform attributeType="xml"'+
212 'attributeName="transform" type="translate"'+
213 'values="0 0; 0 20; 0 0"'+
214 'begin="0" dur="0.8s" repeatCount="indefinite" />'+
215 '</rect>'+
216 '<rect x="10" y="0" width="4" height="10" fill="#333">'+
217 '<animateTransform attributeType="xml"'+
218 'attributeName="transform" type="translate"'+
219 'values="0 0; 0 20; 0 0"'+
220 'begin="0.2s" dur="0.8s" repeatCount="indefinite" />'+
221 '</rect>'+
222 '<rect x="20" y="0" width="4" height="10" fill="#333">'+
223 '<animateTransform attributeType="xml"'+
224 'attributeName="transform" type="translate"'+
225 'values="0 0; 0 20; 0 0"'+
226 'begin="0.4s" dur="0.8s" repeatCount="indefinite" />'+
227 '</rect>'+
228 '</svg>';
229 break;
230 case 'plg_2':
231 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">'+
232 '<rect x="0" y="10" width="4" height="10" fill="#333" opacity="0.2">'+
233 '<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0s" dur="0.7s" repeatCount="indefinite" />'+
234 '<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0s" dur="0.7s" repeatCount="indefinite" />'+
235 '<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0s" dur="0.7s" repeatCount="indefinite" />'+
236 '</rect>'+
237 '<rect x="8" y="10" width="4" height="10" fill="#333" opacity="0.2">'+
238 '<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+
239 '<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+
240 '<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.15s" dur="0.7s" repeatCount="indefinite" />'+
241 '</rect>'+
242 '<rect x="16" y="10" width="4" height="10" fill="#333" opacity="0.2">'+
243 '<animate attributeName="opacity" attributeType="XML" values="0.2; 1; .2" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+
244 '<animate attributeName="height" attributeType="XML" values="10; 20; 10" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+
245 '<animate attributeName="y" attributeType="XML" values="10; 5; 10" begin="0.3s" dur="0.7s" repeatCount="indefinite" />'+
246 '</rect>'+
247 '</svg>';
248 break;
249 case 'plg_3':
250 loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 105 105" xmlns="http://www.w3.org/2000/svg" fill="#000">'+
251 '<circle cx="12.5" cy="12.5" r="12.5">'+
252 '<animate attributeName="fill-opacity"'+
253 'begin="0s" dur="0.9s"'+
254 'values="1;.2;1" calcMode="linear"'+
255 'repeatCount="indefinite" />'+
256 '</circle>'+
257 '<circle cx="12.5" cy="52.5" r="12.5" fill-opacity=".5">'+
258 '<animate attributeName="fill-opacity"'+
259 'begin="100ms" dur="0.9s"'+
260 'values="1;.2;1" calcMode="linear"'+
261 'repeatCount="indefinite" />'+
262 '</circle>'+
263 '<circle cx="52.5" cy="12.5" r="12.5">'+
264 '<animate attributeName="fill-opacity"'+
265 'begin="300ms" dur="0.9s"'+
266 'values="1;.2;1" calcMode="linear"'+
267 'repeatCount="indefinite" />'+
268 '</circle>'+
269 '<circle cx="52.5" cy="52.5" r="12.5">'+
270 '<animate attributeName="fill-opacity"'+
271 'begin="600ms" dur="0.9s"'+
272 'values="1;.2;1" calcMode="linear"'+
273 'repeatCount="indefinite" />'+
274 '</circle>'+
275 '<circle cx="92.5" cy="12.5" r="12.5">'+
276 '<animate attributeName="fill-opacity"'+
277 'begin="800ms" dur="0.9s"'+
278 'values="1;.2;1" calcMode="linear"'+
279 'repeatCount="indefinite" />'+
280 '</circle>'+
281 '<circle cx="92.5" cy="52.5" r="12.5">'+
282 '<animate attributeName="fill-opacity"'+
283 'begin="400ms" dur="0.9s"'+
284 'values="1;.2;1" calcMode="linear"'+
285 'repeatCount="indefinite" />'+
286 '</circle>'+
287 '<circle cx="12.5" cy="92.5" r="12.5">'+
288 '<animate attributeName="fill-opacity"'+
289 'begin="700ms" dur="0.9s"'+
290 'values="1;.2;1" calcMode="linear"'+
291 'repeatCount="indefinite" />'+
292 '</circle>'+
293 '<circle cx="52.5" cy="92.5" r="12.5">'+
294 '<animate attributeName="fill-opacity"'+
295 'begin="500ms" dur="0.9s"'+
296 'values="1;.2;1" calcMode="linear"'+
297 'repeatCount="indefinite" />'+
298 '</circle>'+
299 '<circle cx="92.5" cy="92.5" r="12.5">'+
300 '<animate attributeName="fill-opacity"'+
301 'begin="200ms" dur="0.9s"'+
302 'values="1;.2;1" calcMode="linear"'+
303 'repeatCount="indefinite" />'+
304 '</circle>'+
305 '</svg>';
306 break;
307 case 'plg_4':
308 loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 57 57" xmlns="http://www.w3.org/2000/svg" stroke="#000">'+
309 '<g fill="none" fill-rule="evenodd">'+
310 '<g transform="translate(1 1)" stroke-width="2">'+
311 '<circle cx="5" cy="50" r="5">'+
312 '<animate attributeName="cy"'+
313 'begin="0s" dur="2.2s"'+
314 'values="50;5;50;50"'+
315 'calcMode="linear"'+
316 'repeatCount="indefinite" />'+
317 '<animate attributeName="cx"'+
318 'begin="0s" dur="2.2s"'+
319 'values="5;27;49;5"'+
320 'calcMode="linear"'+
321 'repeatCount="indefinite" />'+
322 '</circle>'+
323 '<circle cx="27" cy="5" r="5">'+
324 '<animate attributeName="cy"'+
325 'begin="0s" dur="2.2s"'+
326 'from="5" to="5"'+
327 'values="5;50;50;5"'+
328 'calcMode="linear"'+
329 'repeatCount="indefinite" />'+
330 '<animate attributeName="cx"'+
331 'begin="0s" dur="2.2s"'+
332 'from="27" to="27"'+
333 'values="27;49;5;27"'+
334 'calcMode="linear"'+
335 'repeatCount="indefinite" />'+
336 '</circle>'+
337 '<circle cx="49" cy="50" r="5">'+
338 '<animate attributeName="cy"'+
339 'begin="0s" dur="2.2s"'+
340 'values="50;50;5;50"'+
341 'calcMode="linear"'+
342 'repeatCount="indefinite" />'+
343 '<animate attributeName="cx"'+
344 'from="49" to="49"'+
345 'begin="0s" dur="2.2s"'+
346 'values="49;5;27;49"'+
347 'calcMode="linear"'+
348 'repeatCount="indefinite" />'+
349 '</circle>'+
350 '</g>'+
351 '</g>'+
352 '</svg>';
353 break;
354 case 'plg_5':
355 loadSvg = '<svg width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 135 140" xmlns="http://www.w3.org/2000/svg" stroke="#000">'+
356 '<rect y="10" width="15" height="120" rx="6">'+
357 '<animate attributeName="height" begin="0.5s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite" />'+
358 '<animate attributeName="y" begin="0.5s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite" />'+
359 '</rect>'+
360 '<rect x="30" y="10" width="15" height="120" rx="6">'+
361 '<animate attributeName="height" begin="0.25s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+
362 '<animate attributeName="y" begin="0.25s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+
363 '</rect>'+
364 ' <rect x="60" width="15" height="140" rx="6">'+
365 '<animate attributeName="height" begin="0s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+
366 '<animate attributeName="y" begin="0s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+
367 '</rect>'+
368 '<rect x="90" y="10" width="15" height="120" rx="6">'+
369 '<animate attributeName="height" begin="0.25s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+
370 '<animate attributeName="y" begin="0.25s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+
371 '</rect>'+
372 '<rect x="120" y="10" width="15" height="120" rx="6">'+
373 '<animate attributeName="height" begin="0.5s" dur="1s" values="120;110;100;90;80;70;60;50;40;140;120" calcMode="linear" repeatCount="indefinite"/>'+
374 '<animate attributeName="y" begin="0.5s" dur="1s" values="10;15;20;25;30;35;40;45;50;0;10" calcMode="linear" repeatCount="indefinite"/>'+
375 '</rect>'+
376 '</svg>';
377 break;
378 default:
379 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"'+
380 'width='+loadFontSize+' height='+loadFontSize+' viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">'+
381 '<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">'+
382 '<animateTransform attributeType="xml"'+
383 'attributeName="transform"'+
384 'type="rotate"'+
385 'from="0 25 25"'+
386 'to="360 25 25"'+
387 'dur="0.6s"'+
388 'repeatCount="indefinite"/>'+
389 '</path>'+
390 '</svg>';
391 }
392 var layer = $('<div class="apm-opacity-layer-light" style="margin-top: 0">'+
393 '<div class="apm-loading-gif">'+
394 '<div class="apm-loader loader--style3">'+
395 loadSvg+
396 '</div>'+
397 '</div>'+
398 '</div>');
399 form.css({
400 position: 'relative'
401 });
402 form.append(layer);
403 layer.css('opacity', 1);
404 } else {
405 $('.apm-opacity-layer-light').css('opacity', 0).empty();
406 setTimeout(function() {
407 $('.apm-opacity-layer-light').remove();
408 }, 500);
409 }
410 break;
411 case 'message':
412 if (onOff) {
413 var layer = $('<div class="apm-opacity-layer-light apm-load-message-container"><span>'+message+'</span></div>');
414 form.css({
415 position: 'relative'
416 });
417 form.append(layer);
418 layer.css('opacity', 1);
419 setTimeout(function() {
420 $('.apm-load-message-container').remove();
421 }, 500);
422 }
423 else{
424 $('.apm-opacity-layer-light').css('opacity', 0).empty();
425 setTimeout(function() {
426 $('.apm-opacity-layer-dark').remove();
427 }, 500);
428 }
429 break;
430 default:
431 if (onOff) {
432 var layer = $('<div class="apm-opacity-layer-dark"></div>');
433 form.css({
434 position: 'relative'
435 });
436 form.append(layer);
437 layer.css('opacity', 1);
438 } else {
439 $('.apm-opacity-layer-dark').css('opacity', 0);
440 setTimeout(function() {
441 $('.apm-opacity-layer-dark').remove();
442 }, 500);
443 }
444 break;
445 }
446 }
447
448 function sortDate(rateCount, votesSum, answers, formId) {
449 var form = $("#"+formId),
450 sortable = form.attr('data-res-sort'),
451 widths = [];
452 for (var i = 0; i < rateCount; i++) {
453 var answer = answers[i];
454 widths[i] = {};
455 var width = (answer.votes * 100 / votesSum).toFixed(0);
456 widths[i].width = width;
457 widths[i].index = i;
458 }
459 if (sortable === "ASC") {
460 for (var i = 0; i < rateCount; i++) {
461 for (var j = (i + 1); j < rateCount; j++) {
462 if (Number(widths[i].width) > Number(widths[j].width)) {
463 var temp = widths[i].width;
464 widths[i].width = widths[j].width;
465 widths[j].width = temp;
466 temp = widths[i].index;
467 widths[i].index = widths[j].index;
468 widths[j].index = temp;
469 }
470 }
471 }
472 } else if (sortable === "DESC") {
473 for (var i = 0; i < rateCount; i++) {
474 for (var j = (i + 1); j < rateCount; j++) {
475 if (Number(widths[i].width) < Number(widths[j].width)) {
476 var temp = widths[i].width;
477 widths[i].width = widths[j].width;
478 widths[j].width = temp;
479 temp = widths[i].index;
480 widths[i].index = widths[j].index;
481 widths[j].index = temp;
482 }
483 }
484 }
485 }
486 return widths;
487 }
488
489 var apmIcons = {
490 star: "<i class='ays_poll_far ays_poll_fa-star'></i>",
491 star1: "<i class='ays_poll_fas ays_poll_fa-star'></i>",
492 emoji: [
493 "<i class='ays_poll_far ays_poll_fa-dizzy'></i>",
494 "<i class='ays_poll_far ays_poll_fa-smile'></i>",
495 "<i class='ays_poll_far ays_poll_fa-meh'></i>",
496 "<i class='ays_poll_far ays_poll_fa-frown'></i>",
497 "<i class='ays_poll_far ays_poll_fa-tired'></i>",
498 ],
499 emoji1: [
500 "<i class='ays_poll_fas ays_poll_fa-dizzy'></i>",
501 "<i class='ays_poll_fas ays_poll_fa-smile'></i>",
502 "<i class='ays_poll_fas ays_poll_fa-meh'></i>",
503 "<i class='ays_poll_fas ays_poll_fa-frown'></i>",
504 "<i class='ays_poll_fas ays_poll_fa-tired'></i>",
505 ],
506 hand: [
507 "<i class='ays_poll_far ays_poll_fa-thumbs-up'></i>",
508 "<i class='ays_poll_far ays_poll_fa-thumbs-down'></i>"
509 ],
510 hand1: [
511 "<i class='ays_poll_fas ays_poll_fa-thumbs-up'></i>",
512 "<i class='ays_poll_fas ays_poll_fa-thumbs-down'></i>"
513 ],
514 };
515
516 function showInfoForm($form) {
517 $form.find('.ays_question, .apm-answers').fadeOut(0);
518 $infoForm = $form.find('.apm-info-form');
519 $infoForm.fadeIn();
520 $form.find('.ays_finish_poll').val($infoForm.attr('data-text'));
521 $form.find('.ays_finish_poll').attr('style', 'display:initial !important');
522 $form.find('.ays-see-res-button-show').attr('style', 'display:none');
523 $form.attr('data-info-form', '');
524 }
525
526 var emailValivatePattern = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.\w{2,}$/;
527
528 function voting(btnId , type) {
529 if (typeof btnId == "undefined"){
530 btnId = 0;
531 }
532 var btn;
533 if( btnId === 0 ){
534 btn = $(this);
535 }else{
536 btn = btnId;
537 }
538 var seeRes = btn.attr('data-seeRes'),
539 isLimitation = btn.attr('data-limitation') == 'true';
540 formId = btn.attr('data-form'),
541 form = $("#"+formId),
542 pollId = form.attr('data-id'),
543 isRestart = form.attr('data-restart'),
544 voteURLRedirection = form.attr('data-redirect-check'),
545 voteRedirection = form.attr('data-redirection'),
546 infoForm = form.attr('data-info-form'),
547 resultColorsRgba = form.attr('data-res-rgba'),
548 hideBgImage = form.attr('data-hide-bg-image'),
549 hideBgImageDefColor = form.data('hide-bg-image-def-color'),
550 backgroundGradientCheck = form.data('gradient-check'),
551 backgroundGradientC1 = form.data('gradient-c1'),
552 backgroundGradientC2 = form.data('gradient-c2'),
553 backgroundGradientDir = form.data('gradient-dir'),
554 loadEffectFontSize = form.attr('data-load-gif-font-size');
555 enableTopAnimation = form.attr('data-enable-top-animation');
556 topAnimationScroll = form.attr('data-top-animation-scroll');
557 loadEffectMessage = typeof form.data('loadMessage') != "undefined" ? form.data('loadMessage') : "";
558
559 var pollOptions = JSON.parse(window.atob(window.aysPollOptions[formId]));
560 var pollEnableLn = typeof pollOptions.poll_show_social_ln != "undefined" && pollOptions.poll_show_social_ln.length > 0 && pollOptions.poll_show_social_ln == "on" ? true : false;
561 var pollEnableFb = typeof pollOptions.poll_show_social_fb != "undefined" && pollOptions.poll_show_social_fb.length > 0 && pollOptions.poll_show_social_fb == "on" ? true : false;
562 var pollEnableTr = typeof pollOptions.poll_show_social_tr != "undefined" && pollOptions.poll_show_social_tr.length > 0 && pollOptions.poll_show_social_tr == "on" ? true : false;
563 var pollEnableVk = typeof pollOptions.poll_show_social_vk != "undefined" && pollOptions.poll_show_social_vk.length > 0 && pollOptions.poll_show_social_vk == "on" ? true : false;
564 var pollSocialButtons = {
565 linkedIn : pollEnableLn,
566 faceBook : pollEnableFb,
567 twitter : pollEnableTr,
568 vkontakte : pollEnableVk,
569 };
570
571 if( typeof pollOptions.social_links != "undefined" ) {
572 var pollLinkedInLink = pollOptions.social_links.linkedin_link != "" ? pollOptions.social_links.linkedin_link : "";
573 var pollFacebookInLink = pollOptions.social_links.facebook_link != "" ? pollOptions.social_links.facebook_link : "";
574 var pollTwitterLink = pollOptions.social_links.twitter_link != "" ? pollOptions.social_links.twitter_link : "";
575 var pollVkontakteLink = pollOptions.social_links.vkontakte_link != "" ? pollOptions.social_links.vkontakte_link : "";
576 var pollYoutubeLink = pollOptions.social_links.youtube_link != "" ? pollOptions.social_links.youtube_link : "";
577 }
578 var pollSocialLinks = {
579 linkedInLink : pollLinkedInLink,
580 faceBookLink : pollFacebookInLink,
581 twitterLink : pollTwitterLink,
582 vkontakteLink : pollVkontakteLink,
583 youtubeLink : pollYoutubeLink,
584 }
585
586 var data = form.parent().serializeFormJSON();
587
588 if(form.hasClass('choosing-poll') && !seeRes){
589 var allowMultivoteCheck = $('#'+formId).find('input#ays_poll_multivote_min_count').data("allow");
590 if(allowMultivoteCheck){
591 var numberCheckedAnswers = $('#'+formId).find('input:checkbox:checked').length;
592 var numberAllAnswers = $('#'+formId).find('input:checkbox').length;
593 var minimumVotesCount = $('#'+formId).find('input#ays_poll_multivote_min_count').val();
594 var otherAnswer = $('#'+formId).find('input.ays-poll-new-answer-apply-text');
595 var otherAnswerVal = otherAnswer.val();
596 if(otherAnswer.length > 0 && otherAnswerVal != ""){
597 numberCheckedAnswers++;
598 }
599 if( numberAllAnswers < minimumVotesCount){
600 minimumVotesCount = numberAllAnswers;
601 form.find('.ays-poll-multivote-message').html("Minimum votes count shoulde be "+minimumVotesCount);
602 }
603 if(minimumVotesCount > numberCheckedAnswers){
604 form.find('.ays-poll-multivote-message').show();
605 return false;
606 }
607 }
608 }
609
610 if (infoForm) {
611 if (type == "text" && data.answer == ""){
612 return;
613 }
614
615 if ('answer' in data && !seeRes || (('ays_poll_new_answer' in data) && data.ays_poll_new_answer != '')) {
616 return showInfoForm(form);
617 } else if(!seeRes) {
618 return false;
619 }
620 }
621
622 var valid = true;
623 form.find('.apm-info-form input[name]').each(function () {
624 $(this).removeClass('ays_poll_shake');
625 if ($(this).attr('data-required') == 'true' && $(this).val() == "" && !seeRes) {
626 $(this).addClass('apm-invalid');
627 $(this).addClass('ays_red_border');
628 $(this).addClass('ays_poll_shake');
629 valid = false;
630 }
631 });
632
633 var email_val = $('[check_id="'+formId+'"]');
634 if (email_val.attr('type') !== 'hidden' && email_val.attr('check_id') == formId) {
635 if(email_val.val() != ''){
636 if (!(emailValivatePattern.test(email_val.val())) && !seeRes) {
637 email_val.addClass('ays_red_border');
638 email_val.addClass('ays_poll_shake');
639 valid = false;
640 }else{
641 email_val.addClass('ays_green_border');
642 }
643 }
644 }
645
646 var phoneInput = $(document).find("#"+formId).find('input[name="apm_phone"]');
647 var phoneInputVal = phoneInput.val();
648 if(phoneInputVal != '' && typeof phoneInputVal !== 'undefined'){
649 phoneInput.removeClass('ays_red_border');
650 phoneInput.removeClass('ays_green_border');
651 if (!validatePhoneNumber(phoneInput.get(0))) {
652 if (phoneInput.attr('type') !== 'hidden') {
653 phoneInput.addClass('ays_red_border');
654 phoneInput.addClass('ays_poll_shake');
655 valid = false;
656 }
657 }else{
658 phoneInput.addClass('ays_green_border');
659 }
660 }
661
662 if (!valid && !seeRes) {
663 return false;
664 }
665
666 if ((!('answer' in data) && !seeRes) && (!('ays_poll_new_answer' in data) || (('ays_poll_new_answer' in data) && data.ays_poll_new_answer == ''))) return;
667 var userAnswerValue;
668 if (data.answer) {
669 var userAnswerId = data.answer;
670
671 if ($.isArray(userAnswerId)) {
672 var userEachAnswerValue = [];
673
674 for (var i = 0; i < userAnswerId.length; i++) {
675 var userEachAnswer = form.find('input[name="answer"][value="'+userAnswerId[i]+'"]');
676 var userEachAnswerBox = userEachAnswer.parent();
677 userEachAnswerValue.push(userEachAnswerBox.find('span.ays-poll-each-answer-grid').text());
678 }
679
680 userAnswerValue = userEachAnswerValue;
681
682 if (data.ays_poll_new_answer) {
683 userAnswerValue.push(data.ays_poll_new_answer);
684 }
685 } else {
686 var userAnsweInput = form.find('input[name="answer"][value="'+userAnswerId+'"]');
687 var userAnswerBox = userAnsweInput.parent();
688 userAnswerValue = userAnswerBox.find('span.ays-poll-each-answer-grid').text();
689 }
690 } else if(data.ays_poll_new_answer) {
691 userAnswerValue = data.ays_poll_new_answer;
692 }
693 if (seeRes && ('answer' in data)) delete data['answer'];
694 loadEffect(formId, true , loadEffectFontSize,loadEffectMessage);
695 btn.off();
696 data.action = 'ays_finish_poll';
697 data.poll_id = pollId;
698
699 var endDate = GetFullDateTime();
700 data.end_date = endDate;
701
702 // Mute answer sound button
703 var $this = $(document).find('.ays_finish_poll').data("form");
704 var currentContainer = $(document).find("#"+$this);
705 var soundEls = currentContainer.find('.ays_music_sound');
706 if(soundEls.hasClass("ays_music_sound")){
707 soundEls.removeClass("ays_sound_active");
708 soundEls.addClass("ays_poll_display_none");
709 }
710 if($(document).scrollTop() >= form.offset().top){
711 form.goToPoll(enableTopAnimation,topAnimationScroll);
712 }
713
714 $.ajax({
715 url: poll_maker_ajax_public.ajax_url,
716 dataType: 'json',
717 method:'post',
718 data: data,
719 success: function(res) {
720 var answers_sounds = $("#"+formId).parent().find('.ays_poll_ans_sound').get(0);
721 if(answers_sounds){
722 setTimeout(function() {
723 resetPlaying(answers_sounds);
724 }, 1000);
725 }
726 if(hideBgImage == 'true'){
727 if(!backgroundGradientCheck){
728 $(document).find("#"+formId).css("background-image", "none");
729 $(document).find("#"+formId).css("background-color", hideBgImageDefColor);
730 }
731 else{
732 $(document).find("#"+formId).css("background-image", "linear-gradient("+backgroundGradientDir+", "+backgroundGradientC1+", "+backgroundGradientC2+")");
733 }
734 }
735 $("#"+formId+" .ays_poll_cb_and_a").hide();
736 $("#"+formId+" .ays_poll_show_timer").hide();
737 var delay = $('.ays-poll-main').find('div.box-apm[data-delay]').attr('data-delay');
738 delayCountDown(delay);
739 loadEffect(formId, false , loadEffectFontSize,loadEffectMessage);
740 form.parent().next().prop('disabled', false);
741 $('.answer-' + formId).parent().remove(); //for removing apm-answer
742 form.find('.ays_poll_passed_count').remove();
743 form.find('.apm-info-form').remove();
744 var redirectMessage = voteRedirection ? form.find('.redirectionAfterVote').clone(true) : '';
745 $("#"+formId+" .apm-button-box").remove();
746 var hideRes = form.attr('data-res');
747 var resultContainer = $("#"+formId).parent().find('.box-apm');
748
749 var hideResOption = false;
750 var pollSocialLinksHeading = "";
751 var pollSocialButtonsHeading = "";
752 if(typeof res.styles != "undefined"){
753
754 if(typeof res.styles['hide_results'] != "undefined"){
755 hideResOption = res.styles['hide_results'].length > 0 && res.styles['hide_results'] != 1 ? true : false;
756 }
757
758 if(typeof res.styles['poll_social_links_heading'] != "undefined"){
759 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'] : "";
760 }
761
762 if(typeof res.styles['poll_social_buttons_heading'] != "undefined"){
763 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'] : "";
764 }
765
766 var result_message = typeof res.styles['result_message'] != "undefined" && res.styles['result_message'] != "" ? res.styles['result_message'] : "";
767
768 if (!isLimitation) {
769 form.find('.apm-title-box.ays_res_mess').html(result_message);
770 }
771
772 var hide_results_text = typeof res.styles['hide_results_text'] != "undefined" && res.styles['hide_results_text'] != "" ? res.styles['hide_results_text'] : "";
773 form.find('.ays-poll-hide-result-box').html(hide_results_text);
774
775 }
776 pollSocialLinks.heading = pollSocialLinksHeading;
777 pollSocialButtons.heading = pollSocialButtonsHeading;
778
779 if( !res.voted_status && !seeRes && hideResOption){
780 var content = '';
781 var limitation_message = (res.styles['limitation_message'] && res.styles['limitation_message'] != '') ? res.styles['limitation_message'] : poll_maker_ajax_public.alreadyVoted;
782 limitation_message = limitation_message.replace(/\\/g, '');
783
784 content += '<div class="ays-poll-vote-message">';
785 content += '<p>'+ limitation_message +'</p>';
786 content += '</div>';
787
788 resultContainer.append(content);
789 }
790
791 if (hideRes != 0) {
792 $("#"+formId+" .ays_question").remove();
793 $("#"+formId+" .hideResults").css("display", "block");
794 }
795 else if ( type == "text" ) {
796 $("#"+formId+" .ays_question").remove();
797 $("#"+formId+" .hideResults").css("display", "block");
798 $("#"+formId+" .ays_res_mess").fadeIn();
799 }
800 else if ( !res.voted_status ) {
801 $("#"+formId+" .hideResults").css("display", "block");
802 }
803 else {
804 form.append('<div class="results-apm" id="pollResultId' +data.poll_id+ '">' + '</div>');
805 var votesSum = 0;
806 var votesMax = 0;
807 var answer;
808 for ( answer in res.answers) {
809 votesSum = Math.abs(res.answers[answer].votes) + votesSum;
810 if (+res.answers[answer].votes > votesMax) {
811 votesMax = +res.answers[answer].votes;
812 }
813 }
814 var answer2 = res.answers;
815
816 // Answer Numbering
817
818 var widths = sortDate(res.answers.length, votesSum, answer2, formId );
819 //show votes count
820 var showvotescounts = true;
821 if (res.styles.show_votes_count == 0) {
822 showvotescounts = false;
823 }
824
825 //show result percent
826 var showrespercent = true;
827 if (res.styles.show_res_percent == 0) {
828 showrespercent = false;
829 }
830
831 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";
832
833 if(barChartType == "google_bar_chart") {
834 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;
835 var aysBarChartData = new Array(['', '']);
836 $("#"+formId+" .ays_res_mess").fadeIn();
837 for (var tox in widths) {
838 var chartRealVotes = +answer2[widths[tox].index].votes;
839 var answerTextVal = answer2[widths[tox].index].answer;
840 //var finalAnswerText = ays_poll_restriction_string( 'words', answerTextVal, 2 );
841 answerTextVal = answerTextVal.replace(/\\/g, '');
842 aysBarChartData.push([
843 answerTextVal,
844 parseInt(chartRealVotes)
845 ]);
846 }
847
848 google.charts.load('current', {packages: ['corechart', 'bar']});
849 google.charts.setOnLoadCallback(drawBasic);
850
851 function drawBasic() {
852 var data = google.visualization.arrayToDataTable(aysBarChartData);
853
854 var groupData = google.visualization.data.group(
855 data,
856 [{column: 0, modifier: function () {return 'total'}, type:'string'}],
857 [{column: 1, aggregation: google.visualization.data.sum, type: 'number'}]
858 );
859
860 var formatPercent = new google.visualization.NumberFormat({
861 pattern: '#%'
862 });
863
864 var formatShort = new google.visualization.NumberFormat({
865 pattern: 'short'
866 });
867
868 var view = new google.visualization.DataView(data);
869 view.setColumns([0, 1, {
870 calc: function (dt, row) {
871 if( groupData.getValue(0, 1) == 0 ){
872 return amount;
873 }
874 var amount = formatShort.formatValue(dt.getValue(row, 1));
875 var percent = formatPercent.formatValue(dt.getValue(row, 1) / groupData.getValue(0, 1));
876 return amount + ' (' + percent + ')';
877 },
878 type: 'string',
879 role: 'annotation'
880 }]);
881 var options = {
882 maxWidth: '100%',
883 height: chartHeight,
884 legend: { position: 'none' },
885 axes: {
886 x: {
887 0: { side: 'bottom'}
888 }
889 },
890 bars: 'horizontal',
891 bar: { groupWidth: "90%" },
892 };
893
894 var chart = new google.visualization.BarChart(document.getElementById('pollResultId' + pollId));
895 google.visualization.events.addListener(chart, 'ready', function () {
896 $.each($('text[text-anchor="end"]'), function (index, label) {
897 var labelText = $(label).text();
898 if ($.isArray(userAnswerValue)) {
899 for (var i = 0; i < userAnswerValue.length; i++) {
900 if (labelText == userAnswerValue[i]) {
901 $(this).css('font-weight', '600');
902 }
903 }
904 } else {
905 if (labelText == userAnswerValue) {
906 $(this).css('font-weight', '600');
907 }
908 }
909 });
910 });
911 chart.draw(view,options);
912 }
913 } else if (barChartType == "default_bar_chart") {
914 if(typeof data.answer == "string") {
915 var dataAnswerArr = data.answer.split(",")
916 }
917 else {
918 dataAnswerArr = data.answer;
919 }
920
921 for (var i = 0; i < res.answers.length; i++) {
922 var rightAnswerCheck = (jQuery.inArray(res.answers[widths[i].index].id, dataAnswerArr) !== -1) ? 'ays_check' : '';
923 var starAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.star1 : apmIcons.star;
924 var emojiAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.emoji1 : apmIcons.emoji;
925 var handAnswerCheck = (data.answer == res.answers[widths[i].index].id) ? apmIcons.hand1 : apmIcons.hand;
926 var answer = res.answers;
927 var percentColor = form.attr('data-percent-color');
928
929 var answerDiv = $('<div class="answer-title flex-apm"></div>'),
930 answerBar = $('<div class="answer-percent" data-percent="'+widths[i].width+'"></div>');
931 var userMoreImage;
932 if(res.check_user_pic && res.answers[i].avatar){
933 var userpicsMore = res.answers[widths[i].index].avatar;
934 var userPicsCount = res.check_user_pic_count;
935 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>";
936 if(userpicsMore.length != 0){
937 userpicsMore = userpicsMore.splice(0 , userPicsCount);
938 userpicsMore.push(addedMoreImage);
939 }
940 userMoreImage = $('<div class="ays-user-count">'+userpicsMore.join(' ')+'</div>');
941 }
942
943 if (resultColorsRgba) {
944 answerBar.attr('style', 'background-color:'+hexToRgba(percentColor, widths[i].width/100)+' !important; border: 1px solid ' + percentColor +' !important;');
945 }
946 else{
947 answerBar.attr('style', 'background-color:'+percentColor);
948 }
949
950 answerBar.css({
951 width: '1%'
952 });
953
954 var answerText = '';
955 var pollShowAnswerImage = false;
956 switch (type) {
957 case 'choose':
958 pollShowAnswerImage = (res.styles.poll_enable_answer_image_after_voting == "on") ? true : false;
959 if(pollShowAnswerImage){
960 var answerImage = typeof answer[widths[i].index].answer_img != "undefined" || typeof (answer[widths[i].index].answer_img) != "" ? answer[widths[i].index].answer_img : "";
961 var answerImageBox = $("<div class='ays-poll-answers-image-box-empty-image'></div>");
962 var answerImageIsEmptyClass = "ays-poll-answers-box-no-image";
963 if(answerImage != ""){
964 answerImageIsEmptyClass = "ays-poll-answers-box";
965 answerImageBox = $("<div class='ays-poll-answers-image-box'><img src="+answerImage+" class='ays-poll-answers-current-image'></div>");
966 }
967 var answerTextAndPercent = $("<div class='ays-poll-answer-text-and-percent-box'></div>");
968 var answerMainDiv = $('<div class='+answerImageIsEmptyClass+'></div>');
969 }
970
971 answerText = $('<span class="answer-text '+rightAnswerCheck+'"></span>');
972 var htmlstr = stripSlashes(answer[widths[i].index].answer);
973
974 answerText.html(htmlstr);
975 break;
976 case 'rate':
977 switch (res.view_type) {
978 case 'emoji':
979 answerText = emojiAnswerCheck[res.answers.length / 2 + 1.5 - widths[i].index];
980 break;
981
982 case 'star':
983 for (var j = 0; j <= widths[i].index; j++) {
984 answerText += starAnswerCheck;
985 }
986 break;
987 }
988 answerText = $('<span class="answer-text">'+answerText+'</span>');
989 break;
990 case 'vote':
991 switch (res.view_type) {
992 case 'hand':
993 answerText = handAnswerCheck[widths[i].index];
994 break;
995
996 case 'emoji':
997 answerText = emojiAnswerCheck[2 * widths[i].index + 1];
998 break;
999 }
1000 answerText = $('<span class="answer-text">'+answerText+'</span>');
1001 break;
1002 }
1003
1004 var answerVotes = $('<span class="answer-votes"></span>');
1005 if(showvotescounts){
1006 answerVotes.text(answer[widths[i].index].votes);
1007 }
1008 if(res.check_admin_approval){
1009 if(type == 'choose'){
1010 answerDiv.append("<span class='ays_grid_answer_span' >"+poll_maker_ajax_public.thank_message+"</span>").appendTo("#"+formId+" .results-apm");
1011 break;
1012 }
1013 }
1014
1015 if(!pollShowAnswerImage){
1016 answerDiv.append(answerText).append(answerVotes).appendTo("#"+formId+" .results-apm");
1017 $("#"+formId+" .results-apm").append(userMoreImage).append(answerBar);
1018 }
1019 else{
1020 answerMainDiv.appendTo("#"+formId+" .results-apm");
1021 answerImageBox.appendTo(answerMainDiv);
1022 answerTextAndPercent.appendTo(answerMainDiv);
1023 answerDiv.append(answerText).append(answerVotes).appendTo(answerTextAndPercent);
1024
1025 if(typeof userMoreImage != "undefined"){
1026 answerTextAndPercent.append(userMoreImage);
1027 }
1028
1029 answerBar.appendTo(answerTextAndPercent);
1030 }
1031
1032 $("#"+formId+" .ays_res_mess").fadeIn();
1033 $('.redirectionAfterVote').show();
1034
1035 }
1036
1037 setTimeout(function() {
1038 form.find('.answer-percent').each(function () {
1039 var percent = $(this).attr('data-percent');
1040
1041 $(this).css({
1042 width: (percent || 1) + '%'
1043 });
1044
1045 if (showrespercent) {
1046 var aaa = $(this);
1047 setTimeout(function() {
1048 aaa.text(percent > 5 ? percent + '%' : '');
1049 }, 200);
1050 }
1051 });
1052 }, 100);
1053 }
1054 }
1055
1056 // Remove disable from next button for category polls start
1057 form.parents('.ays_poll_category-container').find('.ays-poll-next-btn').prop('disabled', false);
1058 var vvv = form.parents('.ays_poll_category-container').attr("data-var");
1059 window['showNext' + vvv] = true;
1060 if (typeof(window['catIndex' + vvv]) != 'undefined') {
1061 if (typeof(window['pollsGlobalPool'+vvv]) != 'undefined') {
1062 if (window['catIndex' + vvv] == window['pollsGlobalPool' + vvv].length - 1) {
1063 form.parents('.ays_poll_category-container').find('.ays-poll-next-btn').prop('disabled', true);
1064 }
1065 }
1066
1067 if (window['catIndex' + vvv] == 0 && form.parents('.ays_poll_category-container').find('.results-apm').length > 0) {
1068 form.parents('.ays_poll_category-container').find('.ays-poll-previous-btn').prop('disabled', true);
1069 }
1070 }
1071 // Remove disable from next button for category polls end
1072
1073 if (form.attr('data-show-social') == 1) {
1074 socialBtnAdd(formId, pollSocialButtons);
1075 }
1076 if (form.attr('data-enable-social-links') == 1) {
1077 socialLinksAdd(formId, pollSocialLinks);
1078 }
1079 if (voteURLRedirection == 1) {
1080 var url = form.attr('data-url-href');
1081 var answerRedirectDelay = +form.attr('data-delay');
1082 form.append(redirectMessage);
1083 if (url !== '') {
1084 setTimeout(function() {
1085 location.href = url;
1086 } , answerRedirectDelay * 1000);
1087 }else{
1088 $('.redirectionAfterVote').hide();
1089 }
1090 }else{
1091 voteURLRedirection = false;
1092 }
1093 if (voteRedirection == 1 && voteURLRedirection == false) {
1094 var url = form.attr('data-href');
1095 var delay = +form.attr('data-delay');
1096 form.append(redirectMessage);
1097 setTimeout(function() {
1098 location.href = url;
1099 }, delay * 1000);
1100 }
1101 if (isRestart == 'true') {
1102 showRestart(formId);
1103 }
1104
1105 if(res.check_user_pic){
1106 var checkModal = $(document).find(".ays-poll-avatars-modal-main");
1107 if(checkModal.length < 1){
1108 var avatarsModal = "<div class='ays-poll-avatars-modal-main'>" +
1109 "<div class='ays-poll-avatars-modal-content'>" +
1110 "<div class='ays-poll-avatars-preloader'>" +
1111 "<img class='ays-poll-avatar-pic-loader' src="+res.check_user_pic_loader+">" +
1112 "</div>" +
1113 "<div class='ays-poll-avatars-modal-header'>" +
1114 "<span class='ays-close' id='ays-poll-close-avatars-modal'>&times;</span>" +
1115 "<span style='font-weight: bold;'></span>" +
1116 "</div>" +
1117 "<div class='ays-poll-modal-body' id='ays-poll-avatars-body'></div>" +
1118 "</div>" +
1119 "</div>";
1120 $(document.body).append(avatarsModal);
1121 }
1122 }
1123 },
1124 error: function () {
1125 loadEffect(formId, false , loadEffectFontSize,loadEffectMessage);
1126 $(".user-form-"+formId).fadeOut();
1127 form.parent().next().prop('disabled', false);
1128 $('.answer-' + formId).parent().parent().find('.apm-button-box').remove();
1129 $('.answer-' + formId).remove();
1130 btn.remove();
1131 $("#"+formId+" .ays_question").text("Something went wrong. Please reload page.");
1132 }
1133 });
1134
1135 }
1136
1137 function showRestart(formId) {
1138 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>');
1139 $("#"+formId).append(restartBtn);
1140 }
1141
1142 if ($(document).find('#ays_res_without_see').length > 0) {
1143
1144 let btn = $(document).find('#ays_res_without_see'),
1145 type = $(document).find('#ays_res_without_see').attr('data-polltype');
1146
1147 voting( btn, type );
1148 }
1149
1150 $(document).on('click', '.ays-poll-btn.choosing-btn', function () {
1151 voting( $(this), 'choose' );
1152 });
1153 $(document).on('click', '.ays-poll-btn.rating-btn', function () {
1154 voting( $(this), 'rate' );
1155 });
1156 $(document).on('click', '.ays-poll-btn.voting-btn', function () {
1157 voting( $(this), 'vote' );
1158 });
1159 $(document).on('click', '.ays-poll-btn.text-btn', function () {
1160 voting( $(this), 'text' );
1161 });
1162
1163 $(document).on('change', '.apm-answers-without-submit input', function () {
1164 if ($(this).parent().hasClass('apm-rating')) {
1165 voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'rate');
1166 } else if ($(this).parent().hasClass('apm-voting')) {
1167 voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'vote');
1168 } else if ($(this).parent().hasClass('apm-choosing')) {
1169 voting($(this).parents('.box-apm').find('.apm-button-box input.ays_finish_poll'), 'choose');
1170 }
1171 })
1172
1173 function delayCountDown(sec) {
1174 delaySec = parseInt(sec);
1175 var intervalSec = setInterval(function() {
1176 if (delaySec > 0) {
1177 delaySec--;
1178 $('.ays-poll-main').find('p.redirectionAfterVote span').text(delaySec);
1179 } else {
1180 clearInterval(intervalSec);
1181 }
1182 }, 1000);
1183 }
1184
1185 function resetPlaying(audelems) {
1186 audelems.pause();
1187 audelems.currentTime = 0;
1188 }
1189
1190 function validatePhoneNumber(input) {
1191 var phoneno = /^[+ 0-9-]+$/;
1192 if (typeof input !== 'undefined') {
1193 if (input.value.match(phoneno)) {
1194 return true;
1195 } else {
1196 return false;
1197 }
1198
1199 }
1200 }
1201
1202 /**
1203 * @return {string}
1204 */
1205 function GetFullDateTime(){
1206 var now = new Date();
1207 return [[now.getFullYear(), AddZero(now.getMonth() + 1), AddZero(now.getDate())].join("-"), [AddZero(now.getHours()), AddZero(now.getMinutes()), AddZero(now.getSeconds())].join(":")].join(" ");
1208 }
1209
1210 /**
1211 * @return {string}
1212 */
1213 function AddZero(num) {
1214 return (num >= 0 && num < 10) ? "0" + num : num + "";
1215 }
1216
1217 function hexToRgba(hex, alfa) {
1218 var c;
1219 if (alfa == null) {
1220 alfa = 1;
1221 }
1222 if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
1223 c= hex.substring(1).split('');
1224 if(c.length== 3){
1225 c= [c[0], c[0], c[1], c[1], c[2], c[2]];
1226 }
1227 c= '0x'+c.join('');
1228 return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+alfa+')';
1229 }
1230 }
1231
1232 function ays_poll_restriction_string( type, x, length ){
1233 var tval = '';
1234 if( x.length > 0 && x != null){
1235 tval = x.trim();
1236 }
1237 switch ( type ) {
1238 case 'characters':
1239 break;
1240 case 'words':
1241 if(tval.length > 0 && tval != null && tval.length != ''){
1242 var wordsLength = tval.match(/\S+/g).length;
1243 if (wordsLength > length) {
1244 var trimmed = tval.split(/\s+/, length).join(" ");
1245 x = trimmed + '...';
1246 }
1247 }
1248 break;
1249 default:
1250 break;
1251 }
1252 return x;
1253 }
1254
1255 // Avatars modal start
1256
1257 // Open users avatars modal
1258 $(document).on('click', '.ays-user-image-more', function(e){
1259 $(document).find('div.ays-poll-avatars-preloader').css('display', 'flex');
1260 $(document).find('.ays-poll-avatars-modal-main').aysModal('show');
1261 var $this = $(this);
1262 var answer_id = $(this).data('answerId');
1263 var action = 'ays_poll_get_current_answer_users_pics';
1264 data = {};
1265 data.action = action;
1266 data.answer_id = answer_id;
1267 $.ajax({
1268 url: poll_maker_ajax_public.ajax_url,
1269 dataType: 'json',
1270 method:'post',
1271 data: data,
1272 success: function(response){
1273 for(var avatars of response){
1274 $('div#ays-poll-avatars-body').append(avatars);
1275
1276 }
1277 var answerTitle = $this.parents(".ays-user-count").prev().find(".answer-text").html();
1278 $(document).find('div.ays-poll-avatars-preloader').css('display', 'none');
1279 $(document).find('div.ays-poll-avatars-modal-header span:nth-child(2)').append(answerTitle);
1280 }
1281 });
1282 });
1283
1284 // Close users avatars modal
1285 $(document).on('click', '.ays-close', function () {
1286 $(document).find('.ays-poll-avatars-modal-main').aysModal('hide');
1287 setTimeout(function(){
1288 $(document).find('div#ays-poll-avatars-body').html('');
1289 $(document).find('div.ays-poll-avatars-modal-header span:nth-child(2)').html('');
1290 }, 250);
1291 });
1292
1293 // Cldoe users avatars modal with ESC button
1294 $(document).on("keydown", function(e){
1295 if(e.keyCode === 27){
1296 $(document).find('.ays-close').trigger('click');
1297 return false;
1298 }
1299 });
1300
1301 if(typeof idChecker !== 'undefined'){
1302 var checkResShow = $(document).find("#"+idChecker);
1303 if(checkResShow.data("loadMethod")){
1304 var checkModal = $(document).find(".ays-poll-avatars-modal-main");
1305 if(checkModal.length < 1){
1306 var avatarsModal = "<div class='ays-poll-avatars-modal-main'>" +
1307 "<div class='ays-poll-avatars-modal-content'>" +
1308 "<div class='ays-poll-avatars-preloader'>" +
1309 "<img class='ays-poll-avatar-pic-loader' src="+resLoader+">" +
1310 "</div>" +
1311 "<div class='ays-poll-avatars-modal-header'>" +
1312 "<span class='ays-close' id='ays-poll-close-avatars-modal'>&times;</span>" +
1313 "<span style='font-weight: bold;'></span>" +
1314 "</div>" +
1315 "<div class='ays-poll-modal-body' id='ays-poll-avatars-body'></div>" +
1316 "</div>" +
1317 "</div>";
1318 $(document.body).append(avatarsModal);
1319 }
1320 }
1321 }
1322 // Avatars modal end
1323
1324 })(jQuery);