PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.6
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.6
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.4.6, at admin/js/poll-maker-ays-admin.js

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