PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.10.0
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.10.0
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / assets / js / admin.js

admin.js in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.10.0, at assets/js/admin.js

1,340 lines 54.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4
5 function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
7 function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
9 function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
11 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
13 function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
15 (function ($) {
16 'use strict';
17
18 var styles = {};
19 var campaignInnerPreviewRef = $('.hurrytimer-campaign');
20 var campaignPreviewRef = $('#hurrytimer-campaign-preview');
21 var headlinePreviewRef = campaignInnerPreviewRef.find('.hurrytimer-headline');
22 var timerPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer');
23 var timerDigitPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer-digit');
24 var timerLabelPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer-label');
25 var timerBlockPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer-block');
26 var timerSepPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer-sep');
27 var campaignCTA = campaignInnerPreviewRef.find('.hurrytimer-button');
28 /**
29 * Toggle the given block visibility.
30 * @param {object} toggle
31 * @param {object} block
32 */
33
34 function toggleBlockVisibility(toggle, block) {
35 if (toggle.is(':checked')) {
36 block.removeClass('hidden');
37
38 if ($('input[name=block_separator_visibility]').is(':checked')) {
39 block.next().removeClass('hidden');
40 }
41 } else {
42 block.addClass('hidden');
43 block.next().addClass('hidden');
44 }
45 }
46 /**
47 * Change element color for the preview.
48 *
49 * @param {object} inputElement
50 * @param {string} color
51 */
52
53
54 function changeColor(inputElement) {
55 var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
56
57 if (typeof inputElement === 'string') {
58 inputElement = $('input[name="' + inputElement + '"]');
59 }
60
61 color = color || inputElement.val();
62
63 switch (inputElement.attr('name')) {
64 case 'digit_color':
65 setCSS('.hurrytimer-campaign .hurrytimer-timer-digit', timerDigitPreviewRef, 'color', color, false);
66 setCSS('.hurrytimer-campaign .hurrytimer-timer-sep', timerSepPreviewRef, 'color', color);
67 break;
68
69 case 'block_border_color':
70 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'border-color', color);
71 break;
72
73 case 'block_bg_color':
74 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'background-color', color);
75 break;
76
77 case 'label_color':
78 setCSS('.hurrytimer-campaign .hurrytimer-timer-label', timerLabelPreviewRef, 'color', color);
79 break;
80
81 case 'headline_color':
82 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'color', color);
83 break;
84
85 case 'sticky_bar_bg_color':
86 setCSS('.hurrytimer-sticky', $('.hurrytimer-sticky'), 'background-color', color);
87 break;
88
89 case 'call_to_action[bg_color]':
90 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'background-color', color);
91 break;
92
93 case 'call_to_action[text_color]':
94 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'color', color);
95 break;
96
97 case 'sticky_bar_close_btn_color':
98 setCSS('.hurrytimer-sticky-close svg', $('.hurrytimer-sticky-close svg'), 'fill', color);
99 break;
100 }
101 }
102 /**
103 * Apply CSS for live preview.
104 *
105 * @param {object} element
106 * @param {string} property
107 * @param {string} value
108 * @param {boolean} apply
109 */
110
111
112 function setCSS(selector, element, property, value) {
113 var apply = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
114
115 var _selector = element.selector || selector;
116
117 styles = _objectSpread(_objectSpread({}, styles), {}, _defineProperty({}, _selector, _objectSpread(_objectSpread({}, styles[_selector]), {}, _defineProperty({}, property, value))));
118
119 if (apply) {
120 if ($('#hurryt-styles').length === 0) {
121 $('head').append('<style id="hurryt-styles"></style>');
122 }
123
124 var css = '';
125
126 for (var sel in styles) {
127 css += " ".concat(sel, "{ ").concat(Object.entries(styles[sel]).join(';').replace(/\,/g, ':'), "}");
128 }
129
130 $('#hurryt-styles').html(css);
131 }
132 }
133
134 function removeCSSProperty(element, property) {
135 for (var selector in styles) {
136 if (selector === element.selector) {
137 delete styles[selector][property];
138 }
139 }
140 } // ------------------------------------------------------------
141 // Initialize preview items color.
142 // ------------------------------------------------------------
143
144
145 changeColor('digit_color');
146 changeColor('label_color');
147 changeColor('block_border_color');
148 changeColor('block_bg_color');
149 changeColor('headline_color');
150 changeColor('sticky_bar_bg_color');
151 changeColor('sticky_bar_close_btn_color');
152 changeColor('call_to_action[bg_color]');
153 changeColor('call_to_action[text_color]'); // ------------------------------------------------------------
154 // Input toggle.
155 // ------------------------------------------------------------
156
157 $('.js-hurrytimer-input-toggle').each(function () {
158 var input = $(this);
159 input.hide();
160 var toggle = $("<input \n type=\"hidden\" \n name=\"".concat(input.attr('name'), "\" \n value=\"no\" />\n <span \n class=\"hurrytimer-input-toggle\">\n </span>"));
161 input.before(toggle);
162
163 if (input.prop('checked')) {
164 toggle.addClass('is-on');
165 }
166
167 toggle.on('click', function () {
168 toggle.toggleClass('is-on');
169 input.attr('checked', !input.prop('checked'));
170 input.trigger('change');
171 });
172 }); // ------------------------------------------------------------
173 // Datetime picker.
174 // ------------------------------------------------------------
175
176 $('.hurrytimer-datepicker').each(function () {
177 var $this = $(this);
178 $this.datetimepicker({
179 controlType: 'select',
180 dateFormat: 'yy-mm-dd',
181 timeFormat: 'hh:mm TT',
182 oneLine: true,
183 onSelect: function onSelect(value, instance) {
184 setMonthlyDayTypes($this);
185 }
186 });
187 setMonthlyDayTypes($this);
188 });
189
190 function setMonthlyDayTypes($input) {
191 if ($input.attr('name') === 'recurring_start_time') {
192 var _dayOfMonth = getDayOfMonth($input.datepicker('getDate'));
193
194 var _dayOfWeek = getDayOfWeek($input.datepicker('getDate'));
195
196 $('#recurDayOfMonth').text(_dayOfMonth);
197 $('#recurDayOfWeek').text(_dayOfWeek);
198 }
199 }
200
201 function getDayOfMonth(date) {
202 var dayOfMonth = false;
203 var day = $.datepicker.formatDate('d', date);
204
205 if (day == 1) {
206 dayOfMonth = '1st day';
207 } else if (day == 2) {
208 dayOfMonth = '2nd day';
209 } else if (day == 3) {
210 dayOfMonth = '3rd day';
211 } else {
212 dayOfMonth = day + 'th day';
213 }
214
215 return dayOfMonth;
216 }
217
218 function getDayOfWeek(date) {
219 var dayOfWeek = false;
220 var dayName = $.datepicker.formatDate('DD', date);
221 var day = $.datepicker.formatDate('d', date);
222 var dayIndex = Math.ceil(day / 7);
223
224 if (dayIndex == 1) {
225 dayOfWeek = '1st';
226 } else if (dayIndex == 2) {
227 dayOfWeek = '2nd';
228 } else if (dayIndex == 23) {
229 dayOfWeek = '3rd';
230 } else {
231 dayOfWeek = dayIndex + 'th';
232 }
233
234 dayOfWeek += ' ' + dayName;
235 return dayOfWeek;
236 }
237
238 $('.hurrytimer-timepicker').each(function () {
239 $(this).timepicker({
240 timeFormat: 'hh:mm TT',
241 controlType: 'select',
242 oneLine: true
243 });
244 }); // ------------------------------------------------------------
245 // Handle mode toggle.
246 // ------------------------------------------------------------
247
248 function handleMode(elementRef) {
249 document.querySelectorAll('.mode-settings[data-for^="hurrytMode"]').forEach(function (e) {
250 e.classList.add('hidden');
251 });
252 document.querySelectorAll(".mode-settings[data-for=\"".concat(elementRef.attr('id'), "\"]")).forEach(function (e) {
253 e.classList.remove('hidden');
254 });
255 }
256
257 var toggleRecurringUntil = function toggleRecurringUntil(value) {
258 if (value == 3) {
259 recurringUntilElement.classList.remove('hidden');
260 } else {
261 recurringUntilElement.classList.add('hidden');
262 }
263 };
264
265 var recurringUntilElement = document.querySelector('tr[data-for="hurrytRecurringUntil"]');
266 document.querySelectorAll('input[name="recurring_until"]').forEach(function (e) {
267 e.addEventListener('change', function (e) {
268 return toggleRecurringEndDate(e.target.value);
269 });
270 });
271 document.querySelectorAll('input[name="recurring_until"]:checked').forEach(function (e) {
272 return toggleRecurringUntil(e.value);
273 }); // Handle mode.
274
275 $('input[name=mode]').on('change', function () {
276 handleMode($(this));
277 });
278 handleMode($('input[name=mode]:checked')); // ------------------------------------------------------------
279 // Handle products type dropdown.
280 // ------------------------------------------------------------
281
282 $('#hurrytimer-wc-products-selection-type').on('change', function () {
283 var $this = $(this);
284 var $selectedOption = $this.find('option:selected');
285 var $label = $('.hurrytimer-products-selection-type-label');
286 var $autocompleteWrap = $label.closest('.form-field');
287
288 if ($selectedOption.data('show-autocomplete')) {
289 $label.text($selectedOption.text());
290 $autocompleteWrap.removeClass('hidden');
291 } else {
292 $autocompleteWrap.addClass('hidden');
293 }
294 }).change(); // Handle tabs
295 // ------------------------------------------------------------
296
297 $('.hurrytimer-tabbar a').on('click', function (e) {
298 e.preventDefault();
299 var $tab = $(this);
300 $('.hurrytimer-tabcontent').removeClass('active');
301 $($tab.attr('href')).addClass('active');
302 $tab.parent().siblings().removeClass('active');
303 $tab.parent().addClass('active');
304
305 if ($tab.attr('href').indexOf('appearance') >= 0 || $tab.attr('href').indexOf('styling') >= 0) {
306 $('.hurryt-fullscreen').removeClass('hidden');
307 } else {
308 $('.hurryt-fullscreen').addClass('hidden');
309 }
310 }); // ------------------------------------------------------------
311 // Search for products/Categories
312 // ------------------------------------------------------------
313
314 $('.hurryt-tags-input').select2({
315 tags: true,
316 placeholder: 'Example: http://www.example.com/page',
317 tokenSeparators: [',', ' ']
318 });
319 $('#hurrytimer-wc-products-selection').select2({
320 placeholder: 'Search...',
321 width: '500',
322 minimumInputLength: 2,
323 ajax: {
324 url: hurrytimer_ajax_object.ajax_url,
325 dataType: 'json',
326 data: function data(params) {
327 return {
328 action: 'wcSearchProducts',
329 search: params.term,
330 exclude: $(this).val(),
331 productsSelection: $('#hurrytimer-wc-products-selection-type').val(),
332 type: 'public'
333 };
334 }
335 }
336 }); // ------------------------------------------------------------
337 // Color picker
338 // ------------------------------------------------------------
339
340 $('.hurrytimer-color-input').each(function () {
341 var self = $(this);
342 self.wpColorPicker({
343 width: 220,
344 change: function change(event, ui) {
345 changeColor(self, ui.color.toString());
346 },
347 clear: function clear() {
348 changeColor(self, 'transparent');
349 }
350 });
351 }); // ------------------------------------------------------------
352 // CUSTOM CSS
353 // ------------------------------------------------------------
354 // ------------------------------------------------------------
355 // Handle sub tabbar.
356 // ------------------------------------------------------------
357
358
359 $('.hurrytimer-subtabbar a').on('click', function (e) {
360 e.preventDefault();
361 var self = $(this);
362 $('.hurrytimer-subtabcontent').each(function () {
363 $(this).removeClass('active');
364 });
365 $(self.attr('href')).addClass('active');
366 self.parent().siblings().removeClass('active');
367 self.parent().addClass('active');
368 if (cssEditor) cssEditor.refresh();
369 }); // ------------------------------------------------------------
370 // Accordion.
371 // ------------------------------------------------------------
372
373 $('.hurrytimer-accordion-heading').on('click', function () {
374 var self = $(this);
375 var containerElement = self.parent();
376
377 if (containerElement.hasClass('active')) {
378 containerElement.removeClass('active');
379 } else {
380 containerElement.addClass('active').siblings().removeClass('active');
381 }
382 }); // ------------------------------------------------------------
383 // Enable/disable sticky bar.
384 // ------------------------------------------------------------
385
386 $('input[name=enable_sticky]').on('change', function () {
387 if ($(this).is(':checked')) {
388 campaignPreviewRef.addClass('hurrytimer-sticky');
389 campaignInnerPreviewRef.wrap('<div class="hurrytimer-sticky-inner"></div>');
390
391 if (campaignPreviewRef.hasClass('hurryt-preview-fullscreen')) {
392 setCSS('#hurrytimer-campaign-preview', campaignPreviewRef, 'position', 'fixed', false);
393 setCSS('#hurrytimer-campaign-preview', campaignPreviewRef, 'top', 0);
394 }
395 } else {
396 campaignPreviewRef.removeClass('hurrytimer-sticky');
397 campaignInnerPreviewRef.unwrap('.hurrytimer-sticky-inner');
398 } // refresh dismiss button
399
400
401 if ($('input[name=sticky_bar_dismissible]').is(':checked')) {
402 campaignPreviewRef.find('.hurrytimer-sticky-close').show();
403 } else {
404 campaignPreviewRef.find('.hurrytimer-sticky-close').hide();
405 }
406 });
407 $('input[name=sticky_bar_dismissible]').on('change', function () {
408 if ($(this).is(':checked')) {
409 campaignPreviewRef.find('.hurrytimer-sticky-close').show();
410 } else {
411 campaignPreviewRef.find('.hurrytimer-sticky-close').hide();
412 }
413 }); // ------------------------------------------------------------
414 // Change block display.
415 // ------------------------------------------------------------
416
417 $('select[name=block_display]').on('change', function () {
418 var value = $(this).val();
419 var blockSize = $('input[name="block_size"]').val() + 'px';
420 setCSS('.hurrytimer-campaign .hurrytimer-timer-digit', timerDigitPreviewRef, 'display', value, false);
421 setCSS('.hurrytimer-campaign .hurrytimer-timer-label', timerLabelPreviewRef, 'display', value, false);
422 var blockSizeInput = $(this).closest('.hurrytimer-style-control-field').siblings('.hurrytimer-field-block-size');
423
424 if (value === 'inline') {
425 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'width', 'auto', false);
426 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'height', 'auto', false);
427 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'display', 'inline-block');
428 blockSizeInput.hide();
429 } else {
430 blockSizeInput.show();
431 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'width', blockSize, false);
432 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'height', blockSize, false);
433 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'display', 'flex');
434 }
435 }).change(); // ------------------------------------------------------------
436 // Set digit size.
437 // ------------------------------------------------------------
438
439 $('input[name=digit_size]').on('input keyup paste change', function () {
440 var fontSize = parseInt($(this).val()) + 'px';
441 setCSS('.hurrytimer-campaign .hurrytimer-timer-digit', timerDigitPreviewRef, 'font-size', fontSize, false);
442 setCSS('.hurrytimer-campaign .hurrytimer-timer-sep', timerSepPreviewRef, 'font-size', fontSize);
443 }).change(); // ------------------------------------------------------------
444 // Set CTA text size.
445 // ------------------------------------------------------------
446
447 $('input[name="call_to_action[text_size]"]').on('input keyup paste change', function () {
448 var fontSize = parseInt($(this).val()) + 'px';
449 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'font-size', fontSize);
450 }).change(); // ------------------------------------------------------------
451 // Set block spacing.
452 // ------------------------------------------------------------
453
454 $('input[name=block_spacing]').on('input keyup paste change', function () {
455 var spacing = "".concat($(this).val(), "px");
456
457 if ($('select[name=display]').val() === 'inline') {
458 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'margin-bottom', spacing, false);
459 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'margin-top', spacing);
460 } else {
461 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'margin-left', spacing, false);
462 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'margin-right', spacing);
463 }
464 }).change(); // ------------------------------------------------------------
465 // Set block padding.
466 // ------------------------------------------------------------
467
468 $('input[name=block_padding]').on('input keyup paste change', function () {
469 var padding = parseInt($(this).val()) + 'px';
470 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'padding', padding);
471 }).change(); // ------------------------------------------------------------
472 // Sticky Bar Y padding.
473 // ------------------------------------------------------------
474
475 $('input[name=sticky_bar_padding]').on('input keyup paste change', function () {
476 var padding = "".concat($(this).val(), "px");
477 var stickyBarInner = campaignPreviewRef.find('.hurrytimer-sticky-inner');
478 setCSS('#hurrytimer-campaign-preview .hurrytimer-sticky-inner', stickyBarInner, 'padding-top', padding, false);
479 setCSS('#hurrytimer-campaign-preview .hurrytimer-sticky-inner', stickyBarInner, 'padding-bottom', padding);
480 }).change();
481 $('select[name=sticky_bar_position]').on('input keyup paste change', function () {
482 if ($(this).val() === 'top') {
483 removeCSSProperty(campaignPreviewRef, 'bottom');
484 setCSS('#hurrytimer-campaign-preview', campaignPreviewRef, 'top', 0);
485 } else {//removeCSSProperty(campaignPreviewRef, 'top');
486 // setCSS(campaignPreviewRef, 'bottom', 0);
487 }
488 }).change();
489 $('input[name=headline_spacing]').on('input keyup paste change', function () {
490 var spacing = "".concat($(this).val(), "px");
491
492 if ($('select[name=campaign_display]').val() === 'inline') {
493 if ($('select[name=headline_position]').val() === hurrytimer_ajax_object.headline_pos.above_timer) {
494 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'margin-left', spacing);
495 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'margin-top', 0);
496 } else {
497 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'margin-right', spacing);
498 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'margin-bottom', 0);
499 }
500 } else {
501 if ($('select[name=headline_position]').val() === hurrytimer_ajax_object.headline_pos.above_timer) {
502 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'margin-left', 0);
503 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'margin-top', spacing);
504 } else {
505 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'margin-right', 0);
506 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'margin-bottom', spacing);
507 }
508 }
509 }).change();
510 $('input[name="call_to_action[spacing]"]').on('input keyup paste change', function () {
511 var spacing = "".concat($(this).val(), "px");
512
513 if ($('select[name=campaign_display]').val() === 'inline') {
514 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'margin-right', spacing, false);
515 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'margin-left', spacing);
516 } else {
517 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'margin-top', spacing, false);
518 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'margin-bottom', spacing);
519 }
520 }).change(); // ------------------------------------------------------------
521 // Set label size.
522 // ------------------------------------------------------------
523
524 $('input[name=label_size]').on('input keyup paste change', function () {
525 setCSS('.hurrytimer-campaign .hurrytimer-timer-label', timerLabelPreviewRef, 'font-size', parseInt($(this).val()) + 'px');
526 }).change(); // ------------------------------------------------------------
527 // Set block border width.
528 // ------------------------------------------------------------
529
530 $('input[name=block_border_width]').on('input keyup paste change', function () {
531 var borderSize = parseInt($(this).val());
532 var borderColor = $('input[name=block_border_color]').val() || 'transparent';
533 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'border', borderColor + ' solid ' + borderSize + 'px');
534 }).change(); // ------------------------------------------------------------
535 // Set block border radius.
536 // ------------------------------------------------------------
537
538 $('input[name=block_border_radius]').on('input keyup paste change', function () {
539 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'border-radius', "".concat($(this).val(), "px"));
540 }).change(); // ------------------------------------------------------------
541 // Set block size.
542 // ------------------------------------------------------------
543
544 $('input[name=block_size]').on('input keyup paste change', function () {
545 var value = parseInt($(this).val());
546 var size = value + 'px';
547
548 if (value === 0 || $('select[name=block_display]').val() === 'inline') {
549 size = 'auto';
550 }
551
552 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'width', size, false);
553 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'height', size);
554 }).change(); // ------------------------------------------------------------
555 // Preview headline
556 // ------------------------------------------------------------
557
558 var _id = 'hurryt-headline',
559 _config = {
560 tinymce: {
561 toolbar1: 'fontsizeselect forecolor backcolor bold italic link removeformat',
562 fontsize_formats: '11px 12px 14px 16px 18px 24px 30px 36px 48px',
563 force_br_newlines: false,
564 force_p_newlines: false,
565 forced_root_block: '',
566 content_style: ".mce-content-body {font-size:30px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',sans-serif}",
567 setup: function setup(editor) {
568 editor.on('init', function (e) {
569 $('#' + e.target.id + '_ifr').removeAttr('title');
570 });
571 editor.on('input | paste | keyup | change', function () {
572 var content = editor.getContent({
573 format: 'raw'
574 });
575 headlinePreviewRef.html(content);
576 });
577 }
578 },
579 quicktags: {
580 "buttons": "strong,em,link,del,ins,img"
581 },
582 mediaButtons: true
583 };
584 $(document).on('click', '#hurryt-headline-section', function () {
585 if (typeof wp.editor.initialize == 'function' || typeof wp.oldEditor.initialize == 'function') {
586 if ($(this).next().find('.wp-editor-wrap').length === 0) {
587 if (typeof wp.editor.initialize == 'function') {
588 wp.editor.initialize(_id, _config);
589 } else {
590 wp.oldEditor.initialize(_id, _config);
591 }
592 }
593 }
594 });
595 $(document).on('input paste keyup change', '#hurryt-headline', function () {
596 headlinePreviewRef.html($(this).val().replace(/(?:\r\n|\r|\n)/g, '<br>'));
597 });
598
599 if (headlinePreviewRef.length) {
600 headlinePreviewRef.html($('#hurryt-headline').val().replace(/(?:\r\n|\r|\n)/g, '<br>'));
601 } // ------------------------------------------------------------
602 // Change headline position.
603 // ------------------------------------------------------------
604
605
606 $('select[name=headline_position]').on('change', function () {
607 if (parseInt($(this).val()) === hurrytimer_ajax_object.headline_pos.above_timer) {
608 headlinePreviewRef.after(timerPreviewRef);
609 } else {
610 headlinePreviewRef.before(timerPreviewRef);
611 }
612 }).change(); // ------------------------------------------------------------
613 // Set headline size
614 // ------------------------------------------------------------
615
616 $('input[name=headline_size]').on('input keyup paste change', function () {
617 setCSS('.hurrytimer-campaign .hurrytimer-headline', headlinePreviewRef, 'font-size', parseInt($(this).val()) + 'px');
618 }).change(); // ------------------------------------------------------------
619 // Set label case.
620 // ------------------------------------------------------------
621
622 $('select[name=label_case]').on('change', function () {
623 setCSS('.hurrytimer-campaign .hurrytimer-timer-label', timerLabelPreviewRef, 'text-transform', $(this).val());
624 }).change(); // ------------------------------------------------------------
625 // Set CTA text.
626 // ------------------------------------------------------------
627
628 $('input[name="call_to_action[text]"]').on('change keyup paste input', function () {
629 campaignCTA.text($(this).val());
630 }).change(); // ------------------------------------------------------------
631 // Set CTA horizontal padding
632 // ------------------------------------------------------------
633
634 $('input[name="call_to_action[x_padding]"]').on('input keyup paste change', function () {
635 var padding = "".concat($(this).val(), "px");
636 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'padding-left', padding, false);
637 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'padding-right', padding);
638 }).change(); // ------------------------------------------------------------
639 // Set CTA border radius
640 // ------------------------------------------------------------
641
642 $('input[name="call_to_action[border_radius]"]').on('input keyup paste change', function () {
643 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'border-radius', "".concat($(this).val(), "px"));
644 }).change(); // ------------------------------------------------------------
645 // Set CTA vertical padding
646 // ------------------------------------------------------------
647
648 $('input[name="call_to_action[y_padding]"]').on('input keyup paste change', function () {
649 var padding = parseInt($(this).val()) + 'px';
650 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'padding-top', padding, false);
651 setCSS('.hurrytimer-campaign .hurrytimer-button', campaignCTA, 'padding-bottom', padding);
652 }).change(); // ------------------------------------------------------------
653 // Toggle block separator visibility.
654 // ------------------------------------------------------------
655
656 $('input[name=block_separator_visibility]').on('change', function () {
657 var self = $(this);
658
659 if (!self.is(':checked')) {
660 timerSepPreviewRef.addClass('hidden');
661 return;
662 }
663
664 timerBlockPreviewRef.each(function () {
665 if ($(this).hasClass('hidden')) {
666 $(this).next().addClass('hidden');
667 } else {
668 $(this).next().removeClass('hidden');
669 }
670 });
671 }).change();
672 $('#hurrytimer-months-visibility').on('change', function () {
673 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=months]'));
674 }).change(); // ------------------------------------------------------------
675 // Toggle "days" block visibility.
676 // ------------------------------------------------------------
677
678 $('#hurrytimer-days-visibility').on('change', function () {
679 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=days]'));
680 }).change(); // ------------------------------------------------------------
681 // Toggle "hours" block visibility
682 // ------------------------------------------------------------
683
684 $('#hurrytimer-hours-visibility').on('change', function () {
685 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=hours]'));
686 }).change(); // ---------------------------------------------------------------
687 // Toggle "minutes" block visibility
688 // ---------------------------------------------------------------
689
690 $('#hurrytimer-minutes-visibility').on('change', function () {
691 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=minutes]'));
692 }).change(); // ---------------------------------------------------------------
693 // Toggle "seconds" block visibility
694 // ---------------------------------------------------------------
695
696 $('#hurrytimer-seconds-visibility').on('change', function () {
697 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=seconds]'));
698 }).change(); // ---------------------------------------------------------------
699 // Toggle "headline" block visibility
700 // ---------------------------------------------------------------
701
702 $('#hurrytimer-headline-visibility').on('change', function () {
703 if ($(this).is(':checked')) {
704 headlinePreviewRef.removeClass('hidden');
705 } else {
706 headlinePreviewRef.addClass('hidden');
707 }
708 }).change(); // ---------------------------------------------------------------
709 // Toggle "labels" visibility.
710 //----------------------------------------------------------------
711
712 $('#hurrytimer-label-visibility').on('change', function () {
713 if ($(this).is(':checked')) {
714 timerLabelPreviewRef.removeClass('hidden');
715 } else {
716 timerLabelPreviewRef.addClass('hidden');
717 }
718 }).change(); // ---------------------------------------------------------------
719 // Toggle CTA visibility.
720 // ------------------------------------------------------------
721
722 $('#hurrytimer-cta-enabled').on('change', function () {
723 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('.hurrytimer-button-wrap'));
724 }).change(); // ---------------------------------------------------------------
725 // Input slider.
726 // ------------------------------------------------------------
727
728 var blockSizeSliderElement;
729 var blockSizeInputElement;
730 $('.hurrytimer-input-slider').each(function () {
731 var self = $(this);
732 var boundInputElement = $('input[name="' + self.data('input-name') + '"]');
733 var min = parseInt(boundInputElement.attr('min')) || 0;
734 var max = parseInt(boundInputElement.attr('max')) || 100;
735
736 if (boundInputElement.attr('name') === 'block_size') {
737 min = parseInt($('input[name=digit_size]').val()) || min;
738 blockSizeSliderElement = self;
739 blockSizeInputElement = boundInputElement;
740 }
741
742 self.slider({
743 slide: function slide(_, ui) {
744 boundInputElement.val(ui.value);
745 boundInputElement.trigger('input');
746
747 if (boundInputElement.attr('name') === 'digit_size') {
748 $('input[name=block_size]').attr('min', ui.value);
749 blockSizeSliderElement.slider('option', 'min', ui.value);
750
751 if (blockSizeInputElement.val() < ui.value) {
752 blockSizeSliderElement.slider('option', 'value', ui.value);
753 blockSizeInputElement.val(ui.value);
754 blockSizeInputElement.trigger('input');
755 }
756 }
757 },
758 max: max,
759 min: min,
760 value: boundInputElement.val()
761 });
762 }); // ------------------------------------------------------------
763 // ------------------------------------------------------------
764 // Add new action
765 // ------------------------------------------------------------
766
767 $('#hurrytimer-new-action').on('click', function () {
768 //removeif(pro)
769 if ($('.hurrytimer-action-block').length === 1) {
770 return;
771 } // endremoveif(pro)
772
773
774 var action = $('.hurrytimer-action-block').last().clone(true, true);
775 action.find('.hurrytimer-action-block-subfields').addClass('hidden');
776 var fields = action.find(':input');
777
778 for (var i = 0; i < fields.length; i++) {
779 fields[i].name = fields[i].name.replace(/actions\[(\d+)\]\[(\w+)\]/, function (fm, i, name) {
780 return 'actions[' + ++i + '][' + name + ']';
781 });
782 }
783
784 $(this).parent().before(action);
785
786 if ($('.hurrytimer-action-block').length === 1) {
787 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').addClass('hidden');
788 } else {
789 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').removeClass('hidden');
790 }
791 }); // ------------------------------------------------------------
792 // Handle action selection
793 // ------------------------------------------------------------
794
795 $('#hurrytimer-actions').on('change', '.hurrytimer-action-select', function () {
796 handleActionChange($(this));
797 });
798 $('.hurrytimer-action-select').each(function () {
799 handleActionChange($(this));
800 });
801
802 function handleActionChange(element) {
803 // removeIf(pro)
804 if (element.find(':selected').data('pro-feat') !== undefined) {
805 $('.hurryt-pro-feat').removeClass('hidden');
806 return;
807 } else {
808 $('.hurryt-pro-feat').addClass('hidden');
809 } // endRemoveIf(pro)
810
811
812 var action = element.find('option:selected');
813
814 if (+action.val() === 4 && +$('.hurrytimer-mode:checked').val() === 2) {
815 element.parent().find('.hurryt-compat-info').removeClass('hidden');
816 } else {
817 element.parent().find('.hurryt-compat-info').addClass('hidden');
818 }
819
820 var block = element.closest('.hurrytimer-action-block');
821 block.find('.hurrytimer-action-block-subfields').addClass('hidden');
822 block.find('.' + action.data('subfields')).removeClass('hidden');
823 } // ------------------------------------------------------------
824 // Handle action deletion
825 // ------------------------------------------------------------
826
827
828 $('#hurrytimer-actions').on('click', '.hurrytimer-delete-action', function () {
829 if ($('.hurrytimer-action-block').length === 1) return;
830 $(this).closest('.hurrytimer-action-block').remove();
831
832 if ($('.hurrytimer-action-block').length === 1) {
833 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').addClass('hidden');
834 } else {
835 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').removeClass('hidden');
836 }
837 }); // ------------------------------------------------------------
838 // Set "days" label
839 // ------------------------------------------------------------
840
841 $('input[name="labels[days]"]').on('input keyup paste', function () {
842 campaignInnerPreviewRef.find('[data-block=days] .hurrytimer-timer-label').text($(this).val());
843 }).trigger('input');
844 $('input[name="labels[months]"]').on('input keyup paste', function () {
845 campaignInnerPreviewRef.find('[data-block=months] .hurrytimer-timer-label').text($(this).val());
846 }).trigger('input'); // ------------------------------------------------------------
847 // Set "hours" label
848 // ------------------------------------------------------------
849
850 $('input[name="labels[hours]"]').on('input keyup paste', function () {
851 campaignInnerPreviewRef.find('[data-block=hours] .hurrytimer-timer-label').text($(this).val());
852 }).trigger('input'); // ------------------------------------------------------------
853 // Set "minutes" label
854 // ------------------------------------------------------------
855
856 $('input[name="labels[minutes]"]').on('input keyup paste', function () {
857 campaignInnerPreviewRef.find('[data-block=minutes] .hurrytimer-timer-label').text($(this).val());
858 }).trigger('input'); // ------------------------------------------------------------
859 // Set "seconds" label
860 // ------------------------------------------------------------
861
862 $('input[name="labels[seconds]"]').on('input keyup paste', function () {
863 campaignInnerPreviewRef.find('[data-block=seconds] .hurrytimer-timer-label').text($(this).val());
864 }).trigger('input'); // ------------------------------------------------------------
865 // Compaign display
866 // ------------------------------------------------------------
867
868 $('select[name=campaign_display]').on('change', function () {
869 var blockMarginBottom = timerBlockPreviewRef.css('margin-bottom');
870
871 if ($(this).val() === 'inline') {
872 campaignInnerPreviewRef.addClass('hurrytimer-inline');
873 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'margin-bottom', '0');
874 } else {
875 campaignInnerPreviewRef.removeClass('hurrytimer-inline');
876 setCSS('.hurrytimer-campaign .hurrytimer-timer-block', timerBlockPreviewRef, 'margin-bottom', blockMarginBottom);
877 }
878
879 $('input[name="call_to_action[spacing]"]').change();
880 $('input[name="headline_spacing"]').change();
881 }).change(); // ------------------------------------------------------------
882 // Compaign alignment
883 // ------------------------------------------------------------
884
885 $('select[name=campaign_align]').on('change', function () {
886 var value = $(this).val();
887 setCSS('.hurrytimer-campaign', campaignInnerPreviewRef, 'text-align', value);
888
889 if ($('select[name=campaign_display]').val() === 'inline') {
890 return false;
891 }
892
893 switch (value) {
894 case 'left':
895 setCSS('.hurrytimer-campaign .hurrytimer-timer', timerPreviewRef, 'justify-content', 'flex-start');
896 break;
897
898 case 'right':
899 setCSS('.hurrytimer-campaign .hurrytimer-timer', timerPreviewRef, 'justify-content', 'flex-end');
900 break;
901
902 case 'center':
903 setCSS('.hurrytimer-campaign .hurrytimer-timer', timerPreviewRef, 'justify-content', 'center');
904 break;
905 }
906 }).change();
907 $('.hurryt-fullscreen').on('click', function (e) {
908 e.preventDefault();
909
910 if ($(this).hasClass('on')) {
911 campaignPreviewRef.removeClass('hurryt-preview-fullscreen');
912 $(this).removeClass('on');
913
914 if (campaignPreviewRef.hasClass('hurrytimer-sticky')) {
915 setCSS('#hurrytimer-campaign-preview', campaignPreviewRef, 'position', 'relative');
916 }
917 } else {
918 campaignPreviewRef.addClass('hurryt-preview-fullscreen');
919 $(this).addClass('on');
920 }
921 });
922 $('select[name="sticky_bar_pages[]"]').select2({
923 placeholder: 'Search...'
924 }); // Bind select2 to coupons select.
925
926 $('.hurrytimer-action-wc-coupon').each(function () {
927 $(this).select2({
928 placeholder: 'Search coupon...',
929 width: '100%',
930 minimumInputLength: 2,
931 ajax: {
932 url: hurrytimer_ajax_object.ajax_url,
933 dataType: 'json',
934 data: function data(params) {
935 return {
936 action: 'hurrytimer/search_wc_coupon',
937 search: params.term,
938 exclude: $(this).val(),
939 type: 'public',
940 nonce: hurrytimer_ajax_object.ajax_nonce
941 };
942 }
943 }
944 });
945 });
946 $('select[name="sticky_bar_pages[]"]').on('change', function () {
947 if ($(this).val() === null) {
948 $('input[name="sticky_bar_pages[]"]').val([]);
949 } else {
950 $('input[name="sticky_bar_pages[]"]').val("[".concat($(this).val(), "]"));
951 }
952 });
953 $('select[name="sticky_exclude_pages[]"]').select2({
954 placeholder: 'Search...'
955 });
956 $('select[name="sticky_exclude_pages[]"]').on('change', function () {
957 if ($(this).val() === null) {
958 $('input[name="sticky_exclude_pages[]"]').val([]);
959 } else {
960 $('input[name="sticky_exclude_pages[]"]').val("[".concat($(this).val(), "]"));
961 }
962 });
963 $('input[type="checkbox"][name="sticky_bar_show_on_all_pages"]').on('change', function () {
964 if ($('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').length === 0) {
965 $(this).after('<input type="hidden" name="sticky_bar_show_on_all_pages" value="yes" />');
966 }
967
968 if ($(this).is(':checked')) {
969 $('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').val('yes');
970 $('select[name="sticky_bar_pages[]"').attr('disabled', true);
971 } else {
972 $('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').val('no');
973 $('select[name="sticky_bar_pages[]"').attr('disabled', false);
974 }
975 }).change();
976 $(document).on('change', '#hurrytimer-evergreen-restart', function () {
977 if ($(this).val() == 4) {
978 $('#hurrytimer-evergreen-restart-duration').removeClass('hidden'); // removeIf(pro)
979
980 $('#hurrytimer-restart-after-feature-unlock').removeClass('hidden'); // endRemoveIf(pro)
981 } else {
982 $('#hurrytimer-evergreen-restart-duration').addClass('hidden'); // removeIf(pro)
983
984 $('#hurrytimer-restart-after-feature-unlock').addClass('hidden'); // endRemoveIf(pro)
985 }
986 });
987 var $selectedEvergreenRestart = $('#hurrytimer-evergreen-restart').find('option:selected');
988
989 if ($selectedEvergreenRestart.val() == 4) {
990 $('#hurrytimer-evergreen-restart-duration').removeClass('hidden');
991 $('#hurrytimer-restart-after-feature-unlock').removeClass('hidden');
992 } else {
993 $('#hurrytimer-evergreen-restart-duration').addClass('hidden');
994 $('#hurrytimer-restart-after-feature-unlock').addClass('hidden');
995 } // Display tooltips
996
997
998 $('#hurrytimer-settings').tooltip({
999 tooltipClass: 'hurryt-tooltip',
1000 content: function content() {
1001 return $(this).prop('title');
1002 },
1003 position: {
1004 my: 'center bottom-20',
1005 at: 'center top',
1006 using: function using(position, feedback) {
1007 $(this).css(position);
1008 $('<div>').addClass('arrow').addClass(feedback.vertical).addClass(feedback.horizontal).appendTo(this);
1009 }
1010 }
1011 }); // Toggle display
1012
1013 $('.hurryt-sticky-bar-display-on').on('change', function () {
1014 if ($(this).val() === 'specific_pages') {
1015 $('.hurryt_sticky_bar_pages').removeClass('hidden');
1016 $('.hurryt_sticky_exclude_pages').addClass('hidden');
1017 } else if ($(this).val() === 'exclude_pages') {
1018 $('.hurryt_sticky_bar_pages').addClass('hidden');
1019 $('.hurryt_sticky_exclude_pages').removeClass('hidden');
1020 } else {
1021 $('.hurryt_sticky_bar_pages').addClass('hidden');
1022 $('.hurryt_sticky_exclude_pages').addClass('hidden');
1023 }
1024 });
1025
1026 if ($('.hurryt-sticky-bar-display-on:checked').val() === 'specific_pages') {
1027 $('.hurryt_sticky_bar_pages').removeClass('hidden');
1028 $('.hurryt_sticky_exclude_pages').addClass('hidden');
1029 } else if ($('.hurryt-sticky-bar-display-on:checked').val() === 'exclude_pages') {
1030 $('.hurryt_sticky_bar_pages').addClass('hidden');
1031 $('.hurryt_sticky_exclude_pages').removeClass('hidden');
1032 } else {
1033 $('.hurryt_sticky_bar_pages').addClass('hidden');
1034 $('.hurryt_sticky_exclude_pages').addClass('hidden');
1035 }
1036
1037 $('input[name="sticky_bar_dismissible"]').on('change', function () {
1038 if ($(this).is(':checked')) {
1039 $('input[name="sticky_bar_dismiss_timeout"]').prop('disabled', false);
1040 } else {
1041 $('input[name="sticky_bar_dismiss_timeout"]').prop('disabled', true);
1042 }
1043 }).trigger('change');
1044 /**
1045 * Reset evergreen countdown timers for all visitors
1046 */
1047
1048 var resetAllButton = document.getElementById('hurrytResetAll');
1049
1050 if (resetAllButton) {
1051 resetAllButton.addEventListener('click', function (e) {
1052 e.preventDefault();
1053
1054 var _confirm = confirm('Are you sure?');
1055
1056 if (_confirm) {
1057 window.location.href = resetAllButton.getAttribute('data-url');
1058 }
1059 });
1060 } // Failed to remove? retry with default options.
1061
1062
1063 var resetCurrentButton = document.getElementById('hurrytResetCurrent');
1064
1065 if (resetCurrentButton) {
1066 resetCurrentButton.addEventListener('click', function (e) {
1067 e.preventDefault();
1068 var options = {};
1069
1070 if (hurrytimer_ajax_object.COOKIEPATH) {
1071 options.path = hurrytimer_ajax_object.COOKIEPATH;
1072 }
1073
1074 if (hurrytimer_ajax_object.COOKIE_DOMAIN) {
1075 options.domain = hurrytimer_ajax_object.COOKIE_DOMAIN;
1076 }
1077
1078 var campaignCookieName = resetCurrentButton.getAttribute('data-cookie');
1079 Cookies.remove(campaignCookieName, options); // Failed to remove? retry with default options.
1080
1081 if (Cookies.get(campaignCookieName)) {
1082 Cookies.remove(campaignCookieName);
1083 }
1084
1085 Cookies.remove("_ht_CDT-".concat(resetCurrentButton.getAttribute('data-id'), "_dismissed"));
1086 window.location.href = resetCurrentButton.getAttribute('data-url');
1087 });
1088 }
1089
1090 var resetAllEvergreenCampaignsButtons = document.querySelectorAll('.hurrytResetAllEvergreenCampaigns');
1091
1092 if (resetAllEvergreenCampaignsButtons) {
1093 var _iterator = _createForOfIteratorHelper(resetAllEvergreenCampaignsButtons),
1094 _step;
1095
1096 try {
1097 var _loop = function _loop() {
1098 var button = _step.value;
1099 button.addEventListener('click', function (e) {
1100 e.preventDefault();
1101
1102 if (confirm('Are you sure?')) {
1103 var cookies = Cookies.get();
1104 var options = {};
1105
1106 if (hurrytimer_ajax_object.COOKIEPATH) {
1107 options.path = hurrytimer_ajax_object.COOKIEPATH;
1108 }
1109
1110 if (hurrytimer_ajax_object.COOKIE_DOMAIN) {
1111 options.domain = hurrytimer_ajax_object.COOKIE_DOMAIN;
1112 }
1113
1114 for (var name in cookies) {
1115 if (name.startsWith(button.getAttribute('data-cookie-prefix'))) {
1116 Cookies.remove(name, options);
1117
1118 if (Cookies.get(name)) {
1119 Cookies.remove(name);
1120 }
1121 }
1122 }
1123
1124 window.location.href = button.getAttribute('data-url');
1125 }
1126 });
1127 };
1128
1129 for (_iterator.s(); !(_step = _iterator.n()).done;) {
1130 _loop();
1131 }
1132 } catch (err) {
1133 _iterator.e(err);
1134 } finally {
1135 _iterator.f();
1136 }
1137 }
1138
1139 var recurringFrequencyElement = document.getElementById('hurrytRecurringFrequency');
1140 var recurringIntervalElement = document.getElementById('hurrytRecurringInterval');
1141
1142 if (recurringFrequencyElement) {
1143 recurringFrequencyElement.onchange = function (e) {
1144 return toggleRecurringDuration(e.target.value);
1145 };
1146
1147 toggleRecurringDuration(recurringFrequencyElement.value);
1148 }
1149
1150 function toggleRecurringDuration(value) {
1151 var monthsInputElement = document.getElementById('hurrytRecurringMonths');
1152 var daysInputElement = document.getElementById('hurrytRecurringDays');
1153 var hoursInputElement = document.getElementById('hurrytRecurringHours');
1154 var minutesInputElement = document.getElementById('hurrytRecurringMinutes');
1155 var secondsInputElement = document.getElementById('hurrytRecurringSeconds');
1156 var pauseRecurringHoursElement = document.getElementById('hurrytRecurringPauseHours');
1157 var pauseRecurringMinutesElement = document.getElementById('hurrytRecurringPauseMinutes');
1158 var pauseRecurringDaysElement = document.getElementById('hurrytRecurringPauseDays');
1159 var monthsDayTypeElement = document.getElementById('hurrytRecurMonthlyDayType');
1160
1161 if (value !== 'weekly' && $('input[name="recurring_days[]"]:checked').length < 7) {
1162 $('#hurrytimer-recurring-unselected-days-action').show();
1163 } else {
1164 $('#hurrytimer-recurring-unselected-days-action').hide();
1165 }
1166
1167 if (value !== 'monthly') {
1168 document.getElementById('hurrytRecurDaysList').classList.remove('hidden');
1169 monthsDayTypeElement.classList.add('hidden');
1170 $('#ht-recurring-duration').removeClass('hidden');
1171 $('#ht-recurring-duration-option').addClass('hidden');
1172 }
1173
1174 switch (value) {
1175 case 'minutely':
1176 daysInputElement.value = 0;
1177 hoursInputElement.value = 0;
1178 hoursInputElement.parentNode.classList.add('hidden');
1179 daysInputElement.parentNode.classList.add('hidden');
1180 pauseRecurringMinutesElement.parentNode.classList.remove('hidden');
1181 pauseRecurringHoursElement.parentNode.classList.add('hidden');
1182 pauseRecurringHoursElement.value = 0;
1183 pauseRecurringDaysElement.parentNode.classList.add('hidden');
1184 pauseRecurringDaysElement.value = 0;
1185 break;
1186
1187 case 'hourly':
1188 daysInputElement.value = 0;
1189 daysInputElement.parentNode.classList.add('hidden');
1190 hoursInputElement.parentNode.classList.remove('hidden');
1191 pauseRecurringHoursElement.parentNode.classList.remove('hidden');
1192 pauseRecurringMinutesElement.parentNode.classList.remove('hidden');
1193 pauseRecurringDaysElement.parentNode.classList.add('hidden');
1194 pauseRecurringDaysElement.value = 0;
1195 break;
1196
1197 case 'daily':
1198 case 'weekly':
1199 daysInputElement.parentNode.classList.remove('hidden');
1200 hoursInputElement.parentNode.classList.remove('hidden');
1201 pauseRecurringMinutesElement.parentNode.classList.remove('hidden');
1202 pauseRecurringHoursElement.parentNode.classList.remove('hidden');
1203 pauseRecurringDaysElement.parentNode.classList.remove('hidden');
1204 break;
1205
1206 case 'monthly':
1207 daysInputElement.parentNode.classList.remove('hidden');
1208 hoursInputElement.parentNode.classList.remove('hidden');
1209 document.getElementById('hurrytRecurDaysList').classList.add('hidden');
1210 monthsDayTypeElement.classList.remove('hidden');
1211 $('#ht-recurring-duration-option').removeClass('hidden').addClass('hurryt-mb-3');
1212
1213 if ($('input[name="recurring_duration_option"]:checked').val() === 'none') {
1214 $('#ht-recurring-duration').addClass('hidden');
1215 } else {
1216 $('#ht-recurring-duration').removeClass('hidden');
1217 }
1218
1219 pauseRecurringMinutesElement.parentNode.classList.remove('hidden');
1220 pauseRecurringHoursElement.parentNode.classList.remove('hidden');
1221 pauseRecurringDaysElement.parentNode.classList.remove('hidden');
1222 break;
1223
1224 default:
1225 break;
1226 }
1227 }
1228
1229 $('body').on('change', 'input[name="recurring_duration_option"]', function () {
1230 if ($(this).val() === 'none') {
1231 $('#ht-recurring-duration').addClass('hidden');
1232 } else {
1233 $('#ht-recurring-duration').removeClass('hidden');
1234 }
1235 });
1236 $('body').on('click', '.hurryt-add-wc-condition-group', function () {
1237 var _self = $(this);
1238
1239 _self.prop('disabled', true);
1240
1241 _self.next('.spinner').addClass('is-active');
1242
1243 $.get(hurrytimer_ajax_object.ajax_url, {
1244 action: 'add_wc_condition_group',
1245 nonce: hurrytimer_ajax_object.ajax_nonce
1246 }, function (html) {
1247 _self.before(html);
1248 }).always(function () {
1249 _self.prop('disabled', false);
1250
1251 _self.next('.spinner').removeClass('is-active');
1252 });
1253 });
1254 $('body').on('click', '.hurryt-add-wc-condition', function () {
1255 var _self = $(this);
1256
1257 _self.prop('disabled', true);
1258
1259 $.get(hurrytimer_ajax_object.ajax_url, {
1260 action: 'add_wc_condition',
1261 nonce: hurrytimer_ajax_object.ajax_nonce,
1262 group_id: $(this).closest('.hurryt-wc-condition-group').data('group-id')
1263 }, function (html) {
1264 _self.parent().after(html);
1265 }).always(function () {
1266 _self.prop('disabled', false);
1267 });
1268 });
1269 $('body').on('click', '.hurryt-delete-wc-condition', function () {
1270 var _self = $(this);
1271
1272 if (_self.closest('.hurryt-wc-condition-group').find('.hurryt-wc-condition').length === 1) {
1273 _self.closest('.hurryt-wc-condition-group').remove();
1274 } else {
1275 $(this).parent().remove();
1276 }
1277 });
1278 $('body').on('change', '.hurryt-wc-condition-key', function () {
1279 var _self = $(this);
1280
1281 var $value = _self.parent().find('.hurryt-wc-condition-value');
1282
1283 var $operator = _self.parent().find('.hurryt-wc-condition-operator');
1284
1285 $value.prop('disabled', true);
1286 $operator.prop('disabled', true);
1287 $.get(hurrytimer_ajax_object.ajax_url, {
1288 action: 'load_wc_condition',
1289 nonce: hurrytimer_ajax_object.ajax_nonce,
1290 condition_key: _self.val(),
1291 group_id: _self.closest('.hurryt-wc-condition-group').data('group-id')
1292 }, function (html) {
1293 _self.parent().replaceWith(html);
1294 }, 'html').always(function () {
1295 $value.prop('disabled', false);
1296 $operator.prop('disabled', false);
1297 });
1298 }); // open headline tab
1299
1300 $(document).on('click', '.hurryt-open-hl-tab', function (e) {
1301 e.preventDefault();
1302 var $tabs = $('.hurrytimer-tabbar li');
1303 $tabs.removeClass('active');
1304 $tabs.last().addClass('active');
1305 $('.hurrytimer-tabcontent').removeClass('active');
1306 $('#hurrytimer-tabcontent-styling').addClass('active');
1307 $('.hurrytimer-style-control-group').removeClass('active');
1308 $('.hurryt-subtab-hl').addClass('active');
1309 $('#hurryt-headline').focus();
1310 }); // removeIf(pro)
1311
1312 $(document).on('click', '#hurrytUserSessionWrap', function () {
1313 $('#hurrytUserSessionUpgradeNotice').removeClass('hidden');
1314 }); // endRemoveIf(pro)
1315
1316 $(document).on('click', '#hurryt-dismiss-headline-moved-notice', function () {
1317 $(this).parent().remove();
1318 Cookies.set('hurryt_headline_moved_notice_dismissed', '1', {
1319 expires: 365
1320 });
1321 $.post(hurrytimer_ajax_object.ajax_url, {
1322 action: 'hurryt_dismiss_headline_moved_notice',
1323 nonce: hurrytimer_ajax_object.ajax_nonce
1324 });
1325 });
1326 $('input[name="recurring_days[]"]').on('change', function () {
1327 var selected = $('input[name="recurring_days[]"]:checked').length;
1328
1329 if (selected === 7) {
1330 $('#hurrytimer-recurring-unselected-days-action').hide();
1331 } else if ($('#hurrytRecurringFrequency').val() !== 'weekly') {
1332 $('#hurrytimer-recurring-unselected-days-action').show();
1333 }
1334 }).change();
1335 $(document).on('input keyup paste change', '#hurrytRecurringInterval', function () {
1336 $('#ht-monthly-recur-interval').text($(this).val());
1337 });
1338 })(jQuery);
1339 //# sourceMappingURL=admin.js.map
1340