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

827 lines 32.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 console.log($('select[name=block_display]').val());
466 var size = value + 'px';
467
468 if (value === 0 || $('select[name=block_display]').val() === 'inline') {
469 size = 'auto';
470 }
471
472 setCSS(timerBlockPreviewRef, 'width', size, false);
473 setCSS(timerBlockPreviewRef, 'height', size);
474 }).change(); // ------------------------------------------------------------
475 // Bind post title input (headline) to preview.
476 // ------------------------------------------------------------
477
478 var _loaded = false;
479 $('input[name=post_title]').on('input paste keyup change', function () {
480 if ($(this).val().length === 0 && !_loaded) {
481 $(this).val(headlinePreviewRef.text());
482 _loaded = true;
483 return;
484 }
485
486 headlinePreviewRef.html($(this).val());
487 }).change(); // ------------------------------------------------------------
488 // Change headline position.
489 // ------------------------------------------------------------
490
491 $('select[name=headline_position]').on('change', function () {
492 if (parseInt($(this).val()) === hurrytimer_ajax_object.headline_pos.above_timer) {
493 headlinePreviewRef.after(timerPreviewRef);
494 } else {
495 headlinePreviewRef.before(timerPreviewRef);
496 }
497 }).change(); // ------------------------------------------------------------
498 // Set headline size
499 // ------------------------------------------------------------
500
501 $('input[name=headline_size]').on('input keyup paste change', function () {
502 setCSS(headlinePreviewRef, 'font-size', parseInt($(this).val()) + 'px');
503 }).change(); // ------------------------------------------------------------
504 // Set label case.
505 // ------------------------------------------------------------
506
507 $('select[name=label_case]').on('change', function () {
508 setCSS(timerLabelPreviewRef, 'text-transform', $(this).val());
509 }).change(); // ------------------------------------------------------------
510 // Set CTA text.
511 // ------------------------------------------------------------
512
513 $('input[name="call_to_action[text]"]').on('change keyup paste input', function () {
514 campaignCTA.text($(this).val());
515 }); // ------------------------------------------------------------
516 // Set CTA horizontal padding
517 // ------------------------------------------------------------
518
519 $('input[name="call_to_action[x_padding]"]').on('input keyup paste change', function () {
520 var padding = "".concat($(this).val(), "px");
521 setCSS(campaignCTA, 'padding-left', padding, false);
522 setCSS(campaignCTA, 'padding-right', padding);
523 }).change(); // ------------------------------------------------------------
524 // Set CTA border radius
525 // ------------------------------------------------------------
526
527 $('input[name="call_to_action[border_radius]"]').on('input keyup paste change', function () {
528 setCSS(campaignCTA, 'border-radius', "".concat($(this).val(), "px"));
529 }).change(); // ------------------------------------------------------------
530 // Set CTA vertical padding
531 // ------------------------------------------------------------
532
533 $('input[name="call_to_action[y_padding]"]').on('input keyup paste change', function () {
534 var padding = parseInt($(this).val()) + 'px';
535 setCSS(campaignCTA, 'padding-top', padding, false);
536 setCSS(campaignCTA, 'padding-bottom', padding);
537 }).change(); // ------------------------------------------------------------
538 // Toggle block separator visibility.
539 // ------------------------------------------------------------
540
541 $('input[name=block_separator_visibility]').on('change', function () {
542 var self = $(this);
543
544 if (!self.is(':checked')) {
545 timerSepPreviewRef.addClass('hidden');
546 return;
547 }
548
549 timerBlockPreviewRef.each(function () {
550 if ($(this).hasClass('hidden')) {
551 $(this).next().addClass('hidden');
552 } else {
553 $(this).next().removeClass('hidden');
554 }
555 });
556 }).change(); // ------------------------------------------------------------
557 // Toggle "days" block visibility.
558 // ------------------------------------------------------------
559
560 $('#hurrytimer-days-visibility').on('change', function () {
561 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=days]'));
562 }).change(); // ------------------------------------------------------------
563 // Toggle "hours" block visibility
564 // ------------------------------------------------------------
565
566 $('#hurrytimer-hours-visibility').on('change', function () {
567 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=hours]'));
568 }).change(); // ---------------------------------------------------------------
569 // Toggle "minutes" block visibility
570 // ---------------------------------------------------------------
571
572 $('#hurrytimer-minutes-visibility').on('change', function () {
573 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=minutes]'));
574 }).change(); // ---------------------------------------------------------------
575 // Toggle "seconds" block visibility
576 // ---------------------------------------------------------------
577
578 $('#hurrytimer-seconds-visibility').on('change', function () {
579 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('[data-block=seconds]'));
580 }).change(); // ---------------------------------------------------------------
581 // Toggle "headline" block visibility
582 // ---------------------------------------------------------------
583
584 $('#hurrytimer-headline-visibility').on('change', function () {
585 if ($(this).is(':checked')) {
586 headlinePreviewRef.removeClass('hidden');
587 } else {
588 headlinePreviewRef.addClass('hidden');
589 }
590 }).change(); // ---------------------------------------------------------------
591 // Toggle "labels" visibility.
592 //----------------------------------------------------------------
593
594 $('#hurrytimer-label-visibility').on('change', function () {
595 if ($(this).is(':checked')) {
596 timerLabelPreviewRef.removeClass('hidden');
597 } else {
598 timerLabelPreviewRef.addClass('hidden');
599 }
600 }).change(); // ---------------------------------------------------------------
601 // Toggle CTA visibility.
602 // ------------------------------------------------------------
603
604 $('#hurrytimer-cta-enabled').on('change', function () {
605 toggleBlockVisibility($(this), campaignInnerPreviewRef.find('.hurrytimer-button-wrap'));
606 }).change(); // ---------------------------------------------------------------
607 // Input slider.
608 // ------------------------------------------------------------
609
610 var blockSizeSliderElement;
611 var blockSizeInputElement;
612 $('.hurrytimer-input-slider').each(function () {
613 var self = $(this);
614 var boundInputElement = $('input[name="' + self.data('input-name') + '"]');
615 var min = parseInt(boundInputElement.attr('min')) || 0;
616 var max = parseInt(boundInputElement.attr('max')) || 100;
617
618 if (boundInputElement.attr('name') === 'block_size') {
619 min = parseInt($('input[name=digit_size]').val()) || min;
620 blockSizeSliderElement = self;
621 blockSizeInputElement = boundInputElement;
622 }
623
624 self.slider({
625 slide: function slide(_, ui) {
626 boundInputElement.val(ui.value);
627 boundInputElement.trigger('input');
628
629 if (boundInputElement.attr('name') === 'digit_size') {
630 $('input[name=block_size]').attr('min', ui.value);
631 blockSizeSliderElement.slider('option', 'min', ui.value);
632
633 if (blockSizeInputElement.val() < ui.value) {
634 blockSizeSliderElement.slider('option', 'value', ui.value);
635 blockSizeInputElement.val(ui.value);
636 blockSizeInputElement.trigger('input');
637 }
638 }
639 },
640 max: max,
641 min: min,
642 value: boundInputElement.val()
643 });
644 }); // ------------------------------------------------------------
645
646 $('body').on('click', function () {
647 $('.iris-picker').hide();
648 }); // ------------------------------------------------------------
649 // Add new action
650 // ------------------------------------------------------------
651
652 $('#hurrytimer-new-action').on('click', function () {
653 //removeIf(pro)
654 if ($('.hurrytimer-action-block').length === 1) {
655 $('#hurryt-upgrade-alert-actions-feat').modal({
656 closeExisting: true,
657 closeClass: 'hurryt-upgrade-alert-close',
658 closeText: ''
659 });
660 return;
661 } //endRemoveIf(pro)
662
663
664 var action = $('.hurrytimer-action-block').last().clone(true, true);
665 action.find('.hurrytimer-action-block-subfields').addClass('hidden');
666 var fields = action.find(':input');
667
668 for (var i = 0; i < fields.length; i++) {
669 fields[i].name = fields[i].name.replace(/actions\[(\d+)\]\[(\w+)\]/, function (fm, i, name) {
670 return 'actions[' + ++i + '][' + name + ']';
671 });
672 }
673
674 $(this).parent().before(action);
675 }); // ------------------------------------------------------------
676 // Handle action selection
677 // ------------------------------------------------------------
678
679 $('#hurrytimer-actions').on('change', '.hurrytimer-action-select', function () {
680 handleActionChange($(this));
681 });
682 $('.hurrytimer-action-select').each(function () {
683 handleActionChange($(this));
684 });
685
686 function handleActionChange(element) {
687 var action = element.find('option:selected');
688
689 if (+action.val() === 4 && +$('.hurrytimer-mode:checked').val() === 2) {
690 element.next('.hurryt-compat-info').removeClass('hidden');
691 } else {
692 element.next('.hurryt-compat-info').addClass('hidden');
693 }
694
695 var block = element.closest('.hurrytimer-action-block');
696 block.find('.hurrytimer-action-block-subfields').addClass('hidden');
697 block.find('.' + action.data('subfields')).removeClass('hidden');
698 } // ------------------------------------------------------------
699 // Handle action deletion
700 // ------------------------------------------------------------
701
702
703 $('#hurrytimer-actions').on('click', '.hurrytimer-delete-action', function () {
704 if ($('.hurrytimer-action-block').length === 1) return;
705 $(this).closest('.hurrytimer-action-block').remove();
706 }); // ------------------------------------------------------------
707 // Set "days" label
708 // ------------------------------------------------------------
709
710 $('input[name="labels[days]"]').on('input keyup paste', function () {
711 campaignInnerPreviewRef.find('[data-block=days] .hurrytimer-timer-label').text($(this).val());
712 }).trigger('input'); // ------------------------------------------------------------
713 // Set "hours" label
714 // ------------------------------------------------------------
715
716 $('input[name="labels[hours]"]').on('input keyup paste', function () {
717 campaignInnerPreviewRef.find('[data-block=hours] .hurrytimer-timer-label').text($(this).val());
718 }).trigger('input'); // ------------------------------------------------------------
719 // Set "minutes" label
720 // ------------------------------------------------------------
721
722 $('input[name="labels[minutes]"]').on('input keyup paste', function () {
723 campaignInnerPreviewRef.find('[data-block=minutes] .hurrytimer-timer-label').text($(this).val());
724 }).trigger('input'); // ------------------------------------------------------------
725 // Set "seconds" label
726 // ------------------------------------------------------------
727
728 $('input[name="labels[seconds]"]').on('input keyup paste', function () {
729 campaignInnerPreviewRef.find('[data-block=seconds] .hurrytimer-timer-label').text($(this).val());
730 }).trigger('input'); // ------------------------------------------------------------
731 // Compaign display
732 // ------------------------------------------------------------
733
734 $('select[name=campaign_display]').on('change', function () {
735 var blockMarginBottom = timerBlockPreviewRef.css('margin-bottom');
736
737 if ($(this).val() === 'inline') {
738 campaignInnerPreviewRef.addClass('hurrytimer-inline');
739 setCSS(timerBlockPreviewRef, 'margin-bottom', '0');
740 } else {
741 campaignInnerPreviewRef.removeClass('hurrytimer-inline');
742 setCSS(timerBlockPreviewRef, 'margin-bottom', blockMarginBottom);
743 }
744
745 $('input[name="call_to_action[spacing]"]').change();
746 $('input[name="headline_spacing"]').change();
747 }).change(); // ------------------------------------------------------------
748 // Compaign alignment
749 // ------------------------------------------------------------
750
751 $('select[name=campaign_align]').on('change', function () {
752 var value = $(this).val();
753 setCSS(campaignInnerPreviewRef, 'text-align', value);
754
755 if ($('select[name=campaign_display]').val() === 'inline') {
756 return false;
757 }
758
759 switch (value) {
760 case 'left':
761 setCSS(timerPreviewRef, 'justify-content', 'flex-start');
762 break;
763
764 case 'right':
765 setCSS(timerPreviewRef, 'justify-content', 'flex-end');
766 break;
767
768 case 'center':
769 setCSS(timerPreviewRef, 'justify-content', 'center');
770 break;
771 }
772 }).change();
773 $('.hurryt-fullscreen').on('click', function (e) {
774 e.preventDefault();
775
776 if ($(this).hasClass('on')) {
777 campaignPreviewRef.removeClass('hurryt-preview-fullscreen');
778 $(this).removeClass('on');
779
780 if (campaignPreviewRef.hasClass('hurrytimer-sticky')) {
781 setCSS(campaignPreviewRef, 'position', 'relative');
782 }
783 } else {
784 campaignPreviewRef.addClass('hurryt-preview-fullscreen');
785 $(this).addClass('on');
786 }
787 });
788 $('select[name="sticky_bar_pages[]"]').select2();
789 $('select[name="sticky_bar_pages[]"]').on('change', function () {
790 if ($(this).val() === null) {
791 $('input[name="sticky_bar_pages[]"]').val([]);
792 } else {
793 $('input[name="sticky_bar_pages[]"]').val("[".concat($(this).val(), "]"));
794 }
795 });
796 $('input[type="checkbox"][name="sticky_bar_show_on_all_pages"]').on('change', function () {
797 if ($('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').length === 0) {
798 $(this).after('<input type="hidden" name="sticky_bar_show_on_all_pages" value="yes" />');
799 }
800
801 if ($(this).is(':checked')) {
802 $('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').val('yes');
803 $('select[name="sticky_bar_pages[]"').attr('disabled', true);
804 } else {
805 $('input[type="hidden"][name="sticky_bar_show_on_all_pages"]').val('no');
806 $('select[name="sticky_bar_pages[]"').attr('disabled', false);
807 }
808 }).change();
809 $('.js-hurrytimer-restart-coundown'); // Display tooltips
810
811 $('#hurrytimer-settings').tooltip({
812 tooltipClass: 'hurryt-tooltip',
813 content: function content() {
814 return $(this).prop('title');
815 },
816 position: {
817 my: 'center bottom-20',
818 at: 'center top',
819 using: function using(position, feedback) {
820 $(this).css(position);
821 $('<div>').addClass('arrow').addClass(feedback.vertical).addClass(feedback.horizontal).appendTo(this);
822 }
823 }
824 });
825 })(jQuery);
826 //# sourceMappingURL=admin.js.map
827