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

446 lines 16.4 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 campaignPreviewRef = $('.hurrytimer-campaign');
12 var headlinePreviewRef = campaignPreviewRef.find('.hurrytimer-headline');
13 var timerPreviewRef = campaignPreviewRef.find('.hurrytimer-timer');
14 var timerDigitPreviewRef = campaignPreviewRef.find('.hurrytimer-timer-digit');
15 var timerLabelPreviewRef = campaignPreviewRef.find('.hurrytimer-timer-label');
16 var timerBlockPreviewRef = campaignPreviewRef.find('.hurrytimer-timer-block');
17 var timerSepPreviewRef = campaignPreviewRef.find('.hurrytimer-timer-sep');
18
19 function setCSS(element, property, value) {
20 var apply = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
21 styles = _objectSpread({}, styles, _defineProperty({}, element.selector, _objectSpread({}, styles[element.selector], _defineProperty({}, property, value))));
22
23 if (apply) {
24 if ($('#hurryt-styles').length === 0) {
25 $('head').append('<style id="hurryt-styles"></style>');
26 }
27
28 var css = '';
29
30 for (var selector in styles) {
31 css += " ".concat(selector, "{ ").concat(Object.entries(styles[selector]).join(';').replace(/\,/g, ':'), "}");
32 }
33
34 $('#hurryt-styles').html(css);
35 }
36 }
37 /* Input toggle.
38 ------------------------------------------------
39 */
40
41
42 $('.js-hurrytimer-input-toggle').each(function () {
43 var input = $(this);
44 input.hide();
45 var toggle = $("<input \n type=\"hidden\" \n name=\"".concat(input.attr('name'), "\" \n value=\"no\" />\n <span \n class=\"hurrytimer-input-toggle\">\n </span>"));
46 input.before(toggle);
47
48 if (input.prop('checked')) {
49 toggle.addClass('is-on');
50 }
51
52 toggle.on('click', function () {
53 toggle.toggleClass('is-on');
54 input.attr('checked', !input.prop('checked'));
55 input.trigger('change');
56 });
57 }); // Datetime picker.
58 // ------------------------------------------------------------
59
60 $('.hurrytimer-datepicker').datetimepicker({
61 controlType: 'select',
62 dateFormat: 'yy-mm-dd',
63 timeFormat: 'hh:mm TT',
64 oneLine: true
65 }); // Handle mode toggle.
66 // ------------------------------------------------------------
67
68 function handleMode(elementRef) {
69 var evergreenModeSubfields = $('.hurryt-evergreen-mode-subfields');
70 var regularModeSubfields = $('.hurryt-regular-mode-subfields');
71
72 if (parseInt(elementRef.val()) === hurrytimer_ajax_object.mode.evergreen) {
73 evergreenModeSubfields.removeClass('hidden');
74 regularModeSubfields.addClass('hidden');
75 } else {
76 evergreenModeSubfields.addClass('hidden');
77 regularModeSubfields.removeClass('hidden');
78 }
79 } // Handle mode.
80
81
82 $('input[name=mode]').on('change', function () {
83 handleMode($(this));
84 });
85 handleMode($('input[name=mode]:checked')); // Handle products type dropdown.
86 // ------------------------------------------------------------
87
88 $('#hurrytimer-wc-products-selection-type').on('change', function () {
89 var $this = $(this);
90 var $selectedOption = $this.find('option:selected');
91 var $label = $('.hurrytimer-products-selection-type-label');
92 var $autocompleteWrap = $label.closest('.form-field');
93
94 if ($selectedOption.data('show-autocomplete')) {
95 $label.text($selectedOption.text());
96 $autocompleteWrap.removeClass('hidden');
97 } else {
98 $autocompleteWrap.addClass('hidden');
99 }
100 }).change(); // Handle tabs
101 // ------------------------------------------------------------
102
103 $('.hurrytimer-tabbar a').on('click', function (e) {
104 e.preventDefault();
105 var $tab = $(this);
106 $('.hurrytimer-tabcontent').removeClass('active');
107 $($tab.attr('href')).addClass('active');
108 $tab.parent().siblings().removeClass('active');
109 $tab.parent().addClass('active');
110 }); // Search for products/Categories
111 // ------------------------------------------------------------
112 // if ($.select2) {
113
114 $('#hurrytimer-wc-products-selection').select2({
115 placeholder: 'Search...',
116 width: '500',
117 minimumInputLength: 2,
118 ajax: {
119 url: hurrytimer_ajax_object.ajax_url,
120 dataType: 'json',
121 data: function data(params) {
122 return {
123 action: 'wcSearchProducts',
124 search: params.term,
125 exclude: $(this).val(),
126 productsSelection: $('#hurrytimer-wc-products-selection-type').val(),
127 type: 'public'
128 };
129 }
130 }
131 }); // }
132 // Color picker
133 // ------------------------------------------------------------
134
135 $('.hurrytimer-color-input').each(function () {
136 var self = $(this);
137 self.iris({
138 change: function change(event) {
139 changeColor(self, event.target.value);
140 },
141 clear: function clear() {
142 changeColor(self, '#000');
143 },
144 hide: true,
145 border: true
146 }).on('click focus', function (event) {
147 event.stopPropagation();
148 $('.iris-picker').hide();
149 $(this).parent().find('.iris-picker').show();
150 });
151 });
152 /**
153 * Change preview color.
154 *
155 * @param {object} inputElement
156 * @param {string} color
157 */
158
159 function changeColor(inputElement) {
160 var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
161
162 if (typeof inputElement === 'string') {
163 inputElement = $('input[name=' + inputElement + ']');
164 }
165
166 color = color || inputElement.val();
167 var preview = inputElement.parent().find('.hurrytimer-color-preview');
168 preview.css('background-color', color);
169 setCSS(preview, 'background-color', color);
170
171 switch (inputElement.attr('name')) {
172 case 'digit_color':
173 setCSS(timerDigitPreviewRef, 'color', color, false);
174 setCSS(timerSepPreviewRef, 'color', color);
175 break;
176
177 case 'block_border_color':
178 setCSS(timerBlockPreviewRef, 'border-color', color);
179 break;
180
181 case 'block_bg_color':
182 setCSS(timerBlockPreviewRef, 'background-color', color);
183 break;
184
185 case 'label_color':
186 setCSS(timerLabelPreviewRef, 'color', color);
187 break;
188
189 case 'headline_color':
190 setCSS(headlinePreviewRef, 'color', color);
191 }
192 } // Initialize preview items color.
193 // ------------------------------------------------------------
194
195
196 changeColor('digit_color');
197 changeColor('label_color');
198 changeColor('block_border_color');
199 changeColor('block_bg_color');
200 changeColor('headline_color'); // Handle settings tabs
201 // ------------------------------------------------------------
202 $('.hurrytimer-subtabbar a').on('click', function (e) {
203 e.preventDefault();
204 var self = $(this);
205 $('.hurrytimer-subtabcontent').each(function () {
206 $(this).removeClass('active');
207 });
208 $(self.attr('href')).addClass('active');
209 self.parent().siblings().removeClass('active');
210 self.parent().addClass('active'); }); // Accordion.
211 // ------------------------------------------------------------
212
213 $('.hurrytimer-accordion-heading').on('click', function () {
214 var self = $(this);
215 var containerElement = self.parent();
216
217 if (containerElement.hasClass('active')) {
218 containerElement.removeClass('active');
219 } else {
220 containerElement.addClass('active').siblings().removeClass('active');
221 }
222 }); // Visual style editor.
223 // ------------------------------------------------------------
224
225 $('input[name=digit_size]').on('input keyup paste change', function () {
226 var fontSize = parseInt($(this).val()) + 'px';
227 setCSS(timerDigitPreviewRef, 'font-size', fontSize, false);
228 setCSS(timerSepPreviewRef, 'font-size', fontSize);
229 }).change();
230 $('input[name=block_spacing]').on('input keyup paste change', function () {
231 var spacing = parseInt($(this).val()) + 'px'; // timerBlockPreviewRef.css(
232 // { 'margin-left': spacing, 'margin-right': spacing });
233
234 setCSS(timerBlockPreviewRef, 'margin-left', spacing, false);
235 setCSS(timerBlockPreviewRef, 'margin-right', spacing);
236 }).change();
237 $('input[name=block_padding]').on('input keyup paste change', function () {
238 var padding = parseInt($(this).val()) + 'px';
239 setCSS(timerBlockPreviewRef, 'padding', padding);
240 }).change();
241 $('input[name=label_size]').on('input keyup paste change', function () {
242 setCSS(timerLabelPreviewRef, 'font-size', parseInt($(this).val()) + 'px');
243 }).change();
244 $('input[name=block_border_width]').on('input keyup paste change', function () {
245 var borderSize = parseInt($(this).val());
246 var borderColor = $('input[name=block_border_color]').val() || 'transparent';
247 setCSS(timerBlockPreviewRef, 'border', borderColor + ' solid ' + borderSize + 'px');
248 }).change();
249 $('input[name=block_border_radius]').on('input keyup paste change', function () {
250 // timerBlockPreviewRef.css({ 'border-radius': $(this).val() + 'px' });
251 setCSS(timerBlockPreviewRef, 'border-radius', "".concat($(this).val(), "px"));
252 }).change();
253 $('input[name=block_size]').on('input keyup paste change', function () {
254 var value = parseInt($(this).val());
255 var size = value + 'px';
256
257 if (value === 0) {
258 size = 'auto';
259 }
260
261 setCSS(timerBlockPreviewRef, 'width', size, false);
262 setCSS(timerBlockPreviewRef, 'height', size);
263 }).change(); // Bind post title input (headline) to preview.
264
265 $('input[name=post_title]').on('input paste keyup change', function () {
266 headlinePreviewRef.html($(this).val().trim());
267 }).change();
268 $('select[name=headline_position]').on('change', function () {
269 if (parseInt($(this).val()) === hurrytimer_ajax_object.headline_pos.above_timer) {
270 headlinePreviewRef.after(timerPreviewRef);
271 } else {
272 headlinePreviewRef.before(timerPreviewRef);
273 }
274 }).change();
275 $('input[name=headline_size]').on('input keyup paste change', function () {
276 setCSS(headlinePreviewRef, 'font-size', parseInt($(this).val()) + 'px');
277 }).change();
278 $('select[name=label_case]').on('change', function () {
279 setCSS(timerLabelPreviewRef, 'text-transform', $(this).val());
280 }).change();
281 $('input[name=block_separator_visibility]').on('change', function () {
282 var self = $(this);
283
284 if (!self.is(':checked')) {
285 timerSepPreviewRef.addClass('hidden');
286 return;
287 }
288
289 timerBlockPreviewRef.each(function () {
290 if ($(this).hasClass('hidden')) {
291 $(this).next().addClass('hidden');
292 } else {
293 $(this).next().removeClass('hidden');
294 }
295 });
296 }).change();
297 $('#hurrytimer-days-visibility').on('change', function () {
298 toggleBlockVisibility($(this), campaignPreviewRef.find('[data-block=days]'));
299 }).change();
300 $('#hurrytimer-hours-visibility').on('change', function () {
301 toggleBlockVisibility($(this), campaignPreviewRef.find('[data-block=hours]'));
302 }).change();
303 $('#hurrytimer-minutes-visibility').on('change', function () {
304 toggleBlockVisibility($(this), campaignPreviewRef.find('[data-block=minutes]'));
305 }).change();
306 $('#hurrytimer-seconds-visibility').on('change', function () {
307 toggleBlockVisibility($(this), campaignPreviewRef.find('[data-block=seconds]'));
308 }).change();
309 $('#hurrytimer-headline-visibility').on('change', function () {
310 if ($(this).is(':checked')) {
311 headlinePreviewRef.removeClass('hidden');
312 } else {
313 headlinePreviewRef.addClass('hidden');
314 }
315 }).change();
316 /*
317 Toggle label visibility.
318 --------------------------------------------------------
319 */
320
321 $('#hurrytimer-label-visibility').on('change', function () {
322 if ($(this).is(':checked')) {
323 timerLabelPreviewRef.removeClass('hidden');
324 } else {
325 timerLabelPreviewRef.addClass('hidden');
326 }
327 }).change();
328
329 function toggleBlockVisibility(toggle, block) {
330 if (toggle.is(':checked')) {
331 block.removeClass('hidden');
332
333 if ($('input[name=block_separator_visibility]').is(':checked')) {
334 block.next().removeClass('hidden');
335 }
336 } else {
337 block.addClass('hidden');
338 block.next().addClass('hidden');
339 }
340 } // Input slider.
341 // ------------------------------------------------------------
342
343
344 var blockSizeSliderElement;
345 var blockSizeInputElement;
346 $('.hurrytimer-input-slider').each(function () {
347 var self = $(this);
348 var boundInputElement = $('input[name=' + self.data('input-name') + ']');
349 var min = parseInt(boundInputElement.attr('min')) || 0;
350 var max = parseInt(boundInputElement.attr('max')) || 100;
351
352 if (boundInputElement.attr('name') === 'block_size') {
353 min = parseInt($('input[name=digit_size]').val()) || min;
354 blockSizeSliderElement = self;
355 blockSizeInputElement = boundInputElement;
356 }
357
358 self.slider({
359 slide: function slide(event, ui) {
360 boundInputElement.val(ui.value);
361 boundInputElement.trigger('input');
362
363 if (boundInputElement.attr('name') === 'digit_size') {
364 $('input[name=block_size]').attr('min', ui.value);
365 blockSizeSliderElement.slider('option', 'min', ui.value);
366
367 if (blockSizeInputElement.val() < ui.value) {
368 blockSizeSliderElement.slider('option', 'value', ui.value);
369 blockSizeInputElement.val(ui.value);
370 blockSizeInputElement.trigger('input');
371 }
372 }
373 },
374 max: max,
375 min: min,
376 value: boundInputElement.val()
377 });
378 }); // ------------------------------------------------------------
379
380 $('body').on('click', function () {
381 $('.iris-picker').hide();
382 });
383 $('#hurrytimer-new-action').on('click', function () {
384 //removeIf(pro)
385 if ($('.hurrytimer-action-block').length === 1) {
386 $('#hurryt-upgrade-alert-actions-feat').modal({
387 closeExisting: true,
388 closeClass: 'hurryt-upgrade-alert-close',
389 closeText: ''
390 });
391 return;
392 } //endRemoveIf(pro)
393
394
395 var action = $('.hurrytimer-action-block').last().clone(true, true);
396 action.find('.hurrytimer-action-block-subfields').addClass('hidden');
397 var fields = action.find(':input');
398
399 for (var i = 0; i < fields.length; i++) {
400 fields[i].name = fields[i].name.replace(/actions\[(\d+)\]\[(\w+)\]/, function (fm, i, name) {
401 return 'actions[' + ++i + '][' + name + ']';
402 });
403 }
404
405 $(this).parent().before(action);
406 });
407 $('#hurrytimer-actions').on('change', '.hurrytimer-action-select', function () {
408 handleActionChange($(this));
409 });
410 $('.hurrytimer-action-select').each(function () {
411 handleActionChange($(this));
412 });
413
414 function handleActionChange(element) {
415 var action = element.find('option:selected');
416
417 if (+action.val() === 4 && +$('.hurrytimer-mode:checked').val() === 2) {
418 element.next('.hurryt-compat-info').removeClass('hidden');
419 } else {
420 element.next('.hurryt-compat-info').addClass('hidden');
421 }
422
423 var block = element.closest('.hurrytimer-action-block');
424 block.find('.hurrytimer-action-block-subfields').addClass('hidden');
425 block.find('.' + action.data('subfields')).removeClass('hidden');
426 }
427
428 $('#hurrytimer-actions').on('click', '.hurrytimer-delete-action', function () {
429 if ($('.hurrytimer-action-block').length === 1) return;
430 $(this).closest('.hurrytimer-action-block').remove();
431 });
432 $('input[name="labels[days]"]').on('input keyup paste', function () {
433 campaignPreviewRef.find('[data-block=days] .hurrytimer-timer-label').text($(this).val());
434 }).trigger('input');
435 $('input[name="labels[hours]"]').on('input keyup paste', function () {
436 campaignPreviewRef.find('[data-block=hours] .hurrytimer-timer-label').text($(this).val());
437 }).trigger('input');
438 $('input[name="labels[minutes]"]').on('input keyup paste', function () {
439 campaignPreviewRef.find('[data-block=minutes] .hurrytimer-timer-label').text($(this).val());
440 }).trigger('input');
441 $('input[name="labels[seconds]"]').on('input keyup paste', function () {
442 campaignPreviewRef.find('[data-block=seconds] .hurrytimer-timer-label').text($(this).val());
443 }).trigger('input');
444 })(jQuery);
445 //# sourceMappingURL=admin.js.map
446