(function ($) { 'use strict'; // Quick poll submit function $(document).find('#ays-save-quick-poll').on('click', function (e) { var $this = $(this); var title = $(document).find('#ays-quick-poll-title').val(); $this.attr('disabled', true); $this.addClass('quick-poll-save-disabled'); if (title == '') { swal.fire({ type: 'error', html: "

Poll title can't be empty.

", onAfterClose: function() { $this.removeClass('quick-poll-save-disabled'); $this.attr('disabled', false); } }); return false; } var questions = $(document).find('#ays-quick-poll-question').val(); var answersArr = $(document).find('.quick_poll_answer'); for (var i = 0; i < answersArr.length; i++) { if (answersArr.eq(i).val() == '') { swal.fire({ type: 'error', html: '

You must fill all answers

', onAfterClose: function() { $this.removeClass('quick-poll-save-disabled'); $this.attr('disabled', false); } }); return false; } else { answersArr[i] = answersArr.eq(i).val(); } } // var allowAnonimity = $(document).find('#allow_anonimity_switch').is(':checked') ? 1 : 0; var allowMultivote = $(document).find('#allow_multivote_switch').is(':checked') ? 'on' : 'off'; if (allowMultivote == 'on') { var multivote_min_count = $(document).find('#quick-poll-multivote-min-count').val(); var multivote_max_count = $(document).find('#quick-poll-multivote-max-count').val(); } else { var multivote_min_count = 1; var multivote_max_count = 1; } var previewButtonSvgIcon = ''+ ''+ ''; var wp_nonce = $(document).find('#ays_poll_ajax_quick_poll_nonce').val(); var showTitle = $(document).find('#quick-poll-show-title').is(':checked') ? 'on' : 'off'; var quickPollFormData = $('#ays-quick-poll-form').serializeFormJSON(); quickPollFormData.action = 'ays_poll_maker_quick_start'; quickPollFormData['quick-poll-show-title'] = showTitle; quickPollFormData._ajax_nonce = wp_nonce; $.ajax({ url: poll_maker_ajax.ajax_url, method: 'post', dataType: 'json', data: quickPollFormData, success: function (response) { $(document).find('div.ays-poll-preloader').css('display', 'none'); if (response.status === true) { var link = "#"; if( typeof response.preview_url != 'undefined' ){ link = response.preview_url; } $(document).find('#ays-quick-poll-form')[0].reset(); $(document).find('#ays-poll-quick-create .ays-modal-content').addClass('animated bounceOutRight'); $(document).find('#ays-poll-quick-create').modal('hide'); swal({ title: 'Great job', type: 'success', html: '

Your Poll is Created!
Copy the generated shortcode and paste it into any post or page to display Poll.

For more detailed configuration visit edit poll page.

', showCloseButton: true, showCancelButton: true, focusConfirm: false, cancelButtonClass: "ays-poll-preview-popup-cancel-button", confirmButtonText: ' Done', cancelButtonText: 'Preview Poll ' + previewButtonSvgIcon +'', confirmButtonAriaLabel: 'Thumbs up, Done', onAfterClose: function() { $(document).find('#ays-poll-quick-create').removeClass('animated bounceOutRight'); $(document).find('#ays-poll-quick-create').css('display', 'none'); window.location.href = "admin.php?page=poll-maker-ays"; location.reload(); } }) } } }) }) function updateProgress() { var total = $(document).find(".ays-poll-checklist-step").length; var done = $(document).find(".ays-poll-checklist-step input:checked").length; var percent = Math.round((done / total) * 100); $(document).find(".ays-poll-checklist-progress-text").text(percent + "%"); $(document).find(".ays-poll-checklist-progress-bar span").css("width", percent + "%"); } function saveChecklist() { var checked = []; $(document).find(".ays-poll-checklist-step input:checked").each(function () { checked.push($(this).closest(".ays-poll-checklist-step").data("step")); }); $.post(poll_maker_ajax.ajax_url, { action: "ays_poll_save_checklist_progress", nonce: poll_maker_ajax.nonce, steps: checked, }); } $(document).find(".ays-poll-checklist-step").each(function () { var $step = $(this); var $checkbox = $step.find('input[type="checkbox"]'); var $content = $step.find(".ays-poll-checklist-step-content"); var $button = $step.find(".ays-poll-checklist-mark-done"); $checkbox.on("change", function () { if ($(this).is(':checked')) { $step.addClass('completed'); $button.text(poll_maker_ajax.checklistUnmarkAsDone); } else { $step.removeClass('completed'); $button.text(poll_maker_ajax.checklistMarkAsDone); } updateProgress(); saveChecklist(); }); }); $(document).on('click', '.ays-poll-checklist-mark-done', function () { var $button = $(this); var $step = $button.closest('.ays-poll-checklist-step'); var $checkbox = $step.find('input[type="checkbox"]'); var isChecked = $checkbox.prop('checked'); $checkbox.prop('checked', !isChecked); $step.toggleClass('completed', !isChecked); if (isChecked) { $button.text(poll_maker_ajax.checklistMarkAsDone); } else { $button.text(poll_maker_ajax.checklistUnmarkAsDone); } updateProgress(); saveChecklist(); }); $(document).on('click', '.ays-poll-checklist-toggle-step', function () { var $step = $(this).closest('.ays-poll-checklist-step'); var $content = $step.find('.ays-poll-checklist-step-content'); $(document).find('.ays-poll-checklist-step-content').not($content).slideUp(200); $(document).find('.ays-poll-checklist-toggle-step').not(this).removeClass('open'); $content.slideToggle(200); $(this).toggleClass('open'); }); // Reopen checklist on checklist icon click $(document).on('click', '.ays-poll-checklist-open-icon', function () { var $checklist = $(document).find('#ays-poll-checklist-container'); $checklist.show(); $.ajax({ type: 'POST', url: poll_maker_ajax.ajax_url, data: { action: 'ays_poll_checklist_reopen_callback', nonce: poll_maker_ajax.nonce }, success: function () { } }); }); // Hide popup permanently $(document).on('click', '.ays-poll-checklist-popup-close', function () { var $checklist = $(this).closest('.ays-poll-checklist-popup'); $checklist.fadeOut(200); }); $(document).on('click', '.ays-poll-checklist-minimize-btn', function () { var $panel = $(document).find('.ays-poll-checklist-panel'); var $expandedIcon = $(this).find('.ays-poll-checklist-minimize-icon-expanded'); var $collapsedIcon = $(this).find('.ays-poll-checklist-minimize-icon-collapsed'); $panel.toggleClass('ays-poll-checklist-minimized'); if ($panel.hasClass('ays-poll-checklist-minimized')) { $expandedIcon.hide(); $collapsedIcon.show(); } else { $expandedIcon.show(); $collapsedIcon.hide(); } }); $(document).on('click', '.ays-poll-checklist-close-btn', function () { var $checklist = $(this).closest('#ays-poll-checklist-container'); $.ajax({ type: 'POST', url: poll_maker_ajax.ajax_url, data: { action: 'ays_poll_checklist_close_popup', nonce: poll_maker_ajax.nonce }, success: function (response) { if (response.success) { $checklist.fadeOut(200); } else { console.error(response.data); $checklist.fadeOut(200); } if (localStorage.getItem('ays_poll_checklist_popup_closed') !== '1') { $(document).find('.ays-poll-checklist-popup').fadeIn(200); } localStorage.setItem('ays_poll_checklist_popup_closed', '1'); }, error: function() { $checklist.fadeOut(200); } }); }); updateProgress(); })(jQuery)