PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.2.16
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.2.16
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.2.16, at assets/js/admin.js

1,103 lines 41.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
4
5 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; }
6
7 (function ($) {
8 'use strict';
9
10 var styles = {};
11 var campaignInnerPreviewRef = $('.hurrytimer-campaign');
12 var campaignPreviewRef = $('#hurrytimer-campaign-preview');
13 var headlinePreviewRef = campaignInnerPreviewRef.find('.hurrytimer-headline');
14 var timerPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer');
15 var timerDigitPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer-digit');
16 var timerLabelPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer-label');
17 var timerBlockPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer-block');
18 var timerSepPreviewRef = campaignInnerPreviewRef.find('.hurrytimer-timer-sep');
19 var campaignCTA = campaignInnerPreviewRef.find('.hurrytimer-button');
20 /**
21 * Toggle the given block visibility.
22 * @param {object} toggle
23 * @param {object} block
24 */
25
26 function toggleBlockVisibility(toggle, block) {
27 if (toggle.is(':checked')) {
28 block.removeClass('hidden');
29
30 if ($('input[name=block_separator_visibility]').is(':checked')) {
31 block.next().removeClass('hidden');
32 }
33 } else {
34 block.addClass('hidden');
35 block.next().addClass('hidden');
36 }
37 }
38 /**
39 * Change element color for the preview.
40 *
41 * @param {object} inputElement
42 * @param {string} color
43 */
44
45
46 function changeColor(inputElement) {
47 var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
48
49 if (typeof inputElement === 'string') {
50 inputElement = $('input[name="' + inputElement + '"]');
51 }
52
53 color = color || inputElement.val();
54 var preview = inputElement.parent().find('.hurrytimer-color-preview');
55 preview.css('background-color', color);
56
57 if (color === 'transparent') {
58 preview.addClass('transparent');
59 } else {
60 preview.removeClass('transparent');
61 }
62
63 setCSS(preview, 'background-color', color);
64
65 switch (inputElement.attr('name')) {
66 case 'digit_color':
67 setCSS(timerDigitPreviewRef, 'color', color, false);
68 setCSS(timerSepPreviewRef, 'color', color);
69 break;
70
71 case 'block_border_color':
72 setCSS(timerBlockPreviewRef, 'border-color', color);
73 break;
74
75 case 'block_bg_color':
76 setCSS(timerBlockPreviewRef, 'background-color', color);
77 break;
78
79 case 'label_color':
80 setCSS(timerLabelPreviewRef, 'color', color);
81 break;
82
83 case 'headline_color':
84 setCSS(headlinePreviewRef, 'color', color);
85 break;
86
87 case 'sticky_bar_bg_color':
88 setCSS($('.hurrytimer-sticky'), 'background-color', color);
89 break;
90
91 case 'call_to_action[bg_color]':
92 setCSS(campaignCTA, 'background-color', color);
93 break;
94
95 case 'call_to_action[text_color]':
96 setCSS(campaignCTA, 'color', color);
97 break;
98
99 case 'sticky_bar_close_btn_color':
100 setCSS($('.hurrytimer-sticky-close svg'), 'fill', color);
101 break;
102 }
103 }
104 /**
105 * Apply CSS for live preview.
106 *
107 * @param {object} element
108 * @param {string} property
109 * @param {string} value
110 * @param {boolean} apply
111 */
112
113
114 function setCSS(element, property, value) {
115 var apply = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
116 styles = _objectSpread({}, styles, _defineProperty({}, element.selector, _objectSpread({}, styles[element.selector], _defineProperty({}, property, value))));
117
118 if (apply) {
119 if ($('#hurryt-styles').length === 0) {
120 $('head').append('<style id="hurryt-styles"></style>');
121 }
122
123 var css = '';
124
125 for (var selector in styles) {
126 css += " ".concat(selector, "{ ").concat(Object.entries(styles[selector]).join(';').replace(/\,/g, ':'), "}");
127 }
128
129 $('#hurryt-styles').html(css);
130 }
131 }
132
133 function removeCSSProperty(element, property) {
134 for (var selector in styles) {
135 if (selector === element.selector) {
136 delete styles[selector][property];
137 }
138 }
139 } // ------------------------------------------------------------
140 // Initialize preview items color.
141 // ------------------------------------------------------------
142
143
144 changeColor('digit_color');
145 changeColor('label_color');
146 changeColor('block_border_color');
147 changeColor('block_bg_color');
148 changeColor('headline_color');
149 changeColor('sticky_bar_bg_color');
150 changeColor('sticky_bar_close_btn_color');
151 changeColor('call_to_action[bg_color]');
152 changeColor('call_to_action[text_color]'); // ------------------------------------------------------------
153 // Input toggle.
154 // ------------------------------------------------------------
155
156 $('.js-hurrytimer-input-toggle').each(function () {
157 var input = $(this);
158 input.hide();
159 var toggle = $("<input \n type=\"hidden\" \n name=\"".concat(input.attr('name'), "\" \n value=\"no\" />\n <span \n class=\"hurrytimer-input-toggle\">\n </span>"));
160 input.before(toggle);
161
162 if (input.prop('checked')) {
163 toggle.addClass('is-on');
164 }
165
166 toggle.on('click', function () {
167 toggle.toggleClass('is-on');
168 input.attr('checked', !input.prop('checked'));
169 input.trigger('change');
170 });
171 }); // ------------------------------------------------------------
172 // Datetime picker.
173 // ------------------------------------------------------------
174
175 $('.hurrytimer-datepicker').each(function () {
176 $(this).datetimepicker({
177 controlType: 'select',
178 dateFormat: 'yy-mm-dd',
179 timeFormat: 'hh:mm TT',
180 oneLine: true
181 });
182 });
183 $('.hurrytimer-timepicker').each(function () {
184 $(this).timepicker({
185 timeFormat: 'hh:mm TT',
186 controlType: 'select',
187 oneLine: true
188 });
189 }); // ------------------------------------------------------------
190 // Handle mode toggle.
191 // ------------------------------------------------------------
192
193 function handleMode(elementRef) {
194 document.querySelectorAll('.mode-settings[data-for^="hurrytMode"]').forEach(function (e) {
195 e.classList.add('hidden');
196 });
197 document.querySelectorAll(".mode-settings[data-for=\"".concat(elementRef.attr('id'), "\"]")).forEach(function (e) {
198 e.classList.remove('hidden');
199 });
200 }
201
202 var toggleRecurringUntil = function toggleRecurringUntil(value) {
203 if (value == 3) {
204 recurringUntilElement.classList.remove('hidden');
205 } else {
206 recurringUntilElement.classList.add('hidden');
207 }
208 };
209
210 var recurringUntilElement = document.querySelector('tr[data-for="hurrytRecurringUntil"]');
211 document.querySelectorAll('input[name="recurring_until"]').forEach(function (e) {
212 e.addEventListener('change', function (e) {
213 return toggleRecurringEndDate(e.target.value);
214 });
215 });
216 document.querySelectorAll('input[name="recurring_until"]:checked').forEach(function (e) {
217 return toggleRecurringUntil(e.value);
218 }); // Handle mode.
219
220 $('input[name=mode]').on('change', function () {
221 handleMode($(this));
222 });
223 handleMode($('input[name=mode]:checked')); // ------------------------------------------------------------
224 // Handle products type dropdown.
225 // ------------------------------------------------------------
226
227 $('#hurrytimer-wc-products-selection-type').on('change', function () {
228 var $this = $(this);
229 var $selectedOption = $this.find('option:selected');
230 var $label = $('.hurrytimer-products-selection-type-label');
231 var $autocompleteWrap = $label.closest('.form-field');
232
233 if ($selectedOption.data('show-autocomplete')) {
234 $label.text($selectedOption.text());
235 $autocompleteWrap.removeClass('hidden');
236 } else {
237 $autocompleteWrap.addClass('hidden');
238 }
239 }).change(); // Handle tabs
240 // ------------------------------------------------------------
241
242 $('.hurrytimer-tabbar a').on('click', function (e) {
243 e.preventDefault();
244 var $tab = $(this);
245 $('.hurrytimer-tabcontent').removeClass('active');
246 $($tab.attr('href')).addClass('active');
247 $tab.parent().siblings().removeClass('active');
248 $tab.parent().addClass('active');
249
250 if ($tab.attr('href').indexOf('appearance') >= 0 || $tab.attr('href').indexOf('styling') >= 0) {
251 $('.hurryt-fullscreen').removeClass('hidden');
252 } else {
253 $('.hurryt-fullscreen').addClass('hidden');
254 }
255 }); // ------------------------------------------------------------
256 // Search for products/Categories
257 // ------------------------------------------------------------
258
259 $('#hurrytimer-wc-products-selection').select2({
260 placeholder: 'Search...',
261 width: '500',
262 minimumInputLength: 2,
263 ajax: {
264 url: hurrytimer_ajax_object.ajax_url,
265 dataType: 'json',
266 data: function data(params) {
267 return {
268 action: 'wcSearchProducts',
269 search: params.term,
270 exclude: $(this).val(),
271 productsSelection: $('#hurrytimer-wc-products-selection-type').val(),
272 type: 'public'
273 };
274 }
275 }
276 }); // ------------------------------------------------------------
277 // Color picker
278 // ------------------------------------------------------------
279
280 $('.hurrytimer-color-input').each(function () {
281 var self = $(this);
282 self.iris({
283 change: function change(event) {
284 changeColor(self, event.target.value);
285 },
286 clear: function clear() {
287 changeColor(self, 'transparent');
288 },
289 palettes: false,
290 hide: true,
291 border: true
292 }).on('click focus', function (event) {
293 event.stopPropagation();
294 $('.iris-picker').hide();
295 $(this).parent().find('.iris-picker').show();
296 });
297 });
298 $('.hurrytimer-color-clear').on('click', function () {
299 var colorInput = $(this).parent().find('.hurrytimer-color-input');
300 colorInput.val('transparent');
301 changeColor(colorInput);
302 }); // ------------------------------------------------------------
303 // CUSTOM CSS
304 // ------------------------------------------------------------
305 // ------------------------------------------------------------
306 // Handle sub tabbar.
307 // ------------------------------------------------------------
308
309
310 $('.hurrytimer-subtabbar a').on('click', function (e) {
311 e.preventDefault();
312 var self = $(this);
313 $('.hurrytimer-subtabcontent').each(function () {
314 $(this).removeClass('active');
315 });
316 $(self.attr('href')).addClass('active');
317 self.parent().siblings().removeClass('active');
318 self.parent().addClass('active');
319 if (cssEditor) cssEditor.refresh();
320 }); // ------------------------------------------------------------
321 // Accordion.
322 // ------------------------------------------------------------
323
324 $('.hurrytimer-accordion-heading').on('click', function () {
325 var self = $(this);
326 var containerElement = self.parent();
327
328 if (containerElement.hasClass('active')) {
329 containerElement.removeClass('active');
330 } else {
331 containerElement.addClass('active').siblings().removeClass('active');
332 }
333 }); // ------------------------------------------------------------
334 // Enable/disable sticky bar.
335 // ------------------------------------------------------------
336
337 $('input[name=enable_sticky]').on('change', function () {
338 if ($(this).is(':checked')) {
339 campaignPreviewRef.addClass('hurrytimer-sticky');
340 campaignInnerPreviewRef.wrap('<div class="hurrytimer-sticky-inner"></div>');
341
342 if (campaignPreviewRef.hasClass('hurryt-preview-fullscreen')) {
343 setCSS(campaignPreviewRef, 'position', 'fixed', false);
344 setCSS(campaignPreviewRef, 'top', 0);
345 }
346 } else {
347 campaignPreviewRef.removeClass('hurrytimer-sticky');
348 campaignInnerPreviewRef.unwrap('.hurrytimer-sticky-inner');
349 } // refresh dismiss button
350
351
352 if ($('input[name=sticky_bar_dismissible]').is(':checked')) {
353 campaignPreviewRef.find('.hurrytimer-sticky-close').show();
354 } else {
355 campaignPreviewRef.find('.hurrytimer-sticky-close').hide();
356 }
357 });
358 $('input[name=sticky_bar_dismissible]').on('change', function () {
359 if ($(this).is(':checked')) {
360 campaignPreviewRef.find('.hurrytimer-sticky-close').show();
361 } else {
362 campaignPreviewRef.find('.hurrytimer-sticky-close').hide();
363 }
364 }); // ------------------------------------------------------------
365 // Change block display.
366 // ------------------------------------------------------------
367
368 $('select[name=block_display]').on('change', function () {
369 var value = $(this).val();
370 var blockSize = $('input[name="block_size"]').val() + 'px';
371 setCSS(timerDigitPreviewRef, 'display', value, false);
372 setCSS(timerLabelPreviewRef, 'display', value, false);
373 var blockSizeInput = $(this).closest('.hurrytimer-style-control-field').siblings('.hurrytimer-field-block-size');
374
375 if (value === 'inline') {
376 setCSS(timerBlockPreviewRef, 'width', 'auto', false);
377 setCSS(timerBlockPreviewRef, 'height', 'auto', false);
378 setCSS(timerBlockPreviewRef, 'display', 'inline-block');
379 blockSizeInput.hide();
380 } else {
381 blockSizeInput.show();
382 setCSS(timerBlockPreviewRef, 'width', blockSize, false);
383 setCSS(timerBlockPreviewRef, 'height', blockSize, false);
384 setCSS(timerBlockPreviewRef, 'display', 'flex');
385 }
386 }).change(); // ------------------------------------------------------------
387 // Set digit size.
388 // ------------------------------------------------------------
389
390 $('input[name=digit_size]').on('input keyup paste change', function () {
391 var fontSize = parseInt($(this).val()) + 'px';
392 setCSS(timerDigitPreviewRef, 'font-size', fontSize, false);
393 setCSS(timerSepPreviewRef, 'font-size', fontSize);
394 }).change(); // ------------------------------------------------------------
395 // Set CTA text size.
396 // ------------------------------------------------------------
397
398 $('input[name="call_to_action[text_size]"]').on('input keyup paste change', function () {
399 var fontSize = parseInt($(this).val()) + 'px';
400 setCSS(campaignCTA, 'font-size', fontSize);
401 }).change(); // ------------------------------------------------------------
402 // Set block spacing.
403 // ------------------------------------------------------------
404
405 $('input[name=block_spacing]').on('input keyup paste change', function () {
406 var spacing = "".concat($(this).val(), "px");
407
408 if ($('select[name=display]').val() === 'inline') {
409 setCSS(timerBlockPreviewRef, 'margin-bottom', spacing, false);
410 setCSS(timerBlockPreviewRef, 'margin-top', spacing);
411 } else {
412 setCSS(timerBlockPreviewRef, 'margin-left', spacing, false);
413 setCSS(timerBlockPreviewRef, 'margin-right', spacing);
414 }
415 }).change(); // ------------------------------------------------------------
416 // Set block padding.
417 // ------------------------------------------------------------
418
419 $('input[name=block_padding]').on('input keyup paste change', function () {
420 var padding = parseInt($(this).val()) + 'px';
421 setCSS(timerBlockPreviewRef, 'padding', padding);
422 }).change(); // ------------------------------------------------------------
423 // Sticky Bar Y padding.
424 // ------------------------------------------------------------
425
426 $('input[name=sticky_bar_padding]').on('input keyup paste change', function () {
427 var padding = "".concat($(this).val(), "px");
428 var stickyBarInner = campaignPreviewRef.find('.hurrytimer-sticky-inner');
429 setCSS(stickyBarInner, 'padding-top', padding, false);
430 setCSS(stickyBarInner, 'padding-bottom', padding);
431 }).change();
432 $('select[name=sticky_bar_position]').on('input keyup paste change', function () {
433 if ($(this).val() === 'top') {
434 removeCSSProperty(campaignPreviewRef, 'bottom');
435 setCSS(campaignPreviewRef, 'top', 0);
436 } else {//removeCSSProperty(campaignPreviewRef, 'top');
437 // setCSS(campaignPreviewRef, 'bottom', 0);
438 }
439 }).change();
440 $('input[name=headline_spacing]').on('input keyup paste change', function () {
441 var spacing = "".concat($(this).val(), "px");
442
443 if ($('select[name=campaign_display]').val() === 'inline') {
444 if ($('select[name=headline_position]').val() === hurrytimer_ajax_object.headline_pos.above_timer) {
445 setCSS(headlinePreviewRef, 'margin-left', spacing);
446 setCSS(headlinePreviewRef, 'margin-top', 0);
447 } else {
448 setCSS(headlinePreviewRef, 'margin-right', spacing);
449 setCSS(headlinePreviewRef, 'margin-bottom', 0);
450 }
451 } else {
452 if ($('select[name=headline_position]').val() === hurrytimer_ajax_object.headline_pos.above_timer) {
453 setCSS(headlinePreviewRef, 'margin-left', 0);
454 setCSS(headlinePreviewRef, 'margin-top', spacing);
455 } else {
456 setCSS(headlinePreviewRef, 'margin-right', 0);
457 setCSS(headlinePreviewRef, 'margin-bottom', spacing);
458 }
459 }
460 }).change();
461 $('input[name="call_to_action[spacing]"]').on('input keyup paste change', function () {
462 var spacing = "".concat($(this).val(), "px");
463
464 if ($('select[name=campaign_display]').val() === 'inline') {
465 setCSS(campaignCTA, 'margin-right', spacing, false);
466 setCSS(campaignCTA, 'margin-left', spacing);
467 } else {
468 setCSS(campaignCTA, 'margin-top', spacing, false);
469 setCSS(campaignCTA, 'margin-bottom', spacing);
470 }
471 }).change(); // ------------------------------------------------------------
472 // Set label size.
473 // ------------------------------------------------------------
474
475 $('input[name=label_size]').on('input keyup paste change', function () {
476 setCSS(timerLabelPreviewRef, 'font-size', parseInt($(this).val()) + 'px');
477 }).change(); // ------------------------------------------------------------
478 // Set block border width.
479 // ------------------------------------------------------------
480
481 $('input[name=block_border_width]').on('input keyup paste change', function () {
482 var borderSize = parseInt($(this).val());
483 var borderColor = $('input[name=block_border_color]').val() || 'transparent';
484 setCSS(timerBlockPreviewRef, 'border', borderColor + ' solid ' + borderSize + 'px');
485 }).change(); // ------------------------------------------------------------
486 // Set block border radius.
487 // ------------------------------------------------------------
488
489 $('input[name=block_border_radius]').on('input keyup paste change', function () {
490 setCSS(timerBlockPreviewRef, 'border-radius', "".concat($(this).val(), "px"));
491 }).change(); // ------------------------------------------------------------
492 // Set block size.
493 // ------------------------------------------------------------
494
495 $('input[name=block_size]').on('input keyup paste change', function () {
496 var value = parseInt($(this).val());
497 var size = value + 'px';
498
499 if (value === 0 || $('select[name=block_display]').val() === 'inline') {
500 size = 'auto';
501 }
502
503 setCSS(timerBlockPreviewRef, 'width', size, false);
504 setCSS(timerBlockPreviewRef, 'height', size);
505 }).change(); // ------------------------------------------------------------
506 // Bind post title input (headline) to preview.
507 // ------------------------------------------------------------
508
509 var _loaded = false;
510 $('input[name=post_title]').on('input paste keyup change', function () {
511 if ($(this).val().length === 0 && !_loaded) {
512 $(this).val(headlinePreviewRef.text());
513 _loaded = true;
514 return;
515 }
516
517 headlinePreviewRef.html($(this).val());
518 }).change(); // ------------------------------------------------------------
519 // Change headline position.
520 // ------------------------------------------------------------
521
522 $('select[name=headline_position]').on('change', function () {
523 if (parseInt($(this).val()) === hurrytimer_ajax_object.headline_pos.above_timer) {
524 headlinePreviewRef.after(timerPreviewRef);
525 } else {
526 headlinePreviewRef.before(timerPreviewRef);
527 }
528 }).change(); // ------------------------------------------------------------
529 // Set headline size
530 // ------------------------------------------------------------
531
532 $('input[name=headline_size]').on('input keyup paste change', function () {
533 setCSS(headlinePreviewRef, 'font-size', parseInt($(this).val()) + 'px');
534 }).change(); // ------------------------------------------------------------
535 // Set label case.
536 // ------------------------------------------------------------
537
538 $('select[name=label_case]').on('change', function () {
539 setCSS(timerLabelPreviewRef, 'text-transform', $(this).val());
540 }).change(); // ------------------------------------------------------------
541 // Set CTA text.
542 // ------------------------------------------------------------
543
544 $('input[name="call_to_action[text]"]').on('change keyup paste input', function () {
545 campaignCTA.text($(this).val());
546 }).change(); // ------------------------------------------------------------
547 // Set CTA horizontal padding
548 // ------------------------------------------------------------
549
550 $('input[name="call_to_action[x_padding]"]').on('input keyup paste change', function () {
551 var padding = "".concat($(this).val(), "px");
552 setCSS(campaignCTA, 'padding-left', padding, false);
553 setCSS(campaignCTA, 'padding-right', padding);
554 }).change(); // ------------------------------------------------------------
555 // Set CTA border radius
556 // ------------------------------------------------------------
557
558 $('input[name="call_to_action[border_radius]"]').on('input keyup paste change', function () {
559 setCSS(campaignCTA, 'border-radius', "".concat($(this).val(), "px"));
560 }).change(); // ------------------------------------------------------------
561 // Set CTA vertical padding
562 // ------------------------------------------------------------
563
564 $('input[name="call_to_action[y_padding]"]').on('input keyup paste change', function () {
565 var padding = parseInt($(this).val()) + 'px';
566 setCSS(campaignCTA, 'padding-top', padding, false);
567 setCSS(campaignCTA, 'padding-bottom', padding);
568 }).change(); // ------------------------------------------------------------
569 // Toggle block separator visibility.
570 // ------------------------------------------------------------
571
572 $('input[name=block_separator_visibility]').on('change', function () {
573 var self = $(this);
574
575 if (!self.is(':checked')) {
576 timerSepPreviewRef.addClass('hidden');
577 return;
578 }
579
580 timerBlockPreviewRef.each(function () {
581 if ($(this).hasClass('hidden')) {
582 $(this).next().addClass('hidden');
583 } else {
584 $(this).next().removeClass('hidden');
585 }
586 });
587 }).change(); // ------------------------------------------------------------
588 // Toggle "days" block visibility.
589 // ------------------------------------------------------------
590
591 $('#hurrytimer-days-visibility').on('change', function () {
592 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=days]'));
593 }).change(); // ------------------------------------------------------------
594 // Toggle "hours" block visibility
595 // ------------------------------------------------------------
596
597 $('#hurrytimer-hours-visibility').on('change', function () {
598 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=hours]'));
599 }).change(); // ---------------------------------------------------------------
600 // Toggle "minutes" block visibility
601 // ---------------------------------------------------------------
602
603 $('#hurrytimer-minutes-visibility').on('change', function () {
604 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=minutes]'));
605 }).change(); // ---------------------------------------------------------------
606 // Toggle "seconds" block visibility
607 // ---------------------------------------------------------------
608
609 $('#hurrytimer-seconds-visibility').on('change', function () {
610 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=seconds]'));
611 }).change(); // ---------------------------------------------------------------
612 // Toggle "headline" block visibility
613 // ---------------------------------------------------------------
614
615 $('#hurrytimer-headline-visibility').on('change', function () {
616 if ($(this).is(':checked')) {
617 headlinePreviewRef.removeClass('hidden');
618 } else {
619 headlinePreviewRef.addClass('hidden');
620 }
621 }).change(); // ---------------------------------------------------------------
622 // Toggle "labels" visibility.
623 //----------------------------------------------------------------
624
625 $('#hurrytimer-label-visibility').on('change', function () {
626 if ($(this).is(':checked')) {
627 timerLabelPreviewRef.removeClass('hidden');
628 } else {
629 timerLabelPreviewRef.addClass('hidden');
630 }
631 }).change(); // ---------------------------------------------------------------
632 // Toggle CTA visibility.
633 // ------------------------------------------------------------
634
635 $('#hurrytimer-cta-enabled').on('change', function () {
636 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('.hurrytimer-button-wrap'));
637 }).change(); // ---------------------------------------------------------------
638 // Input slider.
639 // ------------------------------------------------------------
640
641 var blockSizeSliderElement;
642 var blockSizeInputElement;
643 $('.hurrytimer-input-slider').each(function () {
644 var self = $(this);
645 var boundInputElement = $('input[name="' + self.data('input-name') + '"]');
646 var min = parseInt(boundInputElement.attr('min')) || 0;
647 var max = parseInt(boundInputElement.attr('max')) || 100;
648
649 if (boundInputElement.attr('name') === 'block_size') {
650 min = parseInt($('input[name=digit_size]').val()) || min;
651 blockSizeSliderElement = self;
652 blockSizeInputElement = boundInputElement;
653 }
654
655 self.slider({
656 slide: function slide(_, ui) {
657 boundInputElement.val(ui.value);
658 boundInputElement.trigger('input');
659
660 if (boundInputElement.attr('name') === 'digit_size') {
661 $('input[name=block_size]').attr('min', ui.value);
662 blockSizeSliderElement.slider('option', 'min', ui.value);
663
664 if (blockSizeInputElement.val() < ui.value) {
665 blockSizeSliderElement.slider('option', 'value', ui.value);
666 blockSizeInputElement.val(ui.value);
667 blockSizeInputElement.trigger('input');
668 }
669 }
670 },
671 max: max,
672 min: min,
673 value: boundInputElement.val()
674 });
675 }); // ------------------------------------------------------------
676
677 $('body').on('click', function () {
678 $('.iris-picker').hide();
679 }); // ------------------------------------------------------------
680 // Add new action
681 // ------------------------------------------------------------
682
683 $('#hurrytimer-new-action').on('click', function () {
684 //removeif(pro)
685 if ($('.hurrytimer-action-block').length === 1) {
686 $('#hurryt-upgrade-alert-actions-feat').modal({
687 closeExisting: true,
688 closeClass: 'hurryt-upgrade-alert-close',
689 closeText: ''
690 });
691 return;
692 } // endremoveif(pro)
693
694
695 var action = $('.hurrytimer-action-block').last().clone(true, true);
696 action.find('.hurrytimer-action-block-subfields').addClass('hidden');
697 var fields = action.find(':input');
698
699 for (var i = 0; i < fields.length; i++) {
700 fields[i].name = fields[i].name.replace(/actions\[(\d+)\]\[(\w+)\]/, function (fm, i, name) {
701 return 'actions[' + ++i + '][' + name + ']';
702 });
703 }
704
705 $(this).parent().before(action);
706
707 if ($('.hurrytimer-action-block').length === 1) {
708 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').addClass('hidden');
709 } else {
710 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').removeClass('hidden');
711 }
712 }); // ------------------------------------------------------------
713 // Handle action selection
714 // ------------------------------------------------------------
715
716 $('#hurrytimer-actions').on('change', '.hurrytimer-action-select', function () {
717 handleActionChange($(this));
718 });
719 $('.hurrytimer-action-select').each(function () {
720 handleActionChange($(this));
721 });
722
723 function handleActionChange(element) {
724 var action = element.find('option:selected');
725
726 if (+action.val() === 4 && +$('.hurrytimer-mode:checked').val() === 2) {
727 element.next('.hurryt-compat-info').removeClass('hidden');
728 } else {
729 element.next('.hurryt-compat-info').addClass('hidden');
730 }
731
732 var block = element.closest('.hurrytimer-action-block');
733 block.find('.hurrytimer-action-block-subfields').addClass('hidden');
734 block.find('.' + action.data('subfields')).removeClass('hidden');
735 } // ------------------------------------------------------------
736 // Handle action deletion
737 // ------------------------------------------------------------
738
739
740 $('#hurrytimer-actions').on('click', '.hurrytimer-delete-action', function () {
741 if ($('.hurrytimer-action-block').length === 1) return;
742 $(this).closest('.hurrytimer-action-block').remove();
743
744 if ($('.hurrytimer-action-block').length === 1) {
745 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').addClass('hidden');
746 } else {
747 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').removeClass('hidden');
748 }
749 }); // ------------------------------------------------------------
750 // Set "days" label
751 // ------------------------------------------------------------
752
753 $('input[name="labels[days]"]').on('input keyup paste', function () {
754 campaignInnerPreviewRef.find('[data-block=days] .hurrytimer-timer-label').text($(this).val());
755 }).trigger('input'); // ------------------------------------------------------------
756 // Set "hours" label
757 // ------------------------------------------------------------
758
759 $('input[name="labels[hours]"]').on('input keyup paste', function () {
760 campaignInnerPreviewRef.find('[data-block=hours] .hurrytimer-timer-label').text($(this).val());
761 }).trigger('input'); // ------------------------------------------------------------
762 // Set "minutes" label
763 // ------------------------------------------------------------
764
765 $('input[name="labels[minutes]"]').on('input keyup paste', function () {
766 campaignInnerPreviewRef.find('[data-block=minutes] .hurrytimer-timer-label').text($(this).val());
767 }).trigger('input'); // ------------------------------------------------------------
768 // Set "seconds" label
769 // ------------------------------------------------------------
770
771 $('input[name="labels[seconds]"]').on('input keyup paste', function () {
772 campaignInnerPreviewRef.find('[data-block=seconds] .hurrytimer-timer-label').text($(this).val());
773 }).trigger('input'); // ------------------------------------------------------------
774 // Compaign display
775 // ------------------------------------------------------------
776
777 $('select[name=campaign_display]').on('change', function () {
778 var blockMarginBottom = timerBlockPreviewRef.css('margin-bottom');
779
780 if ($(this).val() === 'inline') {
781 campaignInnerPreviewRef.addClass('hurrytimer-inline');
782 setCSS(timerBlockPreviewRef, 'margin-bottom', '0');
783 } else {
784 campaignInnerPreviewRef.removeClass('hurrytimer-inline');
785 setCSS(timerBlockPreviewRef, 'margin-bottom', blockMarginBottom);
786 }
787
788 $('input[name="call_to_action[spacing]"]').change();
789 $('input[name="headline_spacing"]').change();
790 }).change(); // ------------------------------------------------------------
791 // Compaign alignment
792 // ------------------------------------------------------------
793
794 $('select[name=campaign_align]').on('change', function () {
795 var value = $(this).val();
796 setCSS(campaignInnerPreviewRef, 'text-align', value);
797
798 if ($('select[name=campaign_display]').val() === 'inline') {
799 return false;
800 }
801
802 switch (value) {
803 case 'left':
804 setCSS(timerPreviewRef, 'justify-content', 'flex-start');
805 break;
806
807 case 'right':
808 setCSS(timerPreviewRef, 'justify-content', 'flex-end');
809 break;
810
811 case 'center':
812 setCSS(timerPreviewRef, 'justify-content', 'center');
813 break;
814 }
815 }).change();
816 $('.hurryt-fullscreen').on('click', function (e) {
817 e.preventDefault();
818
819 if ($(this).hasClass('on')) {
820 campaignPreviewRef.removeClass('hurryt-preview-fullscreen');
821 $(this).removeClass('on');
822
823 if (campaignPreviewRef.hasClass('hurrytimer-sticky')) {
824 setCSS(campaignPreviewRef, 'position', 'relative');
825 }
826 } else {
827 campaignPreviewRef.addClass('hurryt-preview-fullscreen');
828 $(this).addClass('on');
829 }
830 });
831 $('select[name="sticky_bar_pages[]"]').select2({
832 placeholder: 'Search...'
833 });
834 $('select[name="sticky_bar_pages[]"]').on('change', function () {
835 if ($(this).val() === null) {
836 $('input[name="sticky_bar_pages[]"]').val([]);
837 } else {
838 $('input[name="sticky_bar_pages[]"]').val("[".concat($(this).val(), "]"));
839 }
840 });
841 $('input[type="checkbox"][name="sticky_bar_show_on_all_pages"]').on('change', function () {
842 if ($('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').length === 0) {
843 $(this).after('<input type="hidden" name="sticky_bar_show_on_all_pages" value="yes" />');
844 }
845
846 if ($(this).is(':checked')) {
847 $('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').val('yes');
848 $('select[name="sticky_bar_pages[]"').attr('disabled', true);
849 } else {
850 $('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').val('no');
851 $('select[name="sticky_bar_pages[]"').attr('disabled', false);
852 }
853 }).change();
854 $('.js-hurrytimer-restart-coundown'); // Display tooltips
855
856 $('#hurrytimer-settings').tooltip({
857 tooltipClass: 'hurryt-tooltip',
858 content: function content() {
859 return $(this).prop('title');
860 },
861 position: {
862 my: 'center bottom-20',
863 at: 'center top',
864 using: function using(position, feedback) {
865 $(this).css(position);
866 $('<div>').addClass('arrow').addClass(feedback.vertical).addClass(feedback.horizontal).appendTo(this);
867 }
868 }
869 }); // Toggle display
870
871 $('.hurryt-sticky-bar-display-on').on('change', function () {
872 if ($(this).val() === 'specific_pages') {
873 $('.hurryt_sticky_bar_pages').removeClass('hidden');
874 } else {
875 $('.hurryt_sticky_bar_pages').addClass('hidden');
876 }
877 });
878
879 if ($('.hurryt-sticky-bar-display-on:checked').val() === 'specific_pages') {
880 $('.hurryt_sticky_bar_pages').removeClass('hidden');
881 } else {
882 $('.hurryt_sticky_bar_pages').addClass('hidden');
883 }
884 /**
885 * Reset evergreen countdown timers for all visitors
886 */
887
888
889 var resetAllButton = document.getElementById('hurrytResetAll');
890
891 if (resetAllButton) {
892 resetAllButton.addEventListener('click', function (e) {
893 e.preventDefault();
894
895 var _confirm = confirm('Are you sure?');
896
897 if (_confirm) {
898 window.location.href = resetAllButton.getAttribute('data-url');
899 }
900 });
901 }
902
903 var resetCurrentButton = document.getElementById('hurrytResetCurrent');
904
905 if (resetCurrentButton) {
906 resetCurrentButton.addEventListener('click', function (e) {
907 e.preventDefault();
908 Cookies.remove(resetCurrentButton.getAttribute('data-cookie'));
909 window.location.href = resetCurrentButton.getAttribute('data-url');
910 });
911 }
912
913 var resetAllEvergreenCampaignsButtons = document.querySelectorAll('.hurrytResetAllEvergreenCampaigns');
914
915 if (resetAllEvergreenCampaignsButtons) {
916 var _iteratorNormalCompletion = true;
917 var _didIteratorError = false;
918 var _iteratorError = undefined;
919
920 try {
921 var _loop = function _loop() {
922 var button = _step.value;
923 button.addEventListener('click', function (e) {
924 e.preventDefault();
925
926 if (confirm('Are you sure?')) {
927 var cookies = Cookies.get();
928
929 for (var name in cookies) {
930 if (name.startsWith(button.getAttribute('data-cookie-prefix'))) {
931 Cookies.remove(name);
932 }
933 }
934
935 window.location.href = button.getAttribute('data-url');
936 }
937 });
938 };
939
940 for (var _iterator = resetAllEvergreenCampaignsButtons[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
941 _loop();
942 }
943 } catch (err) {
944 _didIteratorError = true;
945 _iteratorError = err;
946 } finally {
947 try {
948 if (!_iteratorNormalCompletion && _iterator.return != null) {
949 _iterator.return();
950 }
951 } finally {
952 if (_didIteratorError) {
953 throw _iteratorError;
954 }
955 }
956 }
957 }
958
959 var recurringFrequencyElement = document.getElementById('hurrytRecurringFrequency');
960 var maxDurationElement = document.getElementById('hurrytRecurringDurationMax');
961 var recurringIntervalElement = document.getElementById('hurrytRecurringInterval');
962
963 if (recurringFrequencyElement) {
964 recurringFrequencyElement.onchange = function (e) {
965 return toggleRecurringDuration(e.target.value);
966 };
967
968 toggleRecurringDuration(recurringFrequencyElement.value);
969 }
970
971 function toggleRecurringDuration(value) {
972 console.log(value);
973 var hoursInputElement = document.getElementById('hurrytRecurringHours');
974 var daysInputElement = document.getElementById('hurrytRecurringDays');
975 var minutesInputElement = document.getElementById('hurrytRecurringMinutes');
976
977 switch (value) {
978 case 'minutely':
979 daysInputElement.value = 0;
980 hoursInputElement.value = 0;
981 hoursInputElement.parentNode.classList.add('hidden');
982 daysInputElement.parentNode.classList.add('hidden');
983 maxDurationElement.textContent = "".concat(recurringIntervalElement.value, " minute(s)");
984 break;
985
986 case 'hourly':
987 daysInputElement.value = 0;
988 daysInputElement.parentNode.classList.add('hidden');
989 hoursInputElement.parentNode.classList.remove('hidden');
990 maxDurationElement.textContent = "".concat(recurringIntervalElement.value, " hour(s)");
991 break;
992
993 case 'daily':
994 daysInputElement.parentNode.classList.remove('hidden');
995 hoursInputElement.parentNode.classList.remove('hidden');
996 maxDurationElement.textContent = "".concat(recurringIntervalElement.value, " day(s)");
997 break;
998
999 case 'weekly':
1000 daysInputElement.parentNode.classList.remove('hidden');
1001 hoursInputElement.parentNode.classList.remove('hidden');
1002 maxDurationElement.textContent = "".concat(recurringIntervalElement.value, " week(s)");
1003 break;
1004 }
1005 }
1006
1007 if (recurringIntervalElement) {
1008 recurringIntervalElement.addEventListener('change', validateRecurringDurationEntry);
1009 recurringIntervalElement.addEventListener('keyup', validateRecurringDurationEntry);
1010 recurringIntervalElement.addEventListener('paste', validateRecurringDurationEntry);
1011 validateRecurringDurationEntry();
1012 }
1013
1014 function validateRecurringDurationEntry() {
1015 switch (recurringFrequencyElement.value) {
1016 case 'minutely':
1017 maxDurationElement.textContent = "".concat(recurringIntervalElement.value, " minute(s)");
1018 break;
1019
1020 case 'hourly':
1021 maxDurationElement.textContent = "".concat(recurringIntervalElement.value, " hour(s)");
1022 break;
1023
1024 case 'daily':
1025 maxDurationElement.textContent = "".concat(recurringIntervalElement.value, " day(s)");
1026 break;
1027
1028 case 'weekly':
1029 maxDurationElement.textContent = "".concat(recurringIntervalElement.value, " week(s)");
1030 break;
1031 }
1032
1033 maxDurationElement.parentNode.classList.remove('hidden');
1034 }
1035
1036 $('body').on('click', '.hurryt-add-wc-condition-group', function () {
1037 var _self = $(this);
1038
1039 _self.prop('disabled', true);
1040
1041 _self.next('.spinner').addClass('is-active');
1042
1043 $.get(hurrytimer_ajax_object.ajax_url, {
1044 action: 'add_wc_condition_group',
1045 nonce: hurrytimer_ajax_object.ajax_nonce
1046 }, function (html) {
1047 _self.before(html);
1048 }).always(function () {
1049 _self.prop('disabled', false);
1050
1051 _self.next('.spinner').removeClass('is-active');
1052 });
1053 });
1054 $('body').on('click', '.hurryt-add-wc-condition', function () {
1055 var _self = $(this);
1056
1057 _self.prop('disabled', true);
1058
1059 $.get(hurrytimer_ajax_object.ajax_url, {
1060 action: 'add_wc_condition',
1061 nonce: hurrytimer_ajax_object.ajax_nonce,
1062 group_id: $(this).closest('.hurryt-wc-condition-group').data('group-id')
1063 }, function (html) {
1064 _self.parent().after(html);
1065 }).always(function () {
1066 _self.prop('disabled', false);
1067 });
1068 });
1069 $('body').on('click', '.hurryt-delete-wc-condition', function () {
1070 console.log('deleting condition');
1071
1072 var _self = $(this);
1073
1074 if (_self.closest('.hurryt-wc-condition-group').find('.hurryt-wc-condition').length === 1) {
1075 _self.closest('.hurryt-wc-condition-group').remove();
1076 } else {
1077 $(this).parent().remove();
1078 }
1079 });
1080 $('body').on('change', '.hurryt-wc-condition-key', function () {
1081 var _self = $(this);
1082
1083 var $value = _self.parent().find('.hurryt-wc-condition-value');
1084
1085 var $operator = _self.parent().find('.hurryt-wc-condition-operator');
1086
1087 $value.prop('disabled', true);
1088 $operator.prop('disabled', true);
1089 $.get(hurrytimer_ajax_object.ajax_url, {
1090 action: 'load_wc_condition',
1091 nonce: hurrytimer_ajax_object.ajax_nonce,
1092 condition_key: _self.val(),
1093 group_id: _self.closest('.hurryt-wc-condition-group').data('group-id')
1094 }, function (html) {
1095 _self.parent().replaceWith(html);
1096 }, 'html').always(function () {
1097 $value.prop('disabled', false);
1098 $operator.prop('disabled', false);
1099 });
1100 });
1101 })(jQuery);
1102 //# sourceMappingURL=admin.js.map
1103