PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.3.7
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.3.7
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.3.7, at public/js/poll-maker-public-ajax.js

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