PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.5
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.5
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 5.6.7 All 152 releases
poll-maker / admin / js / poll-maker-ays-admin.js

poll-maker-ays-admin.js in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.4.5, at admin/js/poll-maker-ays-admin.js

3,825 lines 160.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 'use strict';
3
4 window.FontAwesomeConfig = {
5 autoReplaceSvg: false
6 };
7
8 $('.apm-unread').each(function () {
9 var tr = $(this).parent().parent();
10 tr.find('td').each(function () {
11 $(this).css('color', '#dc3545');
12 })
13 });
14
15 $.fn.serializeFormJSON = function () {
16 var o = {},
17 a = this.serializeArray();
18 $.each(a, function () {
19 if (o[this.name]) {
20 if (!o[this.name].push) {
21 o[this.name] = [o[this.name]];
22 }
23 o[this.name].push(this.value || '');
24 } else {
25 o[this.name] = this.value || '';
26 }
27 });
28 return o;
29 };
30
31 $.fn.goToNormal = function() {
32 $('html, body').animate({
33 scrollTop: this.offset().top - 200 + 'px'
34 }, 'normal');
35 return this; // for chaining...
36 }
37
38 $.fn.aysModal = function(action){
39 let $this = $(this);
40
41 var current_popup_id_attr = $this.attr('id');
42 var current_popup_id = "";
43 var current_popup_class = "";
44
45 if (current_popup_id_attr && current_popup_id_attr != "") {
46 current_popup_id = "overlay-" + current_popup_id_attr;
47 current_popup_class = "." + current_popup_id;
48 }
49
50 switch(action){
51 case 'hide':
52 $(this).find('.ays-modal-content').css('animation-name', 'zoomOut');
53 var removeIframe = $this.find('.ays-modal-body iframe');
54 if ( removeIframe.length > 0 ) {
55 $this.find('.ays-modal-body iframe').remove();
56 }
57 setTimeout(function(){
58 $(document.body).removeClass('modal-open');
59 $(document).find('.ays-modal-backdrop'+ current_popup_class).remove();
60 $this.hide();
61 }, 250);
62 break;
63 case 'hide_remove_video':
64 $(this).find('.ays-modal-content').css('animation-name', 'zoomOut');
65 $this.find('.ays-modal-body iframe').remove();
66 setTimeout(function(){
67 $(document.body).removeClass('modal-open');
68 $(document).find('.ays-modal-backdrop'+ current_popup_class).remove();
69 $this.hide();
70 }, 250);
71 break;
72 case 'show_flex':
73 $this.css('display', 'flex');
74 $(this).find('.ays-modal-content').css('animation-name', 'zoomIn');
75 $(document).find('.modal-backdrop').remove();
76 $(document.body).append('<div class="ays-modal-backdrop '+ current_popup_id +'"></div>');
77 $(document.body).addClass('modal-open');
78 case 'show':
79 default:
80 $this.show();
81 $(this).find('.ays-modal-content').css('animation-name', 'zoomIn');
82 $(document).find('.modal-backdrop').remove();
83 $(document.body).append('<div class="ays-modal-backdrop '+ current_popup_id +'"></div>');
84 $(document.body).addClass('modal-open');
85 break;
86 }
87 }
88
89 $(document).find('.ays_poll_aysDropdown').aysDropdown();
90 $(document).find('[data-toggle="dropdown"]').dropdown();
91
92 $('[data-toggle="tooltip"]').tooltip();
93
94 // copy shortcode
95 $(document).find('.ays-poll-copy-image').on('click', function(){
96 var _this = this;
97 var input = $(_this).parent().find('input.ays-poll-shortcode-input');
98 var length = input.val().length;
99
100 input[0].focus();
101 input[0].setSelectionRange(0, length);
102 document.execCommand('copy');
103
104 $(_this).attr('data-original-title', pollLangObj.copied);
105 $(_this).tooltip('show');
106 });
107
108 $(document).find('.ays-poll-copy-image').on('mouseleave', function(){
109 var _this = this;
110
111 $(_this).attr('data-original-title', pollLangObj.clickForCopy);
112 });
113
114 // Users limits
115 if ($('#apm_limit_users').prop('checked')) {
116 $('.if-limit-users ').fadeIn();
117 }
118
119 $('#ays_enable_restriction_pass').on('change', function () {
120 if ($(this).prop('checked')) {
121 if(!$('#ays_enable_logged_users').prop('checked')) {
122 $('#ays_enable_logged_users').trigger('click');
123 }
124 } else {
125 $('.if-users-roles').fadeOut();
126 }
127 });
128
129 if ($('#ays_enable_logged_users').prop('checked')) {
130 $('.if-logged-in').fadeIn();
131 }
132
133 if ($('#ays_enable_restriction_pass').prop('checked')) {
134 $('.if-users-roles').fadeIn();
135 }
136
137 $('#ays_enable_logged_users').on('change', function () {
138 if (!$(this).prop('checked')) {
139 $('#ays_enable_restriction_pass').prop('checked', false);
140 $('.if-users-roles').fadeOut();
141 }
142 });
143
144 // Email notification
145 if ($('#ays_notify_by_email_on').prop('checked')) {
146 $('.if-notify-email').fadeIn();
147 }
148 $('#ays_notify_by_email_on').on('change', function () {
149 $('.if-notify-email').fadeToggle();
150 });
151
152 // Redirect after vote
153 if ($('#ays_redirect_after_vote').prop('checked')) {
154 $('.if-redirect-after-vote').fadeIn();
155 }
156 $('#ays_redirect_after_vote').on('change', function () {
157 $('.if-redirect-after-vote').fadeToggle();
158 });
159
160 // Answer Sound
161 if ($('#ays_enable_asnwers_sound').prop('checked')) {
162 $('.if_answer_sound').fadeIn();
163 }
164 $('#ays_enable_asnwers_sound').on('change', function () {
165 $('.if_answer_sound').fadeToggle();
166 });
167
168 //Hide results
169 $('.if-ays-poll-hide-results').css("display", "flex").hide();
170 if ($('#ays-poll-hide-results').prop('checked')) {
171 $('.if-ays-poll-hide-results').fadeIn();
172 }
173 $('#ays-poll-hide-results').on('change', function () {
174 // $('.if-ays-poll-hide-results').fadeToggle();
175 if ($('#ays-poll-hide-results').prop('checked')) {
176 $('#ays-poll-allow-not-vote').prop('checked', false);
177 }
178 });
179
180 //Allow not to vote
181 $('#ays-poll-allow-not-vote').on('change', function () {
182 if ($('#ays-poll-allow-not-vote').prop('checked')) {
183 $('#ays-poll-hide-results').prop('checked', false);
184 $('.if-ays-poll-hide-results').fadeOut();
185 }
186 });
187
188 //Loading effect
189 $('.if-loading-gif').css("display", "flex").hide();
190 if ($('#ays-poll-load-effect').val() == 'load_gif') {
191 $('.if-loading-gif').fadeIn();
192 }
193 if ($('#ays-poll-load-effect').val() == 'message') {
194 $('.if-loading-message').fadeIn();
195 }
196 $('#ays-poll-load-effect').on('change', function () {
197 var effect = $(this).val();
198 var sizeCont = $(document).find(".ays_load_gif_cont");
199 var sizeContLine = $(document).find(".ays_line_changeing");
200 if (effect == 'load_gif') {
201 $('.if-loading-gif').fadeIn();
202 $('.if-loading-message').hide();
203 if(sizeCont.hasClass("display_none")){
204 sizeCont.removeClass("display_none");
205 }
206 if(sizeContLine.hasClass("ays_hr_display_none")){
207 sizeContLine.removeClass("ays_hr_display_none");
208 }
209 }
210 else if(effect == 'message'){
211 $('.if-loading-message').fadeIn();
212 $('.if-loading-gif').hide();
213 }
214 else {
215 $('.if-loading-gif').fadeOut();
216 $('.if-loading-message').fadeOut();
217 if(!sizeCont.hasClass("display_none")){
218 sizeCont.addClass("display_none");
219 sizeContLine.addClass("ays_hr_display_none");
220 }
221 if(!sizeContLine.hasClass("ays_hr_display_none")){
222 sizeContLine.addClass("ays_hr_display_none");
223 }
224 }
225 });
226
227 //User data form
228 $(".ays-poll-sel-fields input[type='checkbox']").on('change', function () {
229 var id = $(this).val();
230 if ($(this).prop('checked')) {
231 $('#ays-poll-box-rfield-' + id).fadeIn();
232 } else {
233 $('#ays-poll-box-rfield-' + id).find('input').prop('checked', false);
234 $('#ays-poll-box-rfield-' + id).fadeOut();
235 }
236 });
237
238 $(document).find('#ays_user_roles_poll').select2({
239 placeholder: 'Select role'
240 });
241
242 $('.apm-cat-select2').select2({
243 placeholder: 'Select category'
244 });
245 $('select.ays-select').not('.ays-select-search').select2({
246 minimumResultsForSearch: -1
247 });
248 $('.ays-select-search').select2();
249
250 $(document).on('click', 'a.add-question-image', function (e) {
251 openMediaUploader(e, $(this));
252 });
253 $(document).on('click', 'a.add-bg-image', function (e) {
254 openMediaUploaderBg(e, $(this));
255 });
256 $(document).on('click', 'a.add-logo-image', function (e) {
257 openMediaUploaderLogo(e, $(this));
258 });
259
260 $(document).on('click', '.ays-remove-question-img', function () {
261 $(this).parent().find('img#ays-poll-img').attr('src', '');
262 $(this).parent().find('input#ays-poll-image').val('').trigger('change');
263 $(this).parent().fadeOut();
264 $(document).find('.ays-field label a.add-question-image').text('Add Image');
265 $('.ays-poll-img').remove();
266 });
267 $(document).on('click', '.ays-remove-bg-img', function () {
268 $('img#ays-poll-bg-img').attr('src', '');
269 $('input#ays-poll-bg-image').val('').trigger('change');
270 $('.ays-poll-bg-image-container').parent().fadeOut(300);
271 $(this).parents(".form-group.row").find('a.add-bg-image').html('Add Image');
272 $('.box-apm').css('background-image', 'unset');
273 $('#ays-poll-background-image-options').fadeOut(300);
274 if ($(document).find('#ays-enable-background-gradient').prop('checked')) {
275 toggleBackgrounGradient();
276 }
277 });
278 var themes = [
279 'personal',
280 {
281 'name': 'light',
282 'mainColor': '#0C6291',
283 'textColor': '#0C6291',
284 'buttonTextColor': '#FBFEF9',
285 'buttonBgColor': '#0C6291',
286 'iconColor': '#0C6291',
287 'bgColor': '#FBFEF9',
288 'answerBgColor': '#FBFEF9',
289 'answerHoverColor': '#0C6291',
290 'titleBgColor': 'rgba(255,255,255,0)',
291 'borderColor': '#0C6291',
292 },
293 {
294 'name': 'dark',
295 'mainColor': '#FBFEF9',
296 'textColor': '#FBFEF9',
297 'buttonTextColor': '#222222',
298 'buttonBgColor': '#FBFEF9',
299 'iconColor': '#FBFEF9',
300 'bgColor': '#222222',
301 'answerBgColor': '#222222',
302 'answerHoverColor': '#FBFEF9',
303 'titleBgColor': 'rgba(255,255,255,0)',
304 'borderColor': '#FBFEF9',
305 },
306 {
307 'name': 'minimal',
308 'mainColor': '#7a7a7a',
309 'textColor': '#424242',
310 'buttonTextColor': '#424242',
311 'buttonBgColor': 'rgba(0,0,0,0)',
312 'iconColor': '#999A9C',
313 'bgColor' : 'rgba(0,0,0,0)',
314 'answerBgColor': 'rgba(0,0,0,0)',
315 'answerHoverColor': '#7a7a7a',
316 'titleBgColor': 'rgba(255,255,255,0)',
317 'borderColor': '#7a7a7a',
318 },
319 ];
320
321 $(document).on('click', '.delete a[href]', function(){
322 return confirm('Do you want to delete?');
323 });
324
325 function ays_youtube_parser(url){
326 var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
327 var match = url.match(regExp);
328 return (match&&match[7].length==11)? match[7] : false;
329 }
330
331 function openMediaUploader(e, element) {
332 e.preventDefault();
333 var aysUploader = wp.media({
334 title: 'Upload',
335 button: {
336 text: 'Upload'
337 },
338 multiple: false
339 }).on('select', function () {
340 var attachment = aysUploader.state().get('selection').first().toJSON();
341 if (attachment.type != 'image') {
342 return alert('Please load image file');
343 }
344 element.text('Edit Image');
345 $('.ays-poll-question-image-container').fadeIn();
346 $('img#ays-poll-img').attr('src', attachment.url);
347 $('input#ays-poll-image').val(attachment.url).trigger('change');
348 $('.apm-img-box').empty().fadeIn().append("<img class='ays-poll-img' src='"+attachment.url+"'>");
349 }).open();
350 return false;
351 }
352
353 function openMediaUploaderBg(e, element) {
354 e.preventDefault();
355 var aysUploader = wp.media({
356 title: 'Upload',
357 button: {
358 text: 'Upload'
359 },
360 multiple: false
361 }).on('select', function () {
362 var attachment = aysUploader.state().get('selection').first().toJSON();
363 var attachmentUrl = attachment.url;
364 if (attachment.type != 'image') {
365 return alert('Please load image file');
366 }
367 element.text('Edit Image');
368 $('.ays-poll-bg-image-container').parent().fadeIn();
369 $('img#ays-poll-bg-img').attr('src', attachmentUrl);
370 $('input#ays-poll-bg-image').val(attachmentUrl).trigger('change');
371 $('.box-apm').css('background-image', "url('"+ attachmentUrl +"')");
372 $('#ays-poll-background-image-options').show();
373 }).open();
374 return false;
375 }
376
377 function openMediaUploaderLogo(e, element) {
378 e.preventDefault();
379 var aysUploader = wp.media({
380 title: 'Upload',
381 button: {
382 text: 'Upload'
383 },
384 multiple: false
385 }).on('select', function () {
386 var attachment = aysUploader.state().get('selection').first().toJSON();
387 var attachmentUrl = attachment.url;
388 if (attachment.type != 'image') {
389 return alert('Please load image file');
390 }
391 element.text('Edit Image');
392 $('.ays-poll-logo-image-container').parent().fadeIn();
393 $('img#ays-poll-logo-img').attr('src', attachmentUrl);
394 $('input#ays-poll-logo-image').val(attachmentUrl).trigger('change');
395 $(document).find(".box-apm").css('position' , 'relative');
396 var imageLiveContainer = $(document).find(".ays_live_logo_container");
397 if(imageLiveContainer.hasClass("display_none")){
398 imageLiveContainer.removeClass("display_none");
399 }
400 imageLiveContainer.show();
401 imageLiveContainer.html("<img src="+attachmentUrl+" width='55' height='55' class='ays_live_image_preview ays_poll_logo_image_main'>");
402 var getClass = $(document).find(".box-apm");
403 if(!getClass.hasClass("ays_logo_cont_image_on")){
404 getClass.addClass("ays_logo_cont_image_on");
405 }
406 $(document).find(".ays-poll-toggle-image-url-box").removeClass("display_none");
407 $(document).find(".ays-poll-toggle-image-title-box").removeClass("display_none");
408 }).open();
409 return false;
410 }
411
412 $(document).find(".add-logo-remove-image").on("click" , function(){
413 $(document).find("#ays-poll-logo-img").attr("src" , '');
414 $(document).find("#ays-poll-logo-image").val('').trigger('change');
415 $(document).find(".ays_logo_image_remove").hide();
416 $(document).find(".box-apm").css('position' , 'static');
417 $(document).find(".ays_live_logo_container").hide();
418 $(document).find(".ays_live_image_preview").attr("src" , '');
419 $(document).find("a.add-logo-image").html("Add Image");
420 $(document).find(".box-apm").removeClass("ays_logo_cont_image_on");
421 $(this).parents(".ays_toggle_parent").find(".ays-poll-toggle-image-url-box").addClass("display_none");
422 $(this).parents(".ays_toggle_parent").find(".ays-poll-toggle-image-title-box").addClass("display_none");
423 });
424
425
426 $('#ays-poll-vote-type').on('change', function () {
427 var $this = $(this);
428 var thisType = 'voting';
429 var thisCount = $this.length;
430 var thisVal = $this.val();
431 livePrevToChoosing(thisType , thisCount , thisVal);
432 switch ($(this).val()) {
433 case 'hand':
434 $('#vote-res').removeClass().addClass('ays_poll_far ays_poll_fa-thumbs-up');
435 break;
436 case 'emoji':
437 $('#vote-res').removeClass().addClass('ays_poll_fas ays_poll_fa-smile');
438 break;
439 default:
440 break;
441 }
442 });
443 $('#ays-poll-rate-type').on('change', function () {
444 var val = $('#ays-poll-rate-value').val();
445 var pollT = 'rating';
446 livePrevToChoosing(pollT , parseInt(val) , $(this).val());
447 switch ($(this).val()) {
448 case 'star':
449 $('#rate-res').removeClass().addClass('ays_poll_fas ays_poll_fa-star');
450 break;
451 case 'emoji':
452 $('#rate-res').removeClass().addClass('ays_poll_fas ays_poll_fa-smile');
453 break;
454 default:
455 break;
456 }
457 });
458
459 function rateType() {
460 var val = $('#ays-poll-rate-value').val();
461 $('#ays-poll-rate-value').empty();
462 for (var i = 10; i > 2; i--) {
463 if ($('#ays-poll-rate-type').val() == 'emoji' && (i == 4 || i > 5)) continue;
464 if (i == 9 || i == 8 || i == 6 ) continue;
465 var selected = '';
466 if (i == val) {
467 selected = 'selected';
468 }
469 var option = $("<option value="+i+" "+ selected +">"+i+"</option>");
470 $('#ays-poll-rate-value').append(option)
471 }
472 $('#ays-poll-rate-value').show();
473 }
474
475 rateType();
476 $('#ays-poll-rate-type').on('change', rateType);
477 $('#ays-poll-rate-value').on('change', function(){
478 var $thisType = $('#ays-poll-rate-type').val();
479 var $thisVal = $(this).val();
480 var $thisCType = 'rating';
481 livePrevToChoosing($thisCType , parseInt($thisVal) , $thisType);
482 });
483
484 $(document).on('click','#add-answer' ,function(){
485 var answersTable = $(document).find('#ays-answers-table');
486 var answersTableTbody = answersTable.find('tbody');
487
488 var aysRedirectChekbox = $(document).find('input[type="checkbox"]#ays_redirect_after_submit');
489 var aysRedirectChekboxClass = '';
490 if(aysRedirectChekbox.prop('checked') == false){
491 aysRedirectChekboxClass = 'ays_poll_display_none';
492 }
493 var latestTr = answersTable.find(".ays_poll_enter_key");
494 var latestTrClass = "";
495 if(latestTr.length > 0){
496 latestTrClass = "ays_poll_enter_key";
497 if(latestTr.hasClass("ays_poll_enter_key")){
498 latestTr.removeClass("ays_poll_enter_key");
499 }
500 }
501 var answersCount = $(document).find('#ays_poll_answers_count').val();
502 var id = 1 + parseInt(answersCount);
503 var content = '';
504 var liveContent = '';
505 var liveAnsCont = $(document).find(".apm-answers");
506 var checkAnsHover = $(document).find("#ays_answer_checker").val();
507 liveContent += "<div class='apm-choosing answer-' data-id="+id+" data-lid="+id+">";
508 liveContent += "<input type='radio' name='answer' >";
509 liveContent += "<label class='ays_label_poll "+checkAnsHover+" ays_label_font_size'></label>";
510 liveContent += "</div>";
511 content += '<tr class="ays-answer-row ui-state-default">';
512 content += '<td class="ays-sort"><div class="ays_poll_move_arrows"></div></td>';
513 content += '<td class="ays-choosing-answer-container">';
514 content += '<input type="text" class="ays-text-input ays-answer-value '+latestTrClass+'" name="ays-poll-answers[]" data-id="'+id+'" data-lid='+id+'>';
515 content += '<input type="hidden" name="ays-poll-answers-ids[]" data-id="'+id+'" value="0">';
516 content += '</td>';
517 content += '<td class="ays-answer-redirect-row '+ aysRedirectChekboxClass +' ">';
518 content += '<input type="text" class="ays-text-input ays_redirect_active" id="ays_submit_redirect_url_'+id+'" name="ays_submit_redirect_url[]" />';
519 content += '</td>';
520 content += '<td>';
521 content += '<label class="ays-label" for="ays-answer">';
522 content += '<a class="ays-poll-add-answer-image add-answer-image-icon"></a>';
523 content += '</label>';
524 content += '<div class="ays-poll-answer-image-container" style="display:none;">';
525 content += '<span class="ays-poll-remove-answer-img"></span>';
526 content += '<img src="" class="ays-poll-answer-img"/>';
527 content += '<input type="hidden" name="ays-poll-answers-images[]" class="ays-poll-answer-image-path" value=""/>';
528 content += '</div>';
529 content += '</td>';
530 content += '<td>';
531 content += '<a href="javascript:void(0)" class="ays-delete-answer" data-id='+id+' data-lid='+id+' data-press-key='+latestTrClass+'>';
532 content += '</a>';
533 content += '</td>';
534 content += '</tr>';
535 liveAnsCont.append(liveContent);
536 answersTableTbody.append(content);
537 var appendedTr = answersTableTbody.find(".ays_poll_enter_key");
538 appendedTr.focus();
539
540 var answersRow = $(document).find('#ays-answers-table tbody tr.ays-answer-row');
541 var index = 1;
542 if (answersRow.length > 0) {
543 answersRow.each(function () {
544 if ($(this).hasClass('even')) {
545 $(this).removeClass('even');
546 }
547 var className = ((index % 2) === 0) ? 'even' : '';
548 index++;
549 $(this).addClass(className);
550 });
551 }
552
553 $(document).find('#ays_poll_answers_count').val(id);
554 });
555
556 $(document).on('click', '.remove-answer', function () {
557 var childId = $(this).attr("data-id");
558 $(document).find('#ays_submit_redirect_url_'+childId).parent().parent().remove();
559 $(this).parent().remove();
560 });
561
562 $(document).on('click', '.ays-delete-answer', function () {
563 var confirmAnswerDelete = window.confirm(pollLangObj.deleteAnswer);
564 if(confirmAnswerDelete) {
565 var $this = $(this);
566 var index = 1;
567 var rowCount = $('tr.ays-answer-row').length;
568 if (rowCount > 2) {
569 $this.parents("tr").css({
570 'animation-name': 'slideOutLeft',
571 'animation-duration': '.3s'
572 });
573 var currentElement = "ays_poll_enter_key";
574 setTimeout(function(){
575 $this.parent('td').parent('tr.ays-answer-row').remove();
576 $(document).find('tr.ays-answer-row').each(function () {
577 if ($(this).hasClass('even')) {
578 $(this).removeClass('even');
579 }
580 var className = ((index % 2) === 0) ? 'even' : '';
581 $(this).addClass(className);
582 $(this).find('span.ays-radio').find('input').attr('id', 'ays-correct-answer-' + index);
583 $(this).find('span.ays-radio').find('input').val(index);
584 $(this).find('span.ays-radio').find('label').attr('for', 'ays-correct-answer-' + index);
585 index++;
586 });
587
588 var latestAnswer = $(document).find("table#ays-answers-table input[name='ays-poll-answers[]']").last();
589 var oldValue = latestAnswer.val();
590 latestAnswer.val(" ").trigger('change');
591 latestAnswer.val(oldValue);
592 latestAnswer.addClass(currentElement);
593 latestAnswer.focus();
594 },300);
595 var $thisDataId = $this.data("lid");
596 $(document).find(".apm-choosing").each(function(){
597 var livePrevDataId = $(this).data("lid");
598 if(livePrevDataId == $thisDataId){
599 $(this).remove();
600 }
601 });
602 }
603 else {
604 swal({
605 type: 'warning',
606 text: pollLangObj.answersMinCount
607 });
608 }
609 }
610
611
612 });
613
614 $(document).on('mouseover', '.remove-answer', function () {
615 $(this).removeClass('ays_poll_fas').addClass('ays_poll_far');
616 });
617 $(document).on('mouseout', '.remove-answer', function () {
618 $(this).removeClass('ays_poll_far').addClass('ays_poll_fas');
619 });
620
621 $(document).find('.nav-tab-wrapper a.nav-tab').on('click', function (e) {
622 var elemenetID = $(this).attr('href');
623 var activeTab = $(this).attr('data-title');
624 var activeTabData = $(this).attr('data-tab');
625 var $this = $(this);
626
627 $(document).find('.nav-tab-wrapper a.nav-tab').each(function () {
628 if ($(this).hasClass('nav-tab-active')) {
629 $(this).removeClass('nav-tab-active');
630 }
631 });
632
633 setTimeout(function() {
634 $this.addClass('nav-tab-active');
635 }, 50);
636
637 $(document).find('.ays-poll-tab-content').each(function () {
638 $(this).css('display', 'none');
639 });
640 $('#ays_poll_active_tab').val(activeTab);
641 $(document).find('#ays_poll_active_tab_settings').val(activeTabData);
642 $(document).find('#ays_poll_active_tab_results').val(activeTabData);
643 $('.ays-poll-tab-content' + elemenetID).css('display', 'block');
644 e.preventDefault();
645 });
646
647 $('.button-primary#ays-button').on('click', function () {
648 $('#ays_poll_active_tab').val("General");
649 });
650
651 $('.button-primary#ays-button-top').on('click', function () {
652 $('#ays_poll_active_tab').val("General");
653 });
654
655 // Submit buttons disableing with loader
656 var subButtons = '.button#ays-button-top,.button#ays-button-top-apply,.button#ays-button,.button#ays-button-apply,input#ays_submit';
657 $(subButtons).on('click', function () {
658 var $this = $(this);
659 submitOnce($this);
660 });
661
662 $(document).find(".button#ays-button-cat").on("click" , function(){
663 var catTitle = $(document).find("#ays-title").val();
664 if(catTitle != ''){
665 var $this = $(this);
666 subButtons += ',.button#ays-button-cat';
667 submitOnce($this);
668 }
669 });
670
671 function submitOnce(subButton){
672 var subLoader = subButton.siblings(".display_none");
673 subLoader.removeClass("display_none");
674 subLoader.css("padding-left" , "8px");
675 subLoader.css("display" , "inline-flex");
676 subLoader.css("align-items" , "center");
677 setTimeout(function() {
678 $(subButtons).attr('disabled', true);
679 }, 50);
680 setTimeout(function() {
681 $(subButtons).attr('disabled', false);
682 subLoader.addClass("display_none");
683 }, 5000);
684 }
685
686 function checkTheme() {
687 var themeId = $(this).find('input').val() || 0;
688 $('.ays_poll_theme_image_div label').each(function () {
689 $(this).removeClass('apm_active_theme');
690 });
691 $(this).find('label').addClass('apm_active_theme');
692 $('.apm-themes-row').attr('data-themeId',themeId);
693 if ($('#ays_poll_show_answers_icon').prop('checked')) {
694 switch(parseInt(themeId)){
695 case 3:
696 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
697 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
698 break;
699 default:
700 var iconsVal = $('input[name="ays_poll_answer_icon"]:checked').val();
701 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
702 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
703 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+iconsVal);
704 break;
705 }
706 }else{
707 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
708 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
709 }
710
711 answerStyleChange(themeId);
712
713 textColorChange({
714 color: themes[themeId].textColor
715 });
716 buttonTextColorChange({
717 color: themes[themeId].buttonTextColor
718 });
719 buttonBgColorChange({
720 color: themes[themeId].buttonBgColor
721 });
722 mainColorChange({
723 color: themes[themeId].mainColor
724 });
725 bgColorChange({
726 color: themes[themeId].bgColor
727 });
728 answerBgColorChange({
729 color: themes[themeId].answerBgColor
730 });
731 titleBgColorChange({
732 color: themes[themeId].titleBgColor
733 });
734 iconColorChange({
735 color: themes[themeId].iconColor
736 });
737 borderColorChange({
738 color: themes[themeId].borderColor
739 });
740 answerHoverColorChange({
741 color: themes[themeId].answerHoverColor
742 });
743
744 $('#ays-poll-text-color').wpColorPicker('color', themes[themeId].textColor);
745 $('#ays-poll-text-color').parent().parent().prev().css({
746 'background-color': themes[themeId].textColor
747 });
748
749 $('#ays-poll-button-text-color').wpColorPicker('color', themes[themeId].buttonTextColor);
750 $('#ays-poll-button-text-color').parent().parent().prev().css({
751 'color': themes[themeId].buttonTextColor
752 });
753
754 $('#ays-poll-button-bg-color').wpColorPicker('color', themes[themeId].buttonBgColor);
755 $('#ays-poll-button-bg-color').parent().parent().prev().css({
756 'background-color': themes[themeId].buttonBgColor
757 });
758
759 $('#ays-poll-answer-hover-color').wpColorPicker('color', themes[themeId].answerHoverColor);
760 $('#ays-poll-answer-hover-color').closest('.wp-picker-input-wrap').prev().css({
761 'background-color': themes[themeId].answerHoverColor
762 });
763
764 $('#ays-poll-main-color').wpColorPicker('color', themes[themeId].mainColor);
765 $('#ays-poll-main-color').parent().parent().prev().css({
766 'background-color': themes[themeId].mainColor
767 });
768
769 $('#ays-poll-bg-color').wpColorPicker('color', themes[themeId].bgColor);
770 $('#ays-poll-bg-color').parent().parent().prev().css({
771 'background-color': themes[themeId].bgColor
772 });
773
774 $('#ays-poll-answer-bg-color').wpColorPicker('color', themes[themeId].answerBgColor);
775 $('#ays-poll-answer-bg-color').parent().parent().prev().css({
776 'background-color': themes[themeId].answerBgColor
777 });
778
779 $('#ays-poll-title-bg-color').wpColorPicker('color', themes[themeId].titleBgColor);
780 $('#ays-poll-title-bg-color').parent().parent().prev().css({
781 'background-color': themes[themeId].titleBgColor
782 });
783
784 $('#ays-poll-icon-color').wpColorPicker('color', themes[themeId].iconColor);
785 $('#ays-poll-icon-color').parent().parent().prev().css({
786 'background-color': themes[themeId].iconColor
787 });
788 }
789
790 //checkTheme();
791 $('.ays_poll_theme_image_div:not(.apm-pro-feature)').on('click', checkTheme);
792
793 function checkType(type) {
794 var checkType = $('#type_choosing').prop('checked');
795 $('.ays_poll_type_image_div label').each(function () {
796 $(this).removeClass('apm_active_type');
797 });
798 $(this).find('label').addClass('apm_active_type');
799
800 var pollTypes = type;
801 var pollTypeCount = 0;
802 var pollVotingType = '';
803 if(pollTypes == 'rating'){
804 pollVotingType = $('#ays-poll-rate-type').val();
805 pollTypeCount = $('#ays-poll-rate-value').val();
806 $(document).find('.ays_poll_option_only_for_rating_voting_types').show();
807 }
808 else if(pollTypes == 'voting'){
809 pollVotingType = $("#ays-poll-vote-type").val();
810 pollTypeCount = $("#ays-poll-vote-type").length;
811 $(document).find('.ays_poll_option_only_for_rating_voting_types').show();
812 }
813 else if(pollTypes == 'text'){
814 pollVotingType = $("input[name='ays_poll_text_type']:checked").val();
815 }
816 livePrevToChoosing(pollTypes ,pollTypeCount, pollVotingType);
817
818 $('[class|="if"].poll-type-block ').hide().find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', false);
819 $('.if-' + pollTypes).css('display', 'flex').find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', true);
820 $(document).find('#ays_poll_question_text_max_length').attr('data-required', false);
821 $(document).find('#ays_poll_text_type_placeholder').attr('data-required', false);
822 $(document).find('#ays_poll_text_type_width').attr('data-required', false);
823 $('.if-choosing').find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', false);
824 checkHr(checkType ,pollTypes);
825
826 if(type == 'text'){
827 ays_tmce_setContent('<p style="text-align: center;">Thank you!</p>','ays_result_message');
828
829 // Set alignment default value to center
830 $(document).find('#apm-dir-center').prop('checked', true);
831 }
832
833 if (type != 'choosing') {
834 $(document).find('.ays_poll_option_only_for_choosing_type').hide();
835
836 if (type != 'text') {
837 $(document).find('.ays_poll_option_for_choosing_type.ays_poll_option_for_text_type').hide();
838 }
839 }
840 }
841
842 function ays_tmce_setContent(content, editor_id, textarea_id) {
843 if ( typeof editor_id == 'undefined' ) editor_id = wpActiveEditor;
844 if ( typeof textarea_id == 'undefined' ) textarea_id = editor_id;
845 if ( $(document).find('#wp-'+editor_id+'-wrap').hasClass('tmce-active') && tinyMCE && tinyMCE.get(editor_id) ) {
846 return tinyMCE.get(editor_id).setContent(content);
847 }else{
848 return $(document).find('#'+textarea_id).val(content);
849 }
850 }
851
852 var pollType = $(document).find('#poll_choose_type_first').val();
853 $('.if-' + pollType).css('display', 'flex').find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', true);
854 $('.if-choosing').find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', false);
855 $(document).find('#ays_poll_question_text_max_length').attr('data-required', false);
856 $(document).find('#ays_poll_text_type_placeholder').attr('data-required', false);
857 $(document).find('#ays_poll_text_type_width').attr('data-required', false);
858
859 $('.ays_poll_type_image_div:not(.apm-pro-feature)').on('click', checkType);
860
861 function livePrevToChoosing(type , countSel , rateType){
862 if (typeof countSel == 'undefined') {
863 countSel = 0;
864 }
865 if (typeof rateType == 'undefined') {
866 countSel = '';
867 }
868 $(document).find('.box-apm').removeClass().addClass('box-apm '+type+'-poll');
869 var content = '';
870 var contText = '';
871 var checkAnsHover = $(document).find("#ays_answer_checker").val();
872 var cClass = '';
873 var contText = '';
874 switch(type){
875 case "choosing":
876 $(document).find(".ays-answer-value").each(function(index){
877 var image = $(this).parents("tr").find(".ays-poll-answer-img").attr("src");
878 var imageContainer = '';
879 var labelContainerClass = '';
880 var imageTextClass = '';
881 if(image != ""){
882 imageContainer = '<div><img src="'+image+'" class="ays-poll-answer-image-live"></div>';
883 labelContainerClass = 'ays_poll_label_without_padding';
884 imageTextClass = 'ays_poll_label_text_with_padding';
885 }
886 cClass = "ays_label_poll "+checkAnsHover+" ays_label_font_size";
887 contText = $(this).val();
888 content += "<div class='apm-"+type+" ays-poll-field ays_poll_list_view_item answer- ' data-id="+index+" data-lid="+index+"> ";
889 content += "<input type='radio' name='answer' id='radio-"+index+"-' value='"+index+"'>";
890 content += "<label class='"+cClass+" "+labelContainerClass+" ays-poll-answer-more-options' for='radio-"+index+"-' >"+imageContainer+" <div><span class='ays-poll-each-answer "+imageTextClass+"'>"+contText+"</span></div></label>";
891 content += "</div>";
892 });
893 break;
894 case "rating":
895 var emoji = new Array(
896 "<i class='ays_poll_far ays_poll_fa-dizzy'></i>",
897 "<i class='ays_poll_far ays_poll_fa-smile'></i>",
898 "<i class='ays_poll_far ays_poll_fa-meh'></i>",
899 "<i class='ays_poll_far ays_poll_fa-frown'></i>",
900 "<i class='ays_poll_far ays_poll_fa-tired'></i>"
901 );
902 if(rateType == 'emoji'){
903 var valueIndex = countSel;
904 if(countSel == 4){
905 valueIndex = 5;
906 }
907 for(var i = 0; i < valueIndex; i++){
908 content += "<div class='apm-"+type+" answer- ' data-id="+i+">";
909 content += "<input type='radio' name='answer' id='radio-"+i+"-' value='"+i+"'>"
910 content += "<label class="+cClass+" for='radio-"+i+"-' >"+emoji[(valueIndex / 2) - i + 1.5]+"</label>"
911 content += "</div>";
912 }
913 }
914 else if(rateType == 'star'){
915 for(var i = 0; i < countSel; i++){
916 contText = "<i class='ays_poll_far ays_poll_fa-star'></i>";
917 content += "<div class='apm-"+type+" answer- ' data-id="+i+">";
918 content += "<input type='radio' name='answer' id='radio-"+i+"-' value='"+i+"'>"
919 content += "<label class="+cClass+" for='radio-"+i+"-' >"+contText+"</label>"
920 content += "</div>";
921 }
922 }
923 break;
924 case "voting":
925 var emojiThumb;
926 var toUp = '';
927 var toDown = '';
928 if(rateType == "hand"){
929 toUp = 'thumbs-up';
930 toDown = 'thumbs-down';
931 }
932 else if(rateType == "emoji"){
933 toUp = 'smile';
934 toDown = 'frown';
935 }
936 var emojiThumb = new Array(
937 '<i class="ays_poll_far ays_poll_fa-'+toUp+'"></i>',
938 '<i class="ays_poll_far ays_poll_fa-'+toDown+'"></i>'
939 );
940 for(var i = 0 ; i <= countSel ; i++){
941 content += "<div class='apm-"+type+" answer- ' data-id="+i+">";
942 content += "<input type='radio' name='answer' id='radio-"+i+"-' value='"+i+"'>"
943 content += "<label class="+cClass+" for='radio-"+i+"-' >"+emojiThumb[i]+"</label>"
944 content += "</div>";
945 }
946 break;
947 case "text":
948 var textType = rateType;
949 var textPlaceholder = $(document).find("#ays_poll_text_type_placeholder");
950 var textPlaceholderVal = textPlaceholder.val();
951 switch(textType){
952 case "short_text":
953 content += "<div class='ays-poll-maker-"+type+"-live-preview' >";
954 content += "<input type='text' id='ays_poll_text_type_short_live' placeholder='"+textPlaceholderVal+"' readonly class='ays-poll-text-type-fields'>"
955 content += "<label for='ays_poll_text_type_short_live'></label>"
956 content += "</div>";
957 break;
958 case "paragraph":
959 content += "<div class='ays-poll-maker-"+type+"-live-preview'>";
960 content += "<textarea id='ays_poll_text_type_paragraph_live' readonly placeholder='"+textPlaceholderVal+"' class='ays-poll-text-type-fields'></textarea>"
961 content += "<label for='ays_poll_text_type_paragraph_live'></label>"
962 content += "</div>";
963 break;
964 }
965 break;
966 }
967 $(document).find(".apm-answers").html(content);
968 }
969 function goToPro() {
970 window.open(
971 'https://ays-pro.com/wordpress/poll-maker/',
972 '_blank'
973 );
974 return false;
975 }
976
977 $(document).on('click', "[id|='select2'] li[id$='-pro']", goToPro);
978 $('.ays_poll_theme_image_div.apm-pro-feature').on('click', goToPro);
979 $('.apm-loader.apm-pro-feature').on('click', goToPro);
980 $('.apm-pro-feature-link').on('click', goToPro);
981
982 //**********************/
983 //LIVE PREVIEW
984 //*********************/
985 var themeId = $('.apm_active_theme+input').val() || 0;
986
987 $(document).find('#ays-poll-main-color').wpColorPicker({
988 defaultColor: themes[themeId].mainColor,
989 change: function(event, ui) {
990 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].mainColor});
991 mainColorChange(ui);
992 }
993 });
994 $(document).find('#ays-poll-text-color').wpColorPicker({
995 defaultColor: themes[themeId].textColor,
996 change: function(event, ui) {
997 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].textColor});
998 textColorChange(ui);
999 }
1000 });
1001 $(document).find('#ays-poll-button-text-color').wpColorPicker({
1002 defaultColor: themes[themeId].buttonTextColor,
1003 change: function(event, ui) {
1004 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].buttonTextColor});
1005 buttonTextColorChange(ui);
1006 }
1007 });
1008 $(document).find('#ays-poll-button-bg-color').wpColorPicker({
1009 defaultColor: themes[themeId].buttonBgColor,
1010 change: function(event, ui) {
1011 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].buttonBgColor});
1012 buttonBgColorChange(ui);
1013 }
1014 });
1015 $(document).find('#ays-poll-icon-color').wpColorPicker({
1016 defaultColor: themes[themeId].iconColor,
1017 change: function(event, ui) {
1018 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].iconColor});
1019 iconColorChange(ui);
1020 }
1021 });
1022 $(document).find('#ays-poll-bg-color').wpColorPicker({
1023 defaultColor: themes[themeId].bgColor,
1024 change: function(event, ui) {
1025 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].bgColor});
1026 bgColorChange(ui);
1027 }
1028 });
1029 $(document).find('#ays-poll-answer-bg-color').wpColorPicker({
1030 defaultColor: themes[themeId].answerBgColor,
1031 change: function(event, ui) {
1032 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].answerBgColor});
1033 answerBgColorChange(ui);
1034 }
1035 });
1036 $(document).find('#ays-poll-answer-hover-color').wpColorPicker({
1037 defaultColor: themes[themeId].answerHoverColor,
1038 change: function(event, ui) {
1039 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].answerHoverColor});
1040 answerHoverColorChange(ui);
1041 }
1042 });
1043 $(document).find('#ays-poll-title-bg-color').wpColorPicker({
1044 defaultColor: themes[themeId].titleBgColor,
1045 change: function(event, ui) {
1046 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].titleBgColor});
1047 titleBgColorChange(ui);
1048 }
1049 });
1050 $(document).find('#ays-poll-box-shadow-color').wpColorPicker({
1051 defaultColor: '#000000',
1052 change: function(event, ui) {
1053 boxShadowColorChange(ui);
1054 }
1055 });
1056
1057
1058 $(document).find('#ays-background-gradient-color-1').wpColorPicker({
1059 defaultColor: '#103251',
1060 change: function(event, ui) {
1061 toggleBackgrounGradient();
1062 }
1063 });
1064 $(document).find('#ays-background-gradient-color-2').wpColorPicker({
1065 defaultColor: '#607593',
1066 change: function(event, ui) {
1067 toggleBackgrounGradient();
1068 }
1069 });
1070
1071 $(document).find('#ays-poll-border-color').wpColorPicker({
1072 defaultColor: '#0C6291',
1073 change: function(event, ui) {
1074 borderColorChange(ui);
1075 }
1076 });
1077 $(document).find('#ays_poll_title_text_shadow_color').wpColorPicker({
1078 defaultColor: 'rgba(255,255,255,0)',
1079 change: function(event, ui) {
1080 textShadowChange(ui);
1081 }
1082 });
1083 $(document).find('.ays-title-text-shadow-coord-change').on('change', function(){
1084 var color = $(document).find('#ays_poll_title_text_shadow_color').val();
1085 textShadowChange(color);
1086 });
1087
1088 $(document).find('#ays_poll_enable_title_text_shadow').on('change', function(){
1089 var color = $(document).find('#ays_poll_title_text_shadow_color').val();
1090 var checkedShadow = $(this).prop('checked');
1091 if(checkedShadow){
1092 textShadowChange(color);
1093 }else{
1094 $(document).find(".apm-title-box > h5").css("text-shadow" , "unset");
1095 }
1096 });
1097
1098 $(document).find('#ays_poll_answers_box_shadow_color').wpColorPicker({
1099 defaultColor: '#0C6291',
1100 change: function(event, ui) {
1101 }
1102 });
1103 if($(document).find('#ays-poll-bg-image').val() != ''){
1104 $('.box-apm').css('background-image', 'url('+ $(document).find('#ays-poll-bg-image').val() +')');
1105 $('.box-apm').css('background-position', $(document).find('#ays-poll-bg-image-pos').val());
1106 }
1107
1108
1109 function mainColorChange(ui) {
1110 var color = ui.color.toString();
1111 document.documentElement.style.setProperty('--theme-main-color', color);
1112 $('#ays-poll-main-color')
1113 .attr('value', color)
1114 .parents('.wp-picker-container')
1115 .find('.color-alpha').css('background-color', color);
1116 }
1117
1118 function textColorChange(ui) {
1119 var color = ui.color.toString();
1120 document.documentElement.style.setProperty('--theme-text-color', color);
1121 $('#ays-poll-text-color')
1122 .attr('value', color)
1123 .parents('.wp-picker-container')
1124 .find('.color-alpha').css('background-color', color);
1125 }
1126
1127 function buttonTextColorChange(ui) {
1128 var color = ui.color.toString();
1129 $(document).find('input[type="button"].ays-poll-btn').css('color', color);
1130 $('#ays-poll-button-text-color')
1131 .attr('value', color)
1132 .parents('.wp-picker-container')
1133 .find('.color-alpha').css('background-color', color);
1134 }
1135
1136 function buttonBgColorChange(ui) {
1137 var color = ui.color.toString();
1138 $(document).find('input[type="button"].ays-poll-btn').css('background-color', color);
1139 $('#ays-poll-button-bg-color')
1140 .attr('value', color)
1141 .parents('.wp-picker-container')
1142 .find('.color-alpha').css('background-color', color);
1143 }
1144
1145 function iconColorChange(ui) {
1146 var color = ui.color.toString();
1147 document.documentElement.style.setProperty('--theme-icon-color', color);
1148 $('#ays-poll-icon-color')
1149 .attr('value', color)
1150 .parents('.wp-picker-container')
1151 .find('.color-alpha').css('background-color', color);
1152 }
1153
1154 function bgColorChange(ui) {
1155 var color = ui.color.toString();
1156 document.documentElement.style.setProperty('--theme-bg-color', color);
1157 $('#ays-poll-bg-color')
1158 .attr('value', color)
1159 .parents('.wp-picker-container')
1160 .find('.color-alpha').css('background-color', color);
1161 }
1162
1163 function borderColorChange(ui) {
1164 var color = ui.color.toString();
1165 $(document).find(".box-apm").css("border-color" , color);
1166 $('#ays-poll-border-color')
1167 .val(color)
1168 .parents('.wp-picker-container')
1169 .find('.color-alpha').css('background-color', color);
1170 }
1171
1172 function textShadowChange(ui , isChecked) {
1173 if (typeof ui == 'object') {
1174 var color = ui.color.toString();
1175 }else{
1176 var color = ui;
1177 }
1178 var x_offset = $(document).find('input#ays_poll_title_text_shadow_x_offset').val() + "px ";
1179 var y_offset = $(document).find('input#ays_poll_title_text_shadow_y_offset').val() + "px ";
1180 var z_offset = $(document).find('input#ays_poll_title_text_shadow_z_offset').val() + "px ";
1181
1182 var boxShadow = x_offset + y_offset + z_offset;
1183 if($(document).find('#ays_poll_enable_title_text_shadow').prop("checked")){
1184 $(document).find(".apm-title-box > h5").css("text-shadow" , boxShadow+" "+ color);
1185
1186 }
1187 $('#ays_poll_title_text_shadow_color')
1188 .val(color)
1189 .parents('.wp-picker-container')
1190 .find('.color-alpha').css('background-color', color);
1191 }
1192
1193 var answer_border_side = $(document).find('#ays-poll-border-side').val();
1194 answerBorderSideChange(answer_border_side);
1195
1196 function answerBorderSideChange(side) {
1197 var checked_answ = $(document).find( '#ays_poll_enable_answer_style').prop("checked");
1198 if (side == 'none' || !checked_answ) {
1199 $(document).find('.box-apm.choosing-poll label').each(function(){
1200 $(this)[0].style.border = 'none';
1201 });
1202 }else{
1203 switch(side) {
1204 case 'all_sides':
1205 $(document).find('.box-apm.choosing-poll label').each(function(){
1206 $(this)[0].style.border = '1px solid';
1207 });
1208 break;
1209 case 'top':
1210 $(document).find('.box-apm.choosing-poll label').each(function(){
1211 $(this)[0].style.border = 'none';
1212 $(this)[0].style.borderTop = '1px solid';
1213 });
1214 break;
1215 case 'bottom':
1216 $(document).find('.box-apm.choosing-poll label').each(function(){
1217 $(this)[0].style.border = 'none';
1218 $(this)[0].style.borderBottom = '1px solid';
1219 });
1220 break;
1221 case 'left':
1222 $(document).find('.box-apm.choosing-poll label').each(function(){
1223 $(this)[0].style.border = 'none';
1224 $(this)[0].style.borderLeft = '1px solid';
1225 });
1226 break;
1227 case 'right':
1228 $(document).find('.box-apm.choosing-poll label').each(function(){
1229 $(this)[0].style.border = 'none';
1230 $(this)[0].style.borderRight = '1px solid';
1231 });
1232 break;
1233 }
1234 }
1235 }
1236
1237 function answerStyleChange(theme_id) {
1238 if (theme_id == 3) {
1239 $('.box-apm').find('.apm-choosing').addClass('ays_poll_minimal_theme');
1240 $('.box-apm').find('.btn.ays-poll-btn').addClass('ays_poll_minimal_theme_btn');
1241 $('#ays_poll_enable_answer_style').prop('checked', false).trigger("change");
1242 $('#ays_poll_answers_box_shadow_enable').prop('checked', false).trigger("change");
1243 $('.ays_answer_style').hide();
1244 answerBorderSideChange("none");
1245 $('#ays-poll-border-width').val(0);
1246 document.documentElement.style.setProperty('--poll-border-width', "0px");
1247 }else{
1248 $('.box-apm').find('.apm-choosing').removeClass('ays_poll_minimal_theme');
1249 $('.box-apm').find('.btn.ays-poll-btn').removeClass('ays_poll_minimal_theme_btn');
1250 $('#ays_poll_enable_answer_style').prop('checked' , true);
1251 $('.ays_answer_style').show();
1252 answerBorderSideChange("all_sides");
1253 }
1254 }
1255
1256 function answerBgColorChange(ui) {
1257 if (typeof ui == 'object') {
1258 var color = ui.color.toString();
1259 }else{
1260 var color = ui;
1261 }
1262
1263 if (color == 'transparent' || !$(document).find('#ays_poll_enable_answer_style').prop("checked")) {
1264 document.documentElement.style.setProperty('--theme-answer-bg-color', "initial");
1265 }else{
1266 document.documentElement.style.setProperty('--theme-answer-bg-color', color);
1267 $('#ays-poll-answer-bg-color')
1268 .attr('value', color)
1269 .parents('.wp-picker-container')
1270 .find('.color-alpha').css('background-color', color);
1271 }
1272
1273 }
1274
1275 function answerHoverColorChange(ui) {
1276 if (typeof ui == 'object') {
1277 var color = ui.color.toString();
1278 } else {
1279 var color = ui;
1280 }
1281
1282 if (color == 'transparent' || !$(document).find('#ays_poll_enable_answer_style').prop("checked")) {
1283 document.documentElement.style.setProperty('--theme-answer-hover-color', "initial");
1284 } else {
1285 document.documentElement.style.setProperty('--theme-answer-hover-color', color);
1286 $('#ays-poll-answer-hover-color')
1287 .attr('value', color)
1288 .parents('.wp-picker-container')
1289 .find('.color-alpha').css('background-color', color);
1290 }
1291 }
1292
1293 function titleBgColorChange(ui) { //aray
1294 var color = ui.color.toString();
1295 document.documentElement.style.setProperty('--theme-title-bg-color', color);
1296 $('#ays-poll-title-bg-color')
1297 .attr('value', color)
1298 .parents('.wp-picker-container')
1299 .find('.color-alpha').css('background-color', color);
1300 }
1301
1302 function boxShadowColorChange(ui) {
1303 if (typeof ui == 'object') {
1304 var color = ui.color.toString();
1305 }else{
1306 var color = ui;
1307 }
1308
1309 if (color == 'transparent' || !$(document).find('#ays_poll_enable_box_shadow').prop("checked")) {
1310 document.documentElement.style.setProperty('--poll-box-shadow', "initial");
1311 }else{
1312 var x_offset = $(document).find('input#ays_poll_box_shadow_x_offset').val() + "px ";
1313 var y_offset = $(document).find('input#ays_poll_box_shadow_y_offset').val() + "px ";
1314 var z_offset = $(document).find('input#ays_poll_box_shadow_z_offset').val() + "px ";
1315
1316 var boxShadow = x_offset + y_offset + z_offset;
1317
1318 document.documentElement.style.setProperty('--poll-box-shadow', color + " " + boxShadow + " 1px");
1319 $('#ays-poll-box-shadow-color')
1320 .attr('value', color)
1321 .parents('.wp-picker-container')
1322 .find('.color-alpha').css('background-color', color);
1323 }
1324 }
1325
1326 /*
1327 ==========================================
1328 Background Gradient
1329 ==========================================
1330 */
1331 function toggleBackgrounGradient() {
1332 if ($(document).find('#ays-enable-background-gradient').prop('checked') || $(document).find('input#ays-poll-bg-image').val() != '') {
1333 if($(document).find('#ays_poll_gradient_direction').val() != '') {
1334 var ays_poll_gradient_direction = $(document).find('#ays_poll_gradient_direction').val();
1335 switch(ays_poll_gradient_direction) {
1336 case "horizontal":
1337 ays_poll_gradient_direction = "to right";
1338 break;
1339 case "diagonal_left_to_right":
1340 ays_poll_gradient_direction = "to bottom right";
1341 break;
1342 case "diagonal_right_to_left":
1343 ays_poll_gradient_direction = "to bottom left";
1344 break;
1345 default:
1346 ays_poll_gradient_direction = "to bottom";
1347 }
1348
1349 if($(document).find('input#ays-poll-bg-image').val() != ''){
1350 return false;
1351 }else{
1352 $(document).find('.box-apm').css({'background-image': "linear-gradient(" + ays_poll_gradient_direction + ", " + $(document).find('input#ays-background-gradient-color-1').val() + ", " + $(document).find('input#ays-background-gradient-color-2').val()+")"
1353 });
1354 }
1355 }
1356 }
1357 else{
1358 $(document).find('.box-apm').css('background-image' , "unset");
1359 return false;
1360 }
1361 }
1362
1363 var ays_poll_box_gradient_color1_picker = {
1364 change: function (e) {
1365 setTimeout(function () {
1366 toggleBackgrounGradient();
1367 }, 1);
1368 }
1369 };
1370
1371 var ays_poll_box_gradient_color2_picker = {
1372 change: function (e) {
1373 setTimeout(function () {
1374 toggleBackgrounGradient();
1375 }, 1);
1376 }
1377 };
1378
1379 function ays_poll_search_box_pagination(listTableClass, searchBox) {
1380 if($(document).find( "." + listTableClass ).length) {
1381 if($(document).find( "#" + searchBox ).length) {
1382 var search_string = $(document).find("#" + searchBox).val();
1383 if(search_string != "") {
1384 $(document).find("."+ listTableClass +" .pagination-links a").each(function() {
1385 if ( typeof this.href != "undefined" && this.href != "" ) {
1386 if ( this.href.indexOf("&s=") < 0 ) {
1387 this.href = this.href + "&s=" + search_string;
1388 }
1389 }
1390 });
1391 }
1392 }
1393 }
1394 }
1395
1396 $(document).find('#ays_poll_gradient_direction').on('change', function () {
1397 toggleBackgrounGradient();
1398 });
1399
1400 $(document).find('#ays-background-gradient-color-1').wpColorPicker(ays_poll_box_gradient_color1_picker);
1401 $(document).find('#ays-background-gradient-color-2').wpColorPicker(ays_poll_box_gradient_color2_picker);
1402
1403 toggleBackgrounGradient();
1404 $(document).find('input#ays-enable-background-gradient').on('change', function () {
1405 toggleBackgrounGradient();
1406 });
1407
1408 $(document).on('click', '.ays-remove-poll-bg-img', function () {
1409 $(document).find('.box-apm').css({'background-image': 'none'});
1410 toggleBackgrounGradient();
1411 });
1412
1413 $(document).find('#ays_poll_enable_answer_style').on('change', function () {
1414 var checkboxProp = $(this).prop('checked');
1415 var color = $(this).prop('checked') ? $(document).find('#ays-poll-answer-bg-color').val() : "transparent";
1416 var hoverColor = $(this).prop('checked') ? $(document).find('#ays-poll-answer-hover-color').val() : "#0C6291";
1417 var side = $(this).prop('checked') ? $(document).find('#ays-poll-border-side').val() : "none";
1418 answerBgColorChange(color);
1419 answerHoverColorChange(hoverColor);
1420 answerBorderSideChange(side);
1421 refreshLivePreview(checkboxProp);
1422 });
1423
1424 $(document).find('#ays_poll_enable_box_shadow').on('change', function () {
1425 var color = $(this).prop('checked') ? $(document).find('#ays-poll-box-shadow-color').val() : "transparent";
1426 boxShadowColorChange(color);
1427 });
1428
1429 $(document).find('input.ays-box-shadow-coord-change').on('change', function () {
1430 var color = $(document).find('#ays-poll-box-shadow-color').val();
1431 boxShadowColorChange(color);
1432 });
1433
1434 $(document).find('#ays-enable-background-gradient').on('change', function () {
1435 var color = $(this).prop('checked') ? $(document).find('#ays-background-gradient-color-1').val() : "transparent";
1436 toggleBackgrounGradient(color);
1437 });
1438
1439 $(document).find('#ays-enable-background-gradient').on('change', function () {
1440 var color = $(this).prop('checked') ? $(document).find('#ays-background-gradient-color-2').val() : "transparent";
1441 toggleBackgrounGradient(color);
1442 });
1443
1444 $('#ays-poll-icon-size').on('change', function () {
1445 var val = (+$(this).val() > 10) ? $(this).val() : 10;
1446 $(this).val(val);
1447 var value = val + 'px';
1448 document.documentElement.style.setProperty('--poll-icons-size', value);
1449 });
1450
1451 $('#ays-poll-width').on('change', function () {
1452 var val = +$(this).val();
1453 if (val === 0) {
1454 val = "100%";
1455 } else {
1456 val = (val > 249 ? val : 250) + "px";
1457 }
1458 document.documentElement.style.setProperty('--poll-width', val);
1459 });
1460
1461 $('#ays-poll-btn-text').on('change', function () {
1462 var val = $(this).val() !== '' ? $(this).val() : "Vote";
1463 $('.ays-poll-btn').val(val)
1464 });
1465
1466 $('#ays-poll-border-style').on('change', function () {
1467 var val = $(this).val();
1468 document.documentElement.style.setProperty('--poll-border-style', val);
1469 });
1470
1471 $('#ays-poll-border-side').on('change', function () {
1472 var val = $(this).val();
1473
1474 switch(val) {
1475 case 'none':
1476 $(document).find('.box-apm.choosing-poll label').each(function(){
1477 $(this)[0].style.border = 'none';
1478 });
1479 break;
1480 case 'all_sides':
1481 $(document).find('.box-apm.choosing-poll label').each(function(){
1482 $(this)[0].style.border = '1px solid';
1483 });
1484 break;
1485 case 'top':
1486 $(document).find('.box-apm.choosing-poll label').each(function(){
1487 $(this)[0].style.border = 'none';
1488 $(this)[0].style.borderTop = '1px solid';
1489 });
1490 break;
1491 case 'bottom':
1492 $(document).find('.box-apm.choosing-poll label').each(function(){
1493 $(this)[0].style.border = 'none';
1494 $(this)[0].style.borderBottom = '1px solid';
1495 });
1496 break;
1497 case 'left':
1498 $(document).find('.box-apm.choosing-poll label').each(function(){
1499 $(this)[0].style.border = 'none';
1500 $(this)[0].style.borderLeft = '1px solid';
1501 });
1502 break;
1503 case 'right':
1504 $(document).find('.box-apm.choosing-poll label').each(function(){
1505 $(this)[0].style.border = 'none';
1506 $(this)[0].style.borderRight = '1px solid';
1507 });
1508 break;
1509 }
1510 });
1511
1512 $(document).on('click', 'a.add-poll-bg-music', function (e) {
1513 openMusicMediaUploader(e, $(this));
1514 });
1515
1516 $('#ays-poll-border-radius').on('change', function () {
1517 var val = $(this).val();
1518 var value = val + 'px';
1519 document.documentElement.style.setProperty('--poll-border-radius', value);
1520 });
1521
1522 $('#ays-poll-border-width').on('change', function () {
1523 var val = $(this).val();
1524 var value = val + 'px';
1525 document.documentElement.style.setProperty('--poll-border-width', value);
1526 });
1527
1528 $('#ays_custom_css').on('change', function () {
1529 var val = $(this).val();
1530 $('#apm-custom-css').html(val);
1531 });
1532
1533 $('#show-title').on('change', function () {
1534 $('.apm-title-box').fadeToggle();
1535 });
1536
1537 $('#ays-poll-title').on('change', function () {
1538 var val = $(this).val();
1539 $('.apm-title-box h5').text(val);
1540 });
1541 var checkAnswerStyle = $(document).find("#ays_poll_enable_answer_style").prop("checked");
1542 $(document).on('change', '.ays-poll-question-font-size,#ays_poll_question_image_height,#ays_answers_view,#ays_poll_answer_img_height,#ays_poll_answer_image_border_radius,#ays_poll_image_background_size,#ays_poll_answers_padding,#ays_poll_answers_margin,#ays_poll_title_font_size,#ays_poll_title_alignment,#ays_poll_text_type_placeholder,#ays_poll_question_image_object_fit,#ays_poll_answers_box_shadow_enable,#ays_poll_answers_box_shadow_color,#ays_poll_answer_border_radius,#ays_poll_answer_box_shadow_x_offset,#ays_poll_answer_box_shadow_y_offset,#ays_poll_answer_box_shadow_z_offset' , function () {
1543 var checkAnswerStyleOnChange = $(document).find("#ays_poll_enable_answer_style").prop("checked");
1544 refreshLivePreview(checkAnswerStyleOnChange);
1545 });
1546
1547 //PRO features lightbox
1548 $('.open-lightbox').on('click', function (e) {
1549 e.preventDefault();
1550 var image = $(this).attr('href');
1551 $('html').addClass('no-scroll');
1552 $('.ays-poll-row ').append('<div class="lightbox-opened"><img src="' + image + '"></div>');
1553 });
1554 $('body').on('click', '.lightbox-opened', function () {
1555 $('html').removeClass('no-scroll');
1556 $('.lightbox-opened').remove();
1557 });
1558
1559 $(document).on('change', '.ays_toggle', function (e) {
1560 var state = $(this).prop('checked');
1561 if ($(this).hasClass('ays_toggle_slide')) {
1562 switch (state) {
1563 case true:
1564 $(this).parent().find('.ays_toggle_target').slideDown(250);
1565 if($(this).parent().find('.ays_toggle_target').hasClass("display_none")){
1566 $(this).parent().find('.ays_toggle_target').removeClass("display_none");
1567 }
1568 break;
1569 case false:
1570 $(this).parent().find('.ays_toggle_target').slideUp(250);
1571 break;
1572 }
1573 } else {
1574 switch (state) {
1575 case true:
1576 $(this).parent().find('.ays_toggle_target').show(250);
1577 break;
1578 case false:
1579 $(this).parent().find('.ays_toggle_target').hide(250);
1580 break;
1581 }
1582 }
1583 });
1584
1585 $(document).on('change', '.ays_toggle_checkbox', function (e) {
1586 var state = $(this).prop('checked');
1587 var parent = $(this).closest('.ays_toggle_parent');
1588
1589 if($(this).hasClass('ays_toggle_slide')){
1590 switch (state) {
1591 case true:
1592 parent.find('.ays_toggle_target').slideDown(500);
1593 break;
1594 case false:
1595 parent.find('.ays_toggle_target').slideUp(500);
1596 break;
1597 }
1598 }else{
1599 var targetEl = parent.find('.ays_toggle_target');
1600 for (let i = 0; i<targetEl.length; i++) {
1601 if(targetEl.eq(i).closest('.ays_toggle_parent')[0] != parent[0]) {
1602 targetEl.splice(i, 1);
1603 i--;
1604 }
1605 }
1606
1607 switch (state) {
1608 case true:
1609 targetEl.show(250);
1610 break;
1611 case false:
1612 targetEl.hide(250);
1613 break;
1614 }
1615 }
1616 });
1617
1618 $(document).on('click', '.ays_poll_block_with_hidden_row_show_row_block, .ays_poll_block_with_hidden_row_hide_row_block', toggleHiddenBlockRow)
1619
1620 function toggleHiddenBlockRow() {
1621 var isShow = $(this).hasClass('ays_poll_block_with_hidden_row_show_row_block');
1622 var mainBlock = $(this).parents('.ays_poll_block_with_hidden_row');
1623
1624 if (isShow) {
1625 $(mainBlock).find(".ays_poll_hidden_block_content").show(200);
1626 $(mainBlock).find(".ays_poll_hidden_hr_content").show(200);
1627 } else {
1628 $(mainBlock).find(".ays_poll_hidden_block_content").hide(200);
1629 $(mainBlock).find(".ays_poll_hidden_hr_content").hide(200);
1630 }
1631 }
1632
1633 let toggle_ddmenu = $(document).find('.toggle_ddmenu');
1634 toggle_ddmenu.on('click', function () {
1635 let ddmenu = $(this).next();
1636 let state = ddmenu.attr('data-expanded');
1637 switch (state) {
1638 case 'true':
1639 $(this).find('.ays_poll_fa').css({
1640 transform: 'rotate(0deg)'
1641 });
1642 ddmenu.attr('data-expanded', 'false');
1643 break;
1644 case 'false':
1645 $(this).find('.ays_poll_fa').css({
1646 transform: 'rotate(90deg)'
1647 });
1648 ddmenu.attr('data-expanded', 'true');
1649 break;
1650 }
1651 });
1652
1653 $(document).find('table.ays-answers-table tbody').sortable({
1654 handle: 'td.ays-sort',
1655 cursor: 'move',
1656 opacity: 0.8,
1657 tolerance: "pointer",
1658 helper: function(e, tr) {
1659 var $originals = tr.children();
1660 var $helper = tr.clone();
1661 $helper.children().each(function(index)
1662 {
1663 // Set helper cell sizes to match the original sizes
1664 $(this).width($originals.eq(index).width());
1665 });
1666 return $helper;
1667 },
1668 axis: 'y',
1669 revert: true,
1670 forcePlaceholderSize: true,
1671 forceHelperSize: true,
1672 start: function(event, ui) {
1673 $(this).find('th:nth-child(4)').addClass('ays_poll_display_none');
1674 $(this).find('th:nth-child(3)').addClass('ays_poll_display_none');
1675 if( $(this).find('td.ays-f-votes-row').hasClass('ays_poll_display_none')){
1676 $(this).find('td:nth-child(4)').addClass('ays_poll_display_none');
1677 }
1678 if( $(this).find('td.ays-answer-redirect-row').hasClass('ays_poll_display_none')){
1679 $(this).find('td:nth-child(3)').addClass('ays_poll_display_none');
1680 }
1681 ui.helper.css('display', 'table')
1682 },
1683 stop: function(event, ui) {
1684 ui.item.css('display', '');
1685 },
1686 update: function (event, ui) {
1687 var className = ui.item.attr('class').split(' ')[0];
1688 $('.ays-answers-table').find('tr.' + className).each(function (index) {
1689 var classEven = (((index + 1) % 2) === 0) ? 'even' : '';
1690 if ($(this).hasClass('even')) {
1691 $(this).removeClass('even');
1692 }
1693 $(this).addClass(classEven);
1694 $(this).children("td:nth-child(2)").find(".ays-answer-value").attr('data-lid' , index).trigger('change');
1695 $(this).children("td:nth-child(5)").find(".ays-delete-answer").attr('data-lid' , index);
1696 });
1697 livePrevToChoosing('choosing');
1698 }
1699 });
1700
1701 // $(document).find('.poll-maker-challenge-cancel').on('click', function() {
1702 // var challengeBox = $(this).closest('.poll-maker-challenge');
1703 // var wp_nonce = $(document).find('#poll_maker_ajax_challenge_cancel_nonce').val();
1704
1705 // $.ajax({
1706 // url: poll.ajax,
1707 // type: 'POST',
1708 // data: {
1709 // action: 'delete_challenge_box',
1710 // _ajax_nonce: wp_nonce
1711 // },
1712 // success: function(response) {
1713 // var result = JSON.parse(response);
1714
1715 // if (result.success) {
1716 // challengeBox.remove();
1717 // }
1718 // }
1719 // });
1720 // })
1721
1722 $(document).find('#ays_poll_create_author').select2({
1723 placeholder: 'Select users',
1724 minimumInputLength: 1,
1725 allowClear: true,
1726 language: {
1727 // You can find all of the options in the language files provided in the
1728 // build. They all must be functions that return the string that should be
1729 // displayed.
1730 inputTooShort: function () {
1731 return poll.pleaseEnterMore;
1732 }
1733 },
1734 ajax: {
1735 url: poll.ajax,
1736 dataType: 'json',
1737 data: function (response) {
1738 var checkedUsers = $(document).find('#ays_poll_create_author').val();
1739 return {
1740 action: 'ays_poll_create_author',
1741 search: response.term,
1742 val: checkedUsers,
1743 };
1744 },
1745 }
1746 });
1747
1748 $(document).on("input", 'input', function (e) {
1749 if (e.keyCode == 13) {
1750 return false;
1751 }
1752 });
1753 // $(document).on("keydown", function (e) {
1754 // if (e.target.nodeName == "TEXTAREA") {
1755 // return true;
1756 // }
1757 // if (e.keyCode == 13) {
1758 // return false;
1759 // }
1760 // if(e.keyCode === 27){
1761 // $(document).find('.ays-modal').aysModal('hide');
1762 // $(document).find('.ays-modal-backdrop').remove();
1763 // return false;
1764 // }
1765 // });
1766
1767 $('.active_date_check').change(function () {
1768 if ($(this).prop('checked')) {
1769 $('.active_date').show(250);
1770 } else {
1771 $('.active_date').hide(250);
1772 }
1773 });
1774
1775 //Each results
1776 if ($('.unread-result-badge.unread-result').length > 0) {
1777 $('.unread-result-badge.unread-result').each(function () {
1778 $(this).parent().parent().find('td').css('font-weight', 'bold')
1779 })
1780 }
1781
1782 //Each results
1783 if ($('.ays_poll_unread').length > 0) {
1784 $('.ays_poll_unread').each(function () {
1785 $(this).parent().parent().find('td').css('font-weight', 'bold')
1786 })
1787 }
1788
1789 $('#ays_poll_show_timer').change(function () {
1790 if ($(this).prop('checked')) {
1791 $('.ays_show_time').show(250);
1792 } else {
1793 $('.ays_show_time').hide(250);
1794 }
1795 });
1796
1797 $('#show_result_btn_schedule').change(function () {
1798 if ($(this).prop('checked')) {
1799 $('.result_btn_see').show(250);
1800 } else {
1801 $('.result_btn_see').hide(250);
1802 }
1803 });
1804
1805 //info_form
1806 $("#ays_poll_info_form").change(function () {
1807 if ($(this).prop('checked')) {
1808 $(this).parents(".form-group").find(".form-group").show(250);
1809 } else {
1810 $(this).parents(".form-group").find(".form-group").hide(250);
1811 }
1812 });
1813
1814 $('#ays_users_roles').select2();
1815 $('#ays_user_roles').select2();
1816 $('[data-toggle="tooltip"]').tooltip();
1817
1818 $(document).find('#ays-deactive, #ays-active, #ays_poll_change_creation_date').datetimepicker({
1819 controlType: 'select',
1820 oneLine: true,
1821 dateFormat: "yy-mm-dd",
1822 timeFormat: "HH:mm:ss"
1823 });
1824
1825 // Codemirror
1826 setTimeout(function(){
1827 if($(document).find('#ays_custom_css').length > 0){
1828 if(wp.codeEditor){
1829 wp.codeEditor.initialize($(document).find('#ays_custom_css'), cm_settings);
1830 }
1831 }
1832 }, 500);
1833
1834 $(document).find('a[href="#tab2"]').on('click', function (e) {
1835 setTimeout(function(){
1836 if($(document).find('#ays_custom_css').length > 0){
1837 var ays_custom_css = $(document).find('#ays_custom_css').html();
1838 if(wp.codeEditor){
1839 $(document).find('#ays_custom_css').next('.CodeMirror').remove();
1840 wp.codeEditor.initialize($(document).find('#ays_custom_css'), cm_settings);
1841 $(document).find('#ays_custom_css').html(ays_custom_css).trigger('change');
1842 }
1843 }
1844 }, 500);
1845 });
1846
1847 var unread_result_parent = $(document).find(".unread-result").parent().parent();
1848
1849 if (unread_result_parent != undefined) {
1850 unread_result_parent.css({"font-weight":"bold"});
1851 }
1852
1853 $(document).find('input[type="checkbox"]#ays_redirect_after_submit').on('change', function(e){
1854 var answerRedirectRow = $(document).find('#ays-answers-table .ays-answer-redirect-row');
1855 if($(this).prop('checked') == false){
1856 answerRedirectRow.addClass('ays_poll_display_none');
1857 }else{
1858 if (answerRedirectRow.hasClass('ays_poll_display_none')) {
1859 answerRedirectRow.removeClass('ays_poll_display_none');
1860 }
1861 }
1862
1863 });
1864
1865 $(document).on('change' ,"#ays_disable_answer_hover", disable_answer_hover);
1866
1867 function disable_answer_hover(){
1868 var checkLabelHover = $(document).find('label.ays_label_poll');
1869 var checkCurrentHover = $(document).find("#ays_answer_checker");
1870 if(checkLabelHover.hasClass('ays_enable_hover') && !checkLabelHover.hasClass('disable_hover')){
1871 checkLabelHover.addClass('disable_hover');
1872 checkLabelHover.removeClass('ays_enable_hover');
1873 checkCurrentHover.val('disable_hover');
1874 }else{
1875 checkLabelHover.addClass('ays_enable_hover');
1876 checkLabelHover.removeClass('disable_hover');
1877 checkCurrentHover.val('ays_enable_hover');
1878 }
1879 }
1880
1881 $('#ays_add_postcat_for_poll').select2();
1882
1883 function openMusicMediaUploader(e, element) {
1884 e.preventDefault();
1885 var aysUploader = wp.media({
1886 title: 'Upload music',
1887 button: {
1888 text: 'Upload'
1889 },
1890 library: {
1891 type: 'audio'
1892 },
1893 multiple: false
1894 }).on('select', function () {
1895 var attachment = aysUploader.state().get('selection').first().toJSON();
1896 element.next().attr('src', attachment.url);
1897 element.parent().find('input.ays_poll_bg_music').val(attachment.url).trigger('change');
1898 }).open();
1899 return false;
1900 }
1901
1902 $(document).find('#ays_poll_bg_image_position').on('change', function () {
1903 var pollContainer = $(document).find('.box-apm ,.choosing-poll');
1904 pollContainer.css({
1905 'background-position': $(this).val()
1906 });
1907 });
1908
1909 $(document).find("#ays_answer_font_size,#ays_poll_answer_font_size_mobile").on("change" , function(){
1910 var thisSize = parseInt($(this).val());
1911 var detectType = $(this).data("device");
1912 if(thisSize < 10){
1913 thisSize = 10;
1914 }
1915 if(thisSize > 90){
1916 thisSize = 90;
1917 }
1918 $(this).val(thisSize);
1919 if(detectType != "mobile"){
1920 $(document).find('.ays_label_font_size').css("font-size" , thisSize + "px");
1921 $(document).find('.ays-poll-text-type-fields').css({ 'font-size': thisSize + "px" });
1922 }
1923 });
1924
1925
1926 refreshLivePreview(checkAnswerStyle);
1927 // function for Live Preview
1928 function refreshLivePreview(checker){
1929 // Defaults
1930 var imageDefaultHeight = "150";
1931 var imageDefaulObjFit = "cover";
1932 var answerDefaultPadding = "10";
1933 var answerDefaultGap = "10";
1934 var answerDefaultFontSize = "16";
1935 var answerDefaultFontSizeMobile = "16";
1936 var titleDefaultFontSize = "20";
1937 var answersBorderRadiusDefault = "0";
1938
1939 // Boxes
1940 var imageBoxes = $(document).find('.box-apm .ays-poll-answer-image-live');
1941 var answerLabelBoxes = $(document).find('.box-apm label.ays-poll-answer-more-options');
1942 var answerMainBoxes = $(document).find('.box-apm .apm-choosing');
1943 // Answer Font size
1944 var answerFontSizeMain = $(document).find("#ays_answer_font_size");
1945 var answerFontSize = answerFontSizeMain.val();
1946 // Answer Font size mobile
1947 var answerFontSizeMobileMain = $(document).find("#ays_poll_answer_font_size_mobile");
1948 // Border color
1949 var borderColor = $(document).find("#ays-poll-border-color").val();
1950 // Image Height option
1951 var imageHeight = $(document).find('#ays_poll_answer_img_height').val();
1952 // Image border radius option
1953 var imageBorderRadius = $(document).find('#ays_poll_answer_image_border_radius').val();
1954 // Answer Image object-fit
1955 var imageBgSizeSelect = $(document).find('#ays_poll_image_background_size');
1956 var imageBgSizeVal = imageBgSizeSelect.val();
1957 // Answer padding
1958 var answersPadding = $(document).find('#ays_poll_answers_padding');
1959 var answersPaddingVal = answersPadding.val();
1960 // Answer Gap
1961 var answersMargin = $(document).find('#ays_poll_answers_margin');
1962 var answersMarginVal = answersMargin.val();
1963 // Answer Border radius
1964 var answersBorderRadiusMain = $(document).find('#ays_poll_answer_border_radius');
1965 var answersBorderRadius = answersBorderRadiusMain.val();
1966 // Question image height
1967 var questionImageHeight = $(document).find("#ays_poll_question_image_height").val();
1968 var questionHeight = questionImageHeight == "" ? "100%" : questionImageHeight+"px";
1969 // Question image object-fit
1970 var questionImageObjectFit = $(document).find("#ays_poll_question_image_object_fit").val();
1971 $(document).find(".box-apm .apm-img-box .ays-poll-img").css({"object-fit" : questionImageObjectFit});
1972 // Poll Answer view type
1973 var viewType = $(document).find('#ays_answers_view').val();
1974 var answersCont = $(document).find('.apm-answers');
1975 var answersField = answersCont.find('.ays-poll-field');
1976 var checkTextType = $(document).find('.box-apm.text-poll').length > 0 ? true : false;
1977 // Title font size
1978 var titleFontSizeBox = $(document).find("#ays_poll_title_font_size");
1979 var titleFontSize = titleFontSizeBox.val();
1980 // Poll text type placeholder
1981 var textPlaceholder = $(document).find("#ays_poll_text_type_placeholder");
1982 var textPlaceholderVal = textPlaceholder.val();
1983 $(document).find('.ays-poll-text-type-fields').attr('placeholder' , textPlaceholderVal);
1984 answersCont.find('.ays_label_poll').css({
1985 'display': 'flex',
1986 });
1987 // Title alignment
1988 var titleAlignment = $(document).find("#ays_poll_title_alignment").val();
1989
1990 if(parseInt(imageHeight) < 0){
1991 imageHeight = 0;
1992 $(document).find('#ays_poll_answer_img_height').val(imageHeight);
1993 }
1994 //
1995
1996 //
1997 // Answer box shadow
1998 var answersBoxShadow = $(document).find('#ays_poll_answers_box_shadow_enable').prop('checked');
1999 var answersBoxShadowColor = $(document).find('#ays_poll_answers_box_shadow_color').val();
2000 var answersBoxShadowXOffset = $(document).find('#ays_poll_answer_box_shadow_x_offset').val();
2001 var answersBoxShadowYOffset = $(document).find('#ays_poll_answer_box_shadow_y_offset').val();
2002 var answersBoxShadowZOffset = $(document).find('#ays_poll_answer_box_shadow_z_offset').val();
2003 if(answersBoxShadow){
2004 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
2005 'box-shadow': answersBoxShadowXOffset+'px '+answersBoxShadowYOffset+'px '+answersBoxShadowZOffset+'px '+answersBoxShadowColor,
2006 });
2007 }else{
2008 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
2009 'box-shadow': 'none',
2010 });
2011 }
2012
2013
2014 if(parseInt(answersPaddingVal) < 0){
2015 answersPaddingVal = 0;
2016 answersPadding.val(answersPaddingVal);
2017 }
2018
2019 if(parseInt(answersMarginVal) <= 0){
2020 answersMarginVal = 1;
2021 answersMargin.val(answersMarginVal);
2022 }
2023
2024 if(!checker){
2025 imageBgSizeVal = imageDefaulObjFit;
2026 answersPaddingVal = answerDefaultPadding;
2027 imageHeight = imageDefaultHeight;
2028 answersMarginVal = answerDefaultGap;
2029 answerFontSize = answerDefaultFontSize;
2030 answerFontSizeMain.val(answerDefaultFontSize);
2031 answerFontSizeMobileMain.val(answerDefaultFontSize);
2032 answersBorderRadius = answersBorderRadiusDefault;
2033 answersBorderRadiusMain.val(answersBorderRadiusDefault);
2034 }
2035 // Image Changes
2036 imageBoxes.css({
2037 'height': imageHeight+'px',
2038 'border-radius': imageBorderRadius+'px',
2039 'object-fit': imageBgSizeVal
2040 });
2041
2042 // Answer changes
2043 answerLabelBoxes.css({
2044 'padding': answersPaddingVal+'px'
2045 });
2046
2047 answerMainBoxes.css({
2048 'margin-bottom': answersMarginVal+'px'
2049 });
2050
2051 // Question font size
2052 var pattern = /Android|webOS|iPhone|iPad|Mac|Macintosh|iPod|BlackBerry|IEMobile|Opera Mini/i;
2053 var questnionFontSize;
2054 if( pattern.test(navigator.userAgent) ) {
2055 questnionFontSize = $(document).find("#ays_poll_answers_font_size_mobile").val();
2056 }
2057 else{
2058 questnionFontSize = $(document).find("#ays_poll_answers_font_size_pc").val();
2059 }
2060 $(document).find('.ays_question,.ays_question p').css({ 'font-size': questnionFontSize+"px" });
2061
2062 $(document).find('.ays_label_font_size').css("font-size" , answerFontSize + "px");
2063 $(document).find('.box-apm').css("border-color" , borderColor);
2064
2065 $(document).find(".apm-img-box img.ays-poll-img").css({"height" : questionHeight});
2066
2067 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
2068 'border-radius': +answersBorderRadius+"px",
2069 });
2070
2071 if(titleFontSize < 0){
2072 titleFontSize = 0;
2073 titleFontSizeBox.val(0);
2074 }
2075 $(document).find('.apm-title-box h5').css({
2076 "font-size" : titleFontSize + "px",
2077 "text-align" : titleAlignment,
2078 });
2079 if(viewType == 'list'){
2080 $(document).find('.grid_column_count').hide(250);
2081 answersCont.removeClass('ays_poll_grid_view_container');
2082 answersCont.addClass('ays_poll_list_view_container');
2083 answersField.removeClass('ays_poll_grid_view_item');
2084 answersField.addClass('ays_poll_list_view_item');
2085
2086 answersCont.find('.ays-poll-field.ays_poll_list_view_item').css({
2087 'margin-right': 0,
2088 });
2089 answersCont.find('.ays-poll-answer-image-live').css({
2090 'width': '220px',
2091 });
2092 answersCont.find('span.ays-poll-each-answer').css({
2093 'width': 'initial',
2094 'text-align': 'initial',
2095 'display': 'initial',
2096 });
2097 answersCont.find('.ays_label_poll').css({
2098 'align-items': 'center',
2099 'flex-direction': 'row',
2100 });
2101 }else if(viewType == 'grid' && !checkTextType){
2102 $(document).find('.grid_column_count').show(250);
2103 answersCont.removeClass('ays_poll_list_view_container');
2104 answersCont.addClass('ays_poll_grid_view_container');
2105 answersField.removeClass('ays_poll_list_view_item');
2106 answersField.addClass('ays_poll_grid_view_item');
2107
2108 answersCont.find('.ays-poll-answer-image-live').css({
2109 'width': '100%',
2110 });
2111
2112 answersCont.find('span.ays-poll-each-answer').css({
2113 'width': '100%',
2114 'text-align': 'center',
2115 'display': 'inline-block',
2116 });
2117
2118 var innerLabel = answersField.find("label.ays_poll_label_without_padding");
2119 if(innerLabel.length > 0){
2120 innerLabel.css({
2121 'flex-direction': 'column',
2122 });
2123 }
2124 }
2125 }
2126
2127 var heart_interval = setInterval(function () {
2128 $(document).find('.ays-poll-maker-wrapper i.ays_fa').toggleClass('ays_poll_pulse');
2129 }, 1000);
2130
2131 $(document).on('change' , '.ays-answer-value', function(){
2132 livePrevToChoosing("choosing");
2133 var checkAnswerStyleOnChange = $(document).find("#ays_poll_enable_answer_style").prop("checked");
2134 refreshLivePreview(checkAnswerStyleOnChange);
2135 });
2136
2137 $('#ays_poll_info_form').on('change', function () {
2138 var propCheck = $(this).prop("checked");
2139 var allowCollect = $(document).find(".ays_toggle_target_inverse");
2140 if(propCheck){
2141 allowCollect.find('#ays_allow_collecting_logged_in_users_data').prop("checked" , false);
2142 allowCollect.hide();
2143 }
2144 else{
2145 if(allowCollect.hasClass("display_none")){
2146 allowCollect.removeClass("display_none");
2147 }
2148 allowCollect.show();
2149 }
2150 $('.ays-poll-if-form-on').fadeToggle();
2151 });
2152
2153 // Pro features
2154 $(document).find('#ays_answers_border_color').wpColorPicker({
2155 change: function(event, ui) {
2156 }
2157 });
2158
2159 $(document).find("#ays_see_result_show").on("change" , function(){
2160 var checker = $(this).prop("checked");
2161 var buttonsCont = $(document).find("#ays_poll_show_hide_button");
2162 if(checker){
2163 buttonsCont.show(200);
2164 buttonsCont.css("display" , "flex");
2165 }
2166 else{
2167 buttonsCont.hide(200);
2168 }
2169 });
2170
2171 $(document).find('.ays-poll-question-tab-all-filter-button-top, .ays-poll-question-tab-all-filter-button-bottom').on('click', function(e) {
2172 e.preventDefault();
2173 var $this = $(this);
2174 var parent = $this.parents('.tablenav');
2175
2176 var searchForm = parent.parent();
2177 var searchInput = searchForm.find('input#poll-maker-ays-search-input')
2178 var searchValue = searchInput.val();
2179
2180 var html_name = '';
2181 var top_or_bottom = 'top';
2182
2183 if ( parent.hasClass('bottom') ) {
2184 top_or_bottom = 'bottom';
2185 }
2186
2187 var catFilter = $(document).find('select[name="filterby-'+ top_or_bottom +'"]').val();
2188 var authorFilter = $(document).find('select[name="filterbyauthor-'+ top_or_bottom +'"]').val();
2189 var typeFilter = $(document).find('select[name="filterbytype-'+ top_or_bottom +'"]').val();
2190 var link = location.href;
2191
2192 if (typeof catFilter != "undefined") {
2193 link = catFilterForListTable(link, searchValue, {
2194 what: 'filterby',
2195 value: catFilter
2196 });
2197 }
2198 if (typeof authorFilter != "undefined") {
2199 link = catFilterForListTable(link, searchValue, {
2200 what: 'filterbyauthor',
2201 value: authorFilter
2202 });
2203 }
2204 if (typeof typeFilter != "undefined") {
2205 link = catFilterForListTable(link,searchValue, {
2206 what: 'filterbytype',
2207 value: typeFilter
2208 });
2209 }
2210 document.location.href = link;
2211 })
2212
2213 function catFilterForListTable(link, searchValue, options){
2214 if( options.value != '' ){
2215 options.value = "&" + options.what + "=" + options.value;
2216 var linkModifiedStart = link.split('?')[0];
2217 var linkModified = link.split('?')[1].split('&');
2218 for(var i = 0; i < linkModified.length; i++){
2219 if ( linkModified[i].split("=")[0] == "ays_result_tab" ) {
2220 linkModified.splice(i, 1, "ays_result_tab=poststuff");
2221 }
2222 if(linkModified[i].split("=")[0] == options.what){
2223 linkModified.splice(i, 1);
2224 }
2225 }
2226 linkModified = linkModified.join('&');
2227 if (typeof searchValue != 'undefined' && searchValue != '') {
2228 linkModified = linkModified + "&s=" + searchValue;
2229 }
2230 return linkModifiedStart + "?" + linkModified + options.value;
2231 }else{
2232 var linkModifiedStart = link.split('?')[0];
2233 var linkModified = link.split('?')[1].split('&');
2234 for(var i = 0; i < linkModified.length; i++){
2235 if(linkModified[i].split("=")[0] == options.what){
2236 linkModified.splice(i, 1);
2237 }
2238 }
2239 linkModified = linkModified.join('&');
2240 if (typeof searchValue != 'undefined' && searchValue != '') {
2241 linkModified = linkModified + "&s=" + searchValue;
2242 }
2243 return linkModifiedStart + "?" + linkModified;
2244 }
2245 }
2246
2247 $(document).find('input[type="submit"]#doaction, input[type="submit"]#doaction2').on('click', function(e) {
2248 showConfirmationIfDelete(e);
2249 })
2250
2251 $(document).find("input#poll-maker-ays-search-input + input#search-submit").on("click", function (e) {
2252 var _this = $(this);
2253 var parent = _this.parents('form');
2254
2255 var search_input = parent.find('input#poll-maker-ays-search-input');
2256 var input_value = search_input.val();
2257
2258 var field = 's';
2259 var flag = false;
2260 var url = window.location.href;
2261 if(url.indexOf('?' + field + '=') != -1){
2262 flag = true;
2263 }
2264 else if(url.indexOf('&' + field + '=') != -1){
2265 flag = true;
2266 }
2267
2268 if (flag) {
2269 if (typeof input_value != 'undefined' && input_value != "") {
2270 e.preventDefault();
2271 location.href=location.href.replace(/&s=([^&]$|[^&]*)/i, "&s="+input_value);
2272 }
2273 }
2274 });
2275
2276 function showConfirmationIfDelete(e) {
2277 var $el = $(e.target);
2278 var elParent = $el.parent();
2279 var actionSelect = elParent.find('select[name="action"]');
2280 var action = actionSelect.val();
2281
2282 if (action === 'bulk-delete') {
2283 e.preventDefault();
2284 var confirmDelete = confirm('Are you sure you want to delete?');
2285
2286 if (confirmDelete) {
2287 var form = $el.closest('form');
2288 form.submit()
2289 }
2290 }
2291 }
2292
2293 $(document).on('click', '.ays_polls_each_results_list_table th.manage-column a', function(e) {
2294 var href = $(this).attr('href');
2295 $(this).attr('href', href + '&ays_poll_tab_results=tab2');
2296 })
2297
2298 $(document).on("click", "#ays-poll-dismiss-buttons-content .ays-button, #ays-poll-dismiss-buttons-content-helloween .ays-button-helloween", function(e){
2299 e.preventDefault();
2300
2301 var $this = $(this);
2302 var thisParent = $this.parents("#ays-poll-dismiss-buttons-content");
2303 var mainParent = $this.parents("div.ays_poll_dicount_info");
2304 var closeButton = mainParent.find("button.notice-dismiss");
2305 var attr_plugin = $this.attr('data-plugin');
2306 var wp_nonce = thisParent.find('#poll-maker-ays-sale-banner').val();
2307
2308 if(typeof wp_nonce == 'undefined'){
2309 wp_nonce = $(document).find('#poll-maker-ays-sale-banner').val();
2310 }
2311
2312 var data = {
2313 action: 'ays_poll_dismiss_button',
2314 _ajax_nonce: wp_nonce,
2315 };
2316
2317 $.ajax({
2318 url: poll.ajax,
2319 method: 'post',
2320 dataType: 'json',
2321 data: data,
2322 success: function (response) {
2323 if( response.status ){
2324 closeButton.trigger('click');
2325 } else {
2326 swal.fire({
2327 type: 'info',
2328 html: "<h2>"+ pollLangObj.errorMsg +"</h2><br><h6>"+ pollLangObj.somethingWentWrong +"</h6>"
2329 }).then(function(res) {
2330 closeButton.trigger('click');
2331 });
2332 }
2333 },
2334 error: function(){
2335 swal.fire({
2336 type: 'info',
2337 html: "<h2>"+ pollLangObj.errorMsg +"</h2><br><h6>"+ pollLangObj.somethingWentWrong +"</h6>"
2338 }).then(function(res) {
2339 closeButton.trigger('click');
2340 });
2341 }
2342 });
2343 });
2344
2345 $(document).keydown(function(event) {
2346 var editButton = $(document).find("input#ays-button-top-apply,input#ays-button-apply,input#ays_submit");
2347 if (!(event.which == 83 && event.ctrlKey) && !(event.which == 19)){
2348 return true;
2349 }
2350 editButton.trigger("click");
2351 event.preventDefault();
2352 return false;
2353 });
2354
2355 function aysPollGetCookie(c_name) {
2356 if (document.cookie.length > 0) {
2357 var c_start = document.cookie.indexOf(c_name + "=");
2358 if (c_start != -1) {
2359 c_start = c_start + c_name.length + 1;
2360 var c_end = document.cookie.indexOf(";", c_start);
2361 if (c_end == -1) {
2362 c_end = document.cookie.length;
2363 }
2364 return unescape(document.cookie.substring(c_start, c_end));
2365 }
2366 }
2367 return "";
2368 }
2369 // Check new added Poll start
2370 var createdNewPoll = aysPollGetCookie('ays_poll_created_new');
2371 if(createdNewPoll && createdNewPoll > 1){
2372 var url = new URL(window.location.href);
2373
2374 var getCustomPostId = aysPollGetCookie('ays_poll_created_new_'+createdNewPoll+'_post_id');
2375
2376 var link = "#";
2377 if(getCustomPostId){
2378 link = getCustomPostId;
2379 }
2380
2381 // Get a specific GET parameter by name
2382 var parameterValue = url.searchParams.get("action");
2383 var htmlDefaultText = '<p style="margin-top:1rem;">'+ pollLangObj.formMoreDetailed +' <a href="admin.php?page=poll-maker-ays&action=edit&poll=' + createdNewPoll + '">'+ pollLangObj.editPollPage +'</a>.</p>';
2384
2385 var htmlContent = parameterValue && parameterValue == 'edit' ? '' : htmlDefaultText;
2386
2387 var previewButtonSvgIcon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">'+
2388 '<path d="M11.9999 7.21325C11.8231 7.21325 11.6535 7.28349 11.5285 7.40851C11.4035 7.53354 11.3333 7.70311 11.3333 7.87992V12.6666C11.3333 12.8434 11.263 13.013 11.138 13.138C11.013 13.263 10.8434 13.3333 10.6666 13.3333H3.33325C3.15644 13.3333 2.98687 13.263 2.86185 13.138C2.73682 13.013 2.66659 12.8434 2.66659 12.6666V5.33325C2.66659 5.15644 2.73682 4.98687 2.86185 4.86185C2.98687 4.73682 3.15644 4.66658 3.33325 4.66658H8.11992C8.29673 4.66658 8.4663 4.59635 8.59132 4.47132C8.71635 4.3463 8.78658 4.17673 8.78658 3.99992C8.78658 3.82311 8.71635 3.65354 8.59132 3.52851C8.4663 3.40349 8.29673 3.33325 8.11992 3.33325H3.33325C2.80282 3.33325 2.29411 3.54397 1.91904 3.91904C1.54397 4.29411 1.33325 4.80282 1.33325 5.33325V12.6666C1.33325 13.197 1.54397 13.7057 1.91904 14.0808C2.29411 14.4559 2.80282 14.6666 3.33325 14.6666H10.6666C11.197 14.6666 11.7057 14.4559 12.0808 14.0808C12.4559 13.7057 12.6666 13.197 12.6666 12.6666V7.87992C12.6666 7.70311 12.5963 7.53354 12.4713 7.40851C12.3463 7.28349 12.1767 7.21325 11.9999 7.21325ZM14.6133 1.74659C14.5456 1.58369 14.4162 1.45424 14.2533 1.38659C14.1731 1.35242 14.087 1.33431 13.9999 1.33325H9.99992C9.82311 1.33325 9.65354 1.40349 9.52851 1.52851C9.40349 1.65354 9.33325 1.82311 9.33325 1.99992C9.33325 2.17673 9.40349 2.3463 9.52851 2.47132C9.65354 2.59635 9.82311 2.66659 9.99992 2.66659H12.3933L5.52659 9.52658C5.4641 9.58856 5.4145 9.66229 5.38066 9.74353C5.34681 9.82477 5.32939 9.91191 5.32939 9.99992C5.32939 10.0879 5.34681 10.1751 5.38066 10.2563C5.4145 10.3375 5.4641 10.4113 5.52659 10.4733C5.58856 10.5357 5.66229 10.5853 5.74353 10.6192C5.82477 10.653 5.91191 10.6705 5.99992 10.6705C6.08793 10.6705 6.17506 10.653 6.2563 10.6192C6.33754 10.5853 6.41128 10.5357 6.47325 10.4733L13.3333 3.60659V5.99992C13.3333 6.17673 13.4035 6.3463 13.5285 6.47132C13.6535 6.59635 13.8231 6.66658 13.9999 6.66658C14.1767 6.66658 14.3463 6.59635 14.4713 6.47132C14.5963 6.3463 14.6666 6.17673 14.6666 5.99992V1.99992C14.6655 1.9128 14.6474 1.82673 14.6133 1.74659Z" fill="#007DCB"/>'+
2389 '</svg>';
2390
2391 swal({
2392 title: '<strong class="ays-poll-maker-swal2-title">' + pollLangObj.greateJob + '</strong>',
2393 type: 'success',
2394 html: '<p class="ays-poll-maker-swal2-created-row">' + pollLangObj.youPollIsCreated + '</p><p clas="ays-poll-maker-swal2-content-text-row">' + pollLangObj.youCanUuseThisShortcode + '</p><input type="text" id="ays-poll-create-new" onClick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_poll id=\'' + createdNewPoll + '\']" />' + htmlContent,
2395 showCancelButton: true,
2396 showCloseButton: true,
2397 focusConfirm: false,
2398 cancelButtonClass: "ays-poll-preview-popup-cancel-button",
2399 confirmButtonText: '<i class="ays_poll_fas ays_poll_fa_thumbs_up"></i> '+ pollLangObj.done,
2400 confirmButtonAriaLabel: pollLangObj.thumbsUpGreat,
2401 cancelButtonText: '<a href="'+ link +'" target="_blank">'+ pollLangObj.preivewPoll + ' ' + previewButtonSvgIcon +'</a>',
2402 cancelButtonAriaLabel: pollLangObj.thumbsUpGreat,
2403
2404 });
2405 aysPollDeleteCookie('ays_poll_created_new');
2406 aysPollDeleteCookie('ays_poll_created_new_'+createdNewPoll+'_post_id');
2407 }
2408
2409 function aysPollDeleteCookie(name) {
2410 document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
2411 }
2412
2413 // Select default category for poll
2414 $(document).find("#ays_poll_default_type").select2();
2415
2416 // Check if submit button clicked for unsaved changes confirmation box
2417 var subButtons = '.button#ays-button-top, .button#ays-button-top-apply, .button#ays-button, .button#ays-button-apply, .button#ays-button-cat, .button#ays_submit, .button#ays_poll_cancel_top, .button#ays_poll_cancel';
2418 $(document).on('click', subButtons ,function () {
2419 var $this = $(this);
2420 $this.addClass('ays-submit-button-clicked');
2421 });
2422
2423 var aysUnsavedChanges = false;
2424 var formInputs = '#ays-poll-form .ays-poll-tab-content input, #ays-poll-form .ays-poll-tab-content select, ' +
2425 '#ays-poll-form .ays-poll-tab-content textarea, #ays-poll-category-form input, ' +
2426 '#ays-poll-category-form select, #ays-poll-category-form textarea, ' +
2427 '#ays-poll-general-settings-form input, #ays-poll-general-settings-form select, ' +
2428 '#ays-poll-general-settings-form textarea';
2429
2430 $(document).on('change input', formInputs, function() {
2431 aysUnsavedChanges = true;
2432 });
2433
2434 $(window).on('beforeunload', function(event) {
2435 var saveButtons = $(document).find('.button#ays-button-top, .button#ays-button-top-apply, .button#ays-button, .button#ays-button-apply, .button#ays-button-cat, .button#ays_submit, .button#ays_poll_cancel_top, .button#ays_poll_cancel');
2436 var savingButtonsClicked = saveButtons.filter('.ays-submit-button-clicked').length > 0;
2437
2438 if (aysUnsavedChanges && !savingButtonsClicked) {
2439 event.preventDefault();
2440 event.returnValue = true;
2441 }
2442 });
2443
2444
2445 $(document).find("#ays_poll_default_cat").select2({
2446 multiple: true
2447 });
2448
2449 // Create and Delete rows in Answers table
2450 $(document).on("keydown" , "input[name='ays-poll-answers[]']" , function(event) {
2451 var $thisValue = $(this).val();
2452 if (event.keyCode === 13) {
2453 if($(this).hasClass("ays_poll_enter_key")){
2454 var editButton = $(document).find(".ays-click-once");
2455 editButton.trigger("click");
2456 event.preventDefault();
2457 }
2458 else{
2459 var nextInput = $(this).parents("tr").next().find("td.ays-choosing-answer-container input:nth-child(1)");
2460 nextInput.focus();
2461 var oldValue = nextInput.val();
2462 nextInput.val(" ");
2463 nextInput.val(oldValue);
2464 }
2465 }
2466 else if(event.keyCode === 8 && $thisValue == ""){
2467 var editButton = $(this).parents("tr").find("a.ays-delete-answer");
2468 editButton.trigger("click");
2469 event.preventDefault();
2470 }
2471
2472 });
2473
2474 var drawChartLink = $(document).find(".ays_poll_answer_chart_active");
2475 if(drawChartLink.hasClass("nav-tab-active")){
2476 google.charts.load('current', {packages: ['corechart', 'bar']});
2477 google.charts.setOnLoadCallback(drawBasic);
2478 }
2479
2480 $(document).find(".ays_poll_answer_chart_active").on("click" , function(){
2481 google.charts.load('current', {packages: ['corechart', 'bar']});
2482 google.charts.setOnLoadCallback(drawBasic);
2483 });
2484
2485 // Write poll title immediately
2486 $(document).find('#ays-poll-title').on('input', function(e){
2487 var pollTitleVal = $(this).val();
2488 var pollTitle = aysPollstripHTML( pollTitleVal );
2489 $(document).find('.ays_poll_title_in_top').html( pollTitle );
2490 });
2491
2492 function aysPollstripHTML( dirtyString ) {
2493 var container = document.createElement('div');
2494 var text = document.createTextNode(dirtyString);
2495 container.appendChild(text);
2496
2497 return container.innerHTML; // innerHTML will be a xss safe string
2498 }
2499 //
2500
2501 var theme_Ids = $('.apm-themes-row').attr('data-themeid');
2502 if ($('#ays_poll_show_answers_icon').prop('checked') && theme_Ids != 3) {
2503 if ($('input[name="ays_poll_answer_icon"]:checked').prop('checked')) {
2504 var iconVal = $('input[name="ays_poll_answer_icon"]:checked').val();
2505 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2506 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2507 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+iconVal);
2508 }else{
2509 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2510 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2511 }
2512 }else{
2513 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2514 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2515 }
2516
2517 // Answer Icon
2518 $('#ays_poll_show_answers_icon').change(function () {
2519 var themeIds = $('.apm-themes-row').attr('data-themeid');
2520 if ($('#ays_poll_show_answers_icon').prop('checked')) {
2521 switch(parseInt(themeIds)){
2522 case 3:
2523 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2524 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2525 break;
2526 default:
2527 var icons_val = $('input[name="ays_poll_answer_icon"]:checked').val();
2528 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2529 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2530 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+icons_val);
2531 break;
2532 }
2533 }else{
2534 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2535 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2536 }
2537 });
2538
2539 $('.ays_poll_answ_icon').change(function () {
2540 if ($(this).prop('checked')) {
2541 var themesIds = $('.apm-themes-row').attr('data-themeid');
2542 switch(parseInt(themesIds)){
2543 case 3:
2544 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2545 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2546 break;
2547 default:
2548 var icon_val = $(this).val();
2549 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2550 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2551 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+icon_val);
2552 }
2553 }else{
2554 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2555 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2556 }
2557 });
2558
2559 $(document).find('strong.ays-poll-shortcode-box').on('mouseleave', function(){
2560 var _this = $(this);
2561
2562 _this.attr( 'data-original-title', pollLangObj.clickForCopy );
2563 });
2564
2565 // $(document).find("#ays_poll_buttons_size").select2({
2566 // minimumResultsForSearch: -1
2567 // });
2568
2569 // Button styles start
2570 // Size change
2571 $(document).find("#ays_poll_buttons_size").on("change" , function(){
2572 var buttonsSize = $(document).find('#ays_poll_buttons_size').val();
2573 var buttonsFontSize,
2574 buttonsLeftRightPadding,
2575 buttonsTopBottomPadding,
2576 buttonsBorderRadius;
2577
2578 switch(buttonsSize){
2579 case "small":
2580 buttonsFontSize = 14;
2581 buttonsLeftRightPadding = 14;
2582 buttonsTopBottomPadding = 7;
2583 buttonsBorderRadius = 3;
2584 break;
2585 case "large":
2586 buttonsFontSize = 20;
2587 buttonsLeftRightPadding = 30;
2588 buttonsTopBottomPadding = 13;
2589 buttonsBorderRadius = 3;
2590 break;
2591 default:
2592 buttonsFontSize = 17;
2593 buttonsLeftRightPadding = 20;
2594 buttonsTopBottomPadding = 10;
2595 buttonsBorderRadius = 3;
2596 break;
2597 }
2598
2599 $(document).find('#ays_poll_buttons_font_size').val(buttonsFontSize);
2600 $(document).find('#ays_poll_buttons_left_right_padding').val(buttonsLeftRightPadding);
2601 $(document).find('#ays_poll_buttons_top_bottom_padding').val(buttonsTopBottomPadding);
2602 $(document).find('#ays_poll_buttons_border_radius').val(buttonsBorderRadius);
2603
2604 $(document).find('input[type="button"].ays-poll-btn').css({
2605 'font-size' : buttonsFontSize + 'px',
2606 'padding' : buttonsTopBottomPadding+'px '+ buttonsLeftRightPadding+'px',
2607 'border-radius' : buttonsBorderRadius + 'px'
2608 });
2609 });
2610
2611 // Buttons font size
2612 $(document).find("#ays_poll_buttons_font_size").on("change" , function(){
2613 var buttonFontSize = $(this).val();
2614 $(document).find('input[type="button"].ays-poll-btn').css('font-size', buttonFontSize + 'px');
2615 });
2616
2617 $('.ays_buttons_padding').on('change', function () {
2618 var top_bottom = $(document).find('#ays_poll_buttons_top_bottom_padding').val();
2619 var left_top = $(document).find('#ays_poll_buttons_left_right_padding').val();
2620 $(document).find('input[type="button"].ays-poll-btn').css('padding', top_bottom + 'px ' + left_top +'px');
2621 });
2622
2623 $('#ays_poll_buttons_width').on('change', function () {
2624 var buttons_width = $(document).find('#ays_poll_buttons_width').val();
2625 if(buttons_width == ''){
2626 buttons_width = 'auto';
2627 }else{
2628 buttons_width = buttons_width + 'px';
2629 }
2630
2631 $(document).find('input[type="button"].ays-poll-btn').css('width', buttons_width);
2632 });
2633
2634 $('#ays_poll_buttons_border_radius').on('change', function () {
2635 var val = $(this).val();
2636 $(document).find('input[type="button"].ays-poll-btn').css('border-radius', val + 'px');
2637 });
2638
2639 function checkHr(type , pollType) {
2640 var typeChecker = $(document).find(".ays_hr_on");
2641 var textTypeChecker = $(document).find(".ays_hr_on_text");
2642 var rangeType = $('#type_range').prop('checked');
2643 if(!type){
2644 typeChecker.hide();
2645 }
2646 else{
2647 typeChecker.show();
2648 }
2649
2650 if(pollType == "text"){
2651 textTypeChecker.show();
2652 }
2653 else{
2654 textTypeChecker.hide();
2655
2656 }
2657
2658 if(rangeType){
2659 $(document).find(".ays_hr_check").hide();
2660 }
2661 else{
2662 $(document).find(".ays_hr_check").show();
2663 }
2664 }
2665
2666 function check_allow_add_answers_show_up() {
2667 var aa_show = $(document).find('input[type="checkbox"]#ays_poll_allow_add_answers');
2668 let requireAdminApprovalCbState = $(document).find('input[type="checkbox"]#ays_poll_allow_answer_require').prop('checked');
2669
2670 if(!requireAdminApprovalCbState){
2671 $(document).find('.ays_show_user_added').hide();
2672 $(document).find('.ays_show_user_added_hid').each(function () {
2673 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').prop('checked', false);
2674 // $(this).val(0);
2675 });
2676 }else{
2677 $(document).find('.ays_show_user_added').show();
2678 $(document).find('.ays_show_user_added_hid').each(function () {
2679 // $(this).val(1);
2680 // $(this).prop('checked', true);
2681 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').val(1);
2682 });
2683 }
2684 }
2685
2686 function toggleOptionsAccordion(arrowBtn) {
2687 var arrowSvg = arrowBtn.find('svg');
2688 var accordionMainContainer = arrowBtn.parents('.ays-poll-accordion-options-main-container');
2689 var accordionBody = accordionMainContainer.find('.ays-poll-accordion-body');
2690
2691 arrowSvg.toggleClass('ays-poll-accordion-arrow-active');
2692 accordionBody.slideToggle();
2693 }
2694
2695 $(document).find('input[type="checkbox"]#ays_poll_allow_add_answers').on('change', function(e){
2696 if($(this).prop('checked') == false){
2697 // $(document).find('.allow_add_answers_not_show_up').hide();
2698 // $(document).find('.allow_add_answers_not_show_up .ays_toggle_target').hide(250);
2699 $(document).find('#ays_poll_allow_answer_require').removeAttr('checked');
2700 check_allow_add_answers_show_up();
2701 }else{
2702 $(document).find('.allow_add_answers_not_show_up').show();
2703 check_allow_add_answers_show_up();
2704 }
2705
2706 });
2707
2708 $(document).find('input[type="checkbox"]#ays_poll_allow_answer_require').on('change', function(e){
2709 check_allow_add_answers_show_up();
2710 });
2711
2712 // Options accordion effect start
2713 $(document).on('click', '.ays-poll-accordion-header', function() {
2714 toggleOptionsAccordion($(this));
2715 });
2716 // Options accordion effect end
2717
2718 $(document).find('input[type="checkbox"].ays_show_user_added').on('change', function(e){
2719 let selectAllCb = $(document).find('input[type="checkbox"]#ays_poll_require_approve_select_all');
2720 if($(this).prop('checked') == true){
2721 $(this).parent().find('.ays_show_user_added_hid').val(1);
2722 var isAllChecked = 0;
2723 var allShowUserAddedCbArr = $(document).find('input[type="checkbox"].ays_show_user_added');
2724 for (i = 0; i < allShowUserAddedCbArr.length; i++) {
2725 if(allShowUserAddedCbArr.eq(i).prop('checked')) {
2726 isAllChecked++;
2727 }
2728 }
2729 if (isAllChecked === allShowUserAddedCbArr.length && selectAllCb.prop('checked') === false) {
2730 selectAllCb.prop('checked', true);
2731 }
2732 }else{
2733 $(this).parent().find('.ays_show_user_added_hid').val(0);
2734
2735 if (selectAllCb.prop('checked')) {
2736 selectAllCb.prop('checked', false);
2737 }
2738 }
2739 });
2740
2741 $(document).find("#ays_poll_require_approve_select_all").on("change" , function(){
2742 if($(this).prop('checked') == false){
2743 $(document).find('.ays_show_user_added').each(function () {
2744 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').prop('checked', false);
2745 $(this).val(0);
2746 $(this).prop('checked' , false);
2747 $(document).find('.ays_show_user_added_hid').val(0);
2748
2749 });
2750 }else{
2751 $(document).find('.ays_show_user_added').each(function () {
2752 $(this).val(1);
2753 $(this).prop('checked', true);
2754 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').val(1);
2755 $(document).find('.ays_show_user_added_hid').val(1);
2756 });
2757 }
2758 });
2759
2760 // Add answer image (Choosing type) start
2761 $(document).on('click', 'label.ays-label a.ays-poll-add-answer-image', function (e) {
2762 openAnswerMediaUploader(e, $(this));
2763 });
2764
2765 // Select Image
2766 function openAnswerMediaUploader(e, element) {
2767 e.preventDefault();
2768 var addButton = element;
2769 var aysUploader = wp.media({
2770 title: 'Upload',
2771 button: {
2772 text: 'Upload'
2773 },
2774 library: {
2775 type: 'image'
2776 },
2777 multiple: false
2778 }).on('select', function () {
2779 var attachment = aysUploader.state().get('selection').first().toJSON();
2780 addButton.parents().eq(1).find('.ays-poll-add-answer-image').parent().css('display', 'none');
2781 addButton.parents('td').find('.ays-poll-answer-image-container').fadeIn();
2782 addButton.parents('td').find('img.ays-poll-answer-img').attr('src', attachment.url);
2783 addButton.parents('tr').find('input.ays-poll-answer-image-path').val(attachment.url).trigger("change");
2784 if(addButton.hasClass('ays-poll-add-answer-image')){
2785 addButton.parents('td').find('img').attr('src', attachment.url);
2786 addButton.parents('tr').find('input.ays-poll-answer-image').val(attachment.url);
2787 }
2788 }).open();
2789 return false;
2790 }
2791
2792 // Remove Image
2793 $(document).on('click', '.ays-poll-remove-answer-img', function () {
2794 var $this = $(this);
2795 $this.parent().fadeOut();
2796 if($this.parent().hasClass('ays-poll-answer-image-container')){
2797 setTimeout(function(){
2798 $this.parents().eq(1).find('.ays-poll-add-answer-image').show();
2799 $this.parents('td').find('.ays-poll-add-answer-image').parent().css('display', 'block');
2800 $this.parents('td').find('.ays-poll-add-answer-image').css('display', 'inline-block');
2801 $this.parent().find('img.ays-poll-answer-img').attr('src', '');
2802 $this.parent().find('input.ays-poll-answer-image').val('');
2803 $this.parent().find('input.ays-poll-answer-image-path').val('').trigger("change");
2804 },300);
2805 }
2806 });
2807
2808 // Grid view type PRO
2809 $(document).find("#ays_answers_grid_column").on("change" , function(){
2810 var $this = $(this);
2811 if($this.val() != 2){
2812 $this.val(2);
2813 window.open("https://ays-pro.com/wordpress/poll-maker", '_blank');
2814 }
2815 });
2816
2817
2818
2819 $(document).on('change', '.ays-poll-answer-image-path', function(){
2820 livePrevToChoosing('choosing');
2821
2822 $(document).find('#ays-poll-border-side').trigger('change');
2823 $(document).find('#ays_answers_view').trigger('change');
2824 });
2825
2826 $(document).find(".ays-poll-text-types-type").on("change" , function(){
2827 var $this = $(this);
2828 var textType = $this.val();
2829 livePrevToChoosing("text" , 0 , textType);
2830 });
2831 // Add answer image (Choosing type) end
2832
2833 // Poll Responsive tabs start
2834 if($(document).find('.ays-top-menu').width() <= $(document).find('div.ays-top-tab-wrapper').width()){
2835 $(document).find('.ays_menu_left').css('display', 'flex');
2836 $(document).find('.ays_menu_right').css('display', 'flex');
2837 }
2838 $(window).resize(function(){
2839 if($(document).find('.ays-top-menu').width() < $(document).find('div.ays-top-tab-wrapper').width()){
2840 $(document).find('.ays_menu_left').css('display', 'flex');
2841 $(document).find('.ays_menu_right').css('display', 'flex');
2842 }else{
2843 $(document).find('.ays_menu_left').css('display', 'none');
2844 $(document).find('.ays_menu_right').css('display', 'none');
2845 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(0px)');
2846 }
2847 });
2848 var menuItemWidths0 = [];
2849 var menuItemWidths = [];
2850 $(document).find('.ays-top-tab-wrapper .nav-tab').each(function(){
2851 var $this = $(this);
2852 menuItemWidths0.push($this.outerWidth());
2853 });
2854
2855 for(var i = 0; i < menuItemWidths0.length; i+=2){
2856 if(menuItemWidths0.length <= i+1){
2857 menuItemWidths.push(menuItemWidths0[i]);
2858 }else{
2859 menuItemWidths.push(menuItemWidths0[i]+menuItemWidths0[i+1]);
2860 }
2861 }
2862 var menuItemWidth = 0;
2863 for(var i = 0; i < menuItemWidths.length; i++){
2864 menuItemWidth += menuItemWidths[i];
2865 }
2866 menuItemWidth = menuItemWidth / menuItemWidths.length;
2867
2868 $(document).on('click', '.ays_menu_left', function(){
2869 var scroll = parseInt($(this).attr('data-scroll'));
2870 scroll -= menuItemWidth;
2871 if(scroll < 0){
2872 scroll = 0;
2873 }
2874 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(-'+scroll+'px)');
2875 $(this).attr('data-scroll', scroll);
2876 $(document).find('.ays_menu_right').attr('data-scroll', scroll);
2877 });
2878 $(document).on('click', '.ays_menu_right', function(){
2879 var scroll = parseInt($(this).attr('data-scroll'));
2880 var howTranslate = $(document).find('div.ays-top-tab-wrapper').width() - $(document).find('.ays-top-menu').width();
2881 howTranslate += 250;
2882 if(scroll == -1){
2883 scroll = menuItemWidth;
2884 }
2885 scroll += menuItemWidth;
2886 if(scroll > howTranslate){
2887 scroll = Math.abs(howTranslate);
2888 }
2889 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(-'+scroll+'px)');
2890 $(this).attr('data-scroll', scroll);
2891 $(document).find('.ays_menu_left').attr('data-scroll', scroll);
2892 });
2893 // Poll Responsive tabs end
2894
2895
2896 // var checkCountdownIsExists = $(document).find('#ays-poll-countdown-main-container');
2897 var checkCountdownIsExists = $(document).find('#ays-poll-maker-countdown-main-container');
2898 if ( checkCountdownIsExists.length > 0 ) {
2899 var second = 1000,
2900 minute = second * 60,
2901 hour = minute * 60,
2902 day = hour * 24;
2903
2904 // var pollCountdownEndTime = "DEC 05, 2025 23:59:59";
2905 var pollCountdownEndTime = pollLangObj.pollBannerDate;
2906 var countDown_new = new Date(pollCountdownEndTime).getTime();
2907 if ( isNaN(countDown_new) || isFinite(countDown_new) == false ) {
2908 var AYS_POLL_MILLISECONDS = 3 * day;
2909 var countdownStartDate = new Date(Date.now() + AYS_POLL_MILLISECONDS);
2910 var pollCountdownEndTime = countdownStartDate.aysPollCustomFormat( "#YYYY#-#MM#-#DD# #hhhh#:#mm#:#ss#" );
2911 var countDown_new = new Date(pollCountdownEndTime).getTime();
2912 }
2913
2914 aysPollBannerCountdown();
2915
2916 var y = setInterval(function() {
2917
2918 var now = new Date().getTime();
2919 var distance_new = countDown_new - now;
2920
2921 aysPollBannerCountdown();
2922
2923 var countDownDays = document.getElementById("ays-poll-countdown-days");
2924 var countDownHours = document.getElementById("ays-poll-countdown-hours");
2925 var countDownMinutes = document.getElementById("ays-poll-countdown-minutes");
2926 var countDownSeconds = document.getElementById("ays-poll-countdown-seconds");
2927
2928 if(countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null){
2929
2930 var countDownDays_innerText = Math.floor(distance_new / (day));
2931 var countDownHours_innerText = Math.floor((distance_new % (day)) / (hour));
2932 var countDownMinutes_innerText = Math.floor((distance_new % (hour)) / (minute));
2933 var countDownSeconds_innerText = Math.floor((distance_new % (minute)) / second);
2934
2935 if( isNaN(countDownDays_innerText) || isNaN(countDownHours_innerText) || isNaN(countDownMinutes_innerText) || isNaN(countDownSeconds_innerText) ){
2936 var headline = document.getElementById("ays-poll-countdown-headline"),
2937 countdown = document.getElementById("ays-poll-countdown"),
2938 content = document.getElementById("ays-poll-countdown-content");
2939
2940 // headline.innerText = "Sale is over!";
2941 countdown.style.display = "none";
2942 content.style.display = "block";
2943
2944 clearInterval(y);
2945 } else {
2946 countDownDays.innerText = countDownDays_innerText;
2947 countDownHours.innerText = countDownHours_innerText;
2948 countDownMinutes.innerText = countDownMinutes_innerText;
2949 countDownSeconds.innerText = countDownSeconds_innerText;
2950 }
2951 }
2952
2953 //do something later when date is reached
2954 if (distance_new < 0) {
2955 var headline = document.getElementById("ays-poll-countdown-headline"),
2956 countdown = document.getElementById("ays-poll-countdown"),
2957 content = document.getElementById("ays-poll-countdown-content");
2958
2959 // headline.innerText = "Sale is over!";
2960 countdown.style.display = "none";
2961 content.style.display = "block";
2962
2963 clearInterval(y);
2964 }
2965 }, 1000);
2966 }
2967
2968 function aysPollBannerCountdown(){
2969 var now = new Date().getTime();
2970 var distance_new = countDown_new - now;
2971
2972 var countDownDays = document.getElementById("ays-poll-countdown-days");
2973 var countDownHours = document.getElementById("ays-poll-countdown-hours");
2974 var countDownMinutes = document.getElementById("ays-poll-countdown-minutes");
2975 var countDownSeconds = document.getElementById("ays-poll-countdown-seconds");
2976
2977 if((countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null) && distance_new > 0){
2978
2979 var countDownDays_innerText = Math.floor(distance_new / (day));
2980 var countDownHours_innerText = Math.floor((distance_new % (day)) / (hour));
2981 var countDownMinutes_innerText = Math.floor((distance_new % (hour)) / (minute));
2982 var countDownSeconds_innerText = Math.floor((distance_new % (minute)) / second);
2983
2984 if( isNaN(countDownDays_innerText) || isNaN(countDownHours_innerText) || isNaN(countDownMinutes_innerText) || isNaN(countDownSeconds_innerText) ){
2985 var headline = document.getElementById("ays-poll-countdown-headline"),
2986 countdown = document.getElementById("ays-poll-countdown"),
2987 content = document.getElementById("ays-poll-countdown-content");
2988
2989 // headline.innerText = "Sale is over!";
2990 countdown.style.display = "none";
2991 content.style.display = "block";
2992
2993 // clearInterval(y);
2994 } else {
2995 countDownDays.innerText = countDownDays_innerText;
2996 countDownHours.innerText = countDownHours_innerText;
2997 countDownMinutes.innerText = countDownMinutes_innerText;
2998 countDownSeconds.innerText = countDownSeconds_innerText;
2999 }
3000
3001 // countDownDays.innerText = Math.floor(distance_new / (day)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3002 // countDownHours.innerText = Math.floor((distance_new % (day)) / (hour)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3003 // countDownMinutes.innerText = Math.floor((distance_new % (hour)) / (minute)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3004 // countDownSeconds.innerText = Math.floor((distance_new % (minute)) / second).toLocaleString(undefined,{minimumIntegerDigits: 2});
3005 }
3006 }
3007
3008 $(document).on('click', '#ays-polls-next-button, #ays-polls-prev-button, .ays-poll-next-prev-button-class', function(e){
3009 e.preventDefault();
3010 var message = $(this).data('message');
3011 var confirm = window.confirm( message );
3012 if(confirm === true){
3013 window.location.replace($(this).attr('href'));
3014 }
3015 });
3016
3017 // CHOOSE POLL TYPE FROM MODAL START
3018 $(document).find('.ays_poll_layer_box_blocks label.ays-poll-dblclick-layer:not(.ays-poll-type-pro-feature)').on('dblclick',function(){
3019 $(this).parents('.ays_poll_layer_container').find('.ays_poll_select_button_layer input.ays_poll_layer_button').trigger('click');
3020 });
3021
3022 $(document).find('.ays-poll-content-type').on('change',function(){
3023 $(this).parents('.ays_poll_layer_container').find('.ays_poll_select_button_layer input.ays_poll_layer_button').prop('disabled',false).attr("data-type" , $(this).val());
3024 $(document).find('#poll_choose_type').val($(this).val());
3025 });
3026
3027 $(document).find('.ays_poll_layer_button').on('click',function(){
3028 $('.ays_poll_layer_container').css({'position':'unset' , 'display':'none'});
3029 $(document.body).removeClass('ays-poll-modal-open');
3030 $(document).find('.ays-poll-show-result-chart-google').prop("checked", true);
3031
3032 checkType($(this).attr("data-type"));
3033
3034 // var $checklistPanel = $(document).find('.ays-poll-checklist-panel');
3035 // if ($checklistPanel.length > 0) {
3036 // $checklistPanel.show();
3037 // }
3038 })
3039
3040 // Add body class when modal is visible
3041 $(document).ready(function(){
3042 if($('.ays_poll_layer_container').is(':visible')) {
3043 $(document.body).addClass('ays-poll-modal-open');
3044 }
3045 });
3046 // CHOOSE POLL TYPE FROM MODAL END
3047
3048 $(document).find('.ays-poll-open-polls-list').on('click', function(e){
3049 $(this).parents(".ays-poll-subtitle-main-box").find(".ays-poll-polls-data").toggle('fast');
3050 });
3051
3052 $(document).find(".ays-poll-go-to-polls").on("click" , function(e){
3053 e.preventDefault();
3054 var confirmRedirect = window.confirm(pollLangObj.areYouSure);
3055 if(confirmRedirect){
3056 window.location = $(this).attr("href");
3057 }
3058 });
3059
3060 $(document).find('#ays_poll_reset_to_default').on('click', function (e) {
3061 e.preventDefault();
3062
3063 var themeId = $(document).find('.ays-poll-theme-item.apm_active_theme').next('input').val();
3064
3065 $(document).find('.apm-themes-row').attr('data-themeId',themeId);
3066 if ($(document).find('#ays_poll_show_answers_icon').prop('checked')) {
3067 switch(parseInt(themeId)){
3068 case 3:
3069 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3070 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3071 break;
3072 default:
3073 var iconsVal = $('input[name="ays_poll_answer_icon"]:checked').val();
3074 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3075 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3076 $(document).find('.ays_label_poll').addClass('ays_poll_answer_icon_'+iconsVal);
3077 break;
3078 }
3079 }else{
3080 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3081 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3082 }
3083
3084 answerStyleChange(themeId);
3085
3086 textColorChange({
3087 color: themes[themeId].textColor
3088 });
3089 buttonTextColorChange({
3090 color: themes[themeId].buttonTextColor
3091 });
3092 buttonBgColorChange({
3093 color: themes[themeId].buttonBgColor
3094 });
3095 mainColorChange({
3096 color: themes[themeId].mainColor
3097 });
3098 bgColorChange({
3099 color: themes[themeId].bgColor
3100 });
3101 answerBgColorChange({
3102 color: themes[themeId].answerBgColor
3103 });
3104 titleBgColorChange({
3105 color: themes[themeId].titleBgColor
3106 });
3107 iconColorChange({
3108 color: themes[themeId].iconColor
3109 });
3110 borderColorChange({
3111 color: themes[themeId].borderColor
3112 });
3113 $(document).find('#ays-poll-text-color').parent().parent().prev().css({
3114 'background-color': themes[themeId].textColor
3115 });
3116 $(document).find('#ays-poll-text-color').val(themes[themeId].textColor);
3117
3118 $(document).find('#ays-poll-button-text-color').parent().parent().prev().css({
3119 'color': themes[themeId].buttonTextColor
3120 });
3121 $(document).find('#ays-poll-button-text-color').val(themes[themeId].buttonTextColor);
3122
3123 $(document).find('#ays-poll-button-bg-color').parent().parent().prev().css({
3124 'background-color': themes[themeId].buttonBgColor
3125 });
3126 $(document).find('#ays-poll-button-bg-color').val(themes[themeId].buttonBgColor);
3127
3128 $(document).find('#ays-poll-main-color').parent().parent().prev().css({
3129 'background-color': themes[themeId].mainColor
3130 });
3131 $(document).find('#ays-poll-main-color').val(themes[themeId].mainColor);
3132
3133 $(document).find('#ays-poll-bg-color').parent().parent().prev().css({
3134 'background-color': themes[themeId].bgColor
3135 });
3136 $(document).find('#ays-poll-bg-color').val(themes[themeId].bgColor);
3137
3138 $(document).find('#ays-poll-answer-bg-color').parent().parent().prev().css({
3139 'background-color': themes[themeId].answerBgColor
3140 });
3141 $(document).find('#ays-poll-answer-bg-color').val(themes[themeId].answerBgColor);
3142
3143 $(document).find('#ays-poll-answer-hover-color').closest('.wp-picker-input-wrap').prev().css({
3144 'background-color': themes[themeId].answerHoverColor
3145 });
3146 $(document).find('#ays-poll-answer-hover-color').val(themes[themeId].answerHoverColor);
3147
3148 $(document).find('#ays-poll-title-bg-color').parent().parent().prev().css({
3149 'background-color': themes[themeId].titleBgColor
3150 });
3151 $(document).find('#ays-poll-title-bg-color').val(themes[themeId].titleBgColor);
3152
3153 $(document).find('#ays-poll-icon-color').parent().parent().prev().css({
3154 'background-color': themes[themeId].iconColor
3155 });
3156 $(document).find('#ays-poll-icon-color').val(themes[themeId].iconColor);
3157
3158 $(document).find('input#ays-poll-bg-image').val('');
3159 $(document).find('#ays-poll-bg-img').attr('src', '').change();
3160 $(document).find('.ays-poll-bg-image-container').hide().change();
3161 $(document).find('#ays-poll-background-image-options').hide().change();
3162 $(document).find('.add-bg-image.button').text('Add Image');
3163 $(document).find('.add-bg-image.button').show().change();
3164 $(document).find('.box-apm.choosing-poll').css('background-image', '');
3165 $(document).find('#ays_poll_bg_image_position').val('center center').change();
3166 $(document).find("#ays_poll_bg_img_in_finish_page").prop('checked' , false).change();
3167
3168 if(themeId == 3){
3169 $(document).find('#ays-poll-border-side').val('none').change();
3170 }else{
3171 $(document).find('#ays-poll-border-side').val('all_sides').change();
3172 }
3173
3174 $(document).find('input#ays_answer_font_size').val('16').change();
3175 $(document).find('input#ays_poll_answer_font_size_mobile').val('16').change();
3176 $(document).find('input#ays_poll_answer_img_height').val('150').change();
3177 $(document).find('input#ays_poll_answer_image_height_for_mobile').val('150').change();
3178 $(document).find('input#ays_poll_answer_image_border_radius').val('0').change();
3179 $(document).find('#ays_poll_image_background_size').val('cover').change();
3180 $(document).find('input#ays_poll_answers_padding').val('10').change();
3181 $(document).find('input#ays_poll_answers_margin').val('10').change();
3182 $(document).find('input#ays_poll_answer_border_radius').val('0').change();
3183
3184 $(document).find("#ays_poll_show_answers_icon").prop('checked' , false).change();
3185
3186 $(document).find('#ays_answers_view').val('list').change();
3187 $(document).find("#ays_poll_answers_box_shadow_enable").prop('checked' , false).change();
3188 $(document).find('input#ays_poll_title_font_size').val('20').change();
3189 $(document).find('input#ays_poll_title_font_size_mobile').val('20').change();
3190 $(document).find('#ays_poll_title_alignment').val('center').change();
3191 $(document).find('#ays_poll_title_alignment_mobile').val('center').change();
3192 $(document).find("#ays_poll_enable_title_text_shadow").prop('checked' , false).change();
3193 $(document).find('input#ays-poll-icon-size').val('24').change();
3194 $(document).find('input#ays-poll-width').val('0').change();
3195 $(document).find('input#ays_poll_width_for_mobile').val('0').change();
3196 $(document).find('input#ays_poll_min_height').val('').change();
3197 $(document).find('#ays-poll-border-style').val('ridge').change();
3198 $(document).find('input#ays-poll-border-radius').val('0').change();
3199 $(document).find('input#ays-poll-border-width').val('2').change();
3200 $(document).find("#ays_poll_enable_box_shadow").prop('checked' , false).change();
3201 $(document).find("#ays-enable-background-gradient").prop('checked' , false).change();
3202 $(document).find('input#ays_questions_font_size').val('16').change();
3203 $(document).find('input#ays_poll_answers_font_size_mobile').val('16').change();
3204 $(document).find('input#ays_poll_question_image_height').val('').change();
3205 $(document).find('#ays_poll_question_image_object_fit').val('cover').change();
3206 $(document).find('input#ays_poll_mobile_max_width').val('').change();
3207 $(document).find('#ays_poll_buttons_size').val('medium').change();
3208 $(document).find('input#ays_poll_buttons_font_size').val('17').change();
3209 $(document).find('input#ays_poll_buttons_mobile_font_size').val('17').change();
3210 $(document).find('input#ays_poll_buttons_left_right_padding').val('20').change();
3211 $(document).find('input#ays_poll_buttons_top_bottom_padding').val('10').change();
3212 $(document).find('input#ays_poll_buttons_border_radius').val('3').change();
3213 $(document).find('input#ays_poll_buttons_width').val('').change();
3214 $(document).find("#ays_disable_answer_hover").prop('checked' , false).change();
3215
3216 $(document).find(".add-logo-remove-image.button").trigger('click');
3217 $(document).find('input#ays_poll_custom_class').val('').change();
3218
3219 setTimeout(function(){
3220 if($(document).find('#ays_custom_css').length > 0){
3221 if(wp.codeEditor){
3222 $(document).find('#ays_custom_css').next('.CodeMirror').remove();
3223 $(document).find('#ays_custom_css').val('');
3224 wp.codeEditor.initialize($(document).find('#ays_custom_css'), cm_settings);
3225 }
3226 }
3227 }, 100);
3228
3229 $(document).find("#tab2").goToNormal();
3230 });
3231
3232 $(document).on('mouseover', '.ays-dashicons', function(){
3233 var allRateStars = $(document).find('.ays-dashicons');
3234 var index = allRateStars.index(this);
3235 allRateStars.removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3236 for (var i = 0; i <= index; i++) {
3237 allRateStars.eq(i).removeClass('ays-dashicons-star-empty').addClass('ays-dashicons-star-filled');
3238 }
3239 });
3240
3241 $(document).on('mouseleave', '.ays-rated-link', function(){
3242 $(document).find('.ays-dashicons').removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3243 });
3244
3245 var aysPollListTables = $(document).find('#wpcontent #wpbody div.wrap.ays-poll-list-table');
3246
3247 if ( aysPollListTables.length > 0) {
3248 var listTableClass = "";
3249 var searchBox = "";
3250 if( aysPollListTables.hasClass('ays_polls_list_table') ){
3251 listTableClass = 'ays_polls_list_table';
3252 searchBox = 'poll-maker-ays-search-input';
3253 }
3254 else if( aysPollListTables.hasClass('ays_poll_categories_list_table') ){
3255 listTableClass = 'ays_poll_categories_list_table';
3256 searchBox = 'poll-maker-ays-search-input';
3257 }
3258 else if( aysPollListTables.hasClass('ays_poll_results_list_table') ){
3259 listTableClass = 'ays_poll_results_list_table';
3260 searchBox = 'poll-maker-ays-search-input';
3261 }
3262
3263 if( listTableClass != "" && searchBox != "" ){
3264 ays_poll_search_box_pagination(listTableClass, searchBox);
3265 }
3266 }
3267
3268 // Select message vars galleries page | Start
3269 $(document).find('.ays-poll-message-vars-icon').on('click', function(e){
3270 var messageVarsBox = $(this).parents(".ays-poll-message-vars-box");
3271 messageVarsBox.toggleClass("ays-poll-message-vars-open");
3272 messageVarsBox.find(".ays-poll-message-vars-data").toggle('fast');
3273 });
3274
3275 $(document).on( "click" , function(e){
3276 if($(e.target).closest('.ays-poll-message-vars-box').length != 0){
3277 }
3278 else{
3279 $(document).find(".ays-poll-message-vars-box .ays-poll-message-vars-data").hide('fast');
3280 $(document).find(".ays-poll-message-vars-box").removeClass("ays-poll-message-vars-open");
3281 }
3282 });
3283
3284 $(document).find('.ays-poll-message-vars-each-data').on('click', function(e){
3285 var _this = $(this);
3286 var parent = _this.parents('.ays-poll-desc-message-vars-parent');
3287
3288 var textarea = parent.find('textarea.ays-textarea');
3289 var textareaID = textarea.attr('id');
3290
3291 var messageVar = _this.find(".ays-poll-message-vars-each-var").val();
3292
3293 if ( parent.find("#wp-"+ textareaID +"-wrap").hasClass("tmce-active") ){
3294 window.tinyMCE.get(textareaID).setContent( window.tinyMCE.get(textareaID).getContent() + messageVar + " " );
3295 }else{
3296 $(document).find('#'+textareaID).append( " " + messageVar + " ");
3297 }
3298 });
3299 /* Select message vars galleries page | End */
3300
3301 // Check poll result as read start
3302 $(document).find('.ays-show-results').on('click', function (e) {
3303 $(document).find('#ays-results-modal').fadeIn();
3304 $(document).find('div.ays-poll-preloader').css('display', 'flex');
3305
3306 var $this = $(this);
3307 var readStatus = $this.parents('tr').find("td .unread-result-badge");
3308
3309 $('li.toplevel_page_poll-maker-ays .apm-badge.badge-danger').each(function () {
3310 var $unreadCounter = $(this);
3311
3312 if ($unreadCounter.text() != 0) {
3313 if(readStatus.hasClass('unread-result')){
3314 var counter = +$unreadCounter.text();
3315 counter--;
3316 if(counter == 0){
3317 $unreadCounter.hide();
3318 }
3319 $unreadCounter.text(counter);
3320 }
3321 }
3322 else{
3323 $unreadCounter.hide();
3324 }
3325 });
3326
3327 if(readStatus.hasClass('unread-result')){
3328 readStatus.removeClass('unread-result');
3329 }
3330
3331 $(this).css('font-weight' , 'normal');
3332 $(this).parent().css('font-weight' , 'normal');
3333 $(this).parent().siblings().css('font-weight' , 'normal');
3334 var result = $(this).data('result');
3335 var action = 'apm_show_results';
3336 var wp_nonce = $(document).find('#poll_maker_ajax_show_details_report_nonce').val();
3337 $.ajax({
3338 url: poll.ajax,
3339 dataType: 'json',
3340 method: "post",
3341 data: {
3342 result: result,
3343 action: action,
3344 _ajax_nonce: wp_nonce,
3345 is_details: 1
3346 },
3347 success: function(response) {
3348 if (response.status === true) {
3349 $('table#ays-results-table').html(response.rows);
3350 $(document).find('div.ays-poll-preloader').css('display', 'none');
3351 }
3352 }
3353 });
3354 e.preventDefault();
3355 });
3356 // Check poll result as read end
3357
3358 // Close results popup start
3359 $(document).find('#ays-close-results').on('click', function () {
3360 $(document).find('#ays-results-modal').fadeOut();
3361 });
3362 // Close results popup end
3363
3364 // Pro features start
3365 $(document).on('click', '.pro_features_popup', function(e){
3366 e.preventDefault();
3367 var _this = $(this);
3368 var popupModal = $(document).find('#pro-features-popup-modal');
3369
3370 var popupModal_title = _this.find('.pro-features-popup-title');
3371 var popupModal_title_text = popupModal_title.text();
3372
3373 var popupModal_content = _this.find('.pro-features-popup-content').html();
3374 var popupModal_video_link = _this.find('.pro-features-popup-content').attr("data-link");
3375
3376 var popupModal_button = _this.find('.pro-features-popup-button');
3377 var popupModal_button_text = popupModal_button.text();
3378 var popupModal_button_link = popupModal_button.attr("data-link");
3379
3380
3381 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3382 var rightSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-right-section');
3383
3384 rightSection.find('.pro-features-popup-modal-right-box-title').text(popupModal_title_text);
3385 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3386 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3387
3388 rightSection.find('.pro-features-popup-modal-right-box-link').text(popupModal_button_text);
3389 rightSection.find('.pro-features-popup-modal-right-box-link').attr("href", popupModal_button_link);
3390
3391 if ( typeof popupModal_video_link != "undefined" && popupModal_video_link != "") {
3392 var videoID = ays_youtube_parser(popupModal_video_link);
3393 var iframeHTML = '<iframe width="560" height="315" src="https://www.youtube.com/embed/'+ videoID +'" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen loading="lazy"></iframe>';
3394
3395 leftSection.html(iframeHTML);
3396 }
3397
3398 popupModal.aysModal('show_flex');
3399 });
3400
3401 $(document).on('click', '.ays-poll-new-watch-video-button-box, .ays-poll-center-big-watch-video-button-box', function(e){
3402 e.preventDefault();
3403 if( $(this).hasClass('ays-poll-center-big-watch-video-button-box') ){
3404 var _this = $(this).parent().parent().find('.pro_features.pro_features_popup');
3405 } else {
3406 var _this = $(this).parent().find('.pro_features.pro_features_popup');
3407 }
3408 var popupModal = $(document).find('#pro-features-popup-modal');
3409 var popupModal_title = _this.find('.pro-features-popup-title');
3410 var popupModal_title_text = popupModal_title.text();
3411
3412 var popupModal_content = _this.find('.pro-features-popup-content').html();
3413 var popupModal_video_link = _this.find('.pro-features-popup-content').attr("data-link");
3414
3415 var popupModal_button = _this.find('.pro-features-popup-button');
3416 var popupModal_button_text = popupModal_button.text();
3417 var popupModal_button_link = popupModal_button.attr("data-link");
3418
3419
3420 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3421 var rightSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-right-section');
3422
3423 rightSection.find('.pro-features-popup-modal-right-box-title').text(popupModal_title_text);
3424 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3425 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3426
3427 rightSection.find('.pro-features-popup-modal-right-box-link').text(popupModal_button_text);
3428 rightSection.find('.pro-features-popup-modal-right-box-link').attr("href", popupModal_button_link);
3429
3430 if ( typeof popupModal_video_link != "undefined" && popupModal_video_link != "") {
3431 var videoID = ays_youtube_parser(popupModal_video_link);
3432 var iframeHTML = '<iframe width="560" height="315" src="https://www.youtube.com/embed/'+ videoID +'" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen loading="lazy"></iframe>';
3433
3434 leftSection.html(iframeHTML);
3435 }
3436
3437 popupModal.aysModal('show_flex');
3438 });
3439
3440 $(document).find('.ays-close-pro-popup').on('click', function () {
3441 $(this).parents('.ays-modal').aysModal('hide_remove_video');
3442 });
3443 // // Pro features end
3444
3445 $(document).on("click", ".ays-poll-cards-block .ays-poll-card__footer button.status-missing", function(e){
3446 var $this = $(this);
3447 var thisParent = $this.parents(".ays-poll-cards-block");
3448
3449 $this.prop('disabled', true);
3450 $this.addClass('disabled');
3451
3452 var loader_html = '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>';
3453
3454 $this.html(loader_html);
3455
3456 var attr_plugin = $this.attr('data-plugin');
3457 var wp_nonce = thisParent.find('#ays_poll_ajax_install_plugin_nonce').val();
3458
3459 var data = {
3460 action: 'ays_poll_install_plugin',
3461 _ajax_nonce: wp_nonce,
3462 plugin: attr_plugin,
3463 type: 'plugin'
3464 };
3465
3466 $.ajax({
3467 url: poll.ajax,
3468 method: 'post',
3469 dataType: 'json',
3470 data: data,
3471 success: function (response) {
3472 if (response.success) {
3473 swal.fire({
3474 type: 'success',
3475 html: "<h4>"+ response['data']['msg'] +"</h4>"
3476 }).then( function(res) {
3477 if ( $this.hasClass('status-missing') ) {
3478 $this.removeClass('status-missing');
3479 }
3480 $this.text(poll.activated);
3481 $this.addClass('status-active');
3482 });
3483 }
3484 else {
3485 swal.fire({
3486 type: 'info',
3487 html: "<h4>"+ response['data'][0]['message'] +"</h4>"
3488 }).then( function(res) {
3489 $this.text(poll.errorMsg);
3490 });
3491 }
3492 },
3493 error: function(){
3494 swal.fire({
3495 type: 'info',
3496 html: "<h2>"+ poll.loadResource +"</h2><br><h6>"+ poll.somethingWentWrong +"</h6>"
3497 }).then( function(res) {
3498 $this.text(poll.errorMsg);
3499 });
3500 }
3501 });
3502 });
3503
3504 $(document).on("click", ".ays-poll-cards-block .ays-poll-card__footer button.status-installed", function(e){
3505 var $this = $(this);
3506 var thisParent = $this.parents(".ays-poll-cards-block");
3507
3508 $this.prop('disabled', true);
3509 $this.addClass('disabled');
3510
3511 var loader_html = '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>';
3512
3513 $this.html(loader_html);
3514
3515 var attr_plugin = $this.attr('data-plugin');
3516 var wp_nonce = thisParent.find('#ays_poll_ajax_install_plugin_nonce').val();
3517
3518 var data = {
3519 action: 'ays_poll_activate_plugin',
3520 _ajax_nonce: wp_nonce,
3521 plugin: attr_plugin,
3522 type: 'plugin'
3523 };
3524
3525 $.ajax({
3526 url: poll.ajax,
3527 method: 'post',
3528 dataType: 'json',
3529 data: data,
3530 success: function (response) {
3531 if( response.success ){
3532 swal.fire({
3533 type: 'success',
3534 html: "<h4>"+ response['data'] +"</h4>"
3535 }).then( function(res) {
3536 if ( $this.hasClass('status-installed') ) {
3537 $this.removeClass('status-installed');
3538 }
3539 $this.text(poll.activated);
3540 $this.addClass('status-active disabled');
3541 });
3542 } else {
3543 swal.fire({
3544 type: 'info',
3545 html: "<h4>"+ response['data'][0]['message'] +"</h4>"
3546 });
3547 }
3548 },
3549 error: function(){
3550 swal.fire({
3551 type: 'info',
3552 html: "<h2>"+ poll.loadResource +"</h2><br><h6>"+ poll.somethingWentWrong +"</h6>"
3553 }).then( function(res) {
3554 $this.text(poll.errorMsg);
3555 });
3556 }
3557 });
3558 });
3559
3560 // Replace image to YouTube embed video
3561 $(document).on('click', '.ays-poll-youtube-placeholder', function() {
3562 var videoId = $(this).data('video-id');
3563 var iframe = $('<iframe>', {
3564 src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1',
3565 class: '',
3566 width: 560,
3567 height: 315,
3568 frameborder: 0,
3569 allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
3570 allowfullscreen: true,
3571 });
3572 $(this).replaceWith(iframe);
3573 });
3574
3575 })(jQuery);
3576
3577 document.addEventListener("DOMContentLoaded", function() {
3578 var startDate = new Date("2025-09-21");
3579 var endDate = new Date("2025-10-21");
3580 var totalLicenses = 50;
3581 var progressionPattern = new Array(3, 2, 1, 4, 2, 3, 1, 2, 4, 3, 2, 1, 3, 2, 4, 1, 3, 2, 2, 3, 1, 2);
3582 function getCurrentProgress() {
3583 var today = new Date();
3584 // today.setDate(today.getDate() + 1);
3585 var daysPassed = Math.floor((today - startDate) / (1000 * 60 * 60 * 24));
3586 var usedLicenses = 0;
3587 for (var i = 0; i < Math.min(daysPassed, progressionPattern.length); i++) {
3588 usedLicenses += progressionPattern[i];
3589 }
3590 return Math.min(usedLicenses, totalLicenses);
3591 }
3592 function updateProgress() {
3593 var usedLicenses = getCurrentProgress();
3594 var remainingLicenses = totalLicenses - usedLicenses;
3595 var progressPercentage = (usedLicenses / totalLicenses) * 100;
3596 var remainingElement = document.getElementById("remaining-licenses");
3597 var progressElement = document.getElementById("progress-fill");
3598 if (remainingElement) remainingElement.textContent = remainingLicenses;
3599 if (progressElement) progressElement.style.width = progressPercentage + "%";
3600 }
3601 updateProgress();
3602 });
3603
3604 // Copy to clipboard function
3605 function pollCopyToClipboard(text) {
3606 if (navigator.clipboard && window.isSecureContext) {
3607 navigator.clipboard.writeText(text).then(function() {
3608 pollShowCopyNotification(pollLangObj.successCopyCoupon);
3609 }).catch(function() {
3610 fallbackCopyTextToClipboard(text);
3611 });
3612 } else {
3613 fallbackCopyTextToClipboard(text);
3614 }
3615 }
3616
3617 function fallbackCopyTextToClipboard(text) {
3618 var textArea = document.createElement("textarea");
3619 textArea.value = text;
3620 textArea.style.position = "fixed";
3621 textArea.style.top = "-9999px";
3622 textArea.style.left = "-9999px";
3623 document.body.appendChild(textArea);
3624 textArea.focus();
3625 textArea.select();
3626 try {
3627 var successful = document.execCommand("copy");
3628 if (successful) {
3629 pollShowCopyNotification(pollLangObj.successCopyCoupon);
3630 } else {
3631 pollShowCopyNotification(pollLangObj.failedCopyCoupon);
3632 }
3633 } catch (err) {
3634 pollShowCopyNotification(pollLangObj.failedCopyCoupon);
3635 }
3636 document.body.removeChild(textArea);
3637 }
3638
3639 function pollShowCopyNotification(message) {
3640 var notification = document.createElement("div");
3641 notification.className = "ays-poll-copy-notification show";
3642 console.log(notification);
3643 notification.textContent = message;
3644 document.body.appendChild(notification);
3645 setTimeout(function() {
3646 notification.classList.remove("show");
3647 setTimeout(function() {
3648 document.body.removeChild(notification);
3649 }, 300);
3650 }, 2000);
3651 }
3652
3653 function selectElementContents(el) {
3654 if (window.getSelection && document.createRange) {
3655 var _this = jQuery(document).find('strong.ays-poll-shortcode-box');
3656 var text = el.textContent;
3657 var textField = document.createElement('textarea');
3658
3659 textField.innerText = text;
3660 document.body.appendChild(textField);
3661 textField.select();
3662 document.execCommand('copy');
3663 textField.remove();
3664 var sel = window.getSelection();
3665 var range = document.createRange();
3666 range.selectNodeContents(el);
3667 sel.removeAllRanges();
3668 sel.addRange(range);
3669 _this.attr( "data-original-title", pollLangObj.copied );
3670 _this.attr( "title", pollLangObj.copied );
3671 _this.tooltip("show");
3672 } else if (document.selection && document.body.createTextRange) {
3673 var textRange = document.body.createTextRange();
3674 textRange.moveToElementText(el);
3675 textRange.select();
3676 }
3677 }
3678
3679 Date.prototype.aysPollCustomFormat = function( formatString){
3680 var YYYY,YY,MMMM,MMM,MM,M,DDDD,DDD,DD,D,hhhh,hhh,hh,h,mm,m,ss,s,ampm,AMPM,dMod,th;
3681 YY = ((YYYY=this.getFullYear())+"").slice(-2);
3682 MM = (M=this.getMonth()+1)<10?('0'+M):M;
3683 MMM = (MMMM=["January","February","March","April","May","June","July","August","September","October","November","December"][M-1]).substring(0,3);
3684 DD = (D=this.getDate())<10?('0'+D):D;
3685 DDD = (DDDD=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][this.getDay()]).substring(0,3);
3686 th=(D>=10&&D<=20)?'th':((dMod=D%10)==1)?'st':(dMod==2)?'nd':(dMod==3)?'rd':'th';
3687 formatString = formatString.replace("#YYYY#",YYYY).replace("#YY#",YY).replace("#MMMM#",MMMM).replace("#MMM#",MMM).replace("#MM#",MM).replace("#M#",M).replace("#DDDD#",DDDD).replace("#DDD#",DDD).replace("#DD#",DD).replace("#D#",D).replace("#th#",th);
3688 h=(hhh=this.getHours());
3689 if (h==0) h=24;
3690 if (h>12) h-=12;
3691 hh = h<10?('0'+h):h;
3692 hhhh = hhh<10?('0'+hhh):hhh;
3693 AMPM=(ampm=hhh<12?'am':'pm').toUpperCase();
3694 mm=(m=this.getMinutes())<10?('0'+m):m;
3695 ss=(s=this.getSeconds())<10?('0'+s):s;
3696
3697 return formatString.replace("#hhhh#",hhhh).replace("#hhh#",hhh).replace("#hh#",hh).replace("#h#",h).replace("#mm#",mm).replace("#m#",m).replace("#ss#",ss).replace("#s#",s).replace("#ampm#",ampm).replace("#AMPM#",AMPM);
3698 // token: description: example:
3699 // #YYYY# 4-digit year 1999
3700 // #YY# 2-digit year 99
3701 // #MMMM# full month name February
3702 // #MMM# 3-letter month name Feb
3703 // #MM# 2-digit month number 02
3704 // #M# month number 2
3705 // #DDDD# full weekday name Wednesday
3706 // #DDD# 3-letter weekday name Wed
3707 // #DD# 2-digit day number 09
3708 // #D# day number 9
3709 // #th# day ordinal suffix nd
3710 // #hhhh# 2-digit 24-based hour 17
3711 // #hhh# military/24-based hour 17
3712 // #hh# 2-digit hour 05
3713 // #h# hour 5
3714 // #mm# 2-digit minute 07
3715 // #m# minute 7
3716 // #ss# 2-digit second 09
3717 // #s# second 9
3718 // #ampm# "am" or "pm" pm
3719 // #AMPM# "AM" or "PM" PM
3720 };
3721
3722 function drawBasic() {
3723 if(typeof pollAnswerChartObj != "undefined"){
3724 var data = google.visualization.arrayToDataTable(pollAnswerChartObj.answerData);
3725 var rowCount = data.getNumberOfRows();
3726 var multiply;
3727 if(rowCount < 8){
3728 multiply = 40;
3729 }
3730 else{
3731 multiply = 30;
3732 }
3733 var chartAreaHeight = rowCount * multiply;
3734 var chartHeight = chartAreaHeight + 80;
3735
3736 /* === Old type === */
3737 // var options = {
3738 // title: pollAnswerChartObj.pollTitle,
3739 // width: '100%',
3740 // fontSize: 15,
3741 // height: chartHeight,
3742 // chartArea: {
3743 // width: '75%',
3744 // height: '80%'
3745 // },
3746 // hAxis: {
3747 // minValue: 0
3748 // }
3749 // };
3750
3751 /* === New type === */
3752 var options = {
3753 title: pollAnswerChartObj.pollTitle,
3754 width: '100%',
3755 height: chartHeight,
3756 fontSize: 15,
3757 chartArea: {
3758 width: '50%',
3759 height: '80%'
3760 },
3761 hAxis: {
3762 minValue: 0
3763 },
3764 annotations: {
3765 alwaysOutside: true
3766 },
3767 bars: 'horizontal',
3768 bar: { groupWidth: "50%" }
3769 };
3770
3771 var chart = new google.visualization.BarChart(document.getElementById('ays_poll_answer_chart'));
3772 // remove error
3773 // google.visualization.events.(chart, 'error', function (googleError) {
3774 // google.visualization.errors.removeError(googleError.id);
3775 // });
3776
3777 chart.draw(data, options);
3778 resizeChart(chart, data, options);
3779 }
3780 }
3781
3782 function resizeChart(chart, data, options){
3783
3784 //create trigger to resizeEnd event
3785 jQuery(window).resize(function() {
3786 if(this.resizeTO) clearTimeout(this.resizeTO);
3787 this.resizeTO = setTimeout(function() {
3788 jQuery(this).trigger('resizeEnd');
3789 }, 100);
3790 });
3791
3792 //redraw graph when window resize is completed
3793 jQuery(window).on('resizeEnd', function() {
3794 chart.draw(data, options);
3795 });
3796 }
3797
3798 function selectAndCopyElementContents(el) {
3799 if (window.getSelection && document.createRange) {
3800 var _this = jQuery(document).find('.ays-poll-copy-element-box');
3801
3802 var text = el.textContent;
3803 var textField = document.createElement('textarea');
3804
3805 textField.innerText = text;
3806 document.body.appendChild(textField);
3807 textField.select();
3808 document.execCommand('copy');
3809 textField.remove();
3810
3811 var selection = window.getSelection();
3812 selection.setBaseAndExtent(el,0,el,1);
3813
3814 _this.attr( "data-original-title", pollLangObj.copied );
3815 _this.attr( "title", pollLangObj.copied );
3816
3817 _this.tooltip("show");
3818
3819 } else if (document.selection && document.body.createTextRange) {
3820 var textRange = document.body.createTextRange();
3821 textRange.moveToElementText(el);
3822 textRange.select();
3823 }
3824 }
3825