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

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