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

854 lines 33.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').datetimepicker({
176 controlType: 'select',
177 dateFormat: 'yy-mm-dd',
178 timeFormat: 'hh:mm TT',
179 oneLine: true
180 }); // ------------------------------------------------------------
181 // Handle mode toggle.
182 // ------------------------------------------------------------
183
184 function handleMode(elementRef) {
185 var evergreenModeSubfields = $('.hurryt-evergreen-mode-subfields');
186 var regularModeSubfields = $('.hurryt-regular-mode-subfields');
187
188 if (parseInt(elementRef.val()) === hurrytimer_ajax_object.mode.evergreen) {
189 evergreenModeSubfields.removeClass('hidden');
190 regularModeSubfields.addClass('hidden');
191 } else {
192 evergreenModeSubfields.addClass('hidden');
193 regularModeSubfields.removeClass('hidden');
194 }
195 } // Handle mode.
196
197
198 $('input[name=mode]').on('change', function () {
199 handleMode($(this));
200 });
201 handleMode($('input[name=mode]:checked')); // ------------------------------------------------------------
202 // Handle products type dropdown.
203 // ------------------------------------------------------------
204
205 $('#hurrytimer-wc-products-selection-type').on('change', function () {
206 var $this = $(this);
207 var $selectedOption = $this.find('option:selected');
208 var $label = $('.hurrytimer-products-selection-type-label');
209 var $autocompleteWrap = $label.closest('.form-field');
210
211 if ($selectedOption.data('show-autocomplete')) {
212 $label.text($selectedOption.text());
213 $autocompleteWrap.removeClass('hidden');
214 } else {
215 $autocompleteWrap.addClass('hidden');
216 }
217 }).change(); // Handle tabs
218 // ------------------------------------------------------------
219
220 $('.hurrytimer-tabbar a').on('click', function (e) {
221 e.preventDefault();
222 var $tab = $(this);
223 $('.hurrytimer-tabcontent').removeClass('active');
224 $($tab.attr('href')).addClass('active');
225 $tab.parent().siblings().removeClass('active');
226 $tab.parent().addClass('active');
227
228 if ($tab.attr('href').indexOf('appearance') >= 0 || $tab.attr('href').indexOf('styling') >= 0) {
229 $('.hurryt-fullscreen').removeClass('hidden');
230 } else {
231 $('.hurryt-fullscreen').addClass('hidden');
232 }
233 }); // ------------------------------------------------------------
234 // Search for products/Categories
235 // ------------------------------------------------------------
236
237 $('#hurrytimer-wc-products-selection').select2({
238 placeholder: 'Search...',
239 width: '500',
240 minimumInputLength: 2,
241 ajax: {
242 url: hurrytimer_ajax_object.ajax_url,
243 dataType: 'json',
244 data: function data(params) {
245 return {
246 action: 'wcSearchProducts',
247 search: params.term,
248 exclude: $(this).val(),
249 productsSelection: $('#hurrytimer-wc-products-selection-type').val(),
250 type: 'public'
251 };
252 }
253 }
254 }); // ------------------------------------------------------------
255 // Color picker
256 // ------------------------------------------------------------
257
258 $('.hurrytimer-color-input').each(function () {
259 var self = $(this);
260 self.iris({
261 change: function change(event) {
262 changeColor(self, event.target.value);
263 },
264 clear: function clear() {
265 changeColor(self, 'transparent');
266 },
267 palettes: false,
268 hide: true,
269 border: true
270 }).on('click focus', function (event) {
271 event.stopPropagation();
272 $('.iris-picker').hide();
273 $(this).parent().find('.iris-picker').show();
274 });
275 });
276 $('.hurrytimer-color-clear').on('click', function () {
277 var colorInput = $(this).parent().find('.hurrytimer-color-input');
278 colorInput.val('transparent');
279 changeColor(colorInput);
280 }); // ------------------------------------------------------------
281 // CUSTOM CSS
282 // ------------------------------------------------------------
283 // ------------------------------------------------------------
284 // Handle sub tabbar.
285 // ------------------------------------------------------------
286
287 $('.hurrytimer-subtabbar a').on('click', function (e) {
288 e.preventDefault();
289 var self = $(this);
290 $('.hurrytimer-subtabcontent').each(function () {
291 $(this).removeClass('active');
292 });
293 $(self.attr('href')).addClass('active');
294 self.parent().siblings().removeClass('active');
295 self.parent().addClass('active'); }); // ------------------------------------------------------------
296 // Accordion.
297 // ------------------------------------------------------------
298
299 $('.hurrytimer-accordion-heading').on('click', function () {
300 var self = $(this);
301 var containerElement = self.parent();
302
303 if (containerElement.hasClass('active')) {
304 containerElement.removeClass('active');
305 } else {
306 containerElement.addClass('active').siblings().removeClass('active');
307 }
308 }); // ------------------------------------------------------------
309 // Enable/disable sticky bar.
310 // ------------------------------------------------------------
311
312 $('input[name=enable_sticky]').on('change', function () {
313 if ($(this).is(':checked')) {
314 campaignPreviewRef.addClass('hurrytimer-sticky');
315 campaignInnerPreviewRef.wrap('<div class="hurrytimer-sticky-inner"></div>');
316
317 if (campaignPreviewRef.hasClass('hurryt-preview-fullscreen')) {
318 setCSS(campaignPreviewRef, 'position', 'fixed', false);
319 setCSS(campaignPreviewRef, 'top', 0);
320 }
321 } else {
322 campaignPreviewRef.removeClass('hurrytimer-sticky');
323 campaignInnerPreviewRef.unwrap('.hurrytimer-sticky-inner');
324 }
325 });
326 $('input[name=sticky_bar_dismissible]').on('change', function () {
327 if ($(this).is(':checked')) {
328 campaignPreviewRef.find('.hurrytimer-sticky-close').show();
329 } else {
330 campaignPreviewRef.find('.hurrytimer-sticky-close').hide();
331 }
332 }); // ------------------------------------------------------------
333 // Change block display.
334 // ------------------------------------------------------------
335
336 $('select[name=block_display]').on('change', function () {
337 var value = $(this).val();
338 var blockSize = $('input[name="block_size"]').val() + 'px';
339 setCSS(timerDigitPreviewRef, 'display', value, false);
340 setCSS(timerLabelPreviewRef, 'display', value, false);
341 var blockSizeInput = $(this).closest('.hurrytimer-style-control-field').siblings('.hurrytimer-field-block-size');
342
343 if (value === 'inline') {
344 setCSS(timerBlockPreviewRef, 'width', 'auto', false);
345 setCSS(timerBlockPreviewRef, 'height', 'auto', false);
346 setCSS(timerBlockPreviewRef, 'display', 'inline-block');
347 blockSizeInput.hide();
348 } else {
349 blockSizeInput.show();
350 setCSS(timerBlockPreviewRef, 'width', blockSize, false);
351 setCSS(timerBlockPreviewRef, 'height', blockSize, false);
352 setCSS(timerBlockPreviewRef, 'display', 'flex');
353 }
354 }).change(); // ------------------------------------------------------------
355 // Set digit size.
356 // ------------------------------------------------------------
357
358 $('input[name=digit_size]').on('input keyup paste change', function () {
359 var fontSize = parseInt($(this).val()) + 'px';
360 setCSS(timerDigitPreviewRef, 'font-size', fontSize, false);
361 setCSS(timerSepPreviewRef, 'font-size', fontSize);
362 }).change(); // ------------------------------------------------------------
363 // Set CTA text size.
364 // ------------------------------------------------------------
365
366 $('input[name="call_to_action[text_size]"]').on('input keyup paste change', function () {
367 var fontSize = parseInt($(this).val()) + 'px';
368 setCSS(campaignCTA, 'font-size', fontSize);
369 }).change(); // ------------------------------------------------------------
370 // Set block spacing.
371 // ------------------------------------------------------------
372
373 $('input[name=block_spacing]').on('input keyup paste change', function () {
374 var spacing = "".concat($(this).val(), "px");
375
376 if ($('select[name=display]').val() === 'inline') {
377 setCSS(timerBlockPreviewRef, 'margin-bottom', spacing, false);
378 setCSS(timerBlockPreviewRef, 'margin-top', spacing);
379 } else {
380 setCSS(timerBlockPreviewRef, 'margin-left', spacing, false);
381 setCSS(timerBlockPreviewRef, 'margin-right', spacing);
382 }
383 }).change(); // ------------------------------------------------------------
384 // Set block padding.
385 // ------------------------------------------------------------
386
387 $('input[name=block_padding]').on('input keyup paste change', function () {
388 var padding = parseInt($(this).val()) + 'px';
389 setCSS(timerBlockPreviewRef, 'padding', padding);
390 }).change(); // ------------------------------------------------------------
391 // Sticky Bar Y padding.
392 // ------------------------------------------------------------
393
394 $('input[name=sticky_bar_padding]').on('input keyup paste change', function () {
395 var padding = "".concat($(this).val(), "px");
396 var stickyBarInner = campaignPreviewRef.find('.hurrytimer-sticky-inner');
397 setCSS(stickyBarInner, 'padding-top', padding, false);
398 setCSS(stickyBarInner, 'padding-bottom', padding);
399 }).change();
400 $('select[name=sticky_bar_position]').on('input keyup paste change', function () {
401 if ($(this).val() === 'top') {
402 removeCSSProperty(campaignPreviewRef, 'bottom');
403 setCSS(campaignPreviewRef, 'top', 0);
404 } else {//removeCSSProperty(campaignPreviewRef, 'top');
405 // setCSS(campaignPreviewRef, 'bottom', 0);
406 }
407 }).change();
408 $('input[name=headline_spacing]').on('input keyup paste change', function () {
409 var spacing = "".concat($(this).val(), "px");
410
411 if ($('select[name=campaign_display]').val() === 'inline') {
412 if ($('select[name=headline_position]').val() === hurrytimer_ajax_object.headline_pos.above_timer) {
413 setCSS(headlinePreviewRef, 'margin-left', spacing);
414 setCSS(headlinePreviewRef, 'margin-top', 0);
415 } else {
416 setCSS(headlinePreviewRef, 'margin-right', spacing);
417 setCSS(headlinePreviewRef, 'margin-bottom', 0);
418 }
419 } else {
420 if ($('select[name=headline_position]').val() === hurrytimer_ajax_object.headline_pos.above_timer) {
421 setCSS(headlinePreviewRef, 'margin-left', 0);
422 setCSS(headlinePreviewRef, 'margin-top', spacing);
423 } else {
424 setCSS(headlinePreviewRef, 'margin-right', 0);
425 setCSS(headlinePreviewRef, 'margin-bottom', spacing);
426 }
427 }
428 }).change();
429 $('input[name="call_to_action[spacing]"]').on('input keyup paste change', function () {
430 var spacing = "".concat($(this).val(), "px");
431
432 if ($('select[name=campaign_display]').val() === 'inline') {
433 setCSS(campaignCTA, 'margin-right', spacing, false);
434 setCSS(campaignCTA, 'margin-left', spacing);
435 } else {
436 setCSS(campaignCTA, 'margin-top', spacing, false);
437 setCSS(campaignCTA, 'margin-bottom', spacing);
438 }
439 }).change(); // ------------------------------------------------------------
440 // Set label size.
441 // ------------------------------------------------------------
442
443 $('input[name=label_size]').on('input keyup paste change', function () {
444 setCSS(timerLabelPreviewRef, 'font-size', parseInt($(this).val()) + 'px');
445 }).change(); // ------------------------------------------------------------
446 // Set block border width.
447 // ------------------------------------------------------------
448
449 $('input[name=block_border_width]').on('input keyup paste change', function () {
450 var borderSize = parseInt($(this).val());
451 var borderColor = $('input[name=block_border_color]').val() || 'transparent';
452 setCSS(timerBlockPreviewRef, 'border', borderColor + ' solid ' + borderSize + 'px');
453 }).change(); // ------------------------------------------------------------
454 // Set block border radius.
455 // ------------------------------------------------------------
456
457 $('input[name=block_border_radius]').on('input keyup paste change', function () {
458 setCSS(timerBlockPreviewRef, 'border-radius', "".concat($(this).val(), "px"));
459 }).change(); // ------------------------------------------------------------
460 // Set block size.
461 // ------------------------------------------------------------
462
463 $('input[name=block_size]').on('input keyup paste change', function () {
464 var value = parseInt($(this).val());
465 var size = value + 'px';
466
467 if (value === 0 || $('select[name=block_display]').val() === 'inline') {
468 size = 'auto';
469 }
470
471 setCSS(timerBlockPreviewRef, 'width', size, false);
472 setCSS(timerBlockPreviewRef, 'height', size);
473 }).change(); // ------------------------------------------------------------
474 // Bind post title input (headline) to preview.
475 // ------------------------------------------------------------
476
477 var _loaded = false;
478 $('input[name=post_title]').on('input paste keyup change', function () {
479 if ($(this).val().length === 0 && !_loaded) {
480 $(this).val(headlinePreviewRef.text());
481 _loaded = true;
482 return;
483 }
484
485 headlinePreviewRef.html($(this).val());
486 }).change(); // ------------------------------------------------------------
487 // Change headline position.
488 // ------------------------------------------------------------
489
490 $('select[name=headline_position]').on('change', function () {
491 if (parseInt($(this).val()) === hurrytimer_ajax_object.headline_pos.above_timer) {
492 headlinePreviewRef.after(timerPreviewRef);
493 } else {
494 headlinePreviewRef.before(timerPreviewRef);
495 }
496 }).change(); // ------------------------------------------------------------
497 // Set headline size
498 // ------------------------------------------------------------
499
500 $('input[name=headline_size]').on('input keyup paste change', function () {
501 setCSS(headlinePreviewRef, 'font-size', parseInt($(this).val()) + 'px');
502 }).change(); // ------------------------------------------------------------
503 // Set label case.
504 // ------------------------------------------------------------
505
506 $('select[name=label_case]').on('change', function () {
507 setCSS(timerLabelPreviewRef, 'text-transform', $(this).val());
508 }).change(); // ------------------------------------------------------------
509 // Set CTA text.
510 // ------------------------------------------------------------
511
512 $('input[name="call_to_action[text]"]').on('change keyup paste input', function () {
513 campaignCTA.text($(this).val());
514 }).change(); // ------------------------------------------------------------
515 // Set CTA horizontal padding
516 // ------------------------------------------------------------
517
518 $('input[name="call_to_action[x_padding]"]').on('input keyup paste change', function () {
519 var padding = "".concat($(this).val(), "px");
520 setCSS(campaignCTA, 'padding-left', padding, false);
521 setCSS(campaignCTA, 'padding-right', padding);
522 }).change(); // ------------------------------------------------------------
523 // Set CTA border radius
524 // ------------------------------------------------------------
525
526 $('input[name="call_to_action[border_radius]"]').on('input keyup paste change', function () {
527 setCSS(campaignCTA, 'border-radius', "".concat($(this).val(), "px"));
528 }).change(); // ------------------------------------------------------------
529 // Set CTA vertical padding
530 // ------------------------------------------------------------
531
532 $('input[name="call_to_action[y_padding]"]').on('input keyup paste change', function () {
533 var padding = parseInt($(this).val()) + 'px';
534 setCSS(campaignCTA, 'padding-top', padding, false);
535 setCSS(campaignCTA, 'padding-bottom', padding);
536 }).change(); // ------------------------------------------------------------
537 // Toggle block separator visibility.
538 // ------------------------------------------------------------
539
540 $('input[name=block_separator_visibility]').on('change', function () {
541 var self = $(this);
542
543 if (!self.is(':checked')) {
544 timerSepPreviewRef.addClass('hidden');
545 return;
546 }
547
548 timerBlockPreviewRef.each(function () {
549 if ($(this).hasClass('hidden')) {
550 $(this).next().addClass('hidden');
551 } else {
552 $(this).next().removeClass('hidden');
553 }
554 });
555 }).change(); // ------------------------------------------------------------
556 // Toggle "days" block visibility.
557 // ------------------------------------------------------------
558
559 $('#hurrytimer-days-visibility').on('change', function () {
560 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=days]'));
561 }).change(); // ------------------------------------------------------------
562 // Toggle "hours" block visibility
563 // ------------------------------------------------------------
564
565 $('#hurrytimer-hours-visibility').on('change', function () {
566 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=hours]'));
567 }).change(); // ---------------------------------------------------------------
568 // Toggle "minutes" block visibility
569 // ---------------------------------------------------------------
570
571 $('#hurrytimer-minutes-visibility').on('change', function () {
572 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=minutes]'));
573 }).change(); // ---------------------------------------------------------------
574 // Toggle "seconds" block visibility
575 // ---------------------------------------------------------------
576
577 $('#hurrytimer-seconds-visibility').on('change', function () {
578 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=seconds]'));
579 }).change(); // ---------------------------------------------------------------
580 // Toggle "headline" block visibility
581 // ---------------------------------------------------------------
582
583 $('#hurrytimer-headline-visibility').on('change', function () {
584 if ($(this).is(':checked')) {
585 headlinePreviewRef.removeClass('hidden');
586 } else {
587 headlinePreviewRef.addClass('hidden');
588 }
589 }).change(); // ---------------------------------------------------------------
590 // Toggle "labels" visibility.
591 //----------------------------------------------------------------
592
593 $('#hurrytimer-label-visibility').on('change', function () {
594 if ($(this).is(':checked')) {
595 timerLabelPreviewRef.removeClass('hidden');
596 } else {
597 timerLabelPreviewRef.addClass('hidden');
598 }
599 }).change(); // ---------------------------------------------------------------
600 // Toggle CTA visibility.
601 // ------------------------------------------------------------
602
603 $('#hurrytimer-cta-enabled').on('change', function () {
604 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('.hurrytimer-button-wrap'));
605 }).change(); // ---------------------------------------------------------------
606 // Input slider.
607 // ------------------------------------------------------------
608
609 var blockSizeSliderElement;
610 var blockSizeInputElement;
611 $('.hurrytimer-input-slider').each(function () {
612 var self = $(this);
613 var boundInputElement = $('input[name="' + self.data('input-name') + '"]');
614 var min = parseInt(boundInputElement.attr('min')) || 0;
615 var max = parseInt(boundInputElement.attr('max')) || 100;
616
617 if (boundInputElement.attr('name') === 'block_size') {
618 min = parseInt($('input[name=digit_size]').val()) || min;
619 blockSizeSliderElement = self;
620 blockSizeInputElement = boundInputElement;
621 }
622
623 self.slider({
624 slide: function slide(_, ui) {
625 boundInputElement.val(ui.value);
626 boundInputElement.trigger('input');
627
628 if (boundInputElement.attr('name') === 'digit_size') {
629 $('input[name=block_size]').attr('min', ui.value);
630 blockSizeSliderElement.slider('option', 'min', ui.value);
631
632 if (blockSizeInputElement.val() < ui.value) {
633 blockSizeSliderElement.slider('option', 'value', ui.value);
634 blockSizeInputElement.val(ui.value);
635 blockSizeInputElement.trigger('input');
636 }
637 }
638 },
639 max: max,
640 min: min,
641 value: boundInputElement.val()
642 });
643 }); // ------------------------------------------------------------
644
645 $('body').on('click', function () {
646 $('.iris-picker').hide();
647 }); // ------------------------------------------------------------
648 // Add new action
649 // ------------------------------------------------------------
650
651 $('#hurrytimer-new-action').on('click', function () {
652 //removeIf(pro)
653 if ($('.hurrytimer-action-block').length === 1) {
654 $('#hurryt-upgrade-alert-actions-feat').modal({
655 closeExisting: true,
656 closeClass: 'hurryt-upgrade-alert-close',
657 closeText: ''
658 });
659 return;
660 } //endRemoveIf(pro)
661
662
663 var action = $('.hurrytimer-action-block').last().clone(true, true);
664 action.find('.hurrytimer-action-block-subfields').addClass('hidden');
665 var fields = action.find(':input');
666
667 for (var i = 0; i < fields.length; i++) {
668 fields[i].name = fields[i].name.replace(/actions\[(\d+)\]\[(\w+)\]/, function (fm, i, name) {
669 return 'actions[' + ++i + '][' + name + ']';
670 });
671 }
672
673 $(this).parent().before(action);
674
675 if ($('.hurrytimer-action-block').length === 1) {
676 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').addClass('hidden');
677 } else {
678 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').removeClass('hidden');
679 }
680 }); // ------------------------------------------------------------
681 // Handle action selection
682 // ------------------------------------------------------------
683
684 $('#hurrytimer-actions').on('change', '.hurrytimer-action-select', function () {
685 handleActionChange($(this));
686 });
687 $('.hurrytimer-action-select').each(function () {
688 handleActionChange($(this));
689 });
690
691 function handleActionChange(element) {
692 var action = element.find('option:selected');
693
694 if (+action.val() === 4 && +$('.hurrytimer-mode:checked').val() === 2) {
695 element.next('.hurryt-compat-info').removeClass('hidden');
696 } else {
697 element.next('.hurryt-compat-info').addClass('hidden');
698 }
699
700 var block = element.closest('.hurrytimer-action-block');
701 block.find('.hurrytimer-action-block-subfields').addClass('hidden');
702 block.find('.' + action.data('subfields')).removeClass('hidden');
703 } // ------------------------------------------------------------
704 // Handle action deletion
705 // ------------------------------------------------------------
706
707
708 $('#hurrytimer-actions').on('click', '.hurrytimer-delete-action', function () {
709 if ($('.hurrytimer-action-block').length === 1) return;
710 $(this).closest('.hurrytimer-action-block').remove();
711
712 if ($('.hurrytimer-action-block').length === 1) {
713 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').addClass('hidden');
714 } else {
715 $('.hurrytimer-action-block').find('.hurrytimer-delete-action').removeClass('hidden');
716 }
717 }); // ------------------------------------------------------------
718 // Set "days" label
719 // ------------------------------------------------------------
720
721 $('input[name="labels[days]"]').on('input keyup paste', function () {
722 campaignInnerPreviewRef.find('[data-block=days] .hurrytimer-timer-label').text($(this).val());
723 }).trigger('input'); // ------------------------------------------------------------
724 // Set "hours" label
725 // ------------------------------------------------------------
726
727 $('input[name="labels[hours]"]').on('input keyup paste', function () {
728 campaignInnerPreviewRef.find('[data-block=hours] .hurrytimer-timer-label').text($(this).val());
729 }).trigger('input'); // ------------------------------------------------------------
730 // Set "minutes" label
731 // ------------------------------------------------------------
732
733 $('input[name="labels[minutes]"]').on('input keyup paste', function () {
734 campaignInnerPreviewRef.find('[data-block=minutes] .hurrytimer-timer-label').text($(this).val());
735 }).trigger('input'); // ------------------------------------------------------------
736 // Set "seconds" label
737 // ------------------------------------------------------------
738
739 $('input[name="labels[seconds]"]').on('input keyup paste', function () {
740 campaignInnerPreviewRef.find('[data-block=seconds] .hurrytimer-timer-label').text($(this).val());
741 }).trigger('input'); // ------------------------------------------------------------
742 // Compaign display
743 // ------------------------------------------------------------
744
745 $('select[name=campaign_display]').on('change', function () {
746 var blockMarginBottom = timerBlockPreviewRef.css('margin-bottom');
747
748 if ($(this).val() === 'inline') {
749 campaignInnerPreviewRef.addClass('hurrytimer-inline');
750 setCSS(timerBlockPreviewRef, 'margin-bottom', '0');
751 } else {
752 campaignInnerPreviewRef.removeClass('hurrytimer-inline');
753 setCSS(timerBlockPreviewRef, 'margin-bottom', blockMarginBottom);
754 }
755
756 $('input[name="call_to_action[spacing]"]').change();
757 $('input[name="headline_spacing"]').change();
758 }).change(); // ------------------------------------------------------------
759 // Compaign alignment
760 // ------------------------------------------------------------
761
762 $('select[name=campaign_align]').on('change', function () {
763 var value = $(this).val();
764 setCSS(campaignInnerPreviewRef, 'text-align', value);
765
766 if ($('select[name=campaign_display]').val() === 'inline') {
767 return false;
768 }
769
770 switch (value) {
771 case 'left':
772 setCSS(timerPreviewRef, 'justify-content', 'flex-start');
773 break;
774
775 case 'right':
776 setCSS(timerPreviewRef, 'justify-content', 'flex-end');
777 break;
778
779 case 'center':
780 setCSS(timerPreviewRef, 'justify-content', 'center');
781 break;
782 }
783 }).change();
784 $('.hurryt-fullscreen').on('click', function (e) {
785 e.preventDefault();
786
787 if ($(this).hasClass('on')) {
788 campaignPreviewRef.removeClass('hurryt-preview-fullscreen');
789 $(this).removeClass('on');
790
791 if (campaignPreviewRef.hasClass('hurrytimer-sticky')) {
792 setCSS(campaignPreviewRef, 'position', 'relative');
793 }
794 } else {
795 campaignPreviewRef.addClass('hurryt-preview-fullscreen');
796 $(this).addClass('on');
797 }
798 });
799 $('select[name="sticky_bar_pages[]"]').select2({
800 placeholder: 'Search...'
801 });
802 $('select[name="sticky_bar_pages[]"]').on('change', function () {
803 if ($(this).val() === null) {
804 $('input[name="sticky_bar_pages[]"]').val([]);
805 } else {
806 $('input[name="sticky_bar_pages[]"]').val("[".concat($(this).val(), "]"));
807 }
808 });
809 $('input[type="checkbox"][name="sticky_bar_show_on_all_pages"]').on('change', function () {
810 if ($('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').length === 0) {
811 $(this).after('<input type="hidden" name="sticky_bar_show_on_all_pages" value="yes" />');
812 }
813
814 if ($(this).is(':checked')) {
815 $('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').val('yes');
816 $('select[name="sticky_bar_pages[]"').attr('disabled', true);
817 } else {
818 $('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').val('no');
819 $('select[name="sticky_bar_pages[]"').attr('disabled', false);
820 }
821 }).change();
822 $('.js-hurrytimer-restart-coundown'); // Display tooltips
823
824 $('#hurrytimer-settings').tooltip({
825 tooltipClass: 'hurryt-tooltip',
826 content: function content() {
827 return $(this).prop('title');
828 },
829 position: {
830 my: 'center bottom-20',
831 at: 'center top',
832 using: function using(position, feedback) {
833 $(this).css(position);
834 $('<div>').addClass('arrow').addClass(feedback.vertical).addClass(feedback.horizontal).appendTo(this);
835 }
836 }
837 }); // Toggle display
838
839 $('.hurryt-sticky-bar-display-on').on('change', function () {
840 if ($(this).val() === 'specific_pages') {
841 $('.hurryt_sticky_bar_pages').removeClass('hidden');
842 } else {
843 $('.hurryt_sticky_bar_pages').addClass('hidden');
844 }
845 });
846
847 if ($('.hurryt-sticky-bar-display-on:checked').val() === 'specific_pages') {
848 $('.hurryt_sticky_bar_pages').removeClass('hidden');
849 } else {
850 $('.hurryt_sticky_bar_pages').addClass('hidden');
851 }
852 })(jQuery);
853 //# sourceMappingURL=admin.js.map
854