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

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

3,847 lines 161.9 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_font_weight,#ays_poll_title_alignment,#ays_poll_title_text_transform,#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 titleDefaultFontWeight = "normal";
1938 var answersBorderRadiusDefault = "0";
1939
1940 // Boxes
1941 var imageBoxes = $(document).find('.box-apm .ays-poll-answer-image-live');
1942 var answerLabelBoxes = $(document).find('.box-apm label.ays-poll-answer-more-options');
1943 var answerMainBoxes = $(document).find('.box-apm .apm-choosing');
1944 // Answer Font size
1945 var answerFontSizeMain = $(document).find("#ays_answer_font_size");
1946 var answerFontSize = answerFontSizeMain.val();
1947 // Answer Font size mobile
1948 var answerFontSizeMobileMain = $(document).find("#ays_poll_answer_font_size_mobile");
1949 // Border color
1950 var borderColor = $(document).find("#ays-poll-border-color").val();
1951 // Image Height option
1952 var imageHeight = $(document).find('#ays_poll_answer_img_height').val();
1953 // Image border radius option
1954 var imageBorderRadius = $(document).find('#ays_poll_answer_image_border_radius').val();
1955 // Answer Image object-fit
1956 var imageBgSizeSelect = $(document).find('#ays_poll_image_background_size');
1957 var imageBgSizeVal = imageBgSizeSelect.val();
1958 // Answer padding
1959 var answersPadding = $(document).find('#ays_poll_answers_padding');
1960 var answersPaddingVal = answersPadding.val();
1961 // Answer Gap
1962 var answersMargin = $(document).find('#ays_poll_answers_margin');
1963 var answersMarginVal = answersMargin.val();
1964 // Answer Border radius
1965 var answersBorderRadiusMain = $(document).find('#ays_poll_answer_border_radius');
1966 var answersBorderRadius = answersBorderRadiusMain.val();
1967 // Question image height
1968 var questionImageHeight = $(document).find("#ays_poll_question_image_height").val();
1969 var questionHeight = questionImageHeight == "" ? "100%" : questionImageHeight+"px";
1970 // Question image object-fit
1971 var questionImageObjectFit = $(document).find("#ays_poll_question_image_object_fit").val();
1972 $(document).find(".box-apm .apm-img-box .ays-poll-img").css({"object-fit" : questionImageObjectFit});
1973 // Poll Answer view type
1974 var viewType = $(document).find('#ays_answers_view').val();
1975 var answersCont = $(document).find('.apm-answers');
1976 var answersField = answersCont.find('.ays-poll-field');
1977 var checkTextType = $(document).find('.box-apm.text-poll').length > 0 ? true : false;
1978 // Title font size
1979 var titleFontSizeBox = $(document).find("#ays_poll_title_font_size");
1980 var titleFontSize = titleFontSizeBox.val();
1981 // Title font weight
1982 var titleFontWeightBox = $(document).find("#ays_poll_title_font_weight");
1983 var titleFontWeight = titleFontWeightBox.val();
1984 // Poll text type placeholder
1985 var textPlaceholder = $(document).find("#ays_poll_text_type_placeholder");
1986 var textPlaceholderVal = textPlaceholder.val();
1987 $(document).find('.ays-poll-text-type-fields').attr('placeholder' , textPlaceholderVal);
1988 answersCont.find('.ays_label_poll').css({
1989 'display': 'flex',
1990 });
1991 // Title alignment
1992 var titleAlignment = $(document).find("#ays_poll_title_alignment").val();
1993 // Title text transform
1994 var titleTextTransform = $(document).find("#ays_poll_title_text_transform").val();
1995
1996 if(parseInt(imageHeight) < 0){
1997 imageHeight = 0;
1998 $(document).find('#ays_poll_answer_img_height').val(imageHeight);
1999 }
2000 //
2001
2002 //
2003 // Answer box shadow
2004 var answersBoxShadow = $(document).find('#ays_poll_answers_box_shadow_enable').prop('checked');
2005 var answersBoxShadowColor = $(document).find('#ays_poll_answers_box_shadow_color').val();
2006 var answersBoxShadowXOffset = $(document).find('#ays_poll_answer_box_shadow_x_offset').val();
2007 var answersBoxShadowYOffset = $(document).find('#ays_poll_answer_box_shadow_y_offset').val();
2008 var answersBoxShadowZOffset = $(document).find('#ays_poll_answer_box_shadow_z_offset').val();
2009 if(answersBoxShadow){
2010 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
2011 'box-shadow': answersBoxShadowXOffset+'px '+answersBoxShadowYOffset+'px '+answersBoxShadowZOffset+'px '+answersBoxShadowColor,
2012 });
2013 }else{
2014 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
2015 'box-shadow': 'none',
2016 });
2017 }
2018
2019
2020 if(parseInt(answersPaddingVal) < 0){
2021 answersPaddingVal = 0;
2022 answersPadding.val(answersPaddingVal);
2023 }
2024
2025 if(parseInt(answersMarginVal) <= 0){
2026 answersMarginVal = 1;
2027 answersMargin.val(answersMarginVal);
2028 }
2029
2030 if(!checker){
2031 imageBgSizeVal = imageDefaulObjFit;
2032 answersPaddingVal = answerDefaultPadding;
2033 imageHeight = imageDefaultHeight;
2034 answersMarginVal = answerDefaultGap;
2035 answerFontSize = answerDefaultFontSize;
2036 answerFontSizeMain.val(answerDefaultFontSize);
2037 answerFontSizeMobileMain.val(answerDefaultFontSize);
2038 titleFontWeight = titleDefaultFontWeight;
2039 titleFontWeightBox.val(titleDefaultFontWeight);
2040 answersBorderRadius = answersBorderRadiusDefault;
2041 answersBorderRadiusMain.val(answersBorderRadiusDefault);
2042 }
2043 // Image Changes
2044 imageBoxes.css({
2045 'height': imageHeight+'px',
2046 'border-radius': imageBorderRadius+'px',
2047 'object-fit': imageBgSizeVal
2048 });
2049
2050 // Answer changes
2051 answerLabelBoxes.css({
2052 'padding': answersPaddingVal+'px'
2053 });
2054
2055 answerMainBoxes.css({
2056 'margin-bottom': answersMarginVal+'px'
2057 });
2058
2059 // Question font size
2060 var pattern = /Android|webOS|iPhone|iPad|Mac|Macintosh|iPod|BlackBerry|IEMobile|Opera Mini/i;
2061 var questnionFontSize;
2062 if( pattern.test(navigator.userAgent) ) {
2063 questnionFontSize = $(document).find("#ays_poll_answers_font_size_mobile").val();
2064 }
2065 else{
2066 questnionFontSize = $(document).find("#ays_poll_answers_font_size_pc").val();
2067 }
2068 $(document).find('.ays_question,.ays_question p').css({ 'font-size': questnionFontSize+"px" });
2069
2070 $(document).find('.ays_label_font_size').css("font-size" , answerFontSize + "px");
2071 $(document).find('.box-apm').css("border-color" , borderColor);
2072
2073 $(document).find(".apm-img-box img.ays-poll-img").css({"height" : questionHeight});
2074
2075 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
2076 'border-radius': +answersBorderRadius+"px",
2077 });
2078
2079 if(titleFontSize < 0){
2080 titleFontSize = 0;
2081 titleFontSizeBox.val(0);
2082 }
2083 $(document).find('.apm-title-box h5').css({
2084 "font-size" : titleFontSize + "px",
2085 "font-weight" : titleFontWeight,
2086 "text-align" : titleAlignment,
2087 "text-transform" : titleTextTransform,
2088 });
2089 if(viewType == 'list'){
2090 $(document).find('.grid_column_count').hide(250);
2091 answersCont.removeClass('ays_poll_grid_view_container');
2092 answersCont.addClass('ays_poll_list_view_container');
2093 answersField.removeClass('ays_poll_grid_view_item');
2094 answersField.addClass('ays_poll_list_view_item');
2095
2096 answersCont.find('.ays-poll-field.ays_poll_list_view_item').css({
2097 'margin-right': 0,
2098 });
2099 answersCont.find('.ays-poll-answer-image-live').css({
2100 'width': '220px',
2101 });
2102 answersCont.find('span.ays-poll-each-answer').css({
2103 'width': 'initial',
2104 'text-align': 'initial',
2105 'display': 'initial',
2106 });
2107 answersCont.find('.ays_label_poll').css({
2108 'align-items': 'center',
2109 'flex-direction': 'row',
2110 });
2111 }else if(viewType == 'grid' && !checkTextType){
2112 $(document).find('.grid_column_count').show(250);
2113 answersCont.removeClass('ays_poll_list_view_container');
2114 answersCont.addClass('ays_poll_grid_view_container');
2115 answersField.removeClass('ays_poll_list_view_item');
2116 answersField.addClass('ays_poll_grid_view_item');
2117
2118 answersCont.find('.ays-poll-answer-image-live').css({
2119 'width': '100%',
2120 });
2121
2122 answersCont.find('span.ays-poll-each-answer').css({
2123 'width': '100%',
2124 'text-align': 'center',
2125 'display': 'inline-block',
2126 });
2127
2128 var innerLabel = answersField.find("label.ays_poll_label_without_padding");
2129 if(innerLabel.length > 0){
2130 innerLabel.css({
2131 'flex-direction': 'column',
2132 });
2133 }
2134 }
2135 }
2136
2137 var heart_interval = setInterval(function () {
2138 $(document).find('.ays-poll-maker-wrapper i.ays_fa').toggleClass('ays_poll_pulse');
2139 }, 1000);
2140
2141 $(document).on('change' , '.ays-answer-value', function(){
2142 livePrevToChoosing("choosing");
2143 var checkAnswerStyleOnChange = $(document).find("#ays_poll_enable_answer_style").prop("checked");
2144 refreshLivePreview(checkAnswerStyleOnChange);
2145 });
2146
2147 $('#ays_poll_info_form').on('change', function () {
2148 var propCheck = $(this).prop("checked");
2149 var allowCollect = $(document).find(".ays_toggle_target_inverse");
2150 if(propCheck){
2151 allowCollect.find('#ays_allow_collecting_logged_in_users_data').prop("checked" , false);
2152 allowCollect.hide();
2153 }
2154 else{
2155 if(allowCollect.hasClass("display_none")){
2156 allowCollect.removeClass("display_none");
2157 }
2158 allowCollect.show();
2159 }
2160 $('.ays-poll-if-form-on').fadeToggle();
2161 });
2162
2163 // Pro features
2164 $(document).find('#ays_answers_border_color').wpColorPicker({
2165 change: function(event, ui) {
2166 }
2167 });
2168
2169 $(document).find("#ays_see_result_show").on("change" , function(){
2170 var checker = $(this).prop("checked");
2171 var buttonsCont = $(document).find("#ays_poll_show_hide_button");
2172 if(checker){
2173 buttonsCont.show(200);
2174 buttonsCont.css("display" , "flex");
2175 }
2176 else{
2177 buttonsCont.hide(200);
2178 }
2179 });
2180
2181 $(document).find('.ays-poll-question-tab-all-filter-button-top, .ays-poll-question-tab-all-filter-button-bottom, .description-filter-apply-top, .description-filter-apply-bottom').on('click', function(e) {
2182 e.preventDefault();
2183 var $this = $(this);
2184 var parent = $this.parents('.tablenav');
2185
2186 var searchForm = parent.parent();
2187 var searchInput = searchForm.find('input#poll-maker-ays-search-input')
2188 var searchValue = searchInput.val();
2189
2190 var html_name = '';
2191 var top_or_bottom = 'top';
2192
2193 if ( parent.hasClass('bottom') ) {
2194 top_or_bottom = 'bottom';
2195 }
2196
2197 var catFilter = $(document).find('select[name="filterby-'+ top_or_bottom +'"]').val();
2198 var catDescFilter = $(document).find('select[name="filterbyDescription-'+ top_or_bottom +'"]').val();
2199 var authorFilter = $(document).find('select[name="filterbyauthor-'+ top_or_bottom +'"]').val();
2200 var typeFilter = $(document).find('select[name="filterbytype-'+ top_or_bottom +'"]').val();
2201 var link = location.href;
2202
2203 if (typeof catFilter != "undefined") {
2204 link = catFilterForListTable(link, searchValue, {
2205 what: 'filterby',
2206 value: catFilter
2207 });
2208 }
2209 if (typeof catDescFilter != "undefined") {
2210 link = catFilterForListTable(link, searchValue, {
2211 what: 'filterbyDescription',
2212 value: catDescFilter
2213 });
2214 }
2215 if (typeof authorFilter != "undefined") {
2216 link = catFilterForListTable(link, searchValue, {
2217 what: 'filterbyauthor',
2218 value: authorFilter
2219 });
2220 }
2221 if (typeof typeFilter != "undefined") {
2222 link = catFilterForListTable(link,searchValue, {
2223 what: 'filterbytype',
2224 value: typeFilter
2225 });
2226 }
2227 document.location.href = link;
2228 })
2229
2230 function catFilterForListTable(link, searchValue, options){
2231 if( options.value != '' ){
2232 options.value = "&" + options.what + "=" + options.value;
2233 var linkModifiedStart = link.split('?')[0];
2234 var linkModified = link.split('?')[1].split('&');
2235 for(var i = 0; i < linkModified.length; i++){
2236 if ( linkModified[i].split("=")[0] == "ays_result_tab" ) {
2237 linkModified.splice(i, 1, "ays_result_tab=poststuff");
2238 }
2239 if(linkModified[i].split("=")[0] == options.what || linkModified[i].split("=")[0] == 'paged'){
2240 linkModified.splice(i, 1);
2241 i--;
2242 }
2243 }
2244 linkModified = linkModified.join('&');
2245 if (typeof searchValue != 'undefined' && searchValue != '') {
2246 linkModified = linkModified + "&s=" + searchValue;
2247 }
2248 return linkModifiedStart + "?" + linkModified + options.value;
2249 }else{
2250 var linkModifiedStart = link.split('?')[0];
2251 var linkModified = link.split('?')[1].split('&');
2252 for(var i = 0; i < linkModified.length; i++){
2253 if(linkModified[i].split("=")[0] == options.what || linkModified[i].split("=")[0] == 'paged'){
2254 linkModified.splice(i, 1);
2255 i--;
2256 }
2257 }
2258 linkModified = linkModified.join('&');
2259 if (typeof searchValue != 'undefined' && searchValue != '') {
2260 linkModified = linkModified + "&s=" + searchValue;
2261 }
2262 return linkModifiedStart + "?" + linkModified;
2263 }
2264 }
2265
2266 $(document).find('input[type="submit"]#doaction, input[type="submit"]#doaction2').on('click', function(e) {
2267 showConfirmationIfDelete(e);
2268 })
2269
2270 $(document).find("input#poll-maker-ays-search-input + input#search-submit").on("click", function (e) {
2271 var _this = $(this);
2272 var parent = _this.parents('form');
2273
2274 var search_input = parent.find('input#poll-maker-ays-search-input');
2275 var input_value = search_input.val();
2276
2277 var field = 's';
2278 var flag = false;
2279 var url = window.location.href;
2280 if(url.indexOf('?' + field + '=') != -1){
2281 flag = true;
2282 }
2283 else if(url.indexOf('&' + field + '=') != -1){
2284 flag = true;
2285 }
2286
2287 if (flag) {
2288 if (typeof input_value != 'undefined' && input_value != "") {
2289 e.preventDefault();
2290 location.href=location.href.replace(/&s=([^&]$|[^&]*)/i, "&s="+input_value);
2291 }
2292 }
2293 });
2294
2295 function showConfirmationIfDelete(e) {
2296 var $el = $(e.target);
2297 var elParent = $el.parent();
2298 var actionSelect = elParent.find('select[name="action"]');
2299 var action = actionSelect.val();
2300
2301 if (action === 'bulk-delete') {
2302 e.preventDefault();
2303 var confirmDelete = confirm('Are you sure you want to delete?');
2304
2305 if (confirmDelete) {
2306 var form = $el.closest('form');
2307 form.submit()
2308 }
2309 }
2310 }
2311
2312 $(document).on('click', '.ays_polls_each_results_list_table th.manage-column a', function(e) {
2313 var href = $(this).attr('href');
2314 $(this).attr('href', href + '&ays_poll_tab_results=tab2');
2315 })
2316
2317 $(document).on("click", "#ays-poll-dismiss-buttons-content .ays-button, #ays-poll-dismiss-buttons-content-helloween .ays-button-helloween", function(e){
2318 e.preventDefault();
2319
2320 var $this = $(this);
2321 var thisParent = $this.parents("#ays-poll-dismiss-buttons-content");
2322 var mainParent = $this.parents("div.ays_poll_dicount_info");
2323 var closeButton = mainParent.find("button.notice-dismiss");
2324 var attr_plugin = $this.attr('data-plugin');
2325 var wp_nonce = thisParent.find('#poll-maker-ays-sale-banner').val();
2326
2327 if(typeof wp_nonce == 'undefined'){
2328 wp_nonce = $(document).find('#poll-maker-ays-sale-banner').val();
2329 }
2330
2331 var data = {
2332 action: 'ays_poll_dismiss_button',
2333 _ajax_nonce: wp_nonce,
2334 };
2335
2336 $.ajax({
2337 url: poll.ajax,
2338 method: 'post',
2339 dataType: 'json',
2340 data: data,
2341 success: function (response) {
2342 if( response.status ){
2343 closeButton.trigger('click');
2344 } else {
2345 swal.fire({
2346 type: 'info',
2347 html: "<h2>"+ pollLangObj.errorMsg +"</h2><br><h6>"+ pollLangObj.somethingWentWrong +"</h6>"
2348 }).then(function(res) {
2349 closeButton.trigger('click');
2350 });
2351 }
2352 },
2353 error: function(){
2354 swal.fire({
2355 type: 'info',
2356 html: "<h2>"+ pollLangObj.errorMsg +"</h2><br><h6>"+ pollLangObj.somethingWentWrong +"</h6>"
2357 }).then(function(res) {
2358 closeButton.trigger('click');
2359 });
2360 }
2361 });
2362 });
2363
2364 $(document).keydown(function(event) {
2365 var editButton = $(document).find("input#ays-button-top-apply,input#ays-button-apply,input#ays_submit");
2366 if (!(event.which == 83 && event.ctrlKey) && !(event.which == 19)){
2367 return true;
2368 }
2369 editButton.trigger("click");
2370 event.preventDefault();
2371 return false;
2372 });
2373
2374 function aysPollGetCookie(c_name) {
2375 if (document.cookie.length > 0) {
2376 var c_start = document.cookie.indexOf(c_name + "=");
2377 if (c_start != -1) {
2378 c_start = c_start + c_name.length + 1;
2379 var c_end = document.cookie.indexOf(";", c_start);
2380 if (c_end == -1) {
2381 c_end = document.cookie.length;
2382 }
2383 return unescape(document.cookie.substring(c_start, c_end));
2384 }
2385 }
2386 return "";
2387 }
2388 // Check new added Poll start
2389 var createdNewPoll = aysPollGetCookie('ays_poll_created_new');
2390 if(createdNewPoll && createdNewPoll > 1){
2391 var url = new URL(window.location.href);
2392
2393 var getCustomPostId = aysPollGetCookie('ays_poll_created_new_'+createdNewPoll+'_post_id');
2394
2395 var link = "#";
2396 if(getCustomPostId){
2397 link = getCustomPostId;
2398 }
2399
2400 // Get a specific GET parameter by name
2401 var parameterValue = url.searchParams.get("action");
2402 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>';
2403
2404 var htmlContent = parameterValue && parameterValue == 'edit' ? '' : htmlDefaultText;
2405
2406 var previewButtonSvgIcon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">'+
2407 '<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"/>'+
2408 '</svg>';
2409
2410 swal({
2411 title: '<strong class="ays-poll-maker-swal2-title">' + pollLangObj.greateJob + '</strong>',
2412 type: 'success',
2413 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,
2414 showCancelButton: true,
2415 showCloseButton: true,
2416 focusConfirm: false,
2417 cancelButtonClass: "ays-poll-preview-popup-cancel-button",
2418 confirmButtonText: '<i class="ays_poll_fas ays_poll_fa_thumbs_up"></i> '+ pollLangObj.done,
2419 confirmButtonAriaLabel: pollLangObj.thumbsUpGreat,
2420 cancelButtonText: '<a href="'+ link +'" target="_blank">'+ pollLangObj.preivewPoll + ' ' + previewButtonSvgIcon +'</a>',
2421 cancelButtonAriaLabel: pollLangObj.thumbsUpGreat,
2422
2423 });
2424 aysPollDeleteCookie('ays_poll_created_new');
2425 aysPollDeleteCookie('ays_poll_created_new_'+createdNewPoll+'_post_id');
2426 }
2427
2428 function aysPollDeleteCookie(name) {
2429 document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
2430 }
2431
2432 // Select default category for poll
2433 $(document).find("#ays_poll_default_type").select2();
2434
2435 // Check if submit button clicked for unsaved changes confirmation box
2436 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';
2437 $(document).on('click', subButtons ,function () {
2438 var $this = $(this);
2439 $this.addClass('ays-submit-button-clicked');
2440 });
2441
2442 var aysUnsavedChanges = false;
2443 var formInputs = '#ays-poll-form .ays-poll-tab-content input, #ays-poll-form .ays-poll-tab-content select, ' +
2444 '#ays-poll-form .ays-poll-tab-content textarea, #ays-poll-category-form input, ' +
2445 '#ays-poll-category-form select, #ays-poll-category-form textarea, ' +
2446 '#ays-poll-general-settings-form input, #ays-poll-general-settings-form select, ' +
2447 '#ays-poll-general-settings-form textarea';
2448
2449 $(document).on('change input', formInputs, function() {
2450 aysUnsavedChanges = true;
2451 });
2452
2453 $(window).on('beforeunload', function(event) {
2454 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');
2455 var savingButtonsClicked = saveButtons.filter('.ays-submit-button-clicked').length > 0;
2456
2457 if (aysUnsavedChanges && !savingButtonsClicked) {
2458 event.preventDefault();
2459 event.returnValue = true;
2460 }
2461 });
2462
2463
2464 $(document).find("#ays_poll_default_cat").select2({
2465 multiple: true
2466 });
2467
2468 // Create and Delete rows in Answers table
2469 $(document).on("keydown" , "input[name='ays-poll-answers[]']" , function(event) {
2470 var $thisValue = $(this).val();
2471 if (event.keyCode === 13) {
2472 if($(this).hasClass("ays_poll_enter_key")){
2473 var editButton = $(document).find(".ays-click-once");
2474 editButton.trigger("click");
2475 event.preventDefault();
2476 }
2477 else{
2478 var nextInput = $(this).parents("tr").next().find("td.ays-choosing-answer-container input:nth-child(1)");
2479 nextInput.focus();
2480 var oldValue = nextInput.val();
2481 nextInput.val(" ");
2482 nextInput.val(oldValue);
2483 }
2484 }
2485 else if(event.keyCode === 8 && $thisValue == ""){
2486 var editButton = $(this).parents("tr").find("a.ays-delete-answer");
2487 editButton.trigger("click");
2488 event.preventDefault();
2489 }
2490
2491 });
2492
2493 var drawChartLink = $(document).find(".ays_poll_answer_chart_active");
2494 if(drawChartLink.hasClass("nav-tab-active")){
2495 google.charts.load('current', {packages: ['corechart', 'bar']});
2496 google.charts.setOnLoadCallback(drawBasic);
2497 }
2498
2499 $(document).find(".ays_poll_answer_chart_active").on("click" , function(){
2500 google.charts.load('current', {packages: ['corechart', 'bar']});
2501 google.charts.setOnLoadCallback(drawBasic);
2502 });
2503
2504 // Write poll title immediately
2505 $(document).find('#ays-poll-title').on('input', function(e){
2506 var pollTitleVal = $(this).val();
2507 var pollTitle = aysPollstripHTML( pollTitleVal );
2508 $(document).find('.ays_poll_title_in_top').html( pollTitle );
2509 });
2510
2511 function aysPollstripHTML( dirtyString ) {
2512 var container = document.createElement('div');
2513 var text = document.createTextNode(dirtyString);
2514 container.appendChild(text);
2515
2516 return container.innerHTML; // innerHTML will be a xss safe string
2517 }
2518 //
2519
2520 var theme_Ids = $('.apm-themes-row').attr('data-themeid');
2521 if ($('#ays_poll_show_answers_icon').prop('checked') && theme_Ids != 3) {
2522 if ($('input[name="ays_poll_answer_icon"]:checked').prop('checked')) {
2523 var iconVal = $('input[name="ays_poll_answer_icon"]:checked').val();
2524 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2525 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2526 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+iconVal);
2527 }else{
2528 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2529 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2530 }
2531 }else{
2532 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2533 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2534 }
2535
2536 // Answer Icon
2537 $('#ays_poll_show_answers_icon').change(function () {
2538 var themeIds = $('.apm-themes-row').attr('data-themeid');
2539 if ($('#ays_poll_show_answers_icon').prop('checked')) {
2540 switch(parseInt(themeIds)){
2541 case 3:
2542 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2543 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2544 break;
2545 default:
2546 var icons_val = $('input[name="ays_poll_answer_icon"]:checked').val();
2547 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2548 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2549 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+icons_val);
2550 break;
2551 }
2552 }else{
2553 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2554 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2555 }
2556 });
2557
2558 $('.ays_poll_answ_icon').change(function () {
2559 if ($(this).prop('checked')) {
2560 var themesIds = $('.apm-themes-row').attr('data-themeid');
2561 switch(parseInt(themesIds)){
2562 case 3:
2563 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2564 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2565 break;
2566 default:
2567 var icon_val = $(this).val();
2568 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2569 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2570 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+icon_val);
2571 }
2572 }else{
2573 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2574 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2575 }
2576 });
2577
2578 $(document).find('strong.ays-poll-shortcode-box').on('mouseleave', function(){
2579 var _this = $(this);
2580
2581 _this.attr( 'data-original-title', pollLangObj.clickForCopy );
2582 });
2583
2584 // $(document).find("#ays_poll_buttons_size").select2({
2585 // minimumResultsForSearch: -1
2586 // });
2587
2588 // Button styles start
2589 // Size change
2590 $(document).find("#ays_poll_buttons_size").on("change" , function(){
2591 var buttonsSize = $(document).find('#ays_poll_buttons_size').val();
2592 var buttonsFontSize,
2593 buttonsLeftRightPadding,
2594 buttonsTopBottomPadding,
2595 buttonsBorderRadius;
2596
2597 switch(buttonsSize){
2598 case "small":
2599 buttonsFontSize = 14;
2600 buttonsLeftRightPadding = 14;
2601 buttonsTopBottomPadding = 7;
2602 buttonsBorderRadius = 3;
2603 break;
2604 case "large":
2605 buttonsFontSize = 20;
2606 buttonsLeftRightPadding = 30;
2607 buttonsTopBottomPadding = 13;
2608 buttonsBorderRadius = 3;
2609 break;
2610 default:
2611 buttonsFontSize = 17;
2612 buttonsLeftRightPadding = 20;
2613 buttonsTopBottomPadding = 10;
2614 buttonsBorderRadius = 3;
2615 break;
2616 }
2617
2618 $(document).find('#ays_poll_buttons_font_size').val(buttonsFontSize);
2619 $(document).find('#ays_poll_buttons_left_right_padding').val(buttonsLeftRightPadding);
2620 $(document).find('#ays_poll_buttons_top_bottom_padding').val(buttonsTopBottomPadding);
2621 $(document).find('#ays_poll_buttons_border_radius').val(buttonsBorderRadius);
2622
2623 $(document).find('input[type="button"].ays-poll-btn').css({
2624 'font-size' : buttonsFontSize + 'px',
2625 'padding' : buttonsTopBottomPadding+'px '+ buttonsLeftRightPadding+'px',
2626 'border-radius' : buttonsBorderRadius + 'px'
2627 });
2628 });
2629
2630 // Buttons font size
2631 $(document).find("#ays_poll_buttons_font_size").on("change" , function(){
2632 var buttonFontSize = $(this).val();
2633 $(document).find('input[type="button"].ays-poll-btn').css('font-size', buttonFontSize + 'px');
2634 });
2635
2636 $('.ays_buttons_padding').on('change', function () {
2637 var top_bottom = $(document).find('#ays_poll_buttons_top_bottom_padding').val();
2638 var left_top = $(document).find('#ays_poll_buttons_left_right_padding').val();
2639 $(document).find('input[type="button"].ays-poll-btn').css('padding', top_bottom + 'px ' + left_top +'px');
2640 });
2641
2642 $('#ays_poll_buttons_width').on('change', function () {
2643 var buttons_width = $(document).find('#ays_poll_buttons_width').val();
2644 if(buttons_width == ''){
2645 buttons_width = 'auto';
2646 }else{
2647 buttons_width = buttons_width + 'px';
2648 }
2649
2650 $(document).find('input[type="button"].ays-poll-btn').css('width', buttons_width);
2651 });
2652
2653 $('#ays_poll_buttons_border_radius').on('change', function () {
2654 var val = $(this).val();
2655 $(document).find('input[type="button"].ays-poll-btn').css('border-radius', val + 'px');
2656 });
2657
2658 function checkHr(type , pollType) {
2659 var typeChecker = $(document).find(".ays_hr_on");
2660 var textTypeChecker = $(document).find(".ays_hr_on_text");
2661 var rangeType = $('#type_range').prop('checked');
2662 if(!type){
2663 typeChecker.hide();
2664 }
2665 else{
2666 typeChecker.show();
2667 }
2668
2669 if(pollType == "text"){
2670 textTypeChecker.show();
2671 }
2672 else{
2673 textTypeChecker.hide();
2674
2675 }
2676
2677 if(rangeType){
2678 $(document).find(".ays_hr_check").hide();
2679 }
2680 else{
2681 $(document).find(".ays_hr_check").show();
2682 }
2683 }
2684
2685 function check_allow_add_answers_show_up() {
2686 var aa_show = $(document).find('input[type="checkbox"]#ays_poll_allow_add_answers');
2687 let requireAdminApprovalCbState = $(document).find('input[type="checkbox"]#ays_poll_allow_answer_require').prop('checked');
2688
2689 if(!requireAdminApprovalCbState){
2690 $(document).find('.ays_show_user_added').hide();
2691 $(document).find('.ays_show_user_added_hid').each(function () {
2692 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').prop('checked', false);
2693 // $(this).val(0);
2694 });
2695 }else{
2696 $(document).find('.ays_show_user_added').show();
2697 $(document).find('.ays_show_user_added_hid').each(function () {
2698 // $(this).val(1);
2699 // $(this).prop('checked', true);
2700 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').val(1);
2701 });
2702 }
2703 }
2704
2705 function toggleOptionsAccordion(arrowBtn) {
2706 var arrowSvg = arrowBtn.find('svg');
2707 var accordionMainContainer = arrowBtn.parents('.ays-poll-accordion-options-main-container');
2708 var accordionBody = accordionMainContainer.find('.ays-poll-accordion-body');
2709
2710 arrowSvg.toggleClass('ays-poll-accordion-arrow-active');
2711 accordionBody.slideToggle();
2712 }
2713
2714 $(document).find('input[type="checkbox"]#ays_poll_allow_add_answers').on('change', function(e){
2715 if($(this).prop('checked') == false){
2716 // $(document).find('.allow_add_answers_not_show_up').hide();
2717 // $(document).find('.allow_add_answers_not_show_up .ays_toggle_target').hide(250);
2718 $(document).find('#ays_poll_allow_answer_require').removeAttr('checked');
2719 check_allow_add_answers_show_up();
2720 }else{
2721 $(document).find('.allow_add_answers_not_show_up').show();
2722 check_allow_add_answers_show_up();
2723 }
2724
2725 });
2726
2727 $(document).find('input[type="checkbox"]#ays_poll_allow_answer_require').on('change', function(e){
2728 check_allow_add_answers_show_up();
2729 });
2730
2731 // Options accordion effect start
2732 $(document).on('click', '.ays-poll-accordion-header', function() {
2733 toggleOptionsAccordion($(this));
2734 });
2735 // Options accordion effect end
2736
2737 $(document).find('input[type="checkbox"].ays_show_user_added').on('change', function(e){
2738 let selectAllCb = $(document).find('input[type="checkbox"]#ays_poll_require_approve_select_all');
2739 if($(this).prop('checked') == true){
2740 $(this).parent().find('.ays_show_user_added_hid').val(1);
2741 var isAllChecked = 0;
2742 var allShowUserAddedCbArr = $(document).find('input[type="checkbox"].ays_show_user_added');
2743 for (i = 0; i < allShowUserAddedCbArr.length; i++) {
2744 if(allShowUserAddedCbArr.eq(i).prop('checked')) {
2745 isAllChecked++;
2746 }
2747 }
2748 if (isAllChecked === allShowUserAddedCbArr.length && selectAllCb.prop('checked') === false) {
2749 selectAllCb.prop('checked', true);
2750 }
2751 }else{
2752 $(this).parent().find('.ays_show_user_added_hid').val(0);
2753
2754 if (selectAllCb.prop('checked')) {
2755 selectAllCb.prop('checked', false);
2756 }
2757 }
2758 });
2759
2760 $(document).find("#ays_poll_require_approve_select_all").on("change" , function(){
2761 if($(this).prop('checked') == false){
2762 $(document).find('.ays_show_user_added').each(function () {
2763 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').prop('checked', false);
2764 $(this).val(0);
2765 $(this).prop('checked' , false);
2766 $(document).find('.ays_show_user_added_hid').val(0);
2767
2768 });
2769 }else{
2770 $(document).find('.ays_show_user_added').each(function () {
2771 $(this).val(1);
2772 $(this).prop('checked', true);
2773 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').val(1);
2774 $(document).find('.ays_show_user_added_hid').val(1);
2775 });
2776 }
2777 });
2778
2779 // Add answer image (Choosing type) start
2780 $(document).on('click', 'label.ays-label a.ays-poll-add-answer-image', function (e) {
2781 openAnswerMediaUploader(e, $(this));
2782 });
2783
2784 // Select Image
2785 function openAnswerMediaUploader(e, element) {
2786 e.preventDefault();
2787 var addButton = element;
2788 var aysUploader = wp.media({
2789 title: 'Upload',
2790 button: {
2791 text: 'Upload'
2792 },
2793 library: {
2794 type: 'image'
2795 },
2796 multiple: false
2797 }).on('select', function () {
2798 var attachment = aysUploader.state().get('selection').first().toJSON();
2799 addButton.parents().eq(1).find('.ays-poll-add-answer-image').parent().css('display', 'none');
2800 addButton.parents('td').find('.ays-poll-answer-image-container').fadeIn();
2801 addButton.parents('td').find('img.ays-poll-answer-img').attr('src', attachment.url);
2802 addButton.parents('tr').find('input.ays-poll-answer-image-path').val(attachment.url).trigger("change");
2803 if(addButton.hasClass('ays-poll-add-answer-image')){
2804 addButton.parents('td').find('img').attr('src', attachment.url);
2805 addButton.parents('tr').find('input.ays-poll-answer-image').val(attachment.url);
2806 }
2807 }).open();
2808 return false;
2809 }
2810
2811 // Remove Image
2812 $(document).on('click', '.ays-poll-remove-answer-img', function () {
2813 var $this = $(this);
2814 $this.parent().fadeOut();
2815 if($this.parent().hasClass('ays-poll-answer-image-container')){
2816 setTimeout(function(){
2817 $this.parents().eq(1).find('.ays-poll-add-answer-image').show();
2818 $this.parents('td').find('.ays-poll-add-answer-image').parent().css('display', 'block');
2819 $this.parents('td').find('.ays-poll-add-answer-image').css('display', 'inline-block');
2820 $this.parent().find('img.ays-poll-answer-img').attr('src', '');
2821 $this.parent().find('input.ays-poll-answer-image').val('');
2822 $this.parent().find('input.ays-poll-answer-image-path').val('').trigger("change");
2823 },300);
2824 }
2825 });
2826
2827 // Grid view type PRO
2828 $(document).find("#ays_answers_grid_column").on("change" , function(){
2829 var $this = $(this);
2830 if($this.val() != 2){
2831 $this.val(2);
2832 window.open("https://ays-pro.com/wordpress/poll-maker", '_blank');
2833 }
2834 });
2835
2836
2837
2838 $(document).on('change', '.ays-poll-answer-image-path', function(){
2839 livePrevToChoosing('choosing');
2840
2841 $(document).find('#ays-poll-border-side').trigger('change');
2842 $(document).find('#ays_answers_view').trigger('change');
2843 });
2844
2845 $(document).find(".ays-poll-text-types-type").on("change" , function(){
2846 var $this = $(this);
2847 var textType = $this.val();
2848 livePrevToChoosing("text" , 0 , textType);
2849 });
2850 // Add answer image (Choosing type) end
2851
2852 // Poll Responsive tabs start
2853 if($(document).find('.ays-top-menu').width() <= $(document).find('div.ays-top-tab-wrapper').width()){
2854 $(document).find('.ays_menu_left').css('display', 'flex');
2855 $(document).find('.ays_menu_right').css('display', 'flex');
2856 }
2857 $(window).resize(function(){
2858 if($(document).find('.ays-top-menu').width() < $(document).find('div.ays-top-tab-wrapper').width()){
2859 $(document).find('.ays_menu_left').css('display', 'flex');
2860 $(document).find('.ays_menu_right').css('display', 'flex');
2861 }else{
2862 $(document).find('.ays_menu_left').css('display', 'none');
2863 $(document).find('.ays_menu_right').css('display', 'none');
2864 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(0px)');
2865 }
2866 });
2867 var menuItemWidths0 = [];
2868 var menuItemWidths = [];
2869 $(document).find('.ays-top-tab-wrapper .nav-tab').each(function(){
2870 var $this = $(this);
2871 menuItemWidths0.push($this.outerWidth());
2872 });
2873
2874 for(var i = 0; i < menuItemWidths0.length; i+=2){
2875 if(menuItemWidths0.length <= i+1){
2876 menuItemWidths.push(menuItemWidths0[i]);
2877 }else{
2878 menuItemWidths.push(menuItemWidths0[i]+menuItemWidths0[i+1]);
2879 }
2880 }
2881 var menuItemWidth = 0;
2882 for(var i = 0; i < menuItemWidths.length; i++){
2883 menuItemWidth += menuItemWidths[i];
2884 }
2885 menuItemWidth = menuItemWidth / menuItemWidths.length;
2886
2887 $(document).on('click', '.ays_menu_left', function(){
2888 var scroll = parseInt($(this).attr('data-scroll'));
2889 scroll -= menuItemWidth;
2890 if(scroll < 0){
2891 scroll = 0;
2892 }
2893 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(-'+scroll+'px)');
2894 $(this).attr('data-scroll', scroll);
2895 $(document).find('.ays_menu_right').attr('data-scroll', scroll);
2896 });
2897 $(document).on('click', '.ays_menu_right', function(){
2898 var scroll = parseInt($(this).attr('data-scroll'));
2899 var howTranslate = $(document).find('div.ays-top-tab-wrapper').width() - $(document).find('.ays-top-menu').width();
2900 howTranslate += 250;
2901 if(scroll == -1){
2902 scroll = menuItemWidth;
2903 }
2904 scroll += menuItemWidth;
2905 if(scroll > howTranslate){
2906 scroll = Math.abs(howTranslate);
2907 }
2908 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(-'+scroll+'px)');
2909 $(this).attr('data-scroll', scroll);
2910 $(document).find('.ays_menu_left').attr('data-scroll', scroll);
2911 });
2912 // Poll Responsive tabs end
2913
2914
2915 // var checkCountdownIsExists = $(document).find('#ays-poll-countdown-main-container');
2916 var checkCountdownIsExists = $(document).find('#ays-poll-maker-countdown-main-container');
2917 if ( checkCountdownIsExists.length > 0 ) {
2918 var second = 1000,
2919 minute = second * 60,
2920 hour = minute * 60,
2921 day = hour * 24;
2922
2923 // var pollCountdownEndTime = "DEC 05, 2025 23:59:59";
2924 var pollCountdownEndTime = pollLangObj.pollBannerDate;
2925 var countDown_new = new Date(pollCountdownEndTime).getTime();
2926 if ( isNaN(countDown_new) || isFinite(countDown_new) == false ) {
2927 var AYS_POLL_MILLISECONDS = 3 * day;
2928 var countdownStartDate = new Date(Date.now() + AYS_POLL_MILLISECONDS);
2929 var pollCountdownEndTime = countdownStartDate.aysPollCustomFormat( "#YYYY#-#MM#-#DD# #hhhh#:#mm#:#ss#" );
2930 var countDown_new = new Date(pollCountdownEndTime).getTime();
2931 }
2932
2933 aysPollBannerCountdown();
2934
2935 var y = setInterval(function() {
2936
2937 var now = new Date().getTime();
2938 var distance_new = countDown_new - now;
2939
2940 aysPollBannerCountdown();
2941
2942 var countDownDays = document.getElementById("ays-poll-countdown-days");
2943 var countDownHours = document.getElementById("ays-poll-countdown-hours");
2944 var countDownMinutes = document.getElementById("ays-poll-countdown-minutes");
2945 var countDownSeconds = document.getElementById("ays-poll-countdown-seconds");
2946
2947 if(countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null){
2948
2949 var countDownDays_innerText = Math.floor(distance_new / (day));
2950 var countDownHours_innerText = Math.floor((distance_new % (day)) / (hour));
2951 var countDownMinutes_innerText = Math.floor((distance_new % (hour)) / (minute));
2952 var countDownSeconds_innerText = Math.floor((distance_new % (minute)) / second);
2953
2954 if( isNaN(countDownDays_innerText) || isNaN(countDownHours_innerText) || isNaN(countDownMinutes_innerText) || isNaN(countDownSeconds_innerText) ){
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 } else {
2965 countDownDays.innerText = countDownDays_innerText;
2966 countDownHours.innerText = countDownHours_innerText;
2967 countDownMinutes.innerText = countDownMinutes_innerText;
2968 countDownSeconds.innerText = countDownSeconds_innerText;
2969 }
2970 }
2971
2972 //do something later when date is reached
2973 if (distance_new < 0) {
2974 var headline = document.getElementById("ays-poll-countdown-headline"),
2975 countdown = document.getElementById("ays-poll-countdown"),
2976 content = document.getElementById("ays-poll-countdown-content");
2977
2978 // headline.innerText = "Sale is over!";
2979 countdown.style.display = "none";
2980 content.style.display = "block";
2981
2982 clearInterval(y);
2983 }
2984 }, 1000);
2985 }
2986
2987 function aysPollBannerCountdown(){
2988 var now = new Date().getTime();
2989 var distance_new = countDown_new - now;
2990
2991 var countDownDays = document.getElementById("ays-poll-countdown-days");
2992 var countDownHours = document.getElementById("ays-poll-countdown-hours");
2993 var countDownMinutes = document.getElementById("ays-poll-countdown-minutes");
2994 var countDownSeconds = document.getElementById("ays-poll-countdown-seconds");
2995
2996 if((countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null) && distance_new > 0){
2997
2998 var countDownDays_innerText = Math.floor(distance_new / (day));
2999 var countDownHours_innerText = Math.floor((distance_new % (day)) / (hour));
3000 var countDownMinutes_innerText = Math.floor((distance_new % (hour)) / (minute));
3001 var countDownSeconds_innerText = Math.floor((distance_new % (minute)) / second);
3002
3003 if( isNaN(countDownDays_innerText) || isNaN(countDownHours_innerText) || isNaN(countDownMinutes_innerText) || isNaN(countDownSeconds_innerText) ){
3004 var headline = document.getElementById("ays-poll-countdown-headline"),
3005 countdown = document.getElementById("ays-poll-countdown"),
3006 content = document.getElementById("ays-poll-countdown-content");
3007
3008 // headline.innerText = "Sale is over!";
3009 countdown.style.display = "none";
3010 content.style.display = "block";
3011
3012 // clearInterval(y);
3013 } else {
3014 countDownDays.innerText = countDownDays_innerText;
3015 countDownHours.innerText = countDownHours_innerText;
3016 countDownMinutes.innerText = countDownMinutes_innerText;
3017 countDownSeconds.innerText = countDownSeconds_innerText;
3018 }
3019
3020 // countDownDays.innerText = Math.floor(distance_new / (day)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3021 // countDownHours.innerText = Math.floor((distance_new % (day)) / (hour)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3022 // countDownMinutes.innerText = Math.floor((distance_new % (hour)) / (minute)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3023 // countDownSeconds.innerText = Math.floor((distance_new % (minute)) / second).toLocaleString(undefined,{minimumIntegerDigits: 2});
3024 }
3025 }
3026
3027 $(document).on('click', '#ays-polls-next-button, #ays-polls-prev-button, .ays-poll-next-prev-button-class', function(e){
3028 e.preventDefault();
3029 var message = $(this).data('message');
3030 var confirm = window.confirm( message );
3031 if(confirm === true){
3032 window.location.replace($(this).attr('href'));
3033 }
3034 });
3035
3036 // CHOOSE POLL TYPE FROM MODAL START
3037 $(document).find('.ays_poll_layer_box_blocks label.ays-poll-dblclick-layer:not(.ays-poll-type-pro-feature)').on('dblclick',function(){
3038 $(this).parents('.ays_poll_layer_container').find('.ays_poll_select_button_layer input.ays_poll_layer_button').trigger('click');
3039 });
3040
3041 $(document).find('.ays-poll-content-type').on('change',function(){
3042 $(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());
3043 $(document).find('#poll_choose_type').val($(this).val());
3044 });
3045
3046 $(document).find('.ays_poll_layer_button').on('click',function(){
3047 $('.ays_poll_layer_container').css({'position':'unset' , 'display':'none'});
3048 $(document.body).removeClass('ays-poll-modal-open');
3049 $(document).find('.ays-poll-show-result-chart-google').prop("checked", true);
3050
3051 checkType($(this).attr("data-type"));
3052
3053 // var $checklistPanel = $(document).find('.ays-poll-checklist-panel');
3054 // if ($checklistPanel.length > 0) {
3055 // $checklistPanel.show();
3056 // }
3057 })
3058
3059 // Add body class when modal is visible
3060 $(document).ready(function(){
3061 if($('.ays_poll_layer_container').is(':visible')) {
3062 $(document.body).addClass('ays-poll-modal-open');
3063 }
3064 });
3065 // CHOOSE POLL TYPE FROM MODAL END
3066
3067 $(document).find('.ays-poll-open-polls-list').on('click', function(e){
3068 $(this).parents(".ays-poll-subtitle-main-box").find(".ays-poll-polls-data").toggle('fast');
3069 });
3070
3071 $(document).find(".ays-poll-go-to-polls").on("click" , function(e){
3072 e.preventDefault();
3073 var confirmRedirect = window.confirm(pollLangObj.areYouSure);
3074 if(confirmRedirect){
3075 window.location = $(this).attr("href");
3076 }
3077 });
3078
3079 $(document).find('#ays_poll_reset_to_default').on('click', function (e) {
3080 e.preventDefault();
3081
3082 var themeId = $(document).find('.ays-poll-theme-item.apm_active_theme').next('input').val();
3083
3084 $(document).find('.apm-themes-row').attr('data-themeId',themeId);
3085 if ($(document).find('#ays_poll_show_answers_icon').prop('checked')) {
3086 switch(parseInt(themeId)){
3087 case 3:
3088 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3089 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3090 break;
3091 default:
3092 var iconsVal = $('input[name="ays_poll_answer_icon"]:checked').val();
3093 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3094 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3095 $(document).find('.ays_label_poll').addClass('ays_poll_answer_icon_'+iconsVal);
3096 break;
3097 }
3098 }else{
3099 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3100 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3101 }
3102
3103 answerStyleChange(themeId);
3104
3105 textColorChange({
3106 color: themes[themeId].textColor
3107 });
3108 buttonTextColorChange({
3109 color: themes[themeId].buttonTextColor
3110 });
3111 buttonBgColorChange({
3112 color: themes[themeId].buttonBgColor
3113 });
3114 mainColorChange({
3115 color: themes[themeId].mainColor
3116 });
3117 bgColorChange({
3118 color: themes[themeId].bgColor
3119 });
3120 answerBgColorChange({
3121 color: themes[themeId].answerBgColor
3122 });
3123 titleBgColorChange({
3124 color: themes[themeId].titleBgColor
3125 });
3126 iconColorChange({
3127 color: themes[themeId].iconColor
3128 });
3129 borderColorChange({
3130 color: themes[themeId].borderColor
3131 });
3132 $(document).find('#ays-poll-text-color').parent().parent().prev().css({
3133 'background-color': themes[themeId].textColor
3134 });
3135 $(document).find('#ays-poll-text-color').val(themes[themeId].textColor);
3136
3137 $(document).find('#ays-poll-button-text-color').parent().parent().prev().css({
3138 'color': themes[themeId].buttonTextColor
3139 });
3140 $(document).find('#ays-poll-button-text-color').val(themes[themeId].buttonTextColor);
3141
3142 $(document).find('#ays-poll-button-bg-color').parent().parent().prev().css({
3143 'background-color': themes[themeId].buttonBgColor
3144 });
3145 $(document).find('#ays-poll-button-bg-color').val(themes[themeId].buttonBgColor);
3146
3147 $(document).find('#ays-poll-main-color').parent().parent().prev().css({
3148 'background-color': themes[themeId].mainColor
3149 });
3150 $(document).find('#ays-poll-main-color').val(themes[themeId].mainColor);
3151
3152 $(document).find('#ays-poll-bg-color').parent().parent().prev().css({
3153 'background-color': themes[themeId].bgColor
3154 });
3155 $(document).find('#ays-poll-bg-color').val(themes[themeId].bgColor);
3156
3157 $(document).find('#ays-poll-answer-bg-color').parent().parent().prev().css({
3158 'background-color': themes[themeId].answerBgColor
3159 });
3160 $(document).find('#ays-poll-answer-bg-color').val(themes[themeId].answerBgColor);
3161
3162 $(document).find('#ays-poll-answer-hover-color').closest('.wp-picker-input-wrap').prev().css({
3163 'background-color': themes[themeId].answerHoverColor
3164 });
3165 $(document).find('#ays-poll-answer-hover-color').val(themes[themeId].answerHoverColor);
3166
3167 $(document).find('#ays-poll-title-bg-color').parent().parent().prev().css({
3168 'background-color': themes[themeId].titleBgColor
3169 });
3170 $(document).find('#ays-poll-title-bg-color').val(themes[themeId].titleBgColor);
3171
3172 $(document).find('#ays-poll-icon-color').parent().parent().prev().css({
3173 'background-color': themes[themeId].iconColor
3174 });
3175 $(document).find('#ays-poll-icon-color').val(themes[themeId].iconColor);
3176
3177 $(document).find('input#ays-poll-bg-image').val('');
3178 $(document).find('#ays-poll-bg-img').attr('src', '').change();
3179 $(document).find('.ays-poll-bg-image-container').hide().change();
3180 $(document).find('#ays-poll-background-image-options').hide().change();
3181 $(document).find('.add-bg-image.button').text('Add Image');
3182 $(document).find('.add-bg-image.button').show().change();
3183 $(document).find('.box-apm.choosing-poll').css('background-image', '');
3184 $(document).find('#ays_poll_bg_image_position').val('center center').change();
3185 $(document).find("#ays_poll_bg_img_in_finish_page").prop('checked' , false).change();
3186
3187 if(themeId == 3){
3188 $(document).find('#ays-poll-border-side').val('none').change();
3189 }else{
3190 $(document).find('#ays-poll-border-side').val('all_sides').change();
3191 }
3192
3193 $(document).find('input#ays_answer_font_size').val('16').change();
3194 $(document).find('input#ays_poll_answer_font_size_mobile').val('16').change();
3195 $(document).find('input#ays_poll_answer_img_height').val('150').change();
3196 $(document).find('input#ays_poll_answer_image_height_for_mobile').val('150').change();
3197 $(document).find('input#ays_poll_answer_image_border_radius').val('0').change();
3198 $(document).find('#ays_poll_image_background_size').val('cover').change();
3199 $(document).find('input#ays_poll_answers_padding').val('10').change();
3200 $(document).find('input#ays_poll_answers_margin').val('10').change();
3201 $(document).find('input#ays_poll_answer_border_radius').val('0').change();
3202
3203 $(document).find("#ays_poll_show_answers_icon").prop('checked' , false).change();
3204
3205 $(document).find('#ays_answers_view').val('list').change();
3206 $(document).find("#ays_poll_answers_box_shadow_enable").prop('checked' , false).change();
3207 $(document).find('input#ays_poll_title_font_size').val('20').change();
3208 $(document).find('input#ays_poll_title_font_size_mobile').val('20').change();
3209 $(document).find('#ays_poll_title_font_weight').val('normal').change();
3210 $(document).find('#ays_poll_title_font_weight_mobile').val('normal').change();
3211 $(document).find('#ays_poll_title_alignment').val('center').change();
3212 $(document).find('#ays_poll_title_alignment_mobile').val('center').change();
3213 $(document).find('#ays_poll_title_text_transform').val('none').change();
3214 $(document).find("#ays_poll_enable_title_text_shadow").prop('checked' , false).change();
3215 $(document).find('input#ays-poll-icon-size').val('24').change();
3216 $(document).find('input#ays-poll-width').val('0').change();
3217 $(document).find('input#ays_poll_width_for_mobile').val('0').change();
3218 $(document).find('input#ays_poll_min_height').val('').change();
3219 $(document).find('#ays-poll-border-style').val('ridge').change();
3220 $(document).find('input#ays-poll-border-radius').val('0').change();
3221 $(document).find('input#ays-poll-border-width').val('2').change();
3222 $(document).find("#ays_poll_enable_box_shadow").prop('checked' , false).change();
3223 $(document).find("#ays-enable-background-gradient").prop('checked' , false).change();
3224 $(document).find('input#ays_questions_font_size').val('16').change();
3225 $(document).find('input#ays_poll_answers_font_size_mobile').val('16').change();
3226 $(document).find('input#ays_poll_question_image_height').val('').change();
3227 $(document).find('#ays_poll_question_image_object_fit').val('cover').change();
3228 $(document).find('input#ays_poll_mobile_max_width').val('').change();
3229 $(document).find('#ays_poll_buttons_size').val('medium').change();
3230 $(document).find('input#ays_poll_buttons_font_size').val('17').change();
3231 $(document).find('input#ays_poll_buttons_mobile_font_size').val('17').change();
3232 $(document).find('input#ays_poll_buttons_left_right_padding').val('20').change();
3233 $(document).find('input#ays_poll_buttons_top_bottom_padding').val('10').change();
3234 $(document).find('input#ays_poll_buttons_border_radius').val('3').change();
3235 $(document).find('input#ays_poll_buttons_width').val('').change();
3236 $(document).find("#ays_disable_answer_hover").prop('checked' , false).change();
3237
3238 $(document).find(".add-logo-remove-image.button").trigger('click');
3239 $(document).find('input#ays_poll_custom_class').val('').change();
3240
3241 setTimeout(function(){
3242 if($(document).find('#ays_custom_css').length > 0){
3243 if(wp.codeEditor){
3244 $(document).find('#ays_custom_css').next('.CodeMirror').remove();
3245 $(document).find('#ays_custom_css').val('');
3246 wp.codeEditor.initialize($(document).find('#ays_custom_css'), cm_settings);
3247 }
3248 }
3249 }, 100);
3250
3251 $(document).find("#tab2").goToNormal();
3252 });
3253
3254 $(document).on('mouseover', '.ays-dashicons', function(){
3255 var allRateStars = $(document).find('.ays-dashicons');
3256 var index = allRateStars.index(this);
3257 allRateStars.removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3258 for (var i = 0; i <= index; i++) {
3259 allRateStars.eq(i).removeClass('ays-dashicons-star-empty').addClass('ays-dashicons-star-filled');
3260 }
3261 });
3262
3263 $(document).on('mouseleave', '.ays-rated-link', function(){
3264 $(document).find('.ays-dashicons').removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3265 });
3266
3267 var aysPollListTables = $(document).find('#wpcontent #wpbody div.wrap.ays-poll-list-table');
3268
3269 if ( aysPollListTables.length > 0) {
3270 var listTableClass = "";
3271 var searchBox = "";
3272 if( aysPollListTables.hasClass('ays_polls_list_table') ){
3273 listTableClass = 'ays_polls_list_table';
3274 searchBox = 'poll-maker-ays-search-input';
3275 }
3276 else if( aysPollListTables.hasClass('ays_poll_categories_list_table') ){
3277 listTableClass = 'ays_poll_categories_list_table';
3278 searchBox = 'poll-maker-ays-search-input';
3279 }
3280 else if( aysPollListTables.hasClass('ays_poll_results_list_table') ){
3281 listTableClass = 'ays_poll_results_list_table';
3282 searchBox = 'poll-maker-ays-search-input';
3283 }
3284
3285 if( listTableClass != "" && searchBox != "" ){
3286 ays_poll_search_box_pagination(listTableClass, searchBox);
3287 }
3288 }
3289
3290 // Select message vars galleries page | Start
3291 $(document).find('.ays-poll-message-vars-icon').on('click', function(e){
3292 var messageVarsBox = $(this).parents(".ays-poll-message-vars-box");
3293 messageVarsBox.toggleClass("ays-poll-message-vars-open");
3294 messageVarsBox.find(".ays-poll-message-vars-data").toggle('fast');
3295 });
3296
3297 $(document).on( "click" , function(e){
3298 if($(e.target).closest('.ays-poll-message-vars-box').length != 0){
3299 }
3300 else{
3301 $(document).find(".ays-poll-message-vars-box .ays-poll-message-vars-data").hide('fast');
3302 $(document).find(".ays-poll-message-vars-box").removeClass("ays-poll-message-vars-open");
3303 }
3304 });
3305
3306 $(document).find('.ays-poll-message-vars-each-data').on('click', function(e){
3307 var _this = $(this);
3308 var parent = _this.parents('.ays-poll-desc-message-vars-parent');
3309
3310 var textarea = parent.find('textarea.ays-textarea');
3311 var textareaID = textarea.attr('id');
3312
3313 var messageVar = _this.find(".ays-poll-message-vars-each-var").val();
3314
3315 if ( parent.find("#wp-"+ textareaID +"-wrap").hasClass("tmce-active") ){
3316 window.tinyMCE.get(textareaID).setContent( window.tinyMCE.get(textareaID).getContent() + messageVar + " " );
3317 }else{
3318 $(document).find('#'+textareaID).append( " " + messageVar + " ");
3319 }
3320 });
3321 /* Select message vars galleries page | End */
3322
3323 // Check poll result as read start
3324 $(document).find('.ays-show-results').on('click', function (e) {
3325 $(document).find('#ays-results-modal').fadeIn();
3326 $(document).find('div.ays-poll-preloader').css('display', 'flex');
3327
3328 var $this = $(this);
3329 var readStatus = $this.parents('tr').find("td .unread-result-badge");
3330
3331 $('li.toplevel_page_poll-maker-ays .apm-badge.badge-danger').each(function () {
3332 var $unreadCounter = $(this);
3333
3334 if ($unreadCounter.text() != 0) {
3335 if(readStatus.hasClass('unread-result')){
3336 var counter = +$unreadCounter.text();
3337 counter--;
3338 if(counter == 0){
3339 $unreadCounter.hide();
3340 }
3341 $unreadCounter.text(counter);
3342 }
3343 }
3344 else{
3345 $unreadCounter.hide();
3346 }
3347 });
3348
3349 if(readStatus.hasClass('unread-result')){
3350 readStatus.removeClass('unread-result');
3351 }
3352
3353 $(this).css('font-weight' , 'normal');
3354 $(this).parent().css('font-weight' , 'normal');
3355 $(this).parent().siblings().css('font-weight' , 'normal');
3356 var result = $(this).data('result');
3357 var action = 'apm_show_results';
3358 var wp_nonce = $(document).find('#poll_maker_ajax_show_details_report_nonce').val();
3359 $.ajax({
3360 url: poll.ajax,
3361 dataType: 'json',
3362 method: "post",
3363 data: {
3364 result: result,
3365 action: action,
3366 _ajax_nonce: wp_nonce,
3367 is_details: 1
3368 },
3369 success: function(response) {
3370 if (response.status === true) {
3371 $('table#ays-results-table').html(response.rows);
3372 $(document).find('div.ays-poll-preloader').css('display', 'none');
3373 }
3374 }
3375 });
3376 e.preventDefault();
3377 });
3378 // Check poll result as read end
3379
3380 // Close results popup start
3381 $(document).find('#ays-close-results').on('click', function () {
3382 $(document).find('#ays-results-modal').fadeOut();
3383 });
3384 // Close results popup end
3385
3386 // Pro features start
3387 $(document).on('click', '.pro_features_popup', function(e){
3388 e.preventDefault();
3389 var _this = $(this);
3390 var popupModal = $(document).find('#pro-features-popup-modal');
3391
3392 var popupModal_title = _this.find('.pro-features-popup-title');
3393 var popupModal_title_text = popupModal_title.text();
3394
3395 var popupModal_content = _this.find('.pro-features-popup-content').html();
3396 var popupModal_video_link = _this.find('.pro-features-popup-content').attr("data-link");
3397
3398 var popupModal_button = _this.find('.pro-features-popup-button');
3399 var popupModal_button_text = popupModal_button.text();
3400 var popupModal_button_link = popupModal_button.attr("data-link");
3401
3402
3403 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3404 var rightSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-right-section');
3405
3406 rightSection.find('.pro-features-popup-modal-right-box-title').text(popupModal_title_text);
3407 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3408 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3409
3410 rightSection.find('.pro-features-popup-modal-right-box-link').text(popupModal_button_text);
3411 rightSection.find('.pro-features-popup-modal-right-box-link').attr("href", popupModal_button_link);
3412
3413 if ( typeof popupModal_video_link != "undefined" && popupModal_video_link != "") {
3414 var videoID = ays_youtube_parser(popupModal_video_link);
3415 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>';
3416
3417 leftSection.html(iframeHTML);
3418 }
3419
3420 popupModal.aysModal('show_flex');
3421 });
3422
3423 $(document).on('click', '.ays-poll-new-watch-video-button-box, .ays-poll-center-big-watch-video-button-box', function(e){
3424 e.preventDefault();
3425 if( $(this).hasClass('ays-poll-center-big-watch-video-button-box') ){
3426 var _this = $(this).parent().parent().find('.pro_features.pro_features_popup');
3427 } else {
3428 var _this = $(this).parent().find('.pro_features.pro_features_popup');
3429 }
3430 var popupModal = $(document).find('#pro-features-popup-modal');
3431 var popupModal_title = _this.find('.pro-features-popup-title');
3432 var popupModal_title_text = popupModal_title.text();
3433
3434 var popupModal_content = _this.find('.pro-features-popup-content').html();
3435 var popupModal_video_link = _this.find('.pro-features-popup-content').attr("data-link");
3436
3437 var popupModal_button = _this.find('.pro-features-popup-button');
3438 var popupModal_button_text = popupModal_button.text();
3439 var popupModal_button_link = popupModal_button.attr("data-link");
3440
3441
3442 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3443 var rightSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-right-section');
3444
3445 rightSection.find('.pro-features-popup-modal-right-box-title').text(popupModal_title_text);
3446 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3447 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3448
3449 rightSection.find('.pro-features-popup-modal-right-box-link').text(popupModal_button_text);
3450 rightSection.find('.pro-features-popup-modal-right-box-link').attr("href", popupModal_button_link);
3451
3452 if ( typeof popupModal_video_link != "undefined" && popupModal_video_link != "") {
3453 var videoID = ays_youtube_parser(popupModal_video_link);
3454 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>';
3455
3456 leftSection.html(iframeHTML);
3457 }
3458
3459 popupModal.aysModal('show_flex');
3460 });
3461
3462 $(document).find('.ays-close-pro-popup').on('click', function () {
3463 $(this).parents('.ays-modal').aysModal('hide_remove_video');
3464 });
3465 // // Pro features end
3466
3467 $(document).on("click", ".ays-poll-cards-block .ays-poll-card__footer button.status-missing", function(e){
3468 var $this = $(this);
3469 var thisParent = $this.parents(".ays-poll-cards-block");
3470
3471 $this.prop('disabled', true);
3472 $this.addClass('disabled');
3473
3474 var loader_html = '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>';
3475
3476 $this.html(loader_html);
3477
3478 var attr_plugin = $this.attr('data-plugin');
3479 var wp_nonce = thisParent.find('#ays_poll_ajax_install_plugin_nonce').val();
3480
3481 var data = {
3482 action: 'ays_poll_install_plugin',
3483 _ajax_nonce: wp_nonce,
3484 plugin: attr_plugin,
3485 type: 'plugin'
3486 };
3487
3488 $.ajax({
3489 url: poll.ajax,
3490 method: 'post',
3491 dataType: 'json',
3492 data: data,
3493 success: function (response) {
3494 if (response.success) {
3495 swal.fire({
3496 type: 'success',
3497 html: "<h4>"+ response['data']['msg'] +"</h4>"
3498 }).then( function(res) {
3499 if ( $this.hasClass('status-missing') ) {
3500 $this.removeClass('status-missing');
3501 }
3502 $this.text(poll.activated);
3503 $this.addClass('status-active');
3504 });
3505 }
3506 else {
3507 swal.fire({
3508 type: 'info',
3509 html: "<h4>"+ response['data'][0]['message'] +"</h4>"
3510 }).then( function(res) {
3511 $this.text(poll.errorMsg);
3512 });
3513 }
3514 },
3515 error: function(){
3516 swal.fire({
3517 type: 'info',
3518 html: "<h2>"+ poll.loadResource +"</h2><br><h6>"+ poll.somethingWentWrong +"</h6>"
3519 }).then( function(res) {
3520 $this.text(poll.errorMsg);
3521 });
3522 }
3523 });
3524 });
3525
3526 $(document).on("click", ".ays-poll-cards-block .ays-poll-card__footer button.status-installed", function(e){
3527 var $this = $(this);
3528 var thisParent = $this.parents(".ays-poll-cards-block");
3529
3530 $this.prop('disabled', true);
3531 $this.addClass('disabled');
3532
3533 var loader_html = '<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>';
3534
3535 $this.html(loader_html);
3536
3537 var attr_plugin = $this.attr('data-plugin');
3538 var wp_nonce = thisParent.find('#ays_poll_ajax_install_plugin_nonce').val();
3539
3540 var data = {
3541 action: 'ays_poll_activate_plugin',
3542 _ajax_nonce: wp_nonce,
3543 plugin: attr_plugin,
3544 type: 'plugin'
3545 };
3546
3547 $.ajax({
3548 url: poll.ajax,
3549 method: 'post',
3550 dataType: 'json',
3551 data: data,
3552 success: function (response) {
3553 if( response.success ){
3554 swal.fire({
3555 type: 'success',
3556 html: "<h4>"+ response['data'] +"</h4>"
3557 }).then( function(res) {
3558 if ( $this.hasClass('status-installed') ) {
3559 $this.removeClass('status-installed');
3560 }
3561 $this.text(poll.activated);
3562 $this.addClass('status-active disabled');
3563 });
3564 } else {
3565 swal.fire({
3566 type: 'info',
3567 html: "<h4>"+ response['data'][0]['message'] +"</h4>"
3568 });
3569 }
3570 },
3571 error: function(){
3572 swal.fire({
3573 type: 'info',
3574 html: "<h2>"+ poll.loadResource +"</h2><br><h6>"+ poll.somethingWentWrong +"</h6>"
3575 }).then( function(res) {
3576 $this.text(poll.errorMsg);
3577 });
3578 }
3579 });
3580 });
3581
3582 // Replace image to YouTube embed video
3583 $(document).on('click', '.ays-poll-youtube-placeholder', function() {
3584 var videoId = $(this).data('video-id');
3585 var iframe = $('<iframe>', {
3586 src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1',
3587 class: '',
3588 width: 560,
3589 height: 315,
3590 frameborder: 0,
3591 allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
3592 allowfullscreen: true,
3593 });
3594 $(this).replaceWith(iframe);
3595 });
3596
3597 })(jQuery);
3598
3599 document.addEventListener("DOMContentLoaded", function() {
3600 var startDate = new Date("2025-09-21");
3601 var endDate = new Date("2025-10-21");
3602 var totalLicenses = 50;
3603 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);
3604 function getCurrentProgress() {
3605 var today = new Date();
3606 // today.setDate(today.getDate() + 1);
3607 var daysPassed = Math.floor((today - startDate) / (1000 * 60 * 60 * 24));
3608 var usedLicenses = 0;
3609 for (var i = 0; i < Math.min(daysPassed, progressionPattern.length); i++) {
3610 usedLicenses += progressionPattern[i];
3611 }
3612 return Math.min(usedLicenses, totalLicenses);
3613 }
3614 function updateProgress() {
3615 var usedLicenses = getCurrentProgress();
3616 var remainingLicenses = totalLicenses - usedLicenses;
3617 var progressPercentage = (usedLicenses / totalLicenses) * 100;
3618 var remainingElement = document.getElementById("remaining-licenses");
3619 var progressElement = document.getElementById("progress-fill");
3620 if (remainingElement) remainingElement.textContent = remainingLicenses;
3621 if (progressElement) progressElement.style.width = progressPercentage + "%";
3622 }
3623 updateProgress();
3624 });
3625
3626 // Copy to clipboard function
3627 function pollCopyToClipboard(text) {
3628 if (navigator.clipboard && window.isSecureContext) {
3629 navigator.clipboard.writeText(text).then(function() {
3630 pollShowCopyNotification(pollLangObj.successCopyCoupon);
3631 }).catch(function() {
3632 fallbackCopyTextToClipboard(text);
3633 });
3634 } else {
3635 fallbackCopyTextToClipboard(text);
3636 }
3637 }
3638
3639 function fallbackCopyTextToClipboard(text) {
3640 var textArea = document.createElement("textarea");
3641 textArea.value = text;
3642 textArea.style.position = "fixed";
3643 textArea.style.top = "-9999px";
3644 textArea.style.left = "-9999px";
3645 document.body.appendChild(textArea);
3646 textArea.focus();
3647 textArea.select();
3648 try {
3649 var successful = document.execCommand("copy");
3650 if (successful) {
3651 pollShowCopyNotification(pollLangObj.successCopyCoupon);
3652 } else {
3653 pollShowCopyNotification(pollLangObj.failedCopyCoupon);
3654 }
3655 } catch (err) {
3656 pollShowCopyNotification(pollLangObj.failedCopyCoupon);
3657 }
3658 document.body.removeChild(textArea);
3659 }
3660
3661 function pollShowCopyNotification(message) {
3662 var notification = document.createElement("div");
3663 notification.className = "ays-poll-copy-notification show";
3664 console.log(notification);
3665 notification.textContent = message;
3666 document.body.appendChild(notification);
3667 setTimeout(function() {
3668 notification.classList.remove("show");
3669 setTimeout(function() {
3670 document.body.removeChild(notification);
3671 }, 300);
3672 }, 2000);
3673 }
3674
3675 function selectElementContents(el) {
3676 if (window.getSelection && document.createRange) {
3677 var _this = jQuery(document).find('strong.ays-poll-shortcode-box');
3678 var text = el.textContent;
3679 var textField = document.createElement('textarea');
3680
3681 textField.innerText = text;
3682 document.body.appendChild(textField);
3683 textField.select();
3684 document.execCommand('copy');
3685 textField.remove();
3686 var sel = window.getSelection();
3687 var range = document.createRange();
3688 range.selectNodeContents(el);
3689 sel.removeAllRanges();
3690 sel.addRange(range);
3691 _this.attr( "data-original-title", pollLangObj.copied );
3692 _this.attr( "title", pollLangObj.copied );
3693 _this.tooltip("show");
3694 } else if (document.selection && document.body.createTextRange) {
3695 var textRange = document.body.createTextRange();
3696 textRange.moveToElementText(el);
3697 textRange.select();
3698 }
3699 }
3700
3701 Date.prototype.aysPollCustomFormat = function( formatString){
3702 var YYYY,YY,MMMM,MMM,MM,M,DDDD,DDD,DD,D,hhhh,hhh,hh,h,mm,m,ss,s,ampm,AMPM,dMod,th;
3703 YY = ((YYYY=this.getFullYear())+"").slice(-2);
3704 MM = (M=this.getMonth()+1)<10?('0'+M):M;
3705 MMM = (MMMM=["January","February","March","April","May","June","July","August","September","October","November","December"][M-1]).substring(0,3);
3706 DD = (D=this.getDate())<10?('0'+D):D;
3707 DDD = (DDDD=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][this.getDay()]).substring(0,3);
3708 th=(D>=10&&D<=20)?'th':((dMod=D%10)==1)?'st':(dMod==2)?'nd':(dMod==3)?'rd':'th';
3709 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);
3710 h=(hhh=this.getHours());
3711 if (h==0) h=24;
3712 if (h>12) h-=12;
3713 hh = h<10?('0'+h):h;
3714 hhhh = hhh<10?('0'+hhh):hhh;
3715 AMPM=(ampm=hhh<12?'am':'pm').toUpperCase();
3716 mm=(m=this.getMinutes())<10?('0'+m):m;
3717 ss=(s=this.getSeconds())<10?('0'+s):s;
3718
3719 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);
3720 // token: description: example:
3721 // #YYYY# 4-digit year 1999
3722 // #YY# 2-digit year 99
3723 // #MMMM# full month name February
3724 // #MMM# 3-letter month name Feb
3725 // #MM# 2-digit month number 02
3726 // #M# month number 2
3727 // #DDDD# full weekday name Wednesday
3728 // #DDD# 3-letter weekday name Wed
3729 // #DD# 2-digit day number 09
3730 // #D# day number 9
3731 // #th# day ordinal suffix nd
3732 // #hhhh# 2-digit 24-based hour 17
3733 // #hhh# military/24-based hour 17
3734 // #hh# 2-digit hour 05
3735 // #h# hour 5
3736 // #mm# 2-digit minute 07
3737 // #m# minute 7
3738 // #ss# 2-digit second 09
3739 // #s# second 9
3740 // #ampm# "am" or "pm" pm
3741 // #AMPM# "AM" or "PM" PM
3742 };
3743
3744 function drawBasic() {
3745 if(typeof pollAnswerChartObj != "undefined"){
3746 var data = google.visualization.arrayToDataTable(pollAnswerChartObj.answerData);
3747 var rowCount = data.getNumberOfRows();
3748 var multiply;
3749 if(rowCount < 8){
3750 multiply = 40;
3751 }
3752 else{
3753 multiply = 30;
3754 }
3755 var chartAreaHeight = rowCount * multiply;
3756 var chartHeight = chartAreaHeight + 80;
3757
3758 /* === Old type === */
3759 // var options = {
3760 // title: pollAnswerChartObj.pollTitle,
3761 // width: '100%',
3762 // fontSize: 15,
3763 // height: chartHeight,
3764 // chartArea: {
3765 // width: '75%',
3766 // height: '80%'
3767 // },
3768 // hAxis: {
3769 // minValue: 0
3770 // }
3771 // };
3772
3773 /* === New type === */
3774 var options = {
3775 title: pollAnswerChartObj.pollTitle,
3776 width: '100%',
3777 height: chartHeight,
3778 fontSize: 15,
3779 chartArea: {
3780 width: '50%',
3781 height: '80%'
3782 },
3783 hAxis: {
3784 minValue: 0
3785 },
3786 annotations: {
3787 alwaysOutside: true
3788 },
3789 bars: 'horizontal',
3790 bar: { groupWidth: "50%" }
3791 };
3792
3793 var chart = new google.visualization.BarChart(document.getElementById('ays_poll_answer_chart'));
3794 // remove error
3795 // google.visualization.events.(chart, 'error', function (googleError) {
3796 // google.visualization.errors.removeError(googleError.id);
3797 // });
3798
3799 chart.draw(data, options);
3800 resizeChart(chart, data, options);
3801 }
3802 }
3803
3804 function resizeChart(chart, data, options){
3805
3806 //create trigger to resizeEnd event
3807 jQuery(window).resize(function() {
3808 if(this.resizeTO) clearTimeout(this.resizeTO);
3809 this.resizeTO = setTimeout(function() {
3810 jQuery(this).trigger('resizeEnd');
3811 }, 100);
3812 });
3813
3814 //redraw graph when window resize is completed
3815 jQuery(window).on('resizeEnd', function() {
3816 chart.draw(data, options);
3817 });
3818 }
3819
3820 function selectAndCopyElementContents(el) {
3821 if (window.getSelection && document.createRange) {
3822 var _this = jQuery(document).find('.ays-poll-copy-element-box');
3823
3824 var text = el.textContent;
3825 var textField = document.createElement('textarea');
3826
3827 textField.innerText = text;
3828 document.body.appendChild(textField);
3829 textField.select();
3830 document.execCommand('copy');
3831 textField.remove();
3832
3833 var selection = window.getSelection();
3834 selection.setBaseAndExtent(el,0,el,1);
3835
3836 _this.attr( "data-original-title", pollLangObj.copied );
3837 _this.attr( "title", pollLangObj.copied );
3838
3839 _this.tooltip("show");
3840
3841 } else if (document.selection && document.body.createTextRange) {
3842 var textRange = document.body.createTextRange();
3843 textRange.moveToElementText(el);
3844 textRange.select();
3845 }
3846 }
3847