PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 5.6.3
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v5.6.3
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 5.6.6 All 153 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 5.6.3, at admin/js/poll-maker-ays-admin.js

3,546 lines 148.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
626 $(document).find('.nav-tab-wrapper a.nav-tab').each(function () {
627 if ($(this).hasClass('nav-tab-active')) {
628 $(this).removeClass('nav-tab-active');
629 }
630 });
631 $(this).addClass('nav-tab-active');
632 $(document).find('.ays-poll-tab-content').each(function () {
633 $(this).css('display', 'none');
634 });
635 $('#ays_poll_active_tab').val(activeTab);
636 $(document).find('#ays_poll_active_tab_settings').val(activeTabData);
637 $(document).find('#ays_poll_active_tab_results').val(activeTabData);
638 $('.ays-poll-tab-content' + elemenetID).css('display', 'block');
639 e.preventDefault();
640 });
641 $('.button-primary#ays-button').on('click', function () {
642 $('#ays_poll_active_tab').val("General");
643 });
644 $('.button-primary#ays-button-top').on('click', function () {
645 $('#ays_poll_active_tab').val("General");
646 });
647
648 // Submit buttons disableing with loader
649 var subButtons = '.button#ays-button-top,.button#ays-button-top-apply,.button#ays-button,.button#ays-button-apply,input#ays_submit';
650 $(subButtons).on('click', function () {
651 var $this = $(this);
652 submitOnce($this);
653 });
654
655 $(document).find(".button#ays-button-cat").on("click" , function(){
656 var catTitle = $(document).find("#ays-title").val();
657 if(catTitle != ''){
658 var $this = $(this);
659 subButtons += ',.button#ays-button-cat';
660 submitOnce($this);
661 }
662 });
663
664 function submitOnce(subButton){
665 var subLoader = subButton.siblings(".display_none");
666 subLoader.removeClass("display_none");
667 subLoader.css("padding-left" , "8px");
668 subLoader.css("display" , "inline-flex");
669 subLoader.css("align-items" , "center");
670 setTimeout(function() {
671 $(subButtons).attr('disabled', true);
672 }, 50);
673 setTimeout(function() {
674 $(subButtons).attr('disabled', false);
675 subLoader.addClass("display_none");
676 }, 5000);
677 }
678
679 function checkTheme() {
680 var themeId = $(this).find('input').val() || 0;
681 $('.ays_poll_theme_image_div label').each(function () {
682 $(this).removeClass('apm_active_theme');
683 });
684 $(this).find('label').addClass('apm_active_theme');
685 $('.apm-themes-row').attr('data-themeId',themeId);
686 if ($('#ays_poll_show_answers_icon').prop('checked')) {
687 switch(parseInt(themeId)){
688 case 3:
689 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
690 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
691 break;
692 default:
693 var iconsVal = $('input[name="ays_poll_answer_icon"]:checked').val();
694 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
695 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
696 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+iconsVal);
697 break;
698 }
699 }else{
700 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
701 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
702 }
703
704 answerStyleChange(themeId);
705
706 textColorChange({
707 color: themes[themeId].textColor
708 });
709 buttonTextColorChange({
710 color: themes[themeId].buttonTextColor
711 });
712 buttonBgColorChange({
713 color: themes[themeId].buttonBgColor
714 });
715 mainColorChange({
716 color: themes[themeId].mainColor
717 });
718 bgColorChange({
719 color: themes[themeId].bgColor
720 });
721 answerBgColorChange({
722 color: themes[themeId].answerBgColor
723 });
724 titleBgColorChange({
725 color: themes[themeId].titleBgColor
726 });
727 iconColorChange({
728 color: themes[themeId].iconColor
729 });
730 borderColorChange({
731 color: themes[themeId].borderColor
732 });
733 answerHoverColorChange({
734 color: themes[themeId].answerHoverColor
735 });
736
737 $('#ays-poll-text-color').wpColorPicker('color', themes[themeId].textColor);
738 $('#ays-poll-text-color').parent().parent().prev().css({
739 'background-color': themes[themeId].textColor
740 });
741
742 $('#ays-poll-button-text-color').wpColorPicker('color', themes[themeId].buttonTextColor);
743 $('#ays-poll-button-text-color').parent().parent().prev().css({
744 'color': themes[themeId].buttonTextColor
745 });
746
747 $('#ays-poll-button-bg-color').wpColorPicker('color', themes[themeId].buttonBgColor);
748 $('#ays-poll-button-bg-color').parent().parent().prev().css({
749 'background-color': themes[themeId].buttonBgColor
750 });
751
752 $('#ays-poll-answer-hover-color').wpColorPicker('color', themes[themeId].answerHoverColor);
753 $('#ays-poll-answer-hover-color').closest('.wp-picker-input-wrap').prev().css({
754 'background-color': themes[themeId].answerHoverColor
755 });
756
757 $('#ays-poll-main-color').wpColorPicker('color', themes[themeId].mainColor);
758 $('#ays-poll-main-color').parent().parent().prev().css({
759 'background-color': themes[themeId].mainColor
760 });
761
762 $('#ays-poll-bg-color').wpColorPicker('color', themes[themeId].bgColor);
763 $('#ays-poll-bg-color').parent().parent().prev().css({
764 'background-color': themes[themeId].bgColor
765 });
766
767 $('#ays-poll-answer-bg-color').wpColorPicker('color', themes[themeId].answerBgColor);
768 $('#ays-poll-answer-bg-color').parent().parent().prev().css({
769 'background-color': themes[themeId].answerBgColor
770 });
771
772 $('#ays-poll-title-bg-color').wpColorPicker('color', themes[themeId].titleBgColor);
773 $('#ays-poll-title-bg-color').parent().parent().prev().css({
774 'background-color': themes[themeId].titleBgColor
775 });
776
777 $('#ays-poll-icon-color').wpColorPicker('color', themes[themeId].iconColor);
778 $('#ays-poll-icon-color').parent().parent().prev().css({
779 'background-color': themes[themeId].iconColor
780 });
781 }
782
783 //checkTheme();
784 $('.ays_poll_theme_image_div:not(.apm-pro-feature)').on('click', checkTheme);
785
786 function checkType(type) {
787 var checkType = $('#type_choosing').prop('checked');
788 $('.ays_poll_type_image_div label').each(function () {
789 $(this).removeClass('apm_active_type');
790 });
791 $(this).find('label').addClass('apm_active_type');
792
793 var pollTypes = type;
794 var pollTypeCount = 0;
795 var pollVotingType = '';
796 if(pollTypes == 'rating'){
797 pollVotingType = $('#ays-poll-rate-type').val();
798 pollTypeCount = $('#ays-poll-rate-value').val();
799 $(document).find('.ays_poll_option_only_for_rating_voting_types').show();
800 }
801 else if(pollTypes == 'voting'){
802 pollVotingType = $("#ays-poll-vote-type").val();
803 pollTypeCount = $("#ays-poll-vote-type").length;
804 $(document).find('.ays_poll_option_only_for_rating_voting_types').show();
805 }
806 else if(pollTypes == 'text'){
807 pollVotingType = $("input[name='ays_poll_text_type']:checked").val();
808 }
809 livePrevToChoosing(pollTypes ,pollTypeCount, pollVotingType);
810
811 $('[class|="if"].poll-type-block ').hide().find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', false);
812 $('.if-' + pollTypes).css('display', 'flex').find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', true);
813 $(document).find('#ays_poll_question_text_max_length').attr('data-required', false);
814 $(document).find('#ays_poll_text_type_placeholder').attr('data-required', false);
815 $(document).find('#ays_poll_text_type_width').attr('data-required', false);
816 $('.if-choosing').find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', false);
817 checkHr(checkType ,pollTypes);
818
819 if(type == 'text'){
820 ays_tmce_setContent('<p style="text-align: center;">Thank you!</p>','ays_result_message');
821
822 // Set alignment default value to center
823 $(document).find('#apm-dir-center').prop('checked', true);
824 }
825
826 if (type != 'choosing') {
827 $(document).find('.ays_poll_option_only_for_choosing_type').hide();
828
829 if (type != 'text') {
830 $(document).find('.ays_poll_option_for_choosing_type.ays_poll_option_for_text_type').hide();
831 }
832 }
833 }
834
835 function ays_tmce_setContent(content, editor_id, textarea_id) {
836 if ( typeof editor_id == 'undefined' ) editor_id = wpActiveEditor;
837 if ( typeof textarea_id == 'undefined' ) textarea_id = editor_id;
838 if ( $(document).find('#wp-'+editor_id+'-wrap').hasClass('tmce-active') && tinyMCE && tinyMCE.get(editor_id) ) {
839 return tinyMCE.get(editor_id).setContent(content);
840 }else{
841 return $(document).find('#'+textarea_id).val(content);
842 }
843 }
844
845 var pollType = $(document).find('#poll_choose_type_first').val();
846 $('.if-' + pollType).css('display', 'flex').find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', true);
847 $('.if-choosing').find('select, input:not([type="hidden"]):not(.ays_redirect_active)').attr('data-required', false);
848 $(document).find('#ays_poll_question_text_max_length').attr('data-required', false);
849 $(document).find('#ays_poll_text_type_placeholder').attr('data-required', false);
850 $(document).find('#ays_poll_text_type_width').attr('data-required', false);
851
852 $('.ays_poll_type_image_div:not(.apm-pro-feature)').on('click', checkType);
853
854 function livePrevToChoosing(type , countSel , rateType){
855 if (typeof countSel == 'undefined') {
856 countSel = 0;
857 }
858 if (typeof rateType == 'undefined') {
859 countSel = '';
860 }
861 $(document).find('.box-apm').removeClass().addClass('box-apm '+type+'-poll');
862 var content = '';
863 var contText = '';
864 var checkAnsHover = $(document).find("#ays_answer_checker").val();
865 var cClass = '';
866 var contText = '';
867 switch(type){
868 case "choosing":
869 $(document).find(".ays-answer-value").each(function(index){
870 var image = $(this).parents("tr").find(".ays-poll-answer-img").attr("src");
871 var imageContainer = '';
872 var labelContainerClass = '';
873 var imageTextClass = '';
874 if(image != ""){
875 imageContainer = '<div><img src="'+image+'" class="ays-poll-answer-image-live"></div>';
876 labelContainerClass = 'ays_poll_label_without_padding';
877 imageTextClass = 'ays_poll_label_text_with_padding';
878 }
879 cClass = "ays_label_poll "+checkAnsHover+" ays_label_font_size";
880 contText = $(this).val();
881 content += "<div class='apm-"+type+" ays-poll-field ays_poll_list_view_item answer- ' data-id="+index+" data-lid="+index+"> ";
882 content += "<input type='radio' name='answer' id='radio-"+index+"-' value='"+index+"'>";
883 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>";
884 content += "</div>";
885 });
886 break;
887 case "rating":
888 var emoji = new Array(
889 "<i class='ays_poll_far ays_poll_fa-dizzy'></i>",
890 "<i class='ays_poll_far ays_poll_fa-smile'></i>",
891 "<i class='ays_poll_far ays_poll_fa-meh'></i>",
892 "<i class='ays_poll_far ays_poll_fa-frown'></i>",
893 "<i class='ays_poll_far ays_poll_fa-tired'></i>"
894 );
895 if(rateType == 'emoji'){
896 var valueIndex = countSel;
897 if(countSel == 4){
898 valueIndex = 5;
899 }
900 for(var i = 0; i < valueIndex; i++){
901 content += "<div class='apm-"+type+" answer- ' data-id="+i+">";
902 content += "<input type='radio' name='answer' id='radio-"+i+"-' value='"+i+"'>"
903 content += "<label class="+cClass+" for='radio-"+i+"-' >"+emoji[(valueIndex / 2) - i + 1.5]+"</label>"
904 content += "</div>";
905 }
906 }
907 else if(rateType == 'star'){
908 for(var i = 0; i < countSel; i++){
909 contText = "<i class='ays_poll_far ays_poll_fa-star'></i>";
910 content += "<div class='apm-"+type+" answer- ' data-id="+i+">";
911 content += "<input type='radio' name='answer' id='radio-"+i+"-' value='"+i+"'>"
912 content += "<label class="+cClass+" for='radio-"+i+"-' >"+contText+"</label>"
913 content += "</div>";
914 }
915 }
916 break;
917 case "voting":
918 var emojiThumb;
919 var toUp = '';
920 var toDown = '';
921 if(rateType == "hand"){
922 toUp = 'thumbs-up';
923 toDown = 'thumbs-down';
924 }
925 else if(rateType == "emoji"){
926 toUp = 'smile';
927 toDown = 'frown';
928 }
929 var emojiThumb = new Array(
930 '<i class="ays_poll_far ays_poll_fa-'+toUp+'"></i>',
931 '<i class="ays_poll_far ays_poll_fa-'+toDown+'"></i>'
932 );
933 for(var i = 0 ; i <= countSel ; i++){
934 content += "<div class='apm-"+type+" answer- ' data-id="+i+">";
935 content += "<input type='radio' name='answer' id='radio-"+i+"-' value='"+i+"'>"
936 content += "<label class="+cClass+" for='radio-"+i+"-' >"+emojiThumb[i]+"</label>"
937 content += "</div>";
938 }
939 break;
940 case "text":
941 var textType = rateType;
942 var textPlaceholder = $(document).find("#ays_poll_text_type_placeholder");
943 var textPlaceholderVal = textPlaceholder.val();
944 switch(textType){
945 case "short_text":
946 content += "<div class='ays-poll-maker-"+type+"-live-preview' >";
947 content += "<input type='text' id='ays_poll_text_type_short_live' placeholder='"+textPlaceholderVal+"' readonly class='ays-poll-text-type-fields'>"
948 content += "<label for='ays_poll_text_type_short_live'></label>"
949 content += "</div>";
950 break;
951 case "paragraph":
952 content += "<div class='ays-poll-maker-"+type+"-live-preview'>";
953 content += "<textarea id='ays_poll_text_type_paragraph_live' readonly placeholder='"+textPlaceholderVal+"' class='ays-poll-text-type-fields'></textarea>"
954 content += "<label for='ays_poll_text_type_paragraph_live'></label>"
955 content += "</div>";
956 break;
957 }
958 break;
959 }
960 $(document).find(".apm-answers").html(content);
961 }
962 function goToPro() {
963 window.open(
964 'https://ays-pro.com/wordpress/poll-maker/',
965 '_blank'
966 );
967 return false;
968 }
969
970 $(document).on('click', "[id|='select2'] li[id$='-pro']", goToPro);
971 $('.ays_poll_theme_image_div.apm-pro-feature').on('click', goToPro);
972 $('.apm-loader.apm-pro-feature').on('click', goToPro);
973 $('.apm-pro-feature-link').on('click', goToPro);
974
975 //**********************/
976 //LIVE PREVIEW
977 //*********************/
978 var themeId = $('.apm_active_theme+input').val() || 0;
979
980 $(document).find('#ays-poll-main-color').wpColorPicker({
981 defaultColor: themes[themeId].mainColor,
982 change: function(event, ui) {
983 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].mainColor});
984 mainColorChange(ui);
985 }
986 });
987 $(document).find('#ays-poll-text-color').wpColorPicker({
988 defaultColor: themes[themeId].textColor,
989 change: function(event, ui) {
990 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].textColor});
991 textColorChange(ui);
992 }
993 });
994 $(document).find('#ays-poll-button-text-color').wpColorPicker({
995 defaultColor: themes[themeId].buttonTextColor,
996 change: function(event, ui) {
997 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].buttonTextColor});
998 buttonTextColorChange(ui);
999 }
1000 });
1001 $(document).find('#ays-poll-button-bg-color').wpColorPicker({
1002 defaultColor: themes[themeId].buttonBgColor,
1003 change: function(event, ui) {
1004 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].buttonBgColor});
1005 buttonBgColorChange(ui);
1006 }
1007 });
1008 $(document).find('#ays-poll-icon-color').wpColorPicker({
1009 defaultColor: themes[themeId].iconColor,
1010 change: function(event, ui) {
1011 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].iconColor});
1012 iconColorChange(ui);
1013 }
1014 });
1015 $(document).find('#ays-poll-bg-color').wpColorPicker({
1016 defaultColor: themes[themeId].bgColor,
1017 change: function(event, ui) {
1018 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].bgColor});
1019 bgColorChange(ui);
1020 }
1021 });
1022 $(document).find('#ays-poll-answer-bg-color').wpColorPicker({
1023 defaultColor: themes[themeId].answerBgColor,
1024 change: function(event, ui) {
1025 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].answerBgColor});
1026 answerBgColorChange(ui);
1027 }
1028 });
1029 $(document).find('#ays-poll-answer-hover-color').wpColorPicker({
1030 defaultColor: themes[themeId].answerHoverColor,
1031 change: function(event, ui) {
1032 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].answerHoverColor});
1033 answerHoverColorChange(ui);
1034 }
1035 });
1036 $(document).find('#ays-poll-title-bg-color').wpColorPicker({
1037 defaultColor: themes[themeId].titleBgColor,
1038 change: function(event, ui) {
1039 $(this).wpColorPicker({defaultColor: themes[$('.apm_active_theme+input').val()].titleBgColor});
1040 titleBgColorChange(ui);
1041 }
1042 });
1043 $(document).find('#ays-poll-box-shadow-color').wpColorPicker({
1044 defaultColor: '#000000',
1045 change: function(event, ui) {
1046 boxShadowColorChange(ui);
1047 }
1048 });
1049
1050
1051 $(document).find('#ays-background-gradient-color-1').wpColorPicker({
1052 defaultColor: '#103251',
1053 change: function(event, ui) {
1054 toggleBackgrounGradient();
1055 }
1056 });
1057 $(document).find('#ays-background-gradient-color-2').wpColorPicker({
1058 defaultColor: '#607593',
1059 change: function(event, ui) {
1060 toggleBackgrounGradient();
1061 }
1062 });
1063
1064 $(document).find('#ays-poll-border-color').wpColorPicker({
1065 defaultColor: '#0C6291',
1066 change: function(event, ui) {
1067 borderColorChange(ui);
1068 }
1069 });
1070 $(document).find('#ays_poll_title_text_shadow_color').wpColorPicker({
1071 defaultColor: 'rgba(255,255,255,0)',
1072 change: function(event, ui) {
1073 textShadowChange(ui);
1074 }
1075 });
1076 $(document).find('.ays-title-text-shadow-coord-change').on('change', function(){
1077 var color = $(document).find('#ays_poll_title_text_shadow_color').val();
1078 textShadowChange(color);
1079 });
1080
1081 $(document).find('#ays_poll_enable_title_text_shadow').on('change', function(){
1082 var color = $(document).find('#ays_poll_title_text_shadow_color').val();
1083 var checkedShadow = $(this).prop('checked');
1084 if(checkedShadow){
1085 textShadowChange(color);
1086 }else{
1087 $(document).find(".apm-title-box > h5").css("text-shadow" , "unset");
1088 }
1089 });
1090
1091 $(document).find('#ays_poll_answers_box_shadow_color').wpColorPicker({
1092 defaultColor: '#0C6291',
1093 change: function(event, ui) {
1094 }
1095 });
1096 if($(document).find('#ays-poll-bg-image').val() != ''){
1097 $('.box-apm').css('background-image', 'url('+ $(document).find('#ays-poll-bg-image').val() +')');
1098 $('.box-apm').css('background-position', $(document).find('#ays-poll-bg-image-pos').val());
1099 }
1100
1101
1102 function mainColorChange(ui) {
1103 var color = ui.color.toString();
1104 document.documentElement.style.setProperty('--theme-main-color', color);
1105 $('#ays-poll-main-color')
1106 .attr('value', color)
1107 .parents('.wp-picker-container')
1108 .find('.color-alpha').css('background-color', color);
1109 }
1110
1111 function textColorChange(ui) {
1112 var color = ui.color.toString();
1113 document.documentElement.style.setProperty('--theme-text-color', color);
1114 $('#ays-poll-text-color')
1115 .attr('value', color)
1116 .parents('.wp-picker-container')
1117 .find('.color-alpha').css('background-color', color);
1118 }
1119
1120 function buttonTextColorChange(ui) {
1121 var color = ui.color.toString();
1122 $(document).find('input[type="button"].ays-poll-btn').css('color', color);
1123 $('#ays-poll-button-text-color')
1124 .attr('value', color)
1125 .parents('.wp-picker-container')
1126 .find('.color-alpha').css('background-color', color);
1127 }
1128
1129 function buttonBgColorChange(ui) {
1130 var color = ui.color.toString();
1131 $(document).find('input[type="button"].ays-poll-btn').css('background-color', color);
1132 $('#ays-poll-button-bg-color')
1133 .attr('value', color)
1134 .parents('.wp-picker-container')
1135 .find('.color-alpha').css('background-color', color);
1136 }
1137
1138 function iconColorChange(ui) {
1139 var color = ui.color.toString();
1140 document.documentElement.style.setProperty('--theme-icon-color', color);
1141 $('#ays-poll-icon-color')
1142 .attr('value', color)
1143 .parents('.wp-picker-container')
1144 .find('.color-alpha').css('background-color', color);
1145 }
1146
1147 function bgColorChange(ui) {
1148 var color = ui.color.toString();
1149 document.documentElement.style.setProperty('--theme-bg-color', color);
1150 $('#ays-poll-bg-color')
1151 .attr('value', color)
1152 .parents('.wp-picker-container')
1153 .find('.color-alpha').css('background-color', color);
1154 }
1155
1156 function borderColorChange(ui) {
1157 var color = ui.color.toString();
1158 $(document).find(".box-apm").css("border-color" , color);
1159 $('#ays-poll-border-color')
1160 .val(color)
1161 .parents('.wp-picker-container')
1162 .find('.color-alpha').css('background-color', color);
1163 }
1164
1165 function textShadowChange(ui , isChecked) {
1166 if (typeof ui == 'object') {
1167 var color = ui.color.toString();
1168 }else{
1169 var color = ui;
1170 }
1171 var x_offset = $(document).find('input#ays_poll_title_text_shadow_x_offset').val() + "px ";
1172 var y_offset = $(document).find('input#ays_poll_title_text_shadow_y_offset').val() + "px ";
1173 var z_offset = $(document).find('input#ays_poll_title_text_shadow_z_offset').val() + "px ";
1174
1175 var boxShadow = x_offset + y_offset + z_offset;
1176 if($(document).find('#ays_poll_enable_title_text_shadow').prop("checked")){
1177 $(document).find(".apm-title-box > h5").css("text-shadow" , boxShadow+" "+ color);
1178
1179 }
1180 $('#ays_poll_title_text_shadow_color')
1181 .val(color)
1182 .parents('.wp-picker-container')
1183 .find('.color-alpha').css('background-color', color);
1184 }
1185
1186 var answer_border_side = $(document).find('#ays-poll-border-side').val();
1187 answerBorderSideChange(answer_border_side);
1188
1189 function answerBorderSideChange(side) {
1190 var checked_answ = $(document).find( '#ays_poll_enable_answer_style').prop("checked");
1191 if (side == 'none' || !checked_answ) {
1192 $(document).find('.box-apm.choosing-poll label').each(function(){
1193 $(this)[0].style.border = 'none';
1194 });
1195 }else{
1196 switch(side) {
1197 case 'all_sides':
1198 $(document).find('.box-apm.choosing-poll label').each(function(){
1199 $(this)[0].style.border = '1px solid';
1200 });
1201 break;
1202 case 'top':
1203 $(document).find('.box-apm.choosing-poll label').each(function(){
1204 $(this)[0].style.border = 'none';
1205 $(this)[0].style.borderTop = '1px solid';
1206 });
1207 break;
1208 case 'bottom':
1209 $(document).find('.box-apm.choosing-poll label').each(function(){
1210 $(this)[0].style.border = 'none';
1211 $(this)[0].style.borderBottom = '1px solid';
1212 });
1213 break;
1214 case 'left':
1215 $(document).find('.box-apm.choosing-poll label').each(function(){
1216 $(this)[0].style.border = 'none';
1217 $(this)[0].style.borderLeft = '1px solid';
1218 });
1219 break;
1220 case 'right':
1221 $(document).find('.box-apm.choosing-poll label').each(function(){
1222 $(this)[0].style.border = 'none';
1223 $(this)[0].style.borderRight = '1px solid';
1224 });
1225 break;
1226 }
1227 }
1228 }
1229
1230 function answerStyleChange(theme_id) {
1231 if (theme_id == 3) {
1232 $('.box-apm').find('.apm-choosing').addClass('ays_poll_minimal_theme');
1233 $('.box-apm').find('.btn.ays-poll-btn').addClass('ays_poll_minimal_theme_btn');
1234 $('#ays_poll_enable_answer_style').prop('checked', false).trigger("change");
1235 $('#ays_poll_answers_box_shadow_enable').prop('checked', false).trigger("change");
1236 $('.ays_answer_style').hide();
1237 answerBorderSideChange("none");
1238 $('#ays-poll-border-width').val(0);
1239 document.documentElement.style.setProperty('--poll-border-width', "0px");
1240 }else{
1241 $('.box-apm').find('.apm-choosing').removeClass('ays_poll_minimal_theme');
1242 $('.box-apm').find('.btn.ays-poll-btn').removeClass('ays_poll_minimal_theme_btn');
1243 $('#ays_poll_enable_answer_style').prop('checked' , true);
1244 $('.ays_answer_style').show();
1245 answerBorderSideChange("all_sides");
1246 }
1247 }
1248
1249 function answerBgColorChange(ui) {
1250 if (typeof ui == 'object') {
1251 var color = ui.color.toString();
1252 }else{
1253 var color = ui;
1254 }
1255
1256 if (color == 'transparent' || !$(document).find('#ays_poll_enable_answer_style').prop("checked")) {
1257 document.documentElement.style.setProperty('--theme-answer-bg-color', "initial");
1258 }else{
1259 document.documentElement.style.setProperty('--theme-answer-bg-color', color);
1260 $('#ays-poll-answer-bg-color')
1261 .attr('value', color)
1262 .parents('.wp-picker-container')
1263 .find('.color-alpha').css('background-color', color);
1264 }
1265
1266 }
1267
1268 function answerHoverColorChange(ui) {
1269 if (typeof ui == 'object') {
1270 var color = ui.color.toString();
1271 } else {
1272 var color = ui;
1273 }
1274
1275 if (color == 'transparent' || !$(document).find('#ays_poll_enable_answer_style').prop("checked")) {
1276 document.documentElement.style.setProperty('--theme-answer-hover-color', "initial");
1277 } else {
1278 document.documentElement.style.setProperty('--theme-answer-hover-color', color);
1279 $('#ays-poll-answer-hover-color')
1280 .attr('value', color)
1281 .parents('.wp-picker-container')
1282 .find('.color-alpha').css('background-color', color);
1283 }
1284 }
1285
1286 function titleBgColorChange(ui) { //aray
1287 var color = ui.color.toString();
1288 document.documentElement.style.setProperty('--theme-title-bg-color', color);
1289 $('#ays-poll-title-bg-color')
1290 .attr('value', color)
1291 .parents('.wp-picker-container')
1292 .find('.color-alpha').css('background-color', color);
1293 }
1294
1295 function boxShadowColorChange(ui) {
1296 if (typeof ui == 'object') {
1297 var color = ui.color.toString();
1298 }else{
1299 var color = ui;
1300 }
1301
1302 if (color == 'transparent' || !$(document).find('#ays_poll_enable_box_shadow').prop("checked")) {
1303 document.documentElement.style.setProperty('--poll-box-shadow', "initial");
1304 }else{
1305 var x_offset = $(document).find('input#ays_poll_box_shadow_x_offset').val() + "px ";
1306 var y_offset = $(document).find('input#ays_poll_box_shadow_y_offset').val() + "px ";
1307 var z_offset = $(document).find('input#ays_poll_box_shadow_z_offset').val() + "px ";
1308
1309 var boxShadow = x_offset + y_offset + z_offset;
1310
1311 document.documentElement.style.setProperty('--poll-box-shadow', color + " " + boxShadow + " 1px");
1312 $('#ays-poll-box-shadow-color')
1313 .attr('value', color)
1314 .parents('.wp-picker-container')
1315 .find('.color-alpha').css('background-color', color);
1316 }
1317 }
1318
1319 /*
1320 ==========================================
1321 Background Gradient
1322 ==========================================
1323 */
1324 function toggleBackgrounGradient() {
1325 if ($(document).find('#ays-enable-background-gradient').prop('checked') || $(document).find('input#ays-poll-bg-image').val() != '') {
1326 if($(document).find('#ays_poll_gradient_direction').val() != '') {
1327 var ays_poll_gradient_direction = $(document).find('#ays_poll_gradient_direction').val();
1328 switch(ays_poll_gradient_direction) {
1329 case "horizontal":
1330 ays_poll_gradient_direction = "to right";
1331 break;
1332 case "diagonal_left_to_right":
1333 ays_poll_gradient_direction = "to bottom right";
1334 break;
1335 case "diagonal_right_to_left":
1336 ays_poll_gradient_direction = "to bottom left";
1337 break;
1338 default:
1339 ays_poll_gradient_direction = "to bottom";
1340 }
1341
1342 if($(document).find('input#ays-poll-bg-image').val() != ''){
1343 return false;
1344 }else{
1345 $(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()+")"
1346 });
1347 }
1348 }
1349 }
1350 else{
1351 $(document).find('.box-apm').css('background-image' , "unset");
1352 return false;
1353 }
1354 }
1355
1356 var ays_poll_box_gradient_color1_picker = {
1357 change: function (e) {
1358 setTimeout(function () {
1359 toggleBackgrounGradient();
1360 }, 1);
1361 }
1362 };
1363
1364 var ays_poll_box_gradient_color2_picker = {
1365 change: function (e) {
1366 setTimeout(function () {
1367 toggleBackgrounGradient();
1368 }, 1);
1369 }
1370 };
1371
1372 function ays_poll_search_box_pagination(listTableClass, searchBox) {
1373 if($(document).find( "." + listTableClass ).length) {
1374 if($(document).find( "#" + searchBox ).length) {
1375 var search_string = $(document).find("#" + searchBox).val();
1376 if(search_string != "") {
1377 $(document).find("."+ listTableClass +" .pagination-links a").each(function() {
1378 if ( typeof this.href != "undefined" && this.href != "" ) {
1379 if ( this.href.indexOf("&s=") < 0 ) {
1380 this.href = this.href + "&s=" + search_string;
1381 }
1382 }
1383 });
1384 }
1385 }
1386 }
1387 }
1388
1389 $(document).find('#ays_poll_gradient_direction').on('change', function () {
1390 toggleBackgrounGradient();
1391 });
1392
1393 $(document).find('#ays-background-gradient-color-1').wpColorPicker(ays_poll_box_gradient_color1_picker);
1394 $(document).find('#ays-background-gradient-color-2').wpColorPicker(ays_poll_box_gradient_color2_picker);
1395
1396 toggleBackgrounGradient();
1397 $(document).find('input#ays-enable-background-gradient').on('change', function () {
1398 toggleBackgrounGradient();
1399 });
1400
1401 $(document).on('click', '.ays-remove-poll-bg-img', function () {
1402 $(document).find('.box-apm').css({'background-image': 'none'});
1403 toggleBackgrounGradient();
1404 });
1405
1406 $(document).find('#ays_poll_enable_answer_style').on('change', function () {
1407 var checkboxProp = $(this).prop('checked');
1408 var color = $(this).prop('checked') ? $(document).find('#ays-poll-answer-bg-color').val() : "transparent";
1409 var hoverColor = $(this).prop('checked') ? $(document).find('#ays-poll-answer-hover-color').val() : "#0C6291";
1410 var side = $(this).prop('checked') ? $(document).find('#ays-poll-border-side').val() : "none";
1411 answerBgColorChange(color);
1412 answerHoverColorChange(hoverColor);
1413 answerBorderSideChange(side);
1414 refreshLivePreview(checkboxProp);
1415 });
1416
1417 $(document).find('#ays_poll_enable_box_shadow').on('change', function () {
1418 var color = $(this).prop('checked') ? $(document).find('#ays-poll-box-shadow-color').val() : "transparent";
1419 boxShadowColorChange(color);
1420 });
1421
1422 $(document).find('input.ays-box-shadow-coord-change').on('change', function () {
1423 var color = $(document).find('#ays-poll-box-shadow-color').val();
1424 boxShadowColorChange(color);
1425 });
1426
1427 $(document).find('#ays-enable-background-gradient').on('change', function () {
1428 var color = $(this).prop('checked') ? $(document).find('#ays-background-gradient-color-1').val() : "transparent";
1429 toggleBackgrounGradient(color);
1430 });
1431
1432 $(document).find('#ays-enable-background-gradient').on('change', function () {
1433 var color = $(this).prop('checked') ? $(document).find('#ays-background-gradient-color-2').val() : "transparent";
1434 toggleBackgrounGradient(color);
1435 });
1436
1437 $('#ays-poll-icon-size').on('change', function () {
1438 var val = (+$(this).val() > 10) ? $(this).val() : 10;
1439 $(this).val(val);
1440 var value = val + 'px';
1441 document.documentElement.style.setProperty('--poll-icons-size', value);
1442 });
1443
1444 $('#ays-poll-width').on('change', function () {
1445 var val = +$(this).val();
1446 if (val === 0) {
1447 val = "100%";
1448 } else {
1449 val = (val > 249 ? val : 250) + "px";
1450 }
1451 document.documentElement.style.setProperty('--poll-width', val);
1452 });
1453
1454 $('#ays-poll-btn-text').on('change', function () {
1455 var val = $(this).val() !== '' ? $(this).val() : "Vote";
1456 $('.ays-poll-btn').val(val)
1457 });
1458
1459 $('#ays-poll-border-style').on('change', function () {
1460 var val = $(this).val();
1461 document.documentElement.style.setProperty('--poll-border-style', val);
1462 });
1463
1464 $('#ays-poll-border-side').on('change', function () {
1465 var val = $(this).val();
1466
1467 switch(val) {
1468 case 'none':
1469 $(document).find('.box-apm.choosing-poll label').each(function(){
1470 $(this)[0].style.border = 'none';
1471 });
1472 break;
1473 case 'all_sides':
1474 $(document).find('.box-apm.choosing-poll label').each(function(){
1475 $(this)[0].style.border = '1px solid';
1476 });
1477 break;
1478 case 'top':
1479 $(document).find('.box-apm.choosing-poll label').each(function(){
1480 $(this)[0].style.border = 'none';
1481 $(this)[0].style.borderTop = '1px solid';
1482 });
1483 break;
1484 case 'bottom':
1485 $(document).find('.box-apm.choosing-poll label').each(function(){
1486 $(this)[0].style.border = 'none';
1487 $(this)[0].style.borderBottom = '1px solid';
1488 });
1489 break;
1490 case 'left':
1491 $(document).find('.box-apm.choosing-poll label').each(function(){
1492 $(this)[0].style.border = 'none';
1493 $(this)[0].style.borderLeft = '1px solid';
1494 });
1495 break;
1496 case 'right':
1497 $(document).find('.box-apm.choosing-poll label').each(function(){
1498 $(this)[0].style.border = 'none';
1499 $(this)[0].style.borderRight = '1px solid';
1500 });
1501 break;
1502 }
1503 });
1504
1505 $(document).on('click', 'a.add-poll-bg-music', function (e) {
1506 openMusicMediaUploader(e, $(this));
1507 });
1508
1509 $('#ays-poll-border-radius').on('change', function () {
1510 var val = $(this).val();
1511 var value = val + 'px';
1512 document.documentElement.style.setProperty('--poll-border-radius', value);
1513 });
1514
1515 $('#ays-poll-border-width').on('change', function () {
1516 var val = $(this).val();
1517 var value = val + 'px';
1518 document.documentElement.style.setProperty('--poll-border-width', value);
1519 });
1520
1521 $('#ays_custom_css').on('change', function () {
1522 var val = $(this).val();
1523 $('#apm-custom-css').html(val);
1524 });
1525
1526 $('#show-title').on('change', function () {
1527 $('.apm-title-box').fadeToggle();
1528 });
1529
1530 $('#ays-poll-title').on('change', function () {
1531 var val = $(this).val();
1532 $('.apm-title-box h5').text(val);
1533 });
1534 var checkAnswerStyle = $(document).find("#ays_poll_enable_answer_style").prop("checked");
1535 $(document).on('change', '.ays-poll-question-font-size,#ays_poll_question_image_height,#ays_answers_view,#ays_poll_answer_img_height,#ays_poll_answer_image_border_radius,#ays_poll_image_background_size,#ays_poll_answers_padding,#ays_poll_answers_margin,#ays_poll_title_font_size,#ays_poll_title_alignment,#ays_poll_text_type_placeholder,#ays_poll_question_image_object_fit,#ays_poll_answers_box_shadow_enable,#ays_poll_answers_box_shadow_color,#ays_poll_answer_border_radius,#ays_poll_answer_box_shadow_x_offset,#ays_poll_answer_box_shadow_y_offset,#ays_poll_answer_box_shadow_z_offset' , function () {
1536 var checkAnswerStyleOnChange = $(document).find("#ays_poll_enable_answer_style").prop("checked");
1537 refreshLivePreview(checkAnswerStyleOnChange);
1538 });
1539
1540 //PRO features lightbox
1541 $('.open-lightbox').on('click', function (e) {
1542 e.preventDefault();
1543 var image = $(this).attr('href');
1544 $('html').addClass('no-scroll');
1545 $('.ays-poll-row ').append('<div class="lightbox-opened"><img src="' + image + '"></div>');
1546 });
1547 $('body').on('click', '.lightbox-opened', function () {
1548 $('html').removeClass('no-scroll');
1549 $('.lightbox-opened').remove();
1550 });
1551
1552 $(document).on('change', '.ays_toggle', function (e) {
1553 var state = $(this).prop('checked');
1554 if ($(this).hasClass('ays_toggle_slide')) {
1555 switch (state) {
1556 case true:
1557 $(this).parent().find('.ays_toggle_target').slideDown(250);
1558 if($(this).parent().find('.ays_toggle_target').hasClass("display_none")){
1559 $(this).parent().find('.ays_toggle_target').removeClass("display_none");
1560 }
1561 break;
1562 case false:
1563 $(this).parent().find('.ays_toggle_target').slideUp(250);
1564 break;
1565 }
1566 } else {
1567 switch (state) {
1568 case true:
1569 $(this).parent().find('.ays_toggle_target').show(250);
1570 break;
1571 case false:
1572 $(this).parent().find('.ays_toggle_target').hide(250);
1573 break;
1574 }
1575 }
1576 });
1577
1578 $(document).on('change', '.ays_toggle_checkbox', function (e) {
1579 var state = $(this).prop('checked');
1580 var parent = $(this).closest('.ays_toggle_parent');
1581
1582 if($(this).hasClass('ays_toggle_slide')){
1583 switch (state) {
1584 case true:
1585 parent.find('.ays_toggle_target').slideDown(500);
1586 break;
1587 case false:
1588 parent.find('.ays_toggle_target').slideUp(500);
1589 break;
1590 }
1591 }else{
1592 var targetEl = parent.find('.ays_toggle_target');
1593 for (let i = 0; i<targetEl.length; i++) {
1594 if(targetEl.eq(i).closest('.ays_toggle_parent')[0] != parent[0]) {
1595 targetEl.splice(i, 1);
1596 i--;
1597 }
1598 }
1599
1600 switch (state) {
1601 case true:
1602 targetEl.show(250);
1603 break;
1604 case false:
1605 targetEl.hide(250);
1606 break;
1607 }
1608 }
1609 });
1610
1611 $(document).on('click', '.ays_poll_block_with_hidden_row_show_row_block, .ays_poll_block_with_hidden_row_hide_row_block', toggleHiddenBlockRow)
1612
1613 function toggleHiddenBlockRow() {
1614 var isShow = $(this).hasClass('ays_poll_block_with_hidden_row_show_row_block');
1615 var mainBlock = $(this).parents('.ays_poll_block_with_hidden_row');
1616
1617 if (isShow) {
1618 $(mainBlock).find(".ays_poll_hidden_block_content").show(200);
1619 $(mainBlock).find(".ays_poll_hidden_hr_content").show(200);
1620 } else {
1621 $(mainBlock).find(".ays_poll_hidden_block_content").hide(200);
1622 $(mainBlock).find(".ays_poll_hidden_hr_content").hide(200);
1623 }
1624 }
1625
1626 let toggle_ddmenu = $(document).find('.toggle_ddmenu');
1627 toggle_ddmenu.on('click', function () {
1628 let ddmenu = $(this).next();
1629 let state = ddmenu.attr('data-expanded');
1630 switch (state) {
1631 case 'true':
1632 $(this).find('.ays_poll_fa').css({
1633 transform: 'rotate(0deg)'
1634 });
1635 ddmenu.attr('data-expanded', 'false');
1636 break;
1637 case 'false':
1638 $(this).find('.ays_poll_fa').css({
1639 transform: 'rotate(90deg)'
1640 });
1641 ddmenu.attr('data-expanded', 'true');
1642 break;
1643 }
1644 });
1645
1646 $(document).find('table.ays-answers-table tbody').sortable({
1647 handle: 'td.ays-sort',
1648 cursor: 'move',
1649 opacity: 0.8,
1650 tolerance: "pointer",
1651 helper: function(e, tr) {
1652 var $originals = tr.children();
1653 var $helper = tr.clone();
1654 $helper.children().each(function(index)
1655 {
1656 // Set helper cell sizes to match the original sizes
1657 $(this).width($originals.eq(index).width());
1658 });
1659 return $helper;
1660 },
1661 axis: 'y',
1662 revert: true,
1663 forcePlaceholderSize: true,
1664 forceHelperSize: true,
1665 start: function(event, ui) {
1666 $(this).find('th:nth-child(4)').addClass('ays_poll_display_none');
1667 $(this).find('th:nth-child(3)').addClass('ays_poll_display_none');
1668 if( $(this).find('td.ays-f-votes-row').hasClass('ays_poll_display_none')){
1669 $(this).find('td:nth-child(4)').addClass('ays_poll_display_none');
1670 }
1671 if( $(this).find('td.ays-answer-redirect-row').hasClass('ays_poll_display_none')){
1672 $(this).find('td:nth-child(3)').addClass('ays_poll_display_none');
1673 }
1674 ui.helper.css('display', 'table')
1675 },
1676 stop: function(event, ui) {
1677 ui.item.css('display', '');
1678 },
1679 update: function (event, ui) {
1680 var className = ui.item.attr('class').split(' ')[0];
1681 $('.ays-answers-table').find('tr.' + className).each(function (index) {
1682 var classEven = (((index + 1) % 2) === 0) ? 'even' : '';
1683 if ($(this).hasClass('even')) {
1684 $(this).removeClass('even');
1685 }
1686 $(this).addClass(classEven);
1687 $(this).children("td:nth-child(2)").find(".ays-answer-value").attr('data-lid' , index).trigger('change');
1688 $(this).children("td:nth-child(5)").find(".ays-delete-answer").attr('data-lid' , index);
1689 });
1690 livePrevToChoosing('choosing');
1691 }
1692 });
1693
1694 $(document).find('.poll-maker-challenge-cancel').on('click', function() {
1695 var challengeBox = $(this).closest('.poll-maker-challenge');
1696 var wp_nonce = $(document).find('#poll_maker_ajax_challenge_cancel_nonce').val();
1697
1698 $.ajax({
1699 url: poll.ajax,
1700 type: 'POST',
1701 data: {
1702 action: 'delete_challenge_box',
1703 _ajax_nonce: wp_nonce
1704 },
1705 success: function(response) {
1706 var result = JSON.parse(response);
1707
1708 if (result.success) {
1709 challengeBox.remove();
1710 }
1711 }
1712 });
1713 })
1714
1715 $(document).find('#ays_poll_create_author').select2({
1716 placeholder: 'Select users',
1717 minimumInputLength: 1,
1718 allowClear: true,
1719 language: {
1720 // You can find all of the options in the language files provided in the
1721 // build. They all must be functions that return the string that should be
1722 // displayed.
1723 inputTooShort: function () {
1724 return poll.pleaseEnterMore;
1725 }
1726 },
1727 ajax: {
1728 url: poll.ajax,
1729 dataType: 'json',
1730 data: function (response) {
1731 var checkedUsers = $(document).find('#ays_poll_create_author').val();
1732 return {
1733 action: 'ays_poll_create_author',
1734 search: response.term,
1735 val: checkedUsers,
1736 };
1737 },
1738 }
1739 });
1740
1741 $(document).on("input", 'input', function (e) {
1742 if (e.keyCode == 13) {
1743 return false;
1744 }
1745 });
1746 // $(document).on("keydown", function (e) {
1747 // if (e.target.nodeName == "TEXTAREA") {
1748 // return true;
1749 // }
1750 // if (e.keyCode == 13) {
1751 // return false;
1752 // }
1753 // if(e.keyCode === 27){
1754 // $(document).find('.ays-modal').aysModal('hide');
1755 // $(document).find('.ays-modal-backdrop').remove();
1756 // return false;
1757 // }
1758 // });
1759
1760 $('.active_date_check').change(function () {
1761 if ($(this).prop('checked')) {
1762 $('.active_date').show(250);
1763 } else {
1764 $('.active_date').hide(250);
1765 }
1766 });
1767
1768 //Each results
1769 if ($('.unread-result-badge.unread-result').length > 0) {
1770 $('.unread-result-badge.unread-result').each(function () {
1771 $(this).parent().parent().find('td').css('font-weight', 'bold')
1772 })
1773 }
1774
1775 //Each results
1776 if ($('.ays_poll_unread').length > 0) {
1777 $('.ays_poll_unread').each(function () {
1778 $(this).parent().parent().find('td').css('font-weight', 'bold')
1779 })
1780 }
1781
1782 $('#ays_poll_show_timer').change(function () {
1783 if ($(this).prop('checked')) {
1784 $('.ays_show_time').show(250);
1785 } else {
1786 $('.ays_show_time').hide(250);
1787 }
1788 });
1789
1790 $('#show_result_btn_schedule').change(function () {
1791 if ($(this).prop('checked')) {
1792 $('.result_btn_see').show(250);
1793 } else {
1794 $('.result_btn_see').hide(250);
1795 }
1796 });
1797
1798 //info_form
1799 $("#ays_poll_info_form").change(function () {
1800 if ($(this).prop('checked')) {
1801 $(this).parents(".form-group").find(".form-group").show(250);
1802 } else {
1803 $(this).parents(".form-group").find(".form-group").hide(250);
1804 }
1805 });
1806
1807 $('#ays_users_roles').select2();
1808 $('#ays_user_roles').select2();
1809 $('[data-toggle="tooltip"]').tooltip();
1810
1811 $(document).find('#ays-deactive, #ays-active, #ays_poll_change_creation_date').datetimepicker({
1812 controlType: 'select',
1813 oneLine: true,
1814 dateFormat: "yy-mm-dd",
1815 timeFormat: "HH:mm:ss"
1816 });
1817
1818 // Codemirror
1819 setTimeout(function(){
1820 if($(document).find('#ays_custom_css').length > 0){
1821 if(wp.codeEditor){
1822 wp.codeEditor.initialize($(document).find('#ays_custom_css'), cm_settings);
1823 }
1824 }
1825 }, 500);
1826
1827 $(document).find('a[href="#tab2"]').on('click', function (e) {
1828 setTimeout(function(){
1829 if($(document).find('#ays_custom_css').length > 0){
1830 var ays_custom_css = $(document).find('#ays_custom_css').html();
1831 if(wp.codeEditor){
1832 $(document).find('#ays_custom_css').next('.CodeMirror').remove();
1833 wp.codeEditor.initialize($(document).find('#ays_custom_css'), cm_settings);
1834 $(document).find('#ays_custom_css').html(ays_custom_css).trigger('change');
1835 }
1836 }
1837 }, 500);
1838 });
1839
1840 var unread_result_parent = $(document).find(".unread-result").parent().parent();
1841
1842 if (unread_result_parent != undefined) {
1843 unread_result_parent.css({"font-weight":"bold"});
1844 }
1845
1846 $(document).find('input[type="checkbox"]#ays_redirect_after_submit').on('change', function(e){
1847 var answerRedirectRow = $(document).find('#ays-answers-table .ays-answer-redirect-row');
1848 if($(this).prop('checked') == false){
1849 answerRedirectRow.addClass('ays_poll_display_none');
1850 }else{
1851 if (answerRedirectRow.hasClass('ays_poll_display_none')) {
1852 answerRedirectRow.removeClass('ays_poll_display_none');
1853 }
1854 }
1855
1856 });
1857
1858 $(document).on('change' ,"#ays_disable_answer_hover", disable_answer_hover);
1859
1860 function disable_answer_hover(){
1861 var checkLabelHover = $(document).find('label.ays_label_poll');
1862 var checkCurrentHover = $(document).find("#ays_answer_checker");
1863 if(checkLabelHover.hasClass('ays_enable_hover') && !checkLabelHover.hasClass('disable_hover')){
1864 checkLabelHover.addClass('disable_hover');
1865 checkLabelHover.removeClass('ays_enable_hover');
1866 checkCurrentHover.val('disable_hover');
1867 }else{
1868 checkLabelHover.addClass('ays_enable_hover');
1869 checkLabelHover.removeClass('disable_hover');
1870 checkCurrentHover.val('ays_enable_hover');
1871 }
1872 }
1873
1874 $('#ays_add_postcat_for_poll').select2();
1875
1876 function openMusicMediaUploader(e, element) {
1877 e.preventDefault();
1878 var aysUploader = wp.media({
1879 title: 'Upload music',
1880 button: {
1881 text: 'Upload'
1882 },
1883 library: {
1884 type: 'audio'
1885 },
1886 multiple: false
1887 }).on('select', function () {
1888 var attachment = aysUploader.state().get('selection').first().toJSON();
1889 element.next().attr('src', attachment.url);
1890 element.parent().find('input.ays_poll_bg_music').val(attachment.url).trigger('change');
1891 }).open();
1892 return false;
1893 }
1894
1895 $(document).find('#ays_poll_bg_image_position').on('change', function () {
1896 var pollContainer = $(document).find('.box-apm ,.choosing-poll');
1897 pollContainer.css({
1898 'background-position': $(this).val()
1899 });
1900 });
1901
1902 $(document).find("#ays_answer_font_size,#ays_poll_answer_font_size_mobile").on("change" , function(){
1903 var thisSize = parseInt($(this).val());
1904 var detectType = $(this).data("device");
1905 if(thisSize < 10){
1906 thisSize = 10;
1907 }
1908 if(thisSize > 90){
1909 thisSize = 90;
1910 }
1911 $(this).val(thisSize);
1912 if(detectType != "mobile"){
1913 $(document).find('.ays_label_font_size').css("font-size" , thisSize + "px");
1914 $(document).find('.ays-poll-text-type-fields').css({ 'font-size': thisSize + "px" });
1915 }
1916 });
1917
1918
1919 refreshLivePreview(checkAnswerStyle);
1920 // function for Live Preview
1921 function refreshLivePreview(checker){
1922 // Defaults
1923 var imageDefaultHeight = "150";
1924 var imageDefaulObjFit = "cover";
1925 var answerDefaultPadding = "10";
1926 var answerDefaultGap = "10";
1927 var answerDefaultFontSize = "16";
1928 var answerDefaultFontSizeMobile = "16";
1929 var titleDefaultFontSize = "20";
1930 var answersBorderRadiusDefault = "0";
1931
1932 // Boxes
1933 var imageBoxes = $(document).find('.box-apm .ays-poll-answer-image-live');
1934 var answerLabelBoxes = $(document).find('.box-apm label.ays-poll-answer-more-options');
1935 var answerMainBoxes = $(document).find('.box-apm .apm-choosing');
1936 // Answer Font size
1937 var answerFontSizeMain = $(document).find("#ays_answer_font_size");
1938 var answerFontSize = answerFontSizeMain.val();
1939 // Answer Font size mobile
1940 var answerFontSizeMobileMain = $(document).find("#ays_poll_answer_font_size_mobile");
1941 // Border color
1942 var borderColor = $(document).find("#ays-poll-border-color").val();
1943 // Image Height option
1944 var imageHeight = $(document).find('#ays_poll_answer_img_height').val();
1945 // Image border radius option
1946 var imageBorderRadius = $(document).find('#ays_poll_answer_image_border_radius').val();
1947 // Answer Image object-fit
1948 var imageBgSizeSelect = $(document).find('#ays_poll_image_background_size');
1949 var imageBgSizeVal = imageBgSizeSelect.val();
1950 // Answer padding
1951 var answersPadding = $(document).find('#ays_poll_answers_padding');
1952 var answersPaddingVal = answersPadding.val();
1953 // Answer Gap
1954 var answersMargin = $(document).find('#ays_poll_answers_margin');
1955 var answersMarginVal = answersMargin.val();
1956 // Answer Border radius
1957 var answersBorderRadiusMain = $(document).find('#ays_poll_answer_border_radius');
1958 var answersBorderRadius = answersBorderRadiusMain.val();
1959 // Question image height
1960 var questionImageHeight = $(document).find("#ays_poll_question_image_height").val();
1961 var questionHeight = questionImageHeight == "" ? "100%" : questionImageHeight+"px";
1962 // Question image object-fit
1963 var questionImageObjectFit = $(document).find("#ays_poll_question_image_object_fit").val();
1964 $(document).find(".box-apm .apm-img-box .ays-poll-img").css({"object-fit" : questionImageObjectFit});
1965 // Poll Answer view type
1966 var viewType = $(document).find('#ays_answers_view').val();
1967 var answersCont = $(document).find('.apm-answers');
1968 var answersField = answersCont.find('.ays-poll-field');
1969 var checkTextType = $(document).find('.box-apm.text-poll').length > 0 ? true : false;
1970 // Title font size
1971 var titleFontSizeBox = $(document).find("#ays_poll_title_font_size");
1972 var titleFontSize = titleFontSizeBox.val();
1973 // Poll text type placeholder
1974 var textPlaceholder = $(document).find("#ays_poll_text_type_placeholder");
1975 var textPlaceholderVal = textPlaceholder.val();
1976 $(document).find('.ays-poll-text-type-fields').attr('placeholder' , textPlaceholderVal);
1977 answersCont.find('.ays_label_poll').css({
1978 'display': 'flex',
1979 });
1980 // Title alignment
1981 var titleAlignment = $(document).find("#ays_poll_title_alignment").val();
1982
1983 if(parseInt(imageHeight) < 0){
1984 imageHeight = 0;
1985 $(document).find('#ays_poll_answer_img_height').val(imageHeight);
1986 }
1987 //
1988
1989 //
1990 // Answer box shadow
1991 var answersBoxShadow = $(document).find('#ays_poll_answers_box_shadow_enable').prop('checked');
1992 var answersBoxShadowColor = $(document).find('#ays_poll_answers_box_shadow_color').val();
1993 var answersBoxShadowXOffset = $(document).find('#ays_poll_answer_box_shadow_x_offset').val();
1994 var answersBoxShadowYOffset = $(document).find('#ays_poll_answer_box_shadow_y_offset').val();
1995 var answersBoxShadowZOffset = $(document).find('#ays_poll_answer_box_shadow_z_offset').val();
1996 if(answersBoxShadow){
1997 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
1998 'box-shadow': answersBoxShadowXOffset+'px '+answersBoxShadowYOffset+'px '+answersBoxShadowZOffset+'px '+answersBoxShadowColor,
1999 });
2000 }else{
2001 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
2002 'box-shadow': 'none',
2003 });
2004 }
2005
2006
2007 if(parseInt(answersPaddingVal) < 0){
2008 answersPaddingVal = 0;
2009 answersPadding.val(answersPaddingVal);
2010 }
2011
2012 if(parseInt(answersMarginVal) <= 0){
2013 answersMarginVal = 1;
2014 answersMargin.val(answersMarginVal);
2015 }
2016
2017 if(!checker){
2018 imageBgSizeVal = imageDefaulObjFit;
2019 answersPaddingVal = answerDefaultPadding;
2020 imageHeight = imageDefaultHeight;
2021 answersMarginVal = answerDefaultGap;
2022 answerFontSize = answerDefaultFontSize;
2023 answerFontSizeMain.val(answerDefaultFontSize);
2024 answerFontSizeMobileMain.val(answerDefaultFontSize);
2025 answersBorderRadius = answersBorderRadiusDefault;
2026 answersBorderRadiusMain.val(answersBorderRadiusDefault);
2027 }
2028 // Image Changes
2029 imageBoxes.css({
2030 'height': imageHeight+'px',
2031 'border-radius': imageBorderRadius+'px',
2032 'object-fit': imageBgSizeVal
2033 });
2034
2035 // Answer changes
2036 answerLabelBoxes.css({
2037 'padding': answersPaddingVal+'px'
2038 });
2039
2040 answerMainBoxes.css({
2041 'margin-bottom': answersMarginVal+'px'
2042 });
2043
2044 // Question font size
2045 var pattern = /Android|webOS|iPhone|iPad|Mac|Macintosh|iPod|BlackBerry|IEMobile|Opera Mini/i;
2046 var questnionFontSize;
2047 if( pattern.test(navigator.userAgent) ) {
2048 questnionFontSize = $(document).find("#ays_poll_answers_font_size_mobile").val();
2049 }
2050 else{
2051 questnionFontSize = $(document).find("#ays_poll_answers_font_size_pc").val();
2052 }
2053 $(document).find('.ays_question,.ays_question p').css({ 'font-size': questnionFontSize+"px" });
2054
2055 $(document).find('.ays_label_font_size').css("font-size" , answerFontSize + "px");
2056 $(document).find('.box-apm').css("border-color" , borderColor);
2057
2058 $(document).find(".apm-img-box img.ays-poll-img").css({"height" : questionHeight});
2059
2060 $(document).find('.ays-poll-answers .ays-field>label,.ays-poll-answers .ays-field >.ays_answer_live_label,label.ays_label_poll').css({
2061 'border-radius': +answersBorderRadius+"px",
2062 });
2063
2064 if(titleFontSize < 0){
2065 titleFontSize = 0;
2066 titleFontSizeBox.val(0);
2067 }
2068 $(document).find('.apm-title-box h5').css({
2069 "font-size" : titleFontSize + "px",
2070 "text-align" : titleAlignment,
2071 });
2072 if(viewType == 'list'){
2073 $(document).find('.grid_column_count').hide(250);
2074 answersCont.removeClass('ays_poll_grid_view_container');
2075 answersCont.addClass('ays_poll_list_view_container');
2076 answersField.removeClass('ays_poll_grid_view_item');
2077 answersField.addClass('ays_poll_list_view_item');
2078
2079 answersCont.find('.ays-poll-field.ays_poll_list_view_item').css({
2080 'margin-right': 0,
2081 });
2082 answersCont.find('.ays-poll-answer-image-live').css({
2083 'width': '220px',
2084 });
2085 answersCont.find('span.ays-poll-each-answer').css({
2086 'width': 'initial',
2087 'text-align': 'initial',
2088 'display': 'initial',
2089 });
2090 answersCont.find('.ays_label_poll').css({
2091 'align-items': 'center',
2092 'flex-direction': 'row',
2093 });
2094 }else if(viewType == 'grid' && !checkTextType){
2095 $(document).find('.grid_column_count').show(250);
2096 answersCont.removeClass('ays_poll_list_view_container');
2097 answersCont.addClass('ays_poll_grid_view_container');
2098 answersField.removeClass('ays_poll_list_view_item');
2099 answersField.addClass('ays_poll_grid_view_item');
2100
2101 answersCont.find('.ays-poll-answer-image-live').css({
2102 'width': '100%',
2103 });
2104
2105 answersCont.find('span.ays-poll-each-answer').css({
2106 'width': '100%',
2107 'text-align': 'center',
2108 'display': 'inline-block',
2109 });
2110
2111 var innerLabel = answersField.find("label.ays_poll_label_without_padding");
2112 if(innerLabel.length > 0){
2113 innerLabel.css({
2114 'flex-direction': 'column',
2115 });
2116 }
2117 }
2118 }
2119
2120 var heart_interval = setInterval(function () {
2121 $(document).find('.ays-poll-maker-wrapper i.ays_fa').toggleClass('ays_poll_pulse');
2122 }, 1000);
2123
2124 $(document).on('change' , '.ays-answer-value', function(){
2125 livePrevToChoosing("choosing");
2126 var checkAnswerStyleOnChange = $(document).find("#ays_poll_enable_answer_style").prop("checked");
2127 refreshLivePreview(checkAnswerStyleOnChange);
2128 });
2129
2130 $('#ays_poll_info_form').on('change', function () {
2131 var propCheck = $(this).prop("checked");
2132 var allowCollect = $(document).find(".ays_toggle_target_inverse");
2133 if(propCheck){
2134 allowCollect.find('#ays_allow_collecting_logged_in_users_data').prop("checked" , false);
2135 allowCollect.hide();
2136 }
2137 else{
2138 if(allowCollect.hasClass("display_none")){
2139 allowCollect.removeClass("display_none");
2140 }
2141 allowCollect.show();
2142 }
2143 $('.ays-poll-if-form-on').fadeToggle();
2144 });
2145
2146 // Pro features
2147 $(document).find('#ays_answers_border_color').wpColorPicker({
2148 change: function(event, ui) {
2149 }
2150 });
2151
2152 $(document).find("#ays_see_result_show").on("change" , function(){
2153 var checker = $(this).prop("checked");
2154 var buttonsCont = $(document).find("#ays_poll_show_hide_button");
2155 if(checker){
2156 buttonsCont.show(200);
2157 buttonsCont.css("display" , "flex");
2158 }
2159 else{
2160 buttonsCont.hide(200);
2161 }
2162 });
2163
2164 $(document).find('.ays-poll-question-tab-all-filter-button-top, .ays-poll-question-tab-all-filter-button-bottom').on('click', function(e) {
2165 e.preventDefault();
2166 var $this = $(this);
2167 var parent = $this.parents('.tablenav');
2168
2169 var searchForm = parent.parent();
2170 var searchInput = searchForm.find('input#poll-maker-ays-search-input')
2171 var searchValue = searchInput.val();
2172
2173 var html_name = '';
2174 var top_or_bottom = 'top';
2175
2176 if ( parent.hasClass('bottom') ) {
2177 top_or_bottom = 'bottom';
2178 }
2179
2180 var catFilter = $(document).find('select[name="filterby-'+ top_or_bottom +'"]').val();
2181 var authorFilter = $(document).find('select[name="filterbyauthor-'+ top_or_bottom +'"]').val();
2182 var typeFilter = $(document).find('select[name="filterbytype-'+ top_or_bottom +'"]').val();
2183 var link = location.href;
2184
2185 if (typeof catFilter != "undefined") {
2186 link = catFilterForListTable(link, searchValue, {
2187 what: 'filterby',
2188 value: catFilter
2189 });
2190 }
2191 if (typeof authorFilter != "undefined") {
2192 link = catFilterForListTable(link, searchValue, {
2193 what: 'filterbyauthor',
2194 value: authorFilter
2195 });
2196 }
2197 if (typeof typeFilter != "undefined") {
2198 link = catFilterForListTable(link,searchValue, {
2199 what: 'filterbytype',
2200 value: typeFilter
2201 });
2202 }
2203 document.location.href = link;
2204 })
2205
2206 function catFilterForListTable(link, searchValue, options){
2207 if( options.value != '' ){
2208 options.value = "&" + options.what + "=" + options.value;
2209 var linkModifiedStart = link.split('?')[0];
2210 var linkModified = link.split('?')[1].split('&');
2211 for(var i = 0; i < linkModified.length; i++){
2212 if ( linkModified[i].split("=")[0] == "ays_result_tab" ) {
2213 linkModified.splice(i, 1, "ays_result_tab=poststuff");
2214 }
2215 if(linkModified[i].split("=")[0] == options.what){
2216 linkModified.splice(i, 1);
2217 }
2218 }
2219 linkModified = linkModified.join('&');
2220 if (typeof searchValue != 'undefined' && searchValue != '') {
2221 linkModified = linkModified + "&s=" + searchValue;
2222 }
2223 return linkModifiedStart + "?" + linkModified + options.value;
2224 }else{
2225 var linkModifiedStart = link.split('?')[0];
2226 var linkModified = link.split('?')[1].split('&');
2227 for(var i = 0; i < linkModified.length; i++){
2228 if(linkModified[i].split("=")[0] == options.what){
2229 linkModified.splice(i, 1);
2230 }
2231 }
2232 linkModified = linkModified.join('&');
2233 if (typeof searchValue != 'undefined' && searchValue != '') {
2234 linkModified = linkModified + "&s=" + searchValue;
2235 }
2236 return linkModifiedStart + "?" + linkModified;
2237 }
2238 }
2239
2240 $(document).find('input[type="submit"]#doaction, input[type="submit"]#doaction2').on('click', function(e) {
2241 showConfirmationIfDelete(e);
2242 })
2243
2244 $(document).find("input#poll-maker-ays-search-input + input#search-submit").on("click", function (e) {
2245 var _this = $(this);
2246 var parent = _this.parents('form');
2247
2248 var search_input = parent.find('input#poll-maker-ays-search-input');
2249 var input_value = search_input.val();
2250
2251 var field = 's';
2252 var flag = false;
2253 var url = window.location.href;
2254 if(url.indexOf('?' + field + '=') != -1){
2255 flag = true;
2256 }
2257 else if(url.indexOf('&' + field + '=') != -1){
2258 flag = true;
2259 }
2260
2261 if (flag) {
2262 if (typeof input_value != 'undefined' && input_value != "") {
2263 e.preventDefault();
2264 location.href=location.href.replace(/&s=([^&]$|[^&]*)/i, "&s="+input_value);
2265 }
2266 }
2267 });
2268
2269 function showConfirmationIfDelete(e) {
2270 var $el = $(e.target);
2271 var elParent = $el.parent();
2272 var actionSelect = elParent.find('select[name="action"]');
2273 var action = actionSelect.val();
2274
2275 if (action === 'bulk-delete') {
2276 e.preventDefault();
2277 var confirmDelete = confirm('Are you sure you want to delete?');
2278
2279 if (confirmDelete) {
2280 var form = $el.closest('form');
2281 form.submit()
2282 }
2283 }
2284 }
2285
2286 $(document).on('click', '.ays_polls_each_results_list_table th.manage-column a', function(e) {
2287 var href = $(this).attr('href');
2288 $(this).attr('href', href + '&ays_poll_tab_results=tab2');
2289 })
2290
2291 $(document).on("click", "#ays-poll-dismiss-buttons-content .ays-button, #ays-poll-dismiss-buttons-content-helloween .ays-button-helloween", function(e){
2292 e.preventDefault();
2293
2294 var $this = $(this);
2295 var thisParent = $this.parents("#ays-poll-dismiss-buttons-content");
2296 var mainParent = $this.parents("div.ays_poll_dicount_info");
2297 var closeButton = mainParent.find("button.notice-dismiss");
2298 var attr_plugin = $this.attr('data-plugin');
2299 var wp_nonce = thisParent.find('#poll-maker-ays-sale-banner').val();
2300
2301 var data = {
2302 action: 'ays_poll_dismiss_button',
2303 _ajax_nonce: wp_nonce,
2304 };
2305
2306 $.ajax({
2307 url: poll.ajax,
2308 method: 'post',
2309 dataType: 'json',
2310 data: data,
2311 success: function (response) {
2312 if( response.status ){
2313 closeButton.trigger('click');
2314 } else {
2315 swal.fire({
2316 type: 'info',
2317 html: "<h2>"+ pollLangObj.errorMsg +"</h2><br><h6>"+ pollLangObj.somethingWentWrong +"</h6>"
2318 }).then(function(res) {
2319 closeButton.trigger('click');
2320 });
2321 }
2322 },
2323 error: function(){
2324 swal.fire({
2325 type: 'info',
2326 html: "<h2>"+ pollLangObj.errorMsg +"</h2><br><h6>"+ pollLangObj.somethingWentWrong +"</h6>"
2327 }).then(function(res) {
2328 closeButton.trigger('click');
2329 });
2330 }
2331 });
2332 });
2333
2334 $(document).keydown(function(event) {
2335 var editButton = $(document).find("input#ays-button-top-apply,input#ays-button-apply,input#ays_submit");
2336 if (!(event.which == 83 && event.ctrlKey) && !(event.which == 19)){
2337 return true;
2338 }
2339 editButton.trigger("click");
2340 event.preventDefault();
2341 return false;
2342 });
2343
2344 function aysPollGetCookie(c_name) {
2345 if (document.cookie.length > 0) {
2346 var c_start = document.cookie.indexOf(c_name + "=");
2347 if (c_start != -1) {
2348 c_start = c_start + c_name.length + 1;
2349 var c_end = document.cookie.indexOf(";", c_start);
2350 if (c_end == -1) {
2351 c_end = document.cookie.length;
2352 }
2353 return unescape(document.cookie.substring(c_start, c_end));
2354 }
2355 }
2356 return "";
2357 }
2358 // Check new added Poll start
2359 var createdNewPoll = aysPollGetCookie('ays_poll_created_new');
2360 if(createdNewPoll && createdNewPoll > 1){
2361 var url = new URL(window.location.href);
2362
2363 // Get a specific GET parameter by name
2364 var parameterValue = url.searchParams.get("action");
2365 var htmlDefaultText = '<p style="margin-top:1rem;">'+ pollLangObj.formMoreDetailed +' <a href="admin.php?page=poll-maker&action=edit&id=' + createdNewPoll + '">'+ pollLangObj.editPollPage +'</a>.</p>';
2366
2367 swal({
2368 title: '<strong>' + pollLangObj.greateJob + '</strong>',
2369 type: 'success',
2370 html: '<p>' + pollLangObj.youCanUuseThisShortcode + '</p><input type="text" id="ays-poll-create-new" onClick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_poll id=\'' + createdNewPoll + '\']" />',
2371 showCloseButton: true,
2372 focusConfirm: false,
2373 confirmButtonText: '<i class="ays_poll_fas ays_poll_fa_thumbs_up"></i> '+ pollLangObj.done,
2374 confirmButtonAriaLabel: pollLangObj.thumbsUpGreat,
2375 });
2376 aysPollDeleteCookie('ays_poll_created_new');
2377 }
2378
2379 function aysPollDeleteCookie(name) {
2380 document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
2381 }
2382
2383 // Select default category for poll
2384 $(document).find("#ays_poll_default_type").select2();
2385
2386 // Check if submit button clicked for unsaved changes confirmation box
2387 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';
2388 $(document).on('click', subButtons ,function () {
2389 var $this = $(this);
2390 $this.addClass('ays-submit-button-clicked');
2391 });
2392
2393 var aysUnsavedChanges = false;
2394 var formInputs = '#ays-poll-form .ays-poll-tab-content input, #ays-poll-form .ays-poll-tab-content select, ' +
2395 '#ays-poll-form .ays-poll-tab-content textarea, #ays-poll-category-form input, ' +
2396 '#ays-poll-category-form select, #ays-poll-category-form textarea, ' +
2397 '#ays-poll-general-settings-form input, #ays-poll-general-settings-form select, ' +
2398 '#ays-poll-general-settings-form textarea';
2399
2400 $(document).on('change input', formInputs, function() {
2401 aysUnsavedChanges = true;
2402 });
2403
2404 $(window).on('beforeunload', function(event) {
2405 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');
2406 var savingButtonsClicked = saveButtons.filter('.ays-submit-button-clicked').length > 0;
2407
2408 if (aysUnsavedChanges && !savingButtonsClicked) {
2409 event.preventDefault();
2410 event.returnValue = true;
2411 }
2412 });
2413
2414
2415 $(document).find("#ays_poll_default_cat").select2({
2416 multiple: true
2417 });
2418
2419 // Create and Delete rows in Answers table
2420 $(document).on("keydown" , "input[name='ays-poll-answers[]']" , function(event) {
2421 var $thisValue = $(this).val();
2422 if (event.keyCode === 13) {
2423 if($(this).hasClass("ays_poll_enter_key")){
2424 var editButton = $(document).find(".ays-click-once");
2425 editButton.trigger("click");
2426 event.preventDefault();
2427 }
2428 else{
2429 var nextInput = $(this).parents("tr").next().find("td.ays-choosing-answer-container input:nth-child(1)");
2430 nextInput.focus();
2431 var oldValue = nextInput.val();
2432 nextInput.val(" ");
2433 nextInput.val(oldValue);
2434 }
2435 }
2436 else if(event.keyCode === 8 && $thisValue == ""){
2437 var editButton = $(this).parents("tr").find("a.ays-delete-answer");
2438 editButton.trigger("click");
2439 event.preventDefault();
2440 }
2441
2442 });
2443
2444 var drawChartLink = $(document).find(".ays_poll_answer_chart_active");
2445 if(drawChartLink.hasClass("nav-tab-active")){
2446 google.charts.load('current', {packages: ['corechart', 'bar']});
2447 google.charts.setOnLoadCallback(drawBasic);
2448 }
2449
2450 $(document).find(".ays_poll_answer_chart_active").on("click" , function(){
2451 google.charts.load('current', {packages: ['corechart', 'bar']});
2452 google.charts.setOnLoadCallback(drawBasic);
2453 });
2454
2455 // Write poll title immediately
2456 $(document).find('#ays-poll-title').on('input', function(e){
2457 var pollTitleVal = $(this).val();
2458 var pollTitle = aysPollstripHTML( pollTitleVal );
2459 $(document).find('.ays_poll_title_in_top').html( pollTitle );
2460 });
2461
2462 function aysPollstripHTML( dirtyString ) {
2463 var container = document.createElement('div');
2464 var text = document.createTextNode(dirtyString);
2465 container.appendChild(text);
2466
2467 return container.innerHTML; // innerHTML will be a xss safe string
2468 }
2469 //
2470
2471 var theme_Ids = $('.apm-themes-row').attr('data-themeid');
2472 if ($('#ays_poll_show_answers_icon').prop('checked') && theme_Ids != 3) {
2473 if ($('input[name="ays_poll_answer_icon"]:checked').prop('checked')) {
2474 var iconVal = $('input[name="ays_poll_answer_icon"]:checked').val();
2475 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2476 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2477 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+iconVal);
2478 }else{
2479 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2480 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2481 }
2482 }else{
2483 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2484 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2485 }
2486
2487 // Answer Icon
2488 $('#ays_poll_show_answers_icon').change(function () {
2489 var themeIds = $('.apm-themes-row').attr('data-themeid');
2490 if ($('#ays_poll_show_answers_icon').prop('checked')) {
2491 switch(parseInt(themeIds)){
2492 case 3:
2493 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2494 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2495 break;
2496 default:
2497 var icons_val = $('input[name="ays_poll_answer_icon"]:checked').val();
2498 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2499 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2500 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+icons_val);
2501 break;
2502 }
2503 }else{
2504 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2505 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2506 }
2507 });
2508
2509 $('.ays_poll_answ_icon').change(function () {
2510 if ($(this).prop('checked')) {
2511 var themesIds = $('.apm-themes-row').attr('data-themeid');
2512 switch(parseInt(themesIds)){
2513 case 3:
2514 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2515 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2516 break;
2517 default:
2518 var icon_val = $(this).val();
2519 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2520 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2521 $('.ays_label_poll').addClass('ays_poll_answer_icon_'+icon_val);
2522 }
2523 }else{
2524 $('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
2525 $('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
2526 }
2527 });
2528
2529 $(document).find('strong.ays-poll-shortcode-box').on('mouseleave', function(){
2530 var _this = $(this);
2531
2532 _this.attr( 'data-original-title', pollLangObj.clickForCopy );
2533 });
2534
2535 // $(document).find("#ays_poll_buttons_size").select2({
2536 // minimumResultsForSearch: -1
2537 // });
2538
2539 // Button styles start
2540 // Size change
2541 $(document).find("#ays_poll_buttons_size").on("change" , function(){
2542 var buttonsSize = $(document).find('#ays_poll_buttons_size').val();
2543 var buttonsFontSize,
2544 buttonsLeftRightPadding,
2545 buttonsTopBottomPadding,
2546 buttonsBorderRadius;
2547
2548 switch(buttonsSize){
2549 case "small":
2550 buttonsFontSize = 14;
2551 buttonsLeftRightPadding = 14;
2552 buttonsTopBottomPadding = 7;
2553 buttonsBorderRadius = 3;
2554 break;
2555 case "large":
2556 buttonsFontSize = 20;
2557 buttonsLeftRightPadding = 30;
2558 buttonsTopBottomPadding = 13;
2559 buttonsBorderRadius = 3;
2560 break;
2561 default:
2562 buttonsFontSize = 17;
2563 buttonsLeftRightPadding = 20;
2564 buttonsTopBottomPadding = 10;
2565 buttonsBorderRadius = 3;
2566 break;
2567 }
2568
2569 $(document).find('#ays_poll_buttons_font_size').val(buttonsFontSize);
2570 $(document).find('#ays_poll_buttons_left_right_padding').val(buttonsLeftRightPadding);
2571 $(document).find('#ays_poll_buttons_top_bottom_padding').val(buttonsTopBottomPadding);
2572 $(document).find('#ays_poll_buttons_border_radius').val(buttonsBorderRadius);
2573
2574 $(document).find('input[type="button"].ays-poll-btn').css({
2575 'font-size' : buttonsFontSize + 'px',
2576 'padding' : buttonsTopBottomPadding+'px '+ buttonsLeftRightPadding+'px',
2577 'border-radius' : buttonsBorderRadius + 'px'
2578 });
2579 });
2580
2581 // Buttons font size
2582 $(document).find("#ays_poll_buttons_font_size").on("change" , function(){
2583 var buttonFontSize = $(this).val();
2584 $(document).find('input[type="button"].ays-poll-btn').css('font-size', buttonFontSize + 'px');
2585 });
2586
2587 $('.ays_buttons_padding').on('change', function () {
2588 var top_bottom = $(document).find('#ays_poll_buttons_top_bottom_padding').val();
2589 var left_top = $(document).find('#ays_poll_buttons_left_right_padding').val();
2590 $(document).find('input[type="button"].ays-poll-btn').css('padding', top_bottom + 'px ' + left_top +'px');
2591 });
2592
2593 $('#ays_poll_buttons_width').on('change', function () {
2594 var buttons_width = $(document).find('#ays_poll_buttons_width').val();
2595 if(buttons_width == ''){
2596 buttons_width = 'auto';
2597 }else{
2598 buttons_width = buttons_width + 'px';
2599 }
2600
2601 $(document).find('input[type="button"].ays-poll-btn').css('width', buttons_width);
2602 });
2603
2604 $('#ays_poll_buttons_border_radius').on('change', function () {
2605 var val = $(this).val();
2606 $(document).find('input[type="button"].ays-poll-btn').css('border-radius', val + 'px');
2607 });
2608
2609 function checkHr(type , pollType) {
2610 var typeChecker = $(document).find(".ays_hr_on");
2611 var textTypeChecker = $(document).find(".ays_hr_on_text");
2612 var rangeType = $('#type_range').prop('checked');
2613 if(!type){
2614 typeChecker.hide();
2615 }
2616 else{
2617 typeChecker.show();
2618 }
2619
2620 if(pollType == "text"){
2621 textTypeChecker.show();
2622 }
2623 else{
2624 textTypeChecker.hide();
2625
2626 }
2627
2628 if(rangeType){
2629 $(document).find(".ays_hr_check").hide();
2630 }
2631 else{
2632 $(document).find(".ays_hr_check").show();
2633 }
2634 }
2635
2636 function check_allow_add_answers_show_up() {
2637 var aa_show = $(document).find('input[type="checkbox"]#ays_poll_allow_add_answers');
2638 let requireAdminApprovalCbState = $(document).find('input[type="checkbox"]#ays_poll_allow_answer_require').prop('checked');
2639
2640 if(!requireAdminApprovalCbState){
2641 $(document).find('.ays_show_user_added').hide();
2642 $(document).find('.ays_show_user_added_hid').each(function () {
2643 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').prop('checked', false);
2644 // $(this).val(0);
2645 });
2646 }else{
2647 $(document).find('.ays_show_user_added').show();
2648 $(document).find('.ays_show_user_added_hid').each(function () {
2649 // $(this).val(1);
2650 // $(this).prop('checked', true);
2651 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').val(1);
2652 });
2653 }
2654 }
2655
2656 function toggleOptionsAccordion(arrowBtn) {
2657 var arrowSvg = arrowBtn.find('svg');
2658 var accordionMainContainer = arrowBtn.parents('.ays-poll-accordion-options-main-container');
2659 var accordionBody = accordionMainContainer.find('.ays-poll-accordion-body');
2660
2661 arrowSvg.toggleClass('ays-poll-accordion-arrow-active');
2662 accordionBody.slideToggle();
2663 }
2664
2665 $(document).find('input[type="checkbox"]#ays_poll_allow_add_answers').on('change', function(e){
2666 if($(this).prop('checked') == false){
2667 // $(document).find('.allow_add_answers_not_show_up').hide();
2668 // $(document).find('.allow_add_answers_not_show_up .ays_toggle_target').hide(250);
2669 $(document).find('#ays_poll_allow_answer_require').removeAttr('checked');
2670 check_allow_add_answers_show_up();
2671 }else{
2672 $(document).find('.allow_add_answers_not_show_up').show();
2673 check_allow_add_answers_show_up();
2674 }
2675
2676 });
2677
2678 $(document).find('input[type="checkbox"]#ays_poll_allow_answer_require').on('change', function(e){
2679 check_allow_add_answers_show_up();
2680 });
2681
2682 // Options accordion effect start
2683 $(document).on('click', '.ays-poll-accordion-header', function() {
2684 toggleOptionsAccordion($(this));
2685 });
2686 // Options accordion effect end
2687
2688 $(document).find('input[type="checkbox"].ays_show_user_added').on('change', function(e){
2689 let selectAllCb = $(document).find('input[type="checkbox"]#ays_poll_require_approve_select_all');
2690 if($(this).prop('checked') == true){
2691 $(this).parent().find('.ays_show_user_added_hid').val(1);
2692 var isAllChecked = 0;
2693 var allShowUserAddedCbArr = $(document).find('input[type="checkbox"].ays_show_user_added');
2694 for (i = 0; i < allShowUserAddedCbArr.length; i++) {
2695 if(allShowUserAddedCbArr.eq(i).prop('checked')) {
2696 isAllChecked++;
2697 }
2698 }
2699 if (isAllChecked === allShowUserAddedCbArr.length && selectAllCb.prop('checked') === false) {
2700 selectAllCb.prop('checked', true);
2701 }
2702 }else{
2703 $(this).parent().find('.ays_show_user_added_hid').val(0);
2704
2705 if (selectAllCb.prop('checked')) {
2706 selectAllCb.prop('checked', false);
2707 }
2708 }
2709 });
2710
2711 $(document).find("#ays_poll_require_approve_select_all").on("change" , function(){
2712 if($(this).prop('checked') == false){
2713 $(document).find('.ays_show_user_added').each(function () {
2714 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').prop('checked', false);
2715 $(this).val(0);
2716 $(this).prop('checked' , false);
2717 $(document).find('.ays_show_user_added_hid').val(0);
2718
2719 });
2720 }else{
2721 $(document).find('.ays_show_user_added').each(function () {
2722 $(this).val(1);
2723 $(this).prop('checked', true);
2724 $(this).parent('.ays-sortable-answers').find('.ays_show_user_added').val(1);
2725 $(document).find('.ays_show_user_added_hid').val(1);
2726 });
2727 }
2728 });
2729
2730 // Add answer image (Choosing type) start
2731 $(document).on('click', 'label.ays-label a.ays-poll-add-answer-image', function (e) {
2732 openAnswerMediaUploader(e, $(this));
2733 });
2734
2735 // Select Image
2736 function openAnswerMediaUploader(e, element) {
2737 e.preventDefault();
2738 var addButton = element;
2739 var aysUploader = wp.media({
2740 title: 'Upload',
2741 button: {
2742 text: 'Upload'
2743 },
2744 library: {
2745 type: 'image'
2746 },
2747 multiple: false
2748 }).on('select', function () {
2749 var attachment = aysUploader.state().get('selection').first().toJSON();
2750 addButton.parents().eq(1).find('.ays-poll-add-answer-image').parent().css('display', 'none');
2751 addButton.parents('td').find('.ays-poll-answer-image-container').fadeIn();
2752 addButton.parents('td').find('img.ays-poll-answer-img').attr('src', attachment.url);
2753 addButton.parents('tr').find('input.ays-poll-answer-image-path').val(attachment.url).trigger("change");
2754 if(addButton.hasClass('ays-poll-add-answer-image')){
2755 addButton.parents('td').find('img').attr('src', attachment.url);
2756 addButton.parents('tr').find('input.ays-poll-answer-image').val(attachment.url);
2757 }
2758 }).open();
2759 return false;
2760 }
2761
2762 // Remove Image
2763 $(document).on('click', '.ays-poll-remove-answer-img', function () {
2764 var $this = $(this);
2765 $this.parent().fadeOut();
2766 if($this.parent().hasClass('ays-poll-answer-image-container')){
2767 setTimeout(function(){
2768 $this.parents().eq(1).find('.ays-poll-add-answer-image').show();
2769 $this.parents('td').find('.ays-poll-add-answer-image').parent().css('display', 'block');
2770 $this.parents('td').find('.ays-poll-add-answer-image').css('display', 'inline-block');
2771 $this.parent().find('img.ays-poll-answer-img').attr('src', '');
2772 $this.parent().find('input.ays-poll-answer-image').val('');
2773 $this.parent().find('input.ays-poll-answer-image-path').val('').trigger("change");
2774 },300);
2775 }
2776 });
2777
2778 // Grid view type PRO
2779 $(document).find("#ays_answers_grid_column").on("change" , function(){
2780 var $this = $(this);
2781 if($this.val() != 2){
2782 $this.val(2);
2783 window.open("https://ays-pro.com/wordpress/poll-maker", '_blank');
2784 }
2785 });
2786
2787
2788
2789 $(document).on('change', '.ays-poll-answer-image-path', function(){
2790 livePrevToChoosing('choosing');
2791
2792 $(document).find('#ays-poll-border-side').trigger('change');
2793 $(document).find('#ays_answers_view').trigger('change');
2794 });
2795
2796 $(document).find(".ays-poll-text-types-type").on("change" , function(){
2797 var $this = $(this);
2798 var textType = $this.val();
2799 livePrevToChoosing("text" , 0 , textType);
2800 });
2801 // Add answer image (Choosing type) end
2802
2803 // Poll Responsive tabs start
2804 if($(document).find('.ays-top-menu').width() <= $(document).find('div.ays-top-tab-wrapper').width()){
2805 $(document).find('.ays_menu_left').css('display', 'flex');
2806 $(document).find('.ays_menu_right').css('display', 'flex');
2807 }
2808 $(window).resize(function(){
2809 if($(document).find('.ays-top-menu').width() < $(document).find('div.ays-top-tab-wrapper').width()){
2810 $(document).find('.ays_menu_left').css('display', 'flex');
2811 $(document).find('.ays_menu_right').css('display', 'flex');
2812 }else{
2813 $(document).find('.ays_menu_left').css('display', 'none');
2814 $(document).find('.ays_menu_right').css('display', 'none');
2815 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(0px)');
2816 }
2817 });
2818 var menuItemWidths0 = [];
2819 var menuItemWidths = [];
2820 $(document).find('.ays-top-tab-wrapper .nav-tab').each(function(){
2821 var $this = $(this);
2822 menuItemWidths0.push($this.outerWidth());
2823 });
2824
2825 for(var i = 0; i < menuItemWidths0.length; i+=2){
2826 if(menuItemWidths0.length <= i+1){
2827 menuItemWidths.push(menuItemWidths0[i]);
2828 }else{
2829 menuItemWidths.push(menuItemWidths0[i]+menuItemWidths0[i+1]);
2830 }
2831 }
2832 var menuItemWidth = 0;
2833 for(var i = 0; i < menuItemWidths.length; i++){
2834 menuItemWidth += menuItemWidths[i];
2835 }
2836 menuItemWidth = menuItemWidth / menuItemWidths.length;
2837
2838 $(document).on('click', '.ays_menu_left', function(){
2839 var scroll = parseInt($(this).attr('data-scroll'));
2840 scroll -= menuItemWidth;
2841 if(scroll < 0){
2842 scroll = 0;
2843 }
2844 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(-'+scroll+'px)');
2845 $(this).attr('data-scroll', scroll);
2846 $(document).find('.ays_menu_right').attr('data-scroll', scroll);
2847 });
2848 $(document).on('click', '.ays_menu_right', function(){
2849 var scroll = parseInt($(this).attr('data-scroll'));
2850 var howTranslate = $(document).find('div.ays-top-tab-wrapper').width() - $(document).find('.ays-top-menu').width();
2851 howTranslate += 7;
2852 if(scroll == -1){
2853 scroll = menuItemWidth;
2854 }
2855 scroll += menuItemWidth;
2856 if(scroll > howTranslate){
2857 scroll = Math.abs(howTranslate);
2858 }
2859 $(document).find('div.ays-top-tab-wrapper').css('transform', 'translate(-'+scroll+'px)');
2860 $(this).attr('data-scroll', scroll);
2861 $(document).find('.ays_menu_left').attr('data-scroll', scroll);
2862 });
2863 // Poll Responsive tabs end
2864
2865
2866 var checkCountdownIsExists = $(document).find('#ays-poll-maker-countdown-main-container');
2867 // var checkCountdownIsExists = $(document).find('#ays-poll-countdown-main-container');
2868 if ( checkCountdownIsExists.length > 0 ) {
2869 var second = 1000,
2870 minute = second * 60,
2871 hour = minute * 60,
2872 day = hour * 24;
2873
2874 var pollCountdownEndTime = pollLangObj.pollBannerDate;
2875 // var pollCountdownEndTime = "DEC 09, 2024 23:59:59";
2876 // var pollCountdownEndTime = "JAN 15, 2025 23:59:59";
2877 var countDown_new = new Date(pollCountdownEndTime).getTime();
2878 if ( isNaN(countDown_new) || isFinite(countDown_new) == false ) {
2879 var AYS_POLL_MILLISECONDS = 3 * day;
2880 var countdownStartDate = new Date(Date.now() + AYS_POLL_MILLISECONDS);
2881 var pollCountdownEndTime = countdownStartDate.aysPollCustomFormat( "#YYYY#-#MM#-#DD# #hhhh#:#mm#:#ss#" );
2882 var countDown_new = new Date(pollCountdownEndTime).getTime();
2883 }
2884
2885 aysPollBannerCountdown();
2886
2887 var y = setInterval(function() {
2888
2889 var now = new Date().getTime();
2890 var distance_new = countDown_new - now;
2891
2892 aysPollBannerCountdown();
2893
2894 var countDownDays = document.getElementById("ays-poll-countdown-days");
2895 var countDownHours = document.getElementById("ays-poll-countdown-hours");
2896 var countDownMinutes = document.getElementById("ays-poll-countdown-minutes");
2897 var countDownSeconds = document.getElementById("ays-poll-countdown-seconds");
2898
2899 if(countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null){
2900
2901 var countDownDays_innerText = Math.floor(distance_new / (day));
2902 var countDownHours_innerText = Math.floor((distance_new % (day)) / (hour));
2903 var countDownMinutes_innerText = Math.floor((distance_new % (hour)) / (minute));
2904 var countDownSeconds_innerText = Math.floor((distance_new % (minute)) / second);
2905
2906 if( isNaN(countDownDays_innerText) || isNaN(countDownHours_innerText) || isNaN(countDownMinutes_innerText) || isNaN(countDownSeconds_innerText) ){
2907 var headline = document.getElementById("ays-poll-countdown-headline"),
2908 countdown = document.getElementById("ays-poll-countdown"),
2909 content = document.getElementById("ays-poll-countdown-content");
2910
2911 // headline.innerText = "Sale is over!";
2912 countdown.style.display = "none";
2913 content.style.display = "block";
2914
2915 clearInterval(y);
2916 } else {
2917 countDownDays.innerText = countDownDays_innerText;
2918 countDownHours.innerText = countDownHours_innerText;
2919 countDownMinutes.innerText = countDownMinutes_innerText;
2920 countDownSeconds.innerText = countDownSeconds_innerText;
2921 }
2922 }
2923
2924 //do something later when date is reached
2925 if (distance_new < 0) {
2926 var headline = document.getElementById("ays-poll-countdown-headline"),
2927 countdown = document.getElementById("ays-poll-countdown"),
2928 content = document.getElementById("ays-poll-countdown-content");
2929
2930 // headline.innerText = "Sale is over!";
2931 countdown.style.display = "none";
2932 content.style.display = "block";
2933
2934 clearInterval(y);
2935 }
2936 }, 1000);
2937 }
2938
2939 function aysPollBannerCountdown(){
2940 var now = new Date().getTime();
2941 var distance_new = countDown_new - now;
2942
2943 var countDownDays = document.getElementById("ays-poll-countdown-days");
2944 var countDownHours = document.getElementById("ays-poll-countdown-hours");
2945 var countDownMinutes = document.getElementById("ays-poll-countdown-minutes");
2946 var countDownSeconds = document.getElementById("ays-poll-countdown-seconds");
2947
2948 if((countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null) && distance_new > 0){
2949
2950 var countDownDays_innerText = Math.floor(distance_new / (day));
2951 var countDownHours_innerText = Math.floor((distance_new % (day)) / (hour));
2952 var countDownMinutes_innerText = Math.floor((distance_new % (hour)) / (minute));
2953 var countDownSeconds_innerText = Math.floor((distance_new % (minute)) / second);
2954
2955 if( isNaN(countDownDays_innerText) || isNaN(countDownHours_innerText) || isNaN(countDownMinutes_innerText) || isNaN(countDownSeconds_innerText) ){
2956 var headline = document.getElementById("ays-poll-countdown-headline"),
2957 countdown = document.getElementById("ays-poll-countdown"),
2958 content = document.getElementById("ays-poll-countdown-content");
2959
2960 // headline.innerText = "Sale is over!";
2961 countdown.style.display = "none";
2962 content.style.display = "block";
2963
2964 // clearInterval(y);
2965 } else {
2966 countDownDays.innerText = countDownDays_innerText;
2967 countDownHours.innerText = countDownHours_innerText;
2968 countDownMinutes.innerText = countDownMinutes_innerText;
2969 countDownSeconds.innerText = countDownSeconds_innerText;
2970 }
2971
2972 // countDownDays.innerText = Math.floor(distance_new / (day)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
2973 // countDownHours.innerText = Math.floor((distance_new % (day)) / (hour)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
2974 // countDownMinutes.innerText = Math.floor((distance_new % (hour)) / (minute)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
2975 // countDownSeconds.innerText = Math.floor((distance_new % (minute)) / second).toLocaleString(undefined,{minimumIntegerDigits: 2});
2976 }
2977 }
2978
2979 $(document).on('click', '#ays-polls-next-button, #ays-polls-prev-button, .ays-poll-next-prev-button-class', function(e){
2980 e.preventDefault();
2981 var message = $(this).data('message');
2982 var confirm = window.confirm( message );
2983 if(confirm === true){
2984 window.location.replace($(this).attr('href'));
2985 }
2986 });
2987
2988 // CHOOSE POLL TYPE FROM MODAL START
2989 $(document).find('.ays_poll_layer_box_blocks label.ays-poll-dblclick-layer:not(.ays-poll-type-pro-feature)').on('dblclick',function(){
2990 $(this).parents('.ays_poll_layer_container').find('.ays_poll_select_button_layer input.ays_poll_layer_button').trigger('click');
2991 });
2992
2993 $(document).find('.ays-poll-content-type').on('change',function(){
2994 $(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());
2995 $(document).find('#poll_choose_type').val($(this).val());
2996 });
2997
2998 $(document).find('.ays_poll_layer_button').on('click',function(){
2999 $('.ays_poll_layer_container').css({'position':'unset' , 'display':'none'});
3000 $(document).find('.ays-poll-show-result-chart-google').prop("checked", true);
3001
3002 checkType($(this).attr("data-type"));
3003 })
3004 // CHOOSE POLL TYPE FROM MODAL END
3005
3006 $(document).find('.ays-poll-open-polls-list').on('click', function(e){
3007 $(this).parents(".ays-poll-subtitle-main-box").find(".ays-poll-polls-data").toggle('fast');
3008 });
3009
3010 $(document).find(".ays-poll-go-to-polls").on("click" , function(e){
3011 e.preventDefault();
3012 var confirmRedirect = window.confirm(pollLangObj.areYouSure);
3013 if(confirmRedirect){
3014 window.location = $(this).attr("href");
3015 }
3016 });
3017
3018 $(document).find('#ays_poll_reset_to_default').on('click', function (e) {
3019 e.preventDefault();
3020
3021 var themeId = $(document).find('.ays-poll-theme-item.apm_active_theme').next('input').val();
3022
3023 $(document).find('.apm-themes-row').attr('data-themeId',themeId);
3024 if ($(document).find('#ays_poll_show_answers_icon').prop('checked')) {
3025 switch(parseInt(themeId)){
3026 case 3:
3027 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3028 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3029 break;
3030 default:
3031 var iconsVal = $('input[name="ays_poll_answer_icon"]:checked').val();
3032 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3033 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3034 $(document).find('.ays_label_poll').addClass('ays_poll_answer_icon_'+iconsVal);
3035 break;
3036 }
3037 }else{
3038 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_checkbox');
3039 $(document).find('.ays_label_poll').removeClass('ays_poll_answer_icon_radio');
3040 }
3041
3042 answerStyleChange(themeId);
3043
3044 textColorChange({
3045 color: themes[themeId].textColor
3046 });
3047 buttonTextColorChange({
3048 color: themes[themeId].buttonTextColor
3049 });
3050 buttonBgColorChange({
3051 color: themes[themeId].buttonBgColor
3052 });
3053 mainColorChange({
3054 color: themes[themeId].mainColor
3055 });
3056 bgColorChange({
3057 color: themes[themeId].bgColor
3058 });
3059 answerBgColorChange({
3060 color: themes[themeId].answerBgColor
3061 });
3062 titleBgColorChange({
3063 color: themes[themeId].titleBgColor
3064 });
3065 iconColorChange({
3066 color: themes[themeId].iconColor
3067 });
3068 borderColorChange({
3069 color: themes[themeId].borderColor
3070 });
3071 $(document).find('#ays-poll-text-color').parent().parent().prev().css({
3072 'background-color': themes[themeId].textColor
3073 });
3074 $(document).find('#ays-poll-text-color').val(themes[themeId].textColor);
3075
3076 $(document).find('#ays-poll-button-text-color').parent().parent().prev().css({
3077 'color': themes[themeId].buttonTextColor
3078 });
3079 $(document).find('#ays-poll-button-text-color').val(themes[themeId].buttonTextColor);
3080
3081 $(document).find('#ays-poll-button-bg-color').parent().parent().prev().css({
3082 'background-color': themes[themeId].buttonBgColor
3083 });
3084 $(document).find('#ays-poll-button-bg-color').val(themes[themeId].buttonBgColor);
3085
3086 $(document).find('#ays-poll-main-color').parent().parent().prev().css({
3087 'background-color': themes[themeId].mainColor
3088 });
3089 $(document).find('#ays-poll-main-color').val(themes[themeId].mainColor);
3090
3091 $(document).find('#ays-poll-bg-color').parent().parent().prev().css({
3092 'background-color': themes[themeId].bgColor
3093 });
3094 $(document).find('#ays-poll-bg-color').val(themes[themeId].bgColor);
3095
3096 $(document).find('#ays-poll-answer-bg-color').parent().parent().prev().css({
3097 'background-color': themes[themeId].answerBgColor
3098 });
3099 $(document).find('#ays-poll-answer-bg-color').val(themes[themeId].answerBgColor);
3100
3101 $(document).find('#ays-poll-answer-hover-color').closest('.wp-picker-input-wrap').prev().css({
3102 'background-color': themes[themeId].answerHoverColor
3103 });
3104 $(document).find('#ays-poll-answer-hover-color').val(themes[themeId].answerHoverColor);
3105
3106 $(document).find('#ays-poll-title-bg-color').parent().parent().prev().css({
3107 'background-color': themes[themeId].titleBgColor
3108 });
3109 $(document).find('#ays-poll-title-bg-color').val(themes[themeId].titleBgColor);
3110
3111 $(document).find('#ays-poll-icon-color').parent().parent().prev().css({
3112 'background-color': themes[themeId].iconColor
3113 });
3114 $(document).find('#ays-poll-icon-color').val(themes[themeId].iconColor);
3115
3116 $(document).find('input#ays-poll-bg-image').val('');
3117 $(document).find('#ays-poll-bg-img').attr('src', '').change();
3118 $(document).find('.ays-poll-bg-image-container').hide().change();
3119 $(document).find('#ays-poll-background-image-options').hide().change();
3120 $(document).find('.add-bg-image.button').text('Add Image');
3121 $(document).find('.add-bg-image.button').show().change();
3122 $(document).find('.box-apm.choosing-poll').css('background-image', '');
3123 $(document).find('#ays_poll_bg_image_position').val('center center').change();
3124 $(document).find("#ays_poll_bg_img_in_finish_page").prop('checked' , false).change();
3125
3126 if(themeId == 3){
3127 $(document).find('#ays-poll-border-side').val('none').change();
3128 }else{
3129 $(document).find('#ays-poll-border-side').val('all_sides').change();
3130 }
3131
3132 $(document).find('input#ays_answer_font_size').val('16').change();
3133 $(document).find('input#ays_poll_answer_font_size_mobile').val('16').change();
3134 $(document).find('input#ays_poll_answer_img_height').val('150').change();
3135 $(document).find('input#ays_poll_answer_image_height_for_mobile').val('150').change();
3136 $(document).find('input#ays_poll_answer_image_border_radius').val('0').change();
3137 $(document).find('#ays_poll_image_background_size').val('cover').change();
3138 $(document).find('input#ays_poll_answers_padding').val('10').change();
3139 $(document).find('input#ays_poll_answers_margin').val('10').change();
3140 $(document).find('input#ays_poll_answer_border_radius').val('0').change();
3141
3142 $(document).find("#ays_poll_show_answers_icon").prop('checked' , false).change();
3143
3144 $(document).find('#ays_answers_view').val('list').change();
3145 $(document).find("#ays_poll_answers_box_shadow_enable").prop('checked' , false).change();
3146 $(document).find('input#ays_poll_title_font_size').val('20').change();
3147 $(document).find('input#ays_poll_title_font_size_mobile').val('20').change();
3148 $(document).find('#ays_poll_title_alignment').val('center').change();
3149 $(document).find('#ays_poll_title_alignment_mobile').val('center').change();
3150 $(document).find("#ays_poll_enable_title_text_shadow").prop('checked' , false).change();
3151 $(document).find('input#ays-poll-icon-size').val('24').change();
3152 $(document).find('input#ays-poll-width').val('0').change();
3153 $(document).find('input#ays_poll_width_for_mobile').val('0').change();
3154 $(document).find('input#ays_poll_min_height').val('').change();
3155 $(document).find('#ays-poll-border-style').val('ridge').change();
3156 $(document).find('input#ays-poll-border-radius').val('0').change();
3157 $(document).find('input#ays-poll-border-width').val('2').change();
3158 $(document).find("#ays_poll_enable_box_shadow").prop('checked' , false).change();
3159 $(document).find("#ays-enable-background-gradient").prop('checked' , false).change();
3160 $(document).find('input#ays_questions_font_size').val('16').change();
3161 $(document).find('input#ays_poll_answers_font_size_mobile').val('16').change();
3162 $(document).find('input#ays_poll_question_image_height').val('').change();
3163 $(document).find('#ays_poll_question_image_object_fit').val('cover').change();
3164 $(document).find('input#ays_poll_mobile_max_width').val('').change();
3165 $(document).find('#ays_poll_buttons_size').val('medium').change();
3166 $(document).find('input#ays_poll_buttons_font_size').val('17').change();
3167 $(document).find('input#ays_poll_buttons_mobile_font_size').val('17').change();
3168 $(document).find('input#ays_poll_buttons_left_right_padding').val('20').change();
3169 $(document).find('input#ays_poll_buttons_top_bottom_padding').val('10').change();
3170 $(document).find('input#ays_poll_buttons_border_radius').val('3').change();
3171 $(document).find('input#ays_poll_buttons_width').val('').change();
3172 $(document).find("#ays_disable_answer_hover").prop('checked' , false).change();
3173
3174 $(document).find(".add-logo-remove-image.button").trigger('click');
3175 $(document).find('input#ays_poll_custom_class').val('').change();
3176
3177 setTimeout(function(){
3178 if($(document).find('#ays_custom_css').length > 0){
3179 if(wp.codeEditor){
3180 $(document).find('#ays_custom_css').next('.CodeMirror').remove();
3181 $(document).find('#ays_custom_css').val('');
3182 wp.codeEditor.initialize($(document).find('#ays_custom_css'), cm_settings);
3183 }
3184 }
3185 }, 100);
3186
3187 $(document).find("#tab2").goToNormal();
3188 });
3189
3190 $(document).on('mouseover', '.ays-dashicons', function(){
3191 var allRateStars = $(document).find('.ays-dashicons');
3192 var index = allRateStars.index(this);
3193 allRateStars.removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3194 for (var i = 0; i <= index; i++) {
3195 allRateStars.eq(i).removeClass('ays-dashicons-star-empty').addClass('ays-dashicons-star-filled');
3196 }
3197 });
3198
3199 $(document).on('mouseleave', '.ays-rated-link', function(){
3200 $(document).find('.ays-dashicons').removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3201 });
3202
3203 var aysPollListTables = $(document).find('#wpcontent #wpbody div.wrap.ays-poll-list-table');
3204
3205 if ( aysPollListTables.length > 0) {
3206 var listTableClass = "";
3207 var searchBox = "";
3208 if( aysPollListTables.hasClass('ays_polls_list_table') ){
3209 listTableClass = 'ays_polls_list_table';
3210 searchBox = 'poll-maker-ays-search-input';
3211 }
3212 else if( aysPollListTables.hasClass('ays_poll_categories_list_table') ){
3213 listTableClass = 'ays_poll_categories_list_table';
3214 searchBox = 'poll-maker-ays-search-input';
3215 }
3216 else if( aysPollListTables.hasClass('ays_poll_results_list_table') ){
3217 listTableClass = 'ays_poll_results_list_table';
3218 searchBox = 'poll-maker-ays-search-input';
3219 }
3220
3221 if( listTableClass != "" && searchBox != "" ){
3222 ays_poll_search_box_pagination(listTableClass, searchBox);
3223 }
3224 }
3225
3226 // Select message vars galleries page | Start
3227 $(document).find('.ays-poll-message-vars-icon').on('click', function(e){
3228 $(this).parents(".ays-poll-message-vars-box").find(".ays-poll-message-vars-data").toggle('fast');
3229 });
3230
3231 $(document).on( "click" , function(e){
3232 if($(e.target).closest('.ays-poll-message-vars-box').length != 0){
3233 }
3234 else{
3235 $(document).find(".ays-poll-message-vars-box .ays-poll-message-vars-data").hide('fast');
3236 }
3237 });
3238
3239 $(document).find('.ays-poll-message-vars-each-data').on('click', function(e){
3240 var _this = $(this);
3241 var parent = _this.parents('.ays-poll-desc-message-vars-parent');
3242
3243 var textarea = parent.find('textarea.ays-textarea');
3244 var textareaID = textarea.attr('id');
3245
3246 var messageVar = _this.find(".ays-poll-message-vars-each-var").val();
3247
3248 if ( parent.find("#wp-"+ textareaID +"-wrap").hasClass("tmce-active") ){
3249 window.tinyMCE.get(textareaID).setContent( window.tinyMCE.get(textareaID).getContent() + messageVar + " " );
3250 }else{
3251 $(document).find('#'+textareaID).append( " " + messageVar + " ");
3252 }
3253 });
3254 /* Select message vars galleries page | End */
3255
3256 // Check poll result as read start
3257 $(document).find('.ays-show-results').on('click', function (e) {
3258 $(document).find('#ays-results-modal').fadeIn();
3259 $(document).find('div.ays-poll-preloader').css('display', 'flex');
3260
3261 var $this = $(this);
3262 var readStatus = $this.parents('tr').find("td .unread-result-badge");
3263
3264 $('li.toplevel_page_poll-maker-ays .apm-badge.badge-danger').each(function () {
3265 var $unreadCounter = $(this);
3266
3267 if ($unreadCounter.text() != 0) {
3268 if(readStatus.hasClass('unread-result')){
3269 var counter = +$unreadCounter.text();
3270 counter--;
3271 if(counter == 0){
3272 $unreadCounter.hide();
3273 }
3274 $unreadCounter.text(counter);
3275 }
3276 }
3277 else{
3278 $unreadCounter.hide();
3279 }
3280 });
3281
3282 if(readStatus.hasClass('unread-result')){
3283 readStatus.removeClass('unread-result');
3284 }
3285
3286 $(this).css('font-weight' , 'normal');
3287 $(this).parent().css('font-weight' , 'normal');
3288 $(this).parent().siblings().css('font-weight' , 'normal');
3289 var result = $(this).data('result');
3290 var action = 'apm_show_results';
3291 var wp_nonce = $(document).find('#poll_maker_ajax_show_details_report_nonce').val();
3292 $.ajax({
3293 url: poll.ajax,
3294 dataType: 'json',
3295 method: "post",
3296 data: {
3297 result: result,
3298 action: action,
3299 _ajax_nonce: wp_nonce,
3300 is_details: 1
3301 },
3302 success: function(response) {
3303 if (response.status === true) {
3304 $('table#ays-results-table').html(response.rows);
3305 $(document).find('div.ays-poll-preloader').css('display', 'none');
3306 }
3307 }
3308 });
3309 e.preventDefault();
3310 });
3311 // Check poll result as read end
3312
3313 // Close results popup start
3314 $(document).find('#ays-close-results').on('click', function () {
3315 $(document).find('#ays-results-modal').fadeOut();
3316 });
3317 // Close results popup end
3318
3319 // Pro features start
3320 $(document).on('click', '.pro_features_popup', function(e){
3321 e.preventDefault();
3322 var _this = $(this);
3323 var popupModal = $(document).find('#pro-features-popup-modal');
3324
3325 var popupModal_title = _this.find('.pro-features-popup-title');
3326 var popupModal_title_text = popupModal_title.text();
3327
3328 var popupModal_content = _this.find('.pro-features-popup-content').html();
3329 var popupModal_video_link = _this.find('.pro-features-popup-content').attr("data-link");
3330
3331 var popupModal_button = _this.find('.pro-features-popup-button');
3332 var popupModal_button_text = popupModal_button.text();
3333 var popupModal_button_link = popupModal_button.attr("data-link");
3334
3335
3336 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3337 var rightSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-right-section');
3338
3339 rightSection.find('.pro-features-popup-modal-right-box-title').text(popupModal_title_text);
3340 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3341 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3342
3343 rightSection.find('.pro-features-popup-modal-right-box-link').text(popupModal_button_text);
3344 rightSection.find('.pro-features-popup-modal-right-box-link').attr("href", popupModal_button_link);
3345
3346 if ( typeof popupModal_video_link != "undefined" && popupModal_video_link != "") {
3347 var videoID = ays_youtube_parser(popupModal_video_link);
3348 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>';
3349
3350 leftSection.html(iframeHTML);
3351 }
3352
3353 popupModal.aysModal('show_flex');
3354 });
3355
3356 $(document).on('click', '.ays-poll-new-watch-video-button-box, .ays-poll-center-big-watch-video-button-box', function(e){
3357 e.preventDefault();
3358 if( $(this).hasClass('ays-poll-center-big-watch-video-button-box') ){
3359 var _this = $(this).parent().parent().find('.pro_features.pro_features_popup');
3360 } else {
3361 var _this = $(this).parent().find('.pro_features.pro_features_popup');
3362 }
3363 var popupModal = $(document).find('#pro-features-popup-modal');
3364 var popupModal_title = _this.find('.pro-features-popup-title');
3365 var popupModal_title_text = popupModal_title.text();
3366
3367 var popupModal_content = _this.find('.pro-features-popup-content').html();
3368 var popupModal_video_link = _this.find('.pro-features-popup-content').attr("data-link");
3369
3370 var popupModal_button = _this.find('.pro-features-popup-button');
3371 var popupModal_button_text = popupModal_button.text();
3372 var popupModal_button_link = popupModal_button.attr("data-link");
3373
3374
3375 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3376 var rightSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-right-section');
3377
3378 rightSection.find('.pro-features-popup-modal-right-box-title').text(popupModal_title_text);
3379 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3380 rightSection.find('.pro-features-popup-modal-right-box-content').html(popupModal_content);
3381
3382 rightSection.find('.pro-features-popup-modal-right-box-link').text(popupModal_button_text);
3383 rightSection.find('.pro-features-popup-modal-right-box-link').attr("href", popupModal_button_link);
3384
3385 if ( typeof popupModal_video_link != "undefined" && popupModal_video_link != "") {
3386 var videoID = ays_youtube_parser(popupModal_video_link);
3387 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>';
3388
3389 leftSection.html(iframeHTML);
3390 }
3391
3392 popupModal.aysModal('show_flex');
3393 });
3394
3395 $(document).find('.ays-close-pro-popup').on('click', function () {
3396 $(this).parents('.ays-modal').aysModal('hide_remove_video');
3397 });
3398 // // Pro features end
3399
3400 })(jQuery);
3401
3402
3403 function selectElementContents(el) {
3404 if (window.getSelection && document.createRange) {
3405 var _this = jQuery(document).find('strong.ays-poll-shortcode-box');
3406 var text = el.textContent;
3407 var textField = document.createElement('textarea');
3408
3409 textField.innerText = text;
3410 document.body.appendChild(textField);
3411 textField.select();
3412 document.execCommand('copy');
3413 textField.remove();
3414 var sel = window.getSelection();
3415 var range = document.createRange();
3416 range.selectNodeContents(el);
3417 sel.removeAllRanges();
3418 sel.addRange(range);
3419 _this.attr( "data-original-title", pollLangObj.copied );
3420 _this.attr( "title", pollLangObj.copied );
3421 _this.tooltip("show");
3422 } else if (document.selection && document.body.createTextRange) {
3423 var textRange = document.body.createTextRange();
3424 textRange.moveToElementText(el);
3425 textRange.select();
3426 }
3427 }
3428
3429 Date.prototype.aysPollCustomFormat = function( formatString){
3430 var YYYY,YY,MMMM,MMM,MM,M,DDDD,DDD,DD,D,hhhh,hhh,hh,h,mm,m,ss,s,ampm,AMPM,dMod,th;
3431 YY = ((YYYY=this.getFullYear())+"").slice(-2);
3432 MM = (M=this.getMonth()+1)<10?('0'+M):M;
3433 MMM = (MMMM=["January","February","March","April","May","June","July","August","September","October","November","December"][M-1]).substring(0,3);
3434 DD = (D=this.getDate())<10?('0'+D):D;
3435 DDD = (DDDD=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][this.getDay()]).substring(0,3);
3436 th=(D>=10&&D<=20)?'th':((dMod=D%10)==1)?'st':(dMod==2)?'nd':(dMod==3)?'rd':'th';
3437 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);
3438 h=(hhh=this.getHours());
3439 if (h==0) h=24;
3440 if (h>12) h-=12;
3441 hh = h<10?('0'+h):h;
3442 hhhh = hhh<10?('0'+hhh):hhh;
3443 AMPM=(ampm=hhh<12?'am':'pm').toUpperCase();
3444 mm=(m=this.getMinutes())<10?('0'+m):m;
3445 ss=(s=this.getSeconds())<10?('0'+s):s;
3446
3447 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);
3448 // token: description: example:
3449 // #YYYY# 4-digit year 1999
3450 // #YY# 2-digit year 99
3451 // #MMMM# full month name February
3452 // #MMM# 3-letter month name Feb
3453 // #MM# 2-digit month number 02
3454 // #M# month number 2
3455 // #DDDD# full weekday name Wednesday
3456 // #DDD# 3-letter weekday name Wed
3457 // #DD# 2-digit day number 09
3458 // #D# day number 9
3459 // #th# day ordinal suffix nd
3460 // #hhhh# 2-digit 24-based hour 17
3461 // #hhh# military/24-based hour 17
3462 // #hh# 2-digit hour 05
3463 // #h# hour 5
3464 // #mm# 2-digit minute 07
3465 // #m# minute 7
3466 // #ss# 2-digit second 09
3467 // #s# second 9
3468 // #ampm# "am" or "pm" pm
3469 // #AMPM# "AM" or "PM" PM
3470 };
3471
3472 function drawBasic() {
3473 if(typeof pollAnswerChartObj != "undefined"){
3474 var data = google.visualization.arrayToDataTable(pollAnswerChartObj.answerData);
3475 var rowCount = data.getNumberOfRows();
3476 var multiply;
3477 if(rowCount < 8){
3478 multiply = 40;
3479 }
3480 else{
3481 multiply = 30;
3482 }
3483 var chartAreaHeight = rowCount * multiply;
3484 var chartHeight = chartAreaHeight + 80;
3485
3486 /* === Old type === */
3487 // var options = {
3488 // title: pollAnswerChartObj.pollTitle,
3489 // width: '100%',
3490 // fontSize: 15,
3491 // height: chartHeight,
3492 // chartArea: {
3493 // width: '75%',
3494 // height: '80%'
3495 // },
3496 // hAxis: {
3497 // minValue: 0
3498 // }
3499 // };
3500
3501 /* === New type === */
3502 var options = {
3503 title: pollAnswerChartObj.pollTitle,
3504 width: '100%',
3505 height: chartHeight,
3506 fontSize: 15,
3507 chartArea: {
3508 width: '50%',
3509 height: '80%'
3510 },
3511 hAxis: {
3512 minValue: 0
3513 },
3514 annotations: {
3515 alwaysOutside: true
3516 },
3517 bars: 'horizontal',
3518 bar: { groupWidth: "50%" }
3519 };
3520
3521 var chart = new google.visualization.BarChart(document.getElementById('ays_poll_answer_chart'));
3522 // remove error
3523 // google.visualization.events.(chart, 'error', function (googleError) {
3524 // google.visualization.errors.removeError(googleError.id);
3525 // });
3526
3527 chart.draw(data, options);
3528 resizeChart(chart, data, options);
3529 }
3530 }
3531
3532 function resizeChart(chart, data, options){
3533
3534 //create trigger to resizeEnd event
3535 jQuery(window).resize(function() {
3536 if(this.resizeTO) clearTimeout(this.resizeTO);
3537 this.resizeTO = setTimeout(function() {
3538 jQuery(this).trigger('resizeEnd');
3539 }, 100);
3540 });
3541
3542 //redraw graph when window resize is completed
3543 jQuery(window).on('resizeEnd', function() {
3544 chart.draw(data, options);
3545 });
3546 }