PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 5.6.0
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v5.6.0
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.0, at admin/js/poll-maker-ays-admin.js

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