PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.5
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.5
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 5.6.7 All 152 releases
poll-maker / admin / js / poll-maker-ays-ajax-admin.js

poll-maker-ays-ajax-admin.js in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.4.5, at admin/js/poll-maker-ays-ajax-admin.js

252 lines 11.9 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 // Quick poll submit function
5 $(document).find('#ays-save-quick-poll').on('click', function (e) {
6 var $this = $(this);
7 var title = $(document).find('#ays-quick-poll-title').val();
8
9 $this.attr('disabled', true);
10 $this.addClass('quick-poll-save-disabled');
11 if (title == '') {
12 swal.fire({
13 type: 'error',
14 html: "<h2>Poll title can't be empty.</h2>",
15 onAfterClose: function() {
16 $this.removeClass('quick-poll-save-disabled');
17 $this.attr('disabled', false);
18 }
19 });
20
21 return false;
22 }
23
24 var questions = $(document).find('#ays-quick-poll-question').val();
25 var answersArr = $(document).find('.quick_poll_answer');
26
27 for (var i = 0; i < answersArr.length; i++) {
28 if (answersArr.eq(i).val() == '') {
29 swal.fire({
30 type: 'error',
31 html: '<h2>You must fill all answers</h2>',
32 onAfterClose: function() {
33 $this.removeClass('quick-poll-save-disabled');
34 $this.attr('disabled', false);
35 }
36 });
37 return false;
38 } else {
39 answersArr[i] = answersArr.eq(i).val();
40 }
41 }
42
43 // var allowAnonimity = $(document).find('#allow_anonimity_switch').is(':checked') ? 1 : 0;
44 var allowMultivote = $(document).find('#allow_multivote_switch').is(':checked') ? 'on' : 'off';
45
46 if (allowMultivote == 'on') {
47 var multivote_min_count = $(document).find('#quick-poll-multivote-min-count').val();
48 var multivote_max_count = $(document).find('#quick-poll-multivote-max-count').val();
49 } else {
50 var multivote_min_count = 1;
51 var multivote_max_count = 1;
52 }
53
54 var previewButtonSvgIcon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">'+
55 '<path d="M11.9999 7.21325C11.8231 7.21325 11.6535 7.28349 11.5285 7.40851C11.4035 7.53354 11.3333 7.70311 11.3333 7.87992V12.6666C11.3333 12.8434 11.263 13.013 11.138 13.138C11.013 13.263 10.8434 13.3333 10.6666 13.3333H3.33325C3.15644 13.3333 2.98687 13.263 2.86185 13.138C2.73682 13.013 2.66659 12.8434 2.66659 12.6666V5.33325C2.66659 5.15644 2.73682 4.98687 2.86185 4.86185C2.98687 4.73682 3.15644 4.66658 3.33325 4.66658H8.11992C8.29673 4.66658 8.4663 4.59635 8.59132 4.47132C8.71635 4.3463 8.78658 4.17673 8.78658 3.99992C8.78658 3.82311 8.71635 3.65354 8.59132 3.52851C8.4663 3.40349 8.29673 3.33325 8.11992 3.33325H3.33325C2.80282 3.33325 2.29411 3.54397 1.91904 3.91904C1.54397 4.29411 1.33325 4.80282 1.33325 5.33325V12.6666C1.33325 13.197 1.54397 13.7057 1.91904 14.0808C2.29411 14.4559 2.80282 14.6666 3.33325 14.6666H10.6666C11.197 14.6666 11.7057 14.4559 12.0808 14.0808C12.4559 13.7057 12.6666 13.197 12.6666 12.6666V7.87992C12.6666 7.70311 12.5963 7.53354 12.4713 7.40851C12.3463 7.28349 12.1767 7.21325 11.9999 7.21325ZM14.6133 1.74659C14.5456 1.58369 14.4162 1.45424 14.2533 1.38659C14.1731 1.35242 14.087 1.33431 13.9999 1.33325H9.99992C9.82311 1.33325 9.65354 1.40349 9.52851 1.52851C9.40349 1.65354 9.33325 1.82311 9.33325 1.99992C9.33325 2.17673 9.40349 2.3463 9.52851 2.47132C9.65354 2.59635 9.82311 2.66659 9.99992 2.66659H12.3933L5.52659 9.52658C5.4641 9.58856 5.4145 9.66229 5.38066 9.74353C5.34681 9.82477 5.32939 9.91191 5.32939 9.99992C5.32939 10.0879 5.34681 10.1751 5.38066 10.2563C5.4145 10.3375 5.4641 10.4113 5.52659 10.4733C5.58856 10.5357 5.66229 10.5853 5.74353 10.6192C5.82477 10.653 5.91191 10.6705 5.99992 10.6705C6.08793 10.6705 6.17506 10.653 6.2563 10.6192C6.33754 10.5853 6.41128 10.5357 6.47325 10.4733L13.3333 3.60659V5.99992C13.3333 6.17673 13.4035 6.3463 13.5285 6.47132C13.6535 6.59635 13.8231 6.66658 13.9999 6.66658C14.1767 6.66658 14.3463 6.59635 14.4713 6.47132C14.5963 6.3463 14.6666 6.17673 14.6666 5.99992V1.99992C14.6655 1.9128 14.6474 1.82673 14.6133 1.74659Z" fill="#007DCB"/>'+
56 '</svg>';
57
58 var wp_nonce = $(document).find('#ays_poll_ajax_quick_poll_nonce').val();
59
60 var showTitle = $(document).find('#quick-poll-show-title').is(':checked') ? 'on' : 'off';
61
62 var quickPollFormData = $('#ays-quick-poll-form').serializeFormJSON();
63 quickPollFormData.action = 'ays_poll_maker_quick_start';
64 quickPollFormData['quick-poll-show-title'] = showTitle;
65 quickPollFormData._ajax_nonce = wp_nonce;
66
67 $.ajax({
68 url: poll_maker_ajax.ajax_url,
69 method: 'post',
70 dataType: 'json',
71 data: quickPollFormData,
72 success: function (response) {
73 $(document).find('div.ays-poll-preloader').css('display', 'none');
74
75 if (response.status === true) {
76 var link = "#";
77 if( typeof response.preview_url != 'undefined' ){
78 link = response.preview_url;
79 }
80
81 $(document).find('#ays-quick-poll-form')[0].reset();
82 $(document).find('#ays-poll-quick-create .ays-modal-content').addClass('animated bounceOutRight');
83 $(document).find('#ays-poll-quick-create').modal('hide');
84 swal({
85 title: '<strong>Great job</strong>',
86 type: 'success',
87 html: '<p>Your Poll is Created!<br>Copy the generated shortcode and paste it into any post or page to display Poll.</p><input type="text" id="quick_poll_shortcode" onClick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_poll id=\'' + response.poll_id + '\']" /><p style="margin-top:1rem;">For more detailed configuration visit <a href="admin.php?page=poll-maker-ays&action=edit&poll=' + response.poll_id + '">edit poll page.</a></p>',
88 showCloseButton: true,
89 showCancelButton: true,
90 focusConfirm: false,
91 cancelButtonClass: "ays-poll-preview-popup-cancel-button",
92 confirmButtonText: '<i class="ays_poll_fas ays_poll_fa_thumbs_up "></i> Done',
93 cancelButtonText: '<a href="'+ link +'" target="_blank">Preview Poll ' + previewButtonSvgIcon +'</a>',
94 confirmButtonAriaLabel: 'Thumbs up, Done',
95 onAfterClose: function() {
96 $(document).find('#ays-poll-quick-create').removeClass('animated bounceOutRight');
97 $(document).find('#ays-poll-quick-create').css('display', 'none');
98 window.location.href = "admin.php?page=poll-maker-ays";
99 location.reload();
100 }
101 })
102 }
103 }
104 })
105
106 })
107
108 function updateProgress() {
109 var total = $(document).find(".ays-poll-checklist-step").length;
110 var done = $(document).find(".ays-poll-checklist-step input:checked").length;
111 var percent = Math.round((done / total) * 100);
112
113 $(document).find(".ays-poll-checklist-progress-text").text(percent + "%");
114 $(document).find(".ays-poll-checklist-progress-bar span").css("width", percent + "%");
115 }
116
117 function saveChecklist() {
118 var checked = [];
119 $(document).find(".ays-poll-checklist-step input:checked").each(function () {
120 checked.push($(this).closest(".ays-poll-checklist-step").data("step"));
121 });
122
123 $.post(poll_maker_ajax.ajax_url, {
124 action: "ays_poll_save_checklist_progress",
125 nonce: poll_maker_ajax.nonce,
126 steps: checked,
127 });
128 }
129
130 $(document).find(".ays-poll-checklist-step").each(function () {
131 var $step = $(this);
132 var $checkbox = $step.find('input[type="checkbox"]');
133 var $content = $step.find(".ays-poll-checklist-step-content");
134 var $button = $step.find(".ays-poll-checklist-mark-done");
135
136 $checkbox.on("change", function () {
137 if ($(this).is(':checked')) {
138 $step.addClass('completed');
139 $button.text(poll_maker_ajax.checklistUnmarkAsDone);
140 } else {
141 $step.removeClass('completed');
142 $button.text(poll_maker_ajax.checklistMarkAsDone);
143 }
144
145 updateProgress();
146 saveChecklist();
147 });
148 });
149
150 $(document).on('click', '.ays-poll-checklist-mark-done', function () {
151 var $button = $(this);
152 var $step = $button.closest('.ays-poll-checklist-step');
153 var $checkbox = $step.find('input[type="checkbox"]');
154
155 var isChecked = $checkbox.prop('checked');
156
157 $checkbox.prop('checked', !isChecked);
158 $step.toggleClass('completed', !isChecked);
159
160 if (isChecked) {
161 $button.text(poll_maker_ajax.checklistMarkAsDone);
162 } else {
163 $button.text(poll_maker_ajax.checklistUnmarkAsDone);
164 }
165
166 updateProgress();
167 saveChecklist();
168 });
169
170 $(document).on('click', '.ays-poll-checklist-toggle-step', function () {
171 var $step = $(this).closest('.ays-poll-checklist-step');
172 var $content = $step.find('.ays-poll-checklist-step-content');
173
174 $(document).find('.ays-poll-checklist-step-content').not($content).slideUp(200);
175 $(document).find('.ays-poll-checklist-toggle-step').not(this).removeClass('open');
176
177 $content.slideToggle(200);
178 $(this).toggleClass('open');
179 });
180
181 // Reopen checklist on checklist icon click
182 $(document).on('click', '.ays-poll-checklist-open-icon', function () {
183 var $checklist = $(document).find('#ays-poll-checklist-container');
184 $checklist.show();
185
186 $.ajax({
187 type: 'POST',
188 url: poll_maker_ajax.ajax_url,
189 data: {
190 action: 'ays_poll_checklist_reopen_callback',
191 nonce: poll_maker_ajax.nonce
192 },
193 success: function () {
194 }
195 });
196 });
197
198 // Hide popup permanently
199 $(document).on('click', '.ays-poll-checklist-popup-close', function () {
200 var $checklist = $(this).closest('.ays-poll-checklist-popup');
201 $checklist.fadeOut(200);
202 });
203
204 $(document).on('click', '.ays-poll-checklist-minimize-btn', function () {
205 var $panel = $(document).find('.ays-poll-checklist-panel');
206 var $expandedIcon = $(this).find('.ays-poll-checklist-minimize-icon-expanded');
207 var $collapsedIcon = $(this).find('.ays-poll-checklist-minimize-icon-collapsed');
208
209 $panel.toggleClass('ays-poll-checklist-minimized');
210
211 if ($panel.hasClass('ays-poll-checklist-minimized')) {
212 $expandedIcon.hide();
213 $collapsedIcon.show();
214 } else {
215 $expandedIcon.show();
216 $collapsedIcon.hide();
217 }
218 });
219
220 $(document).on('click', '.ays-poll-checklist-close-btn', function () {
221 var $checklist = $(this).closest('#ays-poll-checklist-container');
222 $.ajax({
223 type: 'POST',
224 url: poll_maker_ajax.ajax_url,
225 data: {
226 action: 'ays_poll_checklist_close_popup',
227 nonce: poll_maker_ajax.nonce
228 },
229 success: function (response) {
230 if (response.success) {
231 $checklist.fadeOut(200);
232 } else {
233 console.error(response.data);
234 $checklist.fadeOut(200);
235 }
236
237 if (localStorage.getItem('ays_poll_checklist_popup_closed') !== '1') {
238 $(document).find('.ays-poll-checklist-popup').fadeIn(200);
239 }
240
241 localStorage.setItem('ays_poll_checklist_popup_closed', '1');
242 },
243 error: function() {
244 $checklist.fadeOut(200);
245 }
246 });
247 });
248
249 updateProgress();
250
251 })(jQuery)
252