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

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