oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

File too large to show in full — download it above (showing a truncated preview below).

1
2;(function (global, factory) {
3 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4 typeof define === 'function' && define.amd ? define(factory) :
5 global.jSuites = factory();
6}(this, (function () {
7
8var jSuites;
9/******/ (function() { // webpackBootstrap
10/******/ var __webpack_modules__ = ({
11
12/***/ 195:
13/***/ (function(module) {
14
15/**
16 * (c) jSuites Javascript Plugins and Web Components (v4)
17 *
18 * Website: https://jsuites.net
19 * Description: Create amazing web based applications.
20 * Plugin: Organogram
21 *
22 * MIT License
23 */
24
25;(function (global, factory) {
26 true ? module.exports = factory() :
27 0;
28}(this, (function () {
29
30 return (function(str) {
31 function int64(msint_32, lsint_32) {
32 this.highOrder = msint_32;
33 this.lowOrder = lsint_32;
34 }
35
36 var H = [new int64(0x6a09e667, 0xf3bcc908), new int64(0xbb67ae85, 0x84caa73b),
37 new int64(0x3c6ef372, 0xfe94f82b), new int64(0xa54ff53a, 0x5f1d36f1),
38 new int64(0x510e527f, 0xade682d1), new int64(0x9b05688c, 0x2b3e6c1f),
39 new int64(0x1f83d9ab, 0xfb41bd6b), new int64(0x5be0cd19, 0x137e2179)];
40
41 var K = [new int64(0x428a2f98, 0xd728ae22), new int64(0x71374491, 0x23ef65cd),
42 new int64(0xb5c0fbcf, 0xec4d3b2f), new int64(0xe9b5dba5, 0x8189dbbc),
43 new int64(0x3956c25b, 0xf348b538), new int64(0x59f111f1, 0xb605d019),
44 new int64(0x923f82a4, 0xaf194f9b), new int64(0xab1c5ed5, 0xda6d8118),
45 new int64(0xd807aa98, 0xa3030242), new int64(0x12835b01, 0x45706fbe),
46 new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, 0xd5ffb4e2),
47 new int64(0x72be5d74, 0xf27b896f), new int64(0x80deb1fe, 0x3b1696b1),
48 new int64(0x9bdc06a7, 0x25c71235), new int64(0xc19bf174, 0xcf692694),
49 new int64(0xe49b69c1, 0x9ef14ad2), new int64(0xefbe4786, 0x384f25e3),
50 new int64(0x0fc19dc6, 0x8b8cd5b5), new int64(0x240ca1cc, 0x77ac9c65),
51 new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),
52 new int64(0x5cb0a9dc, 0xbd41fbd4), new int64(0x76f988da, 0x831153b5),
53 new int64(0x983e5152, 0xee66dfab), new int64(0xa831c66d, 0x2db43210),
54 new int64(0xb00327c8, 0x98fb213f), new int64(0xbf597fc7, 0xbeef0ee4),
55 new int64(0xc6e00bf3, 0x3da88fc2), new int64(0xd5a79147, 0x930aa725),
56 new int64(0x06ca6351, 0xe003826f), new int64(0x14292967, 0x0a0e6e70),
57 new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),
58 new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, 0x9d95b3df),
59 new int64(0x650a7354, 0x8baf63de), new int64(0x766a0abb, 0x3c77b2a8),
60 new int64(0x81c2c92e, 0x47edaee6), new int64(0x92722c85, 0x1482353b),
61 new int64(0xa2bfe8a1, 0x4cf10364), new int64(0xa81a664b, 0xbc423001),
62 new int64(0xc24b8b70, 0xd0f89791), new int64(0xc76c51a3, 0x0654be30),
63 new int64(0xd192e819, 0xd6ef5218), new int64(0xd6990624, 0x5565a910),
64 new int64(0xf40e3585, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),
65 new int64(0x19a4c116, 0xb8d2d0c8), new int64(0x1e376c08, 0x5141ab53),
66 new int64(0x2748774c, 0xdf8eeb99), new int64(0x34b0bcb5, 0xe19b48a8),
67 new int64(0x391c0cb3, 0xc5c95a63), new int64(0x4ed8aa4a, 0xe3418acb),
68 new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, 0xd6b2b8a3),
69 new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),
70 new int64(0x84c87814, 0xa1f0ab72), new int64(0x8cc70208, 0x1a6439ec),
71 new int64(0x90befffa, 0x23631e28), new int64(0xa4506ceb, 0xde82bde9),
72 new int64(0xbef9a3f7, 0xb2c67915), new int64(0xc67178f2, 0xe372532b),
73 new int64(0xca273ece, 0xea26619c), new int64(0xd186b8c7, 0x21c0c207),
74 new int64(0xeada7dd6, 0xcde0eb1e), new int64(0xf57d4f7f, 0xee6ed178),
75 new int64(0x06f067aa, 0x72176fba), new int64(0x0a637dc5, 0xa2c898a6),
76 new int64(0x113f9804, 0xbef90dae), new int64(0x1b710b35, 0x131c471b),
77 new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),
78 new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, 0x9c100d4c),
79 new int64(0x4cc5d4be, 0xcb3e42b6), new int64(0x597f299c, 0xfc657e2a),
80 new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817)];
81
82 var W = new Array(64);
83 var a, b, c, d, e, f, g, h, i, j;
84 var T1, T2;
85 var charsize = 8;
86
87 function utf8_encode(str) {
88 return unescape(encodeURIComponent(str));
89 }
90
91 function str2binb(str) {
92 var bin = [];
93 var mask = (1 << charsize) - 1;
94 var len = str.length * charsize;
95
96 for (var i = 0; i < len; i += charsize) {
97 bin[i >> 5] |= (str.charCodeAt(i / charsize) & mask) << (32 - charsize - (i % 32));
98 }
99
100 return bin;
101 }
102
103 function binb2hex(binarray) {
104 var hex_tab = "0123456789abcdef";
105 var str = "";
106 var length = binarray.length * 4;
107 var srcByte;
108
109 for (var i = 0; i < length; i += 1) {
110 srcByte = binarray[i >> 2] >> ((3 - (i % 4)) * 8);
111 str += hex_tab.charAt((srcByte >> 4) & 0xF) + hex_tab.charAt(srcByte & 0xF);
112 }
113
114 return str;
115 }
116
117 function safe_add_2(x, y) {
118 var lsw, msw, lowOrder, highOrder;
119
120 lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF);
121 msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16);
122 lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
123
124 lsw = (x.highOrder & 0xFFFF) + (y.highOrder & 0xFFFF) + (msw >>> 16);
125 msw = (x.highOrder >>> 16) + (y.highOrder >>> 16) + (lsw >>> 16);
126 highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
127
128 return new int64(highOrder, lowOrder);
129 }
130
131 function safe_add_4(a, b, c, d) {
132 var lsw, msw, lowOrder, highOrder;
133
134 lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) + (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF);
135 msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) + (c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (lsw >>> 16);
136 lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
137
138 lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) + (c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) + (msw >>> 16);
139 msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) + (c.highOrder >>> 16) + (d.highOrder >>> 16) + (lsw >>> 16);
140 highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
141
142 return new int64(highOrder, lowOrder);
143 }
144
145 function safe_add_5(a, b, c, d, e) {
146 var lsw, msw, lowOrder, highOrder;
147
148 lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) + (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF) + (e.lowOrder & 0xFFFF);
149 msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) + (c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (e.lowOrder >>> 16) + (lsw >>> 16);
150 lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
151
152 lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) + (c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) + (e.highOrder & 0xFFFF) + (msw >>> 16);
153 msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) + (c.highOrder >>> 16) + (d.highOrder >>> 16) + (e.highOrder >>> 16) + (lsw >>> 16);
154 highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
155
156 return new int64(highOrder, lowOrder);
157 }
158
159 function maj(x, y, z) {
160 return new int64(
161 (x.highOrder & y.highOrder) ^ (x.highOrder & z.highOrder) ^ (y.highOrder & z.highOrder),
162 (x.lowOrder & y.lowOrder) ^ (x.lowOrder & z.lowOrder) ^ (y.lowOrder & z.lowOrder)
163 );
164 }
165
166 function ch(x, y, z) {
167 return new int64(
168 (x.highOrder & y.highOrder) ^ (~x.highOrder & z.highOrder),
169 (x.lowOrder & y.lowOrder) ^ (~x.lowOrder & z.lowOrder)
170 );
171 }
172
173 function rotr(x, n) {
174 if (n <= 32) {
175 return new int64(
176 (x.highOrder >>> n) | (x.lowOrder << (32 - n)),
177 (x.lowOrder >>> n) | (x.highOrder << (32 - n))
178 );
179 } else {
180 return new int64(
181 (x.lowOrder >>> n) | (x.highOrder << (32 - n)),
182 (x.highOrder >>> n) | (x.lowOrder << (32 - n))
183 );
184 }
185 }
186
187 function sigma0(x) {
188 var rotr28 = rotr(x, 28);
189 var rotr34 = rotr(x, 34);
190 var rotr39 = rotr(x, 39);
191
192 return new int64(
193 rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,
194 rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder
195 );
196 }
197
198 function sigma1(x) {
199 var rotr14 = rotr(x, 14);
200 var rotr18 = rotr(x, 18);
201 var rotr41 = rotr(x, 41);
202
203 return new int64(
204 rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder,
205 rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder
206 );
207 }
208
209 function gamma0(x) {
210 var rotr1 = rotr(x, 1), rotr8 = rotr(x, 8), shr7 = shr(x, 7);
211
212 return new int64(
213 rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder,
214 rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder
215 );
216 }
217
218 function gamma1(x) {
219 var rotr19 = rotr(x, 19);
220 var rotr61 = rotr(x, 61);
221 var shr6 = shr(x, 6);
222
223 return new int64(
224 rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder,
225 rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder
226 );
227 }
228
229 function shr(x, n) {
230 if (n <= 32) {
231 return new int64(
232 x.highOrder >>> n,
233 x.lowOrder >>> n | (x.highOrder << (32 - n))
234 );
235 } else {
236 return new int64(
237 0,
238 x.highOrder << (32 - n)
239 );
240 }
241 }
242
243 var str = utf8_encode(str);
244 var strlen = str.length*charsize;
245 str = str2binb(str);
246
247 str[strlen >> 5] |= 0x80 << (24 - strlen % 32);
248 str[(((strlen + 128) >> 10) << 5) + 31] = strlen;
249
250 for (var i = 0; i < str.length; i += 32) {
251 a = H[0];
252 b = H[1];
253 c = H[2];
254 d = H[3];
255 e = H[4];
256 f = H[5];
257 g = H[6];
258 h = H[7];
259
260 for (var j = 0; j < 80; j++) {
261 if (j < 16) {
262 W[j] = new int64(str[j*2 + i], str[j*2 + i + 1]);
263 } else {
264 W[j] = safe_add_4(gamma1(W[j - 2]), W[j - 7], gamma0(W[j - 15]), W[j - 16]);
265 }
266
267 T1 = safe_add_5(h, sigma1(e), ch(e, f, g), K[j], W[j]);
268 T2 = safe_add_2(sigma0(a), maj(a, b, c));
269 h = g;
270 g = f;
271 f = e;
272 e = safe_add_2(d, T1);
273 d = c;
274 c = b;
275 b = a;
276 a = safe_add_2(T1, T2);
277 }
278
279 H[0] = safe_add_2(a, H[0]);
280 H[1] = safe_add_2(b, H[1]);
281 H[2] = safe_add_2(c, H[2]);
282 H[3] = safe_add_2(d, H[3]);
283 H[4] = safe_add_2(e, H[4]);
284 H[5] = safe_add_2(f, H[5]);
285 H[6] = safe_add_2(g, H[6]);
286 H[7] = safe_add_2(h, H[7]);
287 }
288
289 var binarray = [];
290 for (var i = 0; i < H.length; i++) {
291 binarray.push(H[i].highOrder);
292 binarray.push(H[i].lowOrder);
293 }
294
295 return binb2hex(binarray);
296 });
297
298})));
299
300
301/***/ })
302
303/******/ });
304/************************************************************************/
305/******/ // The module cache
306/******/ var __webpack_module_cache__ = {};
307/******/
308/******/ // The require function
309/******/ function __webpack_require__(moduleId) {
310/******/ // Check if module is in cache
311/******/ var cachedModule = __webpack_module_cache__[moduleId];
312/******/ if (cachedModule !== undefined) {
313/******/ return cachedModule.exports;
314/******/ }
315/******/ // Create a new module (and put it into the cache)
316/******/ var module = __webpack_module_cache__[moduleId] = {
317/******/ // no module.id needed
318/******/ // no module.loaded needed
319/******/ exports: {}
320/******/ };
321/******/
322/******/ // Execute the module function
323/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
324/******/
325/******/ // Return the exports of the module
326/******/ return module.exports;
327/******/ }
328/******/
329/************************************************************************/
330/******/ /* webpack/runtime/compat get default export */
331/******/ !function() {
332/******/ // getDefaultExport function for compatibility with non-harmony modules
333/******/ __webpack_require__.n = function(module) {
334/******/ var getter = module && module.__esModule ?
335/******/ function() { return module['default']; } :
336/******/ function() { return module; };
337/******/ __webpack_require__.d(getter, { a: getter });
338/******/ return getter;
339/******/ };
340/******/ }();
341/******/
342/******/ /* webpack/runtime/define property getters */
343/******/ !function() {
344/******/ // define getter functions for harmony exports
345/******/ __webpack_require__.d = function(exports, definition) {
346/******/ for(var key in definition) {
347/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
348/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
349/******/ }
350/******/ }
351/******/ };
352/******/ }();
353/******/
354/******/ /* webpack/runtime/hasOwnProperty shorthand */
355/******/ !function() {
356/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
357/******/ }();
358/******/
359/************************************************************************/
360var __webpack_exports__ = {};
361// This entry need to be wrapped in an IIFE because it need to be in strict mode.
362!function() {
363"use strict";
364
365// EXPORTS
366__webpack_require__.d(__webpack_exports__, {
367 "default": function() { return /* binding */ jsuites; }
368});
369
370;// CONCATENATED MODULE: ./src/utils/dictionary.js
371// Update dictionary
372var setDictionary = function(d) {
373 if (! document.dictionary) {
374 document.dictionary = {}
375 }
376 // Replace the key into the dictionary and append the new ones
377 var t = null;
378 var i = null;
379 var k = Object.keys(d);
380 for (i = 0; i < k.length; i++) {
381 document.dictionary[k[i]] = d[k[i]];
382 }
383}
384
385// Translate
386var translate = function(t) {
387 if (typeof(document) !== "undefined" && document.dictionary) {
388 return document.dictionary[t] || t;
389 } else {
390 return t;
391 }
392}
393
394
395/* harmony default export */ var dictionary = ({ setDictionary, translate });
396;// CONCATENATED MODULE: ./src/utils/tracking.js
397 const Tracking = function(component, state) {
398 if (state === true) {
399 window['jSuitesStateControl'] = window['jSuitesStateControl'].filter(function(v) {
400 return v !== null;
401 });
402
403 // Start after all events
404 setTimeout(function() {
405 window['jSuitesStateControl'].push(component);
406 }, 0);
407
408 } else {
409 var index = window['jSuitesStateControl'].indexOf(component);
410 if (index >= 0) {
411 window['jSuitesStateControl'].splice(index, 1);
412 }
413 }
414}
415
416/* harmony default export */ var tracking = (Tracking);
417;// CONCATENATED MODULE: ./src/utils/helpers.js
418var Helpers = {};
419
420// Two digits
421Helpers.two = function(value) {
422 value = '' + value;
423 if (value.length == 1) {
424 value = '0' + value;
425 }
426 return value;
427}
428
429Helpers.focus = function(el) {
430 if (el.textContent.length) {
431 // Handle contenteditable elements
432 const range = document.createRange();
433 const sel = window.getSelection();
434
435 let node = el;
436 // Go as deep as possible to the last text node
437 while (node.lastChild) node = node.lastChild;
438 // Ensure it's a text node
439 if (node.nodeType === Node.TEXT_NODE) {
440 range.setStart(node, node.length);
441 } else {
442 range.setStart(node, node.childNodes.length);
443 }
444 range.collapse(true);
445 sel.removeAllRanges();
446 sel.addRange(range);
447
448 el.scrollLeft = el.scrollWidth;
449 }
450}
451
452Helpers.isNumeric = (function (num) {
453 if (typeof(num) === 'string') {
454 num = num.trim();
455 }
456 return !isNaN(num) && num !== null && num !== '';
457});
458
459Helpers.guid = function() {
460 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
461 var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
462 return v.toString(16);
463 });
464}
465
466Helpers.getNode = function() {
467 var node = document.getSelection().anchorNode;
468 if (node) {
469 return (node.nodeType == 3 ? node.parentNode : node);
470 } else {
471 return null;
472 }
473}
474/**
475 * Generate hash from a string
476 */
477Helpers.hash = function(str) {
478 var hash = 0, i, chr;
479
480 if (str.length === 0) {
481 return hash;
482 } else {
483 for (i = 0; i < str.length; i++) {
484 chr = str.charCodeAt(i);
485 if (chr > 32) {
486 hash = ((hash << 5) - hash) + chr;
487 hash |= 0;
488 }
489 }
490 }
491 return hash;
492}
493
494/**
495 * Generate a random color
496 */
497Helpers.randomColor = function(h) {
498 var lum = -0.25;
499 var hex = String('#' + Math.random().toString(16).slice(2, 8).toUpperCase()).replace(/[^0-9a-f]/gi, '');
500 if (hex.length < 6) {
501 hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
502 }
503 var rgb = [], c, i;
504 for (i = 0; i < 3; i++) {
505 c = parseInt(hex.substr(i * 2, 2), 16);
506 c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
507 rgb.push(("00" + c).substr(c.length));
508 }
509
510 // Return hex
511 if (h == true) {
512 return '#' + Helpers.two(rgb[0].toString(16)) + Helpers.two(rgb[1].toString(16)) + Helpers.two(rgb[2].toString(16));
513 }
514
515 return rgb;
516}
517
518Helpers.getWindowWidth = function() {
519 var w = window,
520 d = document,
521 e = d.documentElement,
522 g = d.getElementsByTagName('body')[0],
523 x = w.innerWidth || e.clientWidth || g.clientWidth;
524 return x;
525}
526
527Helpers.getWindowHeight = function() {
528 var w = window,
529 d = document,
530 e = d.documentElement,
531 g = d.getElementsByTagName('body')[0],
532 y = w.innerHeight|| e.clientHeight|| g.clientHeight;
533 return y;
534}
535
536Helpers.getPosition = function(e) {
537 if (e.changedTouches && e.changedTouches[0]) {
538 var x = e.changedTouches[0].pageX;
539 var y = e.changedTouches[0].pageY;
540 } else {
541 var x = (window.Event) ? e.pageX : e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
542 var y = (window.Event) ? e.pageY : e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
543 }
544
545 return [ x, y ];
546}
547
548Helpers.click = function(el) {
549 if (el.click) {
550 el.click();
551 } else {
552 var evt = new MouseEvent('click', {
553 bubbles: true,
554 cancelable: true,
555 view: window
556 });
557 el.dispatchEvent(evt);
558 }
559}
560
561Helpers.findElement = function(element, condition) {
562 var foundElement = false;
563
564 function path (element) {
565 if (element && ! foundElement) {
566 if (typeof(condition) == 'function') {
567 foundElement = condition(element)
568 } else if (typeof(condition) == 'string') {
569 if (element.classList && element.classList.contains(condition)) {
570 foundElement = element;
571 }
572 }
573 }
574
575 if (element.parentNode && ! foundElement) {
576 path(element.parentNode);
577 }
578 }
579
580 path(element);
581
582 return foundElement;
583}
584
585/* harmony default export */ var helpers = (Helpers);
586;// CONCATENATED MODULE: ./src/utils/path.js
587const isValidPathObj = function(o) {
588 return typeof o === 'object' || typeof o === 'function';
589}
590
591function Path(pathString, value, remove) {
592 // Ensure the path is a valid, non-empty string
593 if (typeof pathString !== 'string' || pathString.length === 0) {
594 return undefined;
595 }
596
597 // Split the path into individual keys and filter out empty keys
598 const keys = pathString.split('.');
599 if (keys.length === 0) {
600 return undefined;
601 }
602
603 // Start with the root object
604 let currentObject = this;
605
606 // Read mode: retrieve a value
607 if (typeof value === 'undefined' && typeof remove === 'undefined') {
608 // Traverse all keys
609 for (let i = 0; i < keys.length; i++) {
610 const key = keys[i];
611 // Check if the current object is valid and has the key
612 if (
613 currentObject != null &&
614 isValidPathObj(currentObject) &&
615 Object.prototype.hasOwnProperty.call(currentObject, key)
616 ) {
617 currentObject = currentObject[key];
618 } else {
619 // Return undefined if the path is invalid or currentObject is null/undefined
620 return undefined;
621 }
622 }
623 // Return the final value
624 return currentObject;
625 }
626
627 // Write mode: set or delete a value
628 // Traverse all keys except the last one
629 for (let i = 0; i < keys.length - 1; i++) {
630 const key = keys[i];
631
632 // Check if the current object is invalid (null/undefined or non-object)
633 if (currentObject == null || ! isValidPathObj(currentObject)) {
634 console.warn(`Cannot set value: path '${pathString}' blocked by invalid object at '${key}'`);
635 return false;
636 }
637
638 // If the key exists but is null/undefined or a non-object, replace it with an empty object
639 if (
640 Object.prototype.hasOwnProperty.call(currentObject, key) &&
641 (currentObject[key] == null || ! isValidPathObj(currentObject[key]))
642 ) {
643 currentObject[key] = {};
644 } else if (!Object.prototype.hasOwnProperty.call(currentObject, key)) {
645 // If the key doesn't exist, create an empty object
646 currentObject[key] = {};
647 }
648
649 // Move to the next level
650 currentObject = currentObject[key];
651 }
652
653 // Handle the final key
654 const finalKey = keys[keys.length - 1];
655
656 // Check if the current object is valid for setting/deleting
657 if (currentObject == null || ! isValidPathObj(currentObject)) {
658 return false;
659 }
660
661 // Delete the property if remove is true
662 if (remove === true) {
663 if (Object.prototype.hasOwnProperty.call(currentObject, finalKey)) {
664 delete currentObject[finalKey];
665 return true;
666 }
667 return false; // Nothing to delete
668 }
669
670 // Set the value
671 currentObject[finalKey] = value;
672 return true;
673}
674;// CONCATENATED MODULE: ./src/utils/sorting.js
675function Sorting(el, options) {
676 var obj = {};
677 obj.options = {};
678
679 var defaults = {
680 pointer: null,
681 direction: null,
682 ondragstart: null,
683 ondragend: null,
684 ondrop: null,
685 }
686
687 var dragElement = null;
688
689 // Loop through the initial configuration
690 for (var property in defaults) {
691 if (options && options.hasOwnProperty(property)) {
692 obj.options[property] = options[property];
693 } else {
694 obj.options[property] = defaults[property];
695 }
696 }
697
698 el.classList.add('jsorting');
699
700 el.addEventListener('dragstart', function(e) {
701 let target = e.target;
702 if (target.nodeType === 3) {
703 if (target.parentNode.getAttribute('draggable') === 'true') {
704 target = target.parentNode;
705 } else {
706 e.preventDefault();
707 e.stopPropagation();
708 return;
709 }
710 }
711
712 if (target.getAttribute('draggable') === 'true') {
713 let position = Array.prototype.indexOf.call(target.parentNode.children, target);
714 dragElement = {
715 element: target,
716 o: position,
717 d: position
718 }
719 target.style.opacity = '0.25';
720
721 if (typeof (obj.options.ondragstart) == 'function') {
722 obj.options.ondragstart(el, target, e);
723 }
724
725 e.dataTransfer.setDragImage(target,0,0);
726 }
727 });
728
729 el.addEventListener('dragover', function(e) {
730 e.preventDefault();
731
732 if (dragElement) {
733 if (getElement(e.target)) {
734 if (e.target.getAttribute('draggable') == 'true' && dragElement.element != e.target) {
735 if (!obj.options.direction) {
736 var condition = e.target.clientHeight / 2 > e.offsetY;
737 } else {
738 var condition = e.target.clientWidth / 2 > e.offsetX;
739 }
740
741 if (condition) {
742 e.target.parentNode.insertBefore(dragElement.element, e.target);
743 } else {
744 e.target.parentNode.insertBefore(dragElement.element, e.target.nextSibling);
745 }
746
747 dragElement.d = Array.prototype.indexOf.call(e.target.parentNode.children, dragElement.element);
748 }
749 }
750 }
751 });
752
753 el.addEventListener('dragleave', function(e) {
754 e.preventDefault();
755 });
756
757 el.addEventListener('dragend', function(e) {
758 e.preventDefault();
759
760 if (dragElement) {
761 if (typeof(obj.options.ondragend) == 'function') {
762 obj.options.ondragend(el, dragElement.element, e);
763 }
764
765 // Cancelled put element to the original position
766 if (dragElement.o < dragElement.d) {
767 e.target.parentNode.insertBefore(dragElement.element, e.target.parentNode.children[dragElement.o]);
768 } else {
769 e.target.parentNode.insertBefore(dragElement.element, e.target.parentNode.children[dragElement.o].nextSibling);
770 }
771
772 dragElement.element.style.opacity = '';
773 dragElement = null;
774 }
775 });
776
777 el.addEventListener('drop', function(e) {
778 e.preventDefault();
779
780 if (dragElement) {
781 if (dragElement.o !== dragElement.d) {
782 if (typeof (obj.options.ondrop) == 'function') {
783 obj.options.ondrop(el, dragElement.o, dragElement.d, dragElement.element, e.target, e);
784 }
785 }
786
787 dragElement.element.style.opacity = '';
788 dragElement = null;
789 }
790 });
791
792 var getElement = function(element) {
793 var sorting = false;
794
795 function path (element) {
796 if (element.className) {
797 if (element.classList.contains('jsorting')) {
798 sorting = true;
799 }
800 }
801
802 if (! sorting) {
803 path(element.parentNode);
804 }
805 }
806
807 path(element);
808
809 return sorting;
810 }
811
812 for (var i = 0; i < el.children.length; i++) {
813 if (! el.children[i].hasAttribute('draggable')) {
814 el.children[i].setAttribute('draggable', 'true');
815 }
816 }
817
818 el.val = function() {
819 var id = null;
820 var data = [];
821 for (var i = 0; i < el.children.length; i++) {
822 if (id = el.children[i].getAttribute('data-id')) {
823 data.push(id);
824 }
825 }
826 return data;
827 }
828
829 return el;
830}
831;// CONCATENATED MODULE: ./src/utils/lazyloading.js
832function LazyLoading(el, options) {
833 var obj = {}
834
835 // Mandatory options
836 if (! options.loadUp || typeof(options.loadUp) != 'function') {
837 options.loadUp = function() {
838 return false;
839 }
840 }
841 if (! options.loadDown || typeof(options.loadDown) != 'function') {
842 options.loadDown = function() {
843 return false;
844 }
845 }
846 // Timer ms
847 if (! options.timer) {
848 options.timer = 100;
849 }
850
851 // Timer
852 var timeControlLoading = null;
853
854 // Controls
855 var scrollControls = function(e) {
856 if (timeControlLoading == null) {
857 var event = false;
858 var scrollTop = el.scrollTop;
859 if (el.scrollTop + (el.clientHeight * 2) >= el.scrollHeight) {
860 if (options.loadDown()) {
861 if (scrollTop == el.scrollTop) {
862 el.scrollTop = el.scrollTop - (el.clientHeight);
863 }
864 event = true;
865 }
866 } else if (el.scrollTop <= el.clientHeight) {
867 if (options.loadUp()) {
868 if (scrollTop == el.scrollTop) {
869 el.scrollTop = el.scrollTop + (el.clientHeight);
870 }
871 event = true;
872 }
873 }
874
875 timeControlLoading = setTimeout(function() {
876 timeControlLoading = null;
877 }, options.timer);
878
879 if (event) {
880 if (typeof(options.onupdate) == 'function') {
881 options.onupdate();
882 }
883 }
884 }
885 }
886
887 // Onscroll
888 el.onscroll = function(e) {
889 scrollControls(e);
890 }
891
892 el.onwheel = function(e) {
893 scrollControls(e);
894 }
895
896 return obj;
897}
898;// CONCATENATED MODULE: ./src/plugins/ajax.js
899function Ajax() {
900 var Component = (function(options, complete) {
901 if (Array.isArray(options)) {
902 // Create multiple request controller
903 var multiple = {
904 instance: [],
905 complete: complete,
906 }
907
908 if (options.length > 0) {
909 for (var i = 0; i < options.length; i++) {
910 options[i].multiple = multiple;
911 multiple.instance.push(Component(options[i]));
912 }
913 }
914
915 return multiple;
916 }
917
918 if (! options.data) {
919 options.data = {};
920 }
921
922 if (options.type) {
923 options.method = options.type;
924 }
925
926 // Default method
927 if (! options.method) {
928 options.method = 'GET';
929 }
930
931 // Default type
932 if (! options.dataType) {
933 options.dataType = 'json';
934 }
935
936 if (options.data) {
937 // Parse object to variables format
938 var parseData = function (value, key) {
939 var vars = [];
940 if (value) {
941 var keys = Object.keys(value);
942 if (keys.length) {
943 for (var i = 0; i < keys.length; i++) {
944 if (key) {
945 var k = key + '[' + keys[i] + ']';
946 } else {
947 var k = keys[i];
948 }
949
950 if (value[k] instanceof FileList) {
951 vars[k] = value[keys[i]];
952 } else if (value[keys[i]] === null || value[keys[i]] === undefined) {
953 vars[k] = '';
954 } else if (typeof(value[keys[i]]) == 'object') {
955 var r = parseData(value[keys[i]], k);
956 var o = Object.keys(r);
957 for (var j = 0; j < o.length; j++) {
958 vars[o[j]] = r[o[j]];
959 }
960 } else {
961 vars[k] = value[keys[i]];
962 }
963 }
964 }
965 }
966
967 return vars;
968 }
969
970 var d = parseData(options.data);
971 var k = Object.keys(d);
972
973 // Data form
974 if (options.method == 'GET') {
975 if (k.length) {
976 var data = [];
977 for (var i = 0; i < k.length; i++) {
978 data.push(k[i] + '=' + encodeURIComponent(d[k[i]]));
979 }
980
981 if (options.url.indexOf('?') < 0) {
982 options.url += '?';
983 }
984 options.url += data.join('&');
985 }
986 } else {
987 var data = new FormData();
988 for (var i = 0; i < k.length; i++) {
989 if (d[k[i]] instanceof FileList) {
990 if (d[k[i]].length) {
991 for (var j = 0; j < d[k[i]].length; j++) {
992 data.append(k[i], d[k[i]][j], d[k[i]][j].name);
993 }
994 }
995 } else {
996 data.append(k[i], d[k[i]]);
997 }
998 }
999 }
1000 }
1001
1002 var httpRequest = new XMLHttpRequest();
1003 httpRequest.open(options.method, options.url, true);
1004
1005 if (options.requestedWith) {
1006 httpRequest.setRequestHeader('X-Requested-With', options.requestedWith);
1007 } else {
1008 if (options.requestedWith !== false) {
1009 httpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
1010 }
1011 }
1012
1013 // Content type
1014 if (options.contentType) {
1015 httpRequest.setRequestHeader('Content-Type', options.contentType);
1016 }
1017
1018 // Headers
1019 if (options.method === 'POST') {
1020 httpRequest.setRequestHeader('Accept', 'application/json');
1021 } else {
1022 if (options.dataType === 'blob') {
1023 httpRequest.responseType = "blob";
1024 } else {
1025 if (! options.contentType) {
1026 if (options.dataType === 'json') {
1027 httpRequest.setRequestHeader('Content-Type', 'text/json');
1028 } else if (options.dataType === 'html') {
1029 httpRequest.setRequestHeader('Content-Type', 'text/html');
1030 }
1031 }
1032 }
1033 }
1034
1035 // No cache
1036 if (options.cache !== true) {
1037 httpRequest.setRequestHeader('pragma', 'no-cache');
1038 httpRequest.setRequestHeader('cache-control', 'no-cache');
1039 }
1040
1041 // Authentication
1042 if (options.withCredentials === true) {
1043 httpRequest.withCredentials = true
1044 }
1045
1046 // Before send
1047 if (typeof(options.beforeSend) == 'function') {
1048 options.beforeSend(httpRequest);
1049 }
1050
1051 // Before send
1052 if (typeof(Component.beforeSend) == 'function') {
1053 Component.beforeSend(httpRequest);
1054 }
1055
1056 if (document.ajax && typeof(document.ajax.beforeSend) == 'function') {
1057 document.ajax.beforeSend(httpRequest);
1058 }
1059
1060 httpRequest.onerror = function() {
1061 if (options.error && typeof(options.error) == 'function') {
1062 options.error({
1063 message: 'Network error: Unable to reach the server.',
1064 status: 0
1065 });
1066 }
1067 }
1068
1069 httpRequest.ontimeout = function() {
1070 if (options.error && typeof(options.error) == 'function') {
1071 options.error({
1072 message: 'Request timed out after ' + httpRequest.timeout + 'ms.',
1073 status: 0
1074 });
1075 }
1076 }
1077
1078 httpRequest.onload = function() {
1079 if (httpRequest.status >= 200 && httpRequest.status < 300) {
1080 if (options.dataType === 'json') {
1081 try {
1082 var result = JSON.parse(httpRequest.responseText);
1083
1084 if (options.success && typeof(options.success) == 'function') {
1085 options.success(result);
1086 }
1087 } catch(err) {
1088 if (options.error && typeof(options.error) == 'function') {
1089 options.error(err, result);
1090 }
1091 }
1092 } else {
1093 if (options.dataType === 'blob') {
1094 var result = httpRequest.response;
1095 } else {
1096 var result = httpRequest.responseText;
1097 }
1098
1099 if (options.success && typeof(options.success) == 'function') {
1100 options.success(result);
1101 }
1102 }
1103 } else {
1104 if (options.error && typeof(options.error) == 'function') {
1105 options.error(httpRequest.responseText, httpRequest.status);
1106 }
1107 }
1108
1109 // Global queue
1110 if (Component.queue && Component.queue.length > 0) {
1111 Component.send(Component.queue.shift());
1112 }
1113
1114 // Global complete method
1115 if (Component.requests && Component.requests.length) {
1116 // Get index of this request in the container
1117 var index = Component.requests.indexOf(httpRequest);
1118 // Remove from the ajax requests container
1119 Component.requests.splice(index, 1);
1120 // Deprecated: Last one?
1121 if (! Component.requests.length) {
1122 // Object event
1123 if (options.complete && typeof(options.complete) == 'function') {
1124 options.complete(result);
1125 }
1126 }
1127 // Group requests
1128 if (options.group) {
1129 if (Component.oncomplete && typeof(Component.oncomplete[options.group]) == 'function') {
1130 if (! Component.pending(options.group)) {
1131 Component.oncomplete[options.group]();
1132 Component.oncomplete[options.group] = null;
1133 }
1134 }
1135 }
1136 // Multiple requests controller
1137 if (options.multiple && options.multiple.instance) {
1138 // Get index of this request in the container
1139 var index = options.multiple.instance.indexOf(httpRequest);
1140 // Remove from the ajax requests container
1141 options.multiple.instance.splice(index, 1);
1142 // If this is the last one call method complete
1143 if (! options.multiple.instance.length) {
1144 if (options.multiple.complete && typeof(options.multiple.complete) == 'function') {
1145 options.multiple.complete(result);
1146 }
1147 }
1148 }
1149 }
1150 }
1151
1152 // Keep the options
1153 httpRequest.options = options;
1154 // Data
1155 httpRequest.data = data;
1156
1157 // Queue
1158 if (options.queue === true && Component.requests.length > 0) {
1159 Component.queue.push(httpRequest);
1160 } else {
1161 Component.send(httpRequest)
1162 }
1163
1164 return httpRequest;
1165 });
1166
1167 Component.send = function(httpRequest) {
1168 if (httpRequest.data) {
1169 if (Array.isArray(httpRequest.data)) {
1170 httpRequest.send(httpRequest.data.join('&'));
1171 } else {
1172 httpRequest.send(httpRequest.data);
1173 }
1174 } else {
1175 httpRequest.send();
1176 }
1177
1178 Component.requests.push(httpRequest);
1179 }
1180
1181 Component.exists = function(url, __callback) {
1182 var http = new XMLHttpRequest();
1183 http.open('HEAD', url, false);
1184 http.send();
1185 if (http.status) {
1186 __callback(http.status);
1187 }
1188 }
1189
1190 Component.pending = function(group) {
1191 var n = 0;
1192 var o = Component.requests;
1193 if (o && o.length) {
1194 for (var i = 0; i < o.length; i++) {
1195 if (! group || group == o[i].options.group) {
1196 n++
1197 }
1198 }
1199 }
1200 return n;
1201 }
1202
1203 Component.oncomplete = {};
1204 Component.requests = [];
1205 Component.queue = [];
1206
1207 return Component
1208}
1209
1210/* harmony default export */ var ajax = (Ajax());
1211;// CONCATENATED MODULE: ./src/plugins/animation.js
1212function Animation() {
1213 const Component = {
1214 loading: {}
1215 }
1216
1217 Component.loading.show = function(timeout) {
1218 if (! Component.loading.element) {
1219 Component.loading.element = document.createElement('div');
1220 Component.loading.element.className = 'jloading';
1221 }
1222 document.body.appendChild(Component.loading.element);
1223
1224 // Max timeout in seconds
1225 if (timeout > 0) {
1226 setTimeout(function() {
1227 Component.loading.hide();
1228 }, timeout * 1000)
1229 }
1230 }
1231
1232 Component.loading.hide = function() {
1233 if (Component.loading.element && Component.loading.element.parentNode) {
1234 document.body.removeChild(Component.loading.element);
1235 }
1236 }
1237
1238 Component.slideLeft = function (element, direction, done) {
1239 if (direction == true) {
1240 element.classList.add('jslide-left-in');
1241 setTimeout(function () {
1242 element.classList.remove('jslide-left-in');
1243 if (typeof (done) == 'function') {
1244 done();
1245 }
1246 }, 400);
1247 } else {
1248 element.classList.add('jslide-left-out');
1249 setTimeout(function () {
1250 element.classList.remove('jslide-left-out');
1251 if (typeof (done) == 'function') {
1252 done();
1253 }
1254 }, 400);
1255 }
1256 }
1257
1258 Component.slideRight = function (element, direction, done) {
1259 if (direction === true) {
1260 element.classList.add('jslide-right-in');
1261 setTimeout(function () {
1262 element.classList.remove('jslide-right-in');
1263 if (typeof (done) == 'function') {
1264 done();
1265 }
1266 }, 400);
1267 } else {
1268 element.classList.add('jslide-right-out');
1269 setTimeout(function () {
1270 element.classList.remove('jslide-right-out');
1271 if (typeof (done) == 'function') {
1272 done();
1273 }
1274 }, 400);
1275 }
1276 }
1277
1278 Component.slideTop = function (element, direction, done) {
1279 if (direction === true) {
1280 element.classList.add('jslide-top-in');
1281 setTimeout(function () {
1282 element.classList.remove('jslide-top-in');
1283 if (typeof (done) == 'function') {
1284 done();
1285 }
1286 }, 400);
1287 } else {
1288 element.classList.add('jslide-top-out');
1289 setTimeout(function () {
1290 element.classList.remove('jslide-top-out');
1291 if (typeof (done) == 'function') {
1292 done();
1293 }
1294 }, 400);
1295 }
1296 }
1297
1298 Component.slideBottom = function (element, direction, done) {
1299 if (direction === true) {
1300 element.classList.add('jslide-bottom-in');
1301 setTimeout(function () {
1302 element.classList.remove('jslide-bottom-in');
1303 if (typeof (done) == 'function') {
1304 done();
1305 }
1306 }, 400);
1307 } else {
1308 element.classList.add('jslide-bottom-out');
1309 setTimeout(function () {
1310 element.classList.remove('jslide-bottom-out');
1311 if (typeof (done) == 'function') {
1312 done();
1313 }
1314 }, 100);
1315 }
1316 }
1317
1318 Component.fadeIn = function (element, done) {
1319 element.style.display = '';
1320 element.classList.add('jfade-in');
1321 setTimeout(function () {
1322 element.classList.remove('jfade-in');
1323 if (typeof (done) == 'function') {
1324 done();
1325 }
1326 }, 2000);
1327 }
1328
1329 Component.fadeOut = function (element, done) {
1330 element.classList.add('jfade-out');
1331 setTimeout(function () {
1332 element.style.display = 'none';
1333 element.classList.remove('jfade-out');
1334 if (typeof (done) == 'function') {
1335 done();
1336 }
1337 }, 1000);
1338 }
1339
1340 return Component;
1341}
1342
1343/* harmony default export */ var animation = (Animation());
1344;// CONCATENATED MODULE: ./src/utils/helpers.date.js
1345
1346
1347
1348function HelpersDate() {
1349 var Component = {};
1350
1351 Component.now = function (date, dateOnly) {
1352 var y = null;
1353 var m = null;
1354 var d = null;
1355 var h = null;
1356 var i = null;
1357 var s = null;
1358
1359 if (Array.isArray(date)) {
1360 y = date[0];
1361 m = date[1];
1362 d = date[2];
1363 h = date[3];
1364 i = date[4];
1365 s = date[5];
1366 } else {
1367 if (! date) {
1368 date = new Date();
1369 }
1370 y = date.getFullYear();
1371 m = date.getMonth() + 1;
1372 d = date.getDate();
1373 h = date.getHours();
1374 i = date.getMinutes();
1375 s = date.getSeconds();
1376 }
1377
1378 if (dateOnly == true) {
1379 return helpers.two(y) + '-' + helpers.two(m) + '-' + helpers.two(d);
1380 } else {
1381 return helpers.two(y) + '-' + helpers.two(m) + '-' + helpers.two(d) + ' ' + helpers.two(h) + ':' + helpers.two(i) + ':' + helpers.two(s);
1382 }
1383 }
1384
1385 Component.toArray = function (value) {
1386 var date = value.split(((value.indexOf('T') !== -1) ? 'T' : ' '));
1387 var time = date[1];
1388 var date = date[0].split('-');
1389 var y = parseInt(date[0]);
1390 var m = parseInt(date[1]);
1391 var d = parseInt(date[2]);
1392 var h = 0;
1393 var i = 0;
1394
1395 if (time) {
1396 time = time.split(':');
1397 h = parseInt(time[0]);
1398 i = parseInt(time[1]);
1399 }
1400 return [y, m, d, h, i, 0];
1401 }
1402
1403 var excelInitialTime = Date.UTC(1900, 0, 0);
1404 var excelLeapYearBug = Date.UTC(1900, 1, 29);
1405 var millisecondsPerDay = 86400000;
1406
1407 /**
1408 * Date to number
1409 */
1410 Component.dateToNum = function (jsDate) {
1411 if (typeof (jsDate) === 'string') {
1412 jsDate = new Date(jsDate + ' GMT+0');
1413 }
1414 var jsDateInMilliseconds = jsDate.getTime();
1415 if (jsDateInMilliseconds >= excelLeapYearBug) {
1416 jsDateInMilliseconds += millisecondsPerDay;
1417 }
1418 jsDateInMilliseconds -= excelInitialTime;
1419
1420 return jsDateInMilliseconds / millisecondsPerDay;
1421 }
1422
1423 /**
1424 * Number to date
1425 *
1426 * IMPORTANT: Excel incorrectly considers 1900 to be a leap year
1427 */
1428 Component.numToDate = function (excelSerialNumber) {
1429 var jsDateInMilliseconds = excelInitialTime + excelSerialNumber * millisecondsPerDay;
1430 if (jsDateInMilliseconds >= excelLeapYearBug) {
1431 jsDateInMilliseconds -= millisecondsPerDay;
1432 }
1433
1434 const d = new Date(jsDateInMilliseconds);
1435
1436 var date = [
1437 d.getUTCFullYear(),
1438 d.getUTCMonth() + 1,
1439 d.getUTCDate(),
1440 d.getUTCHours(),
1441 d.getUTCMinutes(),
1442 d.getUTCSeconds(),
1443 ];
1444
1445 return Component.now(date);
1446 }
1447
1448 let weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
1449 let months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
1450
1451 Object.defineProperty(Component, 'weekdays', {
1452 get: function () {
1453 return weekdays.map(function(v) {
1454 return dictionary.translate(v);
1455 });
1456 },
1457 });
1458
1459 Object.defineProperty(Component, 'weekdaysShort', {
1460 get: function () {
1461 return weekdays.map(function(v) {
1462 return dictionary.translate(v).substring(0,3);
1463 });
1464 },
1465 });
1466
1467 Object.defineProperty(Component, 'months', {
1468 get: function () {
1469 return months.map(function(v) {
1470 return dictionary.translate(v);
1471 });
1472 },
1473 });
1474
1475 Object.defineProperty(Component, 'monthsShort', {
1476 get: function () {
1477 return months.map(function(v) {
1478 return dictionary.translate(v).substring(0,3);
1479 });
1480 },
1481 });
1482
1483 return Component;
1484}
1485
1486/* harmony default export */ var helpers_date = (HelpersDate());
1487;// CONCATENATED MODULE: ./src/plugins/mask.js
1488
1489
1490
1491function Mask() {
1492 // Currency
1493 var tokens = {
1494 // Text
1495 text: [ '@' ],
1496 // Currency tokens
1497 currency: [ '#(.{1})##0?(.{1}0+)?( ?;(.*)?)?', '#' ],
1498 // Scientific
1499 scientific: [ '0{1}(.{1}0+)?E{1}\\+0+' ],
1500 // Percentage
1501 percentage: [ '0{1}(.{1}0+)?%' ],
1502 // Number
1503 numeric: [ '0{1}(.{1}0+)?' ],
1504 // Data tokens
1505 datetime: [ 'YYYY', 'YYY', 'YY', 'MMMMM', 'MMMM', 'MMM', 'MM', 'DDDDD', 'DDDD', 'DDD', 'DD', 'DY', 'DAY', 'WD', 'D', 'Q', 'MONTH', 'MON', 'HH24', 'HH12', 'HH', '\\[H\\]', 'H', 'AM/PM', 'MI', 'SS', 'MS', 'Y', 'M' ],
1506 // Other
1507 general: [ 'A', '0', '[0-9a-zA-Z\$]+', '.']
1508 }
1509
1510 var getDate = function() {
1511 if (this.mask.toLowerCase().indexOf('[h]') !== -1) {
1512 var m = 0;
1513 if (this.date[4]) {
1514 m = parseFloat(this.date[4] / 60);
1515 }
1516 var v = parseInt(this.date[3]) + m;
1517 v /= 24;
1518 } else if (! (this.date[0] && this.date[1] && this.date[2]) && (this.date[3] || this.date[4])) {
1519 v = helpers.two(this.date[3]) + ':' + helpers.two(this.date[4]) + ':' + helpers.two(this.date[5])
1520 } else {
1521 if (this.date[0] && this.date[1] && ! this.date[2]) {
1522 this.date[2] = 1;
1523 }
1524 v = helpers.two(this.date[0]) + '-' + helpers.two(this.date[1]) + '-' + helpers.two(this.date[2]);
1525
1526 if (this.date[3] || this.date[4] || this.date[5]) {
1527 v += ' ' + helpers.two(this.date[3]) + ':' + helpers.two(this.date[4]) + ':' + helpers.two(this.date[5]);
1528 }
1529 }
1530
1531 return v;
1532 }
1533
1534 var extractDate = function() {
1535 var v = '';
1536 if (! (this.date[0] && this.date[1] && this.date[2]) && (this.date[3] || this.date[4])) {
1537 if (this.mask.toLowerCase().indexOf('[h]') !== -1) {
1538 v = parseInt(this.date[3]);
1539 } else {
1540 let h = parseInt(this.date[3]);
1541 if (h < 13 && this.values.indexOf('PM') !== -1) {
1542 v = (h+12) % 24;
1543 } else {
1544 v = h % 24;
1545 }
1546 }
1547 if (this.date[4]) {
1548 v += parseFloat(this.date[4] / 60);
1549 }
1550 if (this.date[5]) {
1551 v += parseFloat(this.date[5] / 3600);
1552 }
1553 v /= 24;
1554 } else if (this.date[0] || this.date[1] || this.date[2] || this.date[3] || this.date[4] || this.date[5]) {
1555 if (this.date[0] && this.date[1] && ! this.date[2]) {
1556 this.date[2] = 1;
1557 }
1558 var t = helpers_date.now(this.date);
1559 v = helpers_date.dateToNum(t);
1560 }
1561
1562 if (isNaN(v)) {
1563 v = '';
1564 }
1565
1566 return v;
1567 }
1568
1569 var isBlank = function(v) {
1570 return v === null || v === '' || v === undefined ? true : false;
1571 }
1572
1573 var isFormula = function(value) {
1574 var v = (''+value)[0];
1575 return v == '=' ? true : false;
1576 }
1577
1578 var isNumeric = function(t) {
1579 return t === 'currency' || t === 'percentage' || t === 'scientific' || t === 'numeric' ? true : false;
1580 }
1581
1582 /**
1583 * Get the decimal defined in the mask configuration
1584 */
1585 var getDecimal = function(v) {
1586 if (v && Number(v) == v) {
1587 return '.';
1588 } else {
1589 if (this.options.decimal) {
1590 return this.options.decimal;
1591 } else {
1592 if (this.locale) {
1593 var t = Intl.NumberFormat(this.locale).format(1.1);
1594 return this.options.decimal = t[1];
1595 } else {
1596 if (! v) {
1597 v = this.mask;
1598 }
1599 var e = new RegExp('0{1}(.{1})0+', 'ig');
1600 var t = e.exec(v);
1601 if (t && t[1] && t[1].length == 1) {
1602 // Save decimal
1603 this.options.decimal = t[1];
1604 // Return decimal
1605 return t[1];
1606 } else {
1607 // Did not find any decimal last resort the default
1608 var e = new RegExp('#{1}(.{1})#+', 'ig');
1609 var t = e.exec(v);
1610 if (t && t[1] && t[1].length == 1) {
1611 if (t[1] === ',') {
1612 this.options.decimal = '.';
1613 } else {
1614 this.options.decimal = ',';
1615 }
1616 } else {
1617 this.options.decimal = '1.1'.toLocaleString().substring(1,2);
1618 }
1619 }
1620 }
1621 }
1622 }
1623
1624 if (this.options.decimal) {
1625 return this.options.decimal;
1626 } else {
1627 return null;
1628 }
1629 }
1630
1631 var ParseValue = function(v, decimal) {
1632 if (v == '') {
1633 return '';
1634 }
1635
1636 // Get decimal
1637 if (! decimal) {
1638 decimal = getDecimal.call(this);
1639 }
1640
1641 // New value
1642 v = (''+v).split(decimal);
1643
1644 // Signal
1645 var signal = v[0].match(/[-]+/g);
1646 if (signal && signal.length) {
1647 signal = true;
1648 } else {
1649 signal = false;
1650 }
1651
1652 v[0] = v[0].match(/[0-9]+/g);
1653
1654 if (v[0]) {
1655 if (signal) {
1656 v[0].unshift('-');
1657 }
1658 v[0] = v[0].join('');
1659 } else {
1660 if (signal) {
1661 v[0] = '-';
1662 }
1663 }
1664
1665 if (v[0] || v[1]) {
1666 if (v[1] !== undefined) {
1667 v[1] = v[1].match(/[0-9]+/g);
1668 if (v[1]) {
1669 v[1] = v[1].join('');
1670 } else {
1671 v[1] = '';
1672 }
1673 }
1674 } else {
1675 return '';
1676 }
1677 return v;
1678 }
1679
1680 var FormatValue = function(v, event) {
1681 if (v === '') {
1682 return '';
1683 }
1684 // Get decimal
1685 var d = getDecimal.call(this);
1686 // Convert value
1687 var o = this.options;
1688 // Parse value
1689 v = ParseValue.call(this, v);
1690 if (v === '') {
1691 return '';
1692 }
1693 var t = null;
1694 // Temporary value
1695 if (v[0]) {
1696 if (o.style === 'percent') {
1697 t = parseFloat(v[0]) / 100;
1698 } else {
1699 t = parseFloat(v[0] + '.1');
1700 }
1701 }
1702
1703 if ((v[0] === '-' || v[0] === '-00') && ! v[1] && (event && event.inputType == "deleteContentBackward")) {
1704 return '';
1705 }
1706
1707 var n = new Intl.NumberFormat(this.locale, o).format(t);
1708 n = n.split(d);
1709
1710 if (o.style === 'percent') {
1711 if (n[0].indexOf('%') !== -1) {
1712 n[0] = n[0].replace('%', '');
1713 n[2] = '%';
1714 }
1715 }
1716
1717 if (typeof(n[1]) !== 'undefined') {
1718 var s = n[1].replace(/[0-9]*/g, '');
1719 if (s) {
1720 n[2] = s;
1721 }
1722 }
1723
1724 if (v[1] !== undefined) {
1725 n[1] = d + v[1];
1726 } else {
1727 n[1] = '';
1728 }
1729
1730 return n.join('');
1731 }
1732
1733 var Format = function(e, event) {
1734 var v = Value.call(e);
1735 if (! v) {
1736 return;
1737 }
1738
1739 // Get decimal
1740 var n = FormatValue.call(this, v, event);
1741 var t = (n.length) - v.length;
1742 var index = Caret.call(e) + t;
1743 // Set value and update caret
1744 Value.call(e, n, index, true);
1745 }
1746
1747 var Extract = function(v) {
1748 // Keep the raw value
1749 var current = ParseValue.call(this, v);
1750 if (current) {
1751 // Negative values
1752 if (current[0] === '-') {
1753 current[0] = '-0';
1754 }
1755 return parseFloat(current.join('.'));
1756 }
1757 return null;
1758 }
1759
1760 /**
1761 * Caret getter and setter methods
1762 */
1763 var Caret = function(index, adjustNumeric) {
1764 if (index === undefined) {
1765 if (this.tagName == 'DIV') {
1766 var pos = 0;
1767 var s = window.getSelection();
1768 if (s) {
1769 if (s.rangeCount !== 0) {
1770 var r = s.getRangeAt(0);
1771 var p = r.cloneRange();
1772 p.selectNodeContents(this);
1773 p.setEnd(r.endContainer, r.endOffset);
1774 pos = p.toString().length;
1775 }
1776 }
1777 return pos;
1778 } else {
1779 return this.selectionStart;
1780 }
1781 } else {
1782 // Get the current value
1783 var n = Value.call(this);
1784
1785 // Review the position
1786 if (adjustNumeric) {
1787 var p = null;
1788 for (var i = 0; i < n.length; i++) {
1789 if (n[i].match(/[\-0-9]/g) || n[i] === '.' || n[i] === ',') {
1790 p = i;
1791 }
1792 }
1793
1794 // If the string has no numbers
1795 if (p === null) {
1796 p = n.indexOf(' ');
1797 }
1798
1799 if (index >= p) {
1800 index = p + 1;
1801 }
1802 }
1803
1804 // Do not update caret
1805 if (index > n.length) {
1806 index = n.length;
1807 }
1808
1809 if (index) {
1810 // Set caret
1811 if (this.tagName == 'DIV') {
1812 var s = window.getSelection();
1813 var r = document.createRange();
1814
1815 if (this.childNodes[0]) {
1816 r.setStart(this.childNodes[0], index);
1817 s.removeAllRanges();
1818 s.addRange(r);
1819 }
1820 } else {
1821 this.selectionStart = index;
1822 this.selectionEnd = index;
1823 }
1824 }
1825 }
1826 }
1827
1828 /**
1829 * Value getter and setter method
1830 */
1831 var Value = function(v, updateCaret, adjustNumeric) {
1832 if (this.tagName == 'DIV') {
1833 if (v === undefined) {
1834 var v = this.innerText;
1835 if (this.value && this.value.length > v.length) {
1836 v = this.value;
1837 }
1838 return v;
1839 } else {
1840 if (this.innerText !== v) {
1841 this.innerText = v;
1842
1843 if (updateCaret) {
1844 Caret.call(this, updateCaret, adjustNumeric);
1845 }
1846 }
1847 }
1848 } else {
1849 if (v === undefined) {
1850 return this.value;
1851 } else {
1852 if (this.value !== v) {
1853 this.value = v;
1854 if (updateCaret) {
1855 Caret.call(this, updateCaret, adjustNumeric);
1856 }
1857 }
1858 }
1859 }
1860 }
1861
1862 // Labels
1863 var weekDaysFull = helpers_date.weekdays;
1864 var weekDays = helpers_date.weekdaysShort;
1865 var monthsFull = helpers_date.months;
1866 var months = helpers_date.monthsShort;
1867
1868 var parser = {
1869 'YEAR': function(v, s) {
1870 var y = ''+new Date().getFullYear();
1871
1872 if (typeof(this.values[this.index]) === 'undefined') {
1873 this.values[this.index] = '';
1874 }
1875 if (parseInt(v) >= 0 && parseInt(v) <= 10) {
1876 if (this.values[this.index].length < s) {
1877 this.values[this.index] += v;
1878 }
1879 }
1880 if (this.values[this.index].length == s) {
1881 if (s == 2) {
1882 var y = y.substr(0,2) + this.values[this.index];
1883 } else if (s == 3) {
1884 var y = y.substr(0,1) + this.values[this.index];
1885 } else if (s == 4) {
1886 var y = this.values[this.index];
1887 }
1888 this.date[0] = y;
1889 this.index++;
1890 }
1891 },
1892 'YYYY': function(v) {
1893 parser.YEAR.call(this, v, 4);
1894 },
1895 'YYY': function(v) {
1896 parser.YEAR.call(this, v, 3);
1897 },
1898 'YY': function(v) {
1899 parser.YEAR.call(this, v, 2);
1900 },
1901 'FIND': function(v, a) {
1902 if (isBlank(this.values[this.index])) {
1903 this.values[this.index] = '';
1904 }
1905 if (this.event && this.event.inputType && this.event.inputType.indexOf('delete') > -1) {
1906 this.values[this.index] += v;
1907 return;
1908 }
1909 var pos = 0;
1910 var count = 0;
1911 var value = (this.values[this.index] + v).toLowerCase();
1912 for (var i = 0; i < a.length; i++) {
1913 if (a[i].toLowerCase().indexOf(value) == 0) {
1914 pos = i;
1915 count++;
1916 }
1917 }
1918 if (count > 1) {
1919 this.values[this.index] += v;
1920 } else if (count == 1) {
1921 // Jump number of chars
1922 var t = (a[pos].length - this.values[this.index].length) - 1;
1923 this.position += t;
1924
1925 this.values[this.index] = a[pos];
1926 this.index++;
1927 return pos;
1928 }
1929 },
1930 'MMM': function(v) {
1931 var ret = parser.FIND.call(this, v, months);
1932 if (ret !== undefined) {
1933 this.date[1] = ret + 1;
1934 }
1935 },
1936 'MON': function(v) {
1937 parser['MMM'].call(this, v);
1938 },
1939 'MMMM': function(v) {
1940 var ret = parser.FIND.call(this, v, monthsFull);
1941 if (ret !== undefined) {
1942 this.date[1] = ret + 1;
1943 }
1944 },
1945 'MONTH': function(v) {
1946 parser['MMMM'].call(this, v);
1947 },
1948 'MMMMM': function(v) {
1949 if (isBlank(this.values[this.index])) {
1950 this.values[this.index] = '';
1951 }
1952 var pos = 0;
1953 var count = 0;
1954 var value = (this.values[this.index] + v).toLowerCase();
1955 for (var i = 0; i < monthsFull.length; i++) {
1956 if (monthsFull[i][0].toLowerCase().indexOf(value) == 0) {
1957 this.values[this.index] = monthsFull[i][0];
1958 this.date[1] = i + 1;
1959 this.index++;
1960 break;
1961 }
1962 }
1963 },
1964 'MM': function(v) {
1965 if (isBlank(this.values[this.index])) {
1966 if (parseInt(v) > 1 && parseInt(v) < 10) {
1967 this.date[1] = this.values[this.index] = '0' + v;
1968 this.index++;
1969 } else if (parseInt(v) < 2) {
1970 this.values[this.index] = v;
1971 }
1972 } else {
1973 if (this.values[this.index] == 1 && parseInt(v) < 3) {
1974 this.date[1] = this.values[this.index] += v;
1975 this.index++;
1976 } else if (this.values[this.index] == 0 && parseInt(v) > 0 && parseInt(v) < 10) {
1977 this.date[1] = this.values[this.index] += v;
1978 this.index++;
1979 }
1980 }
1981 },
1982 'M': function(v) {
1983 var test = false;
1984 if (parseInt(v) >= 0 && parseInt(v) < 10) {
1985 if (isBlank(this.values[this.index])) {
1986 this.values[this.index] = v;
1987 if (v > 1) {
1988 this.date[1] = this.values[this.index];
1989 this.index++;
1990 }
1991 } else {
1992 if (this.values[this.index] == 1 && parseInt(v) < 3) {
1993 this.date[1] = this.values[this.index] += v;
1994 this.index++;
1995 } else if (this.values[this.index] == 0 && parseInt(v) > 0) {
1996 this.date[1] = this.values[this.index] += v;
1997 this.index++;
1998 } else {
1999 var test = true;
2000 }
2001 }
2002 } else {
2003 var test = true;
2004 }
2005
2006 // Re-test
2007 if (test == true) {
2008 var t = parseInt(this.values[this.index]);
2009 if (t > 0 && t < 12) {
2010 this.date[1] = this.values[this.index];
2011 this.index++;
2012 // Repeat the character
2013 this.position--;
2014 }
2015 }
2016 },
2017 'D': function(v) {
2018 var test = false;
2019 if (parseInt(v) >= 0 && parseInt(v) < 10) {
2020 if (isBlank(this.values[this.index])) {
2021 this.values[this.index] = v;
2022 if (parseInt(v) > 3) {
2023 this.date[2] = this.values[this.index];
2024 this.index++;
2025 }
2026 } else {
2027 if (this.values[this.index] == 3 && parseInt(v) < 2) {
2028 this.date[2] = this.values[this.index] += v;
2029 this.index++;
2030 } else if (this.values[this.index] == 1 || this.values[this.index] == 2) {
2031 this.date[2] = this.values[this.index] += v;
2032 this.index++;
2033 } else if (this.values[this.index] == 0 && parseInt(v) > 0) {
2034 this.date[2] = this.values[this.index] += v;
2035 this.index++;
2036 } else {
2037 var test = true;
2038 }
2039 }
2040 } else {
2041 var test = true;
2042 }
2043
2044 // Re-test
2045 if (test == true) {
2046 var t = parseInt(this.values[this.index]);
2047 if (t > 0 && t < 32) {
2048 this.date[2] = this.values[this.index];
2049 this.index++;
2050 // Repeat the character
2051 this.position--;
2052 }
2053 }
2054 },
2055 'DD': function(v) {
2056 if (isBlank(this.values[this.index])) {
2057 if (parseInt(v) > 3 && parseInt(v) < 10) {
2058 this.date[2] = this.values[this.index] = '0' + v;
2059 this.index++;
2060 } else if (parseInt(v) < 10) {
2061 this.values[this.index] = v;
2062 }
2063 } else {
2064 if (this.values[this.index] == 3 && parseInt(v) < 2) {
2065 this.date[2] = this.values[this.index] += v;
2066 this.index++;
2067 } else if ((this.values[this.index] == 1 || this.values[this.index] == 2) && parseInt(v) < 10) {
2068 this.date[2] = this.values[this.index] += v;
2069 this.index++;
2070 } else if (this.values[this.index] == 0 && parseInt(v) > 0 && parseInt(v) < 10) {
2071 this.date[2] = this.values[this.index] += v;
2072 this.index++;
2073 }
2074 }
2075 },
2076 'DDD': function(v) {
2077 parser.FIND.call(this, v, weekDays);
2078 },
2079 'DY': function(v) {
2080 parser['DDD'].call(this, v);
2081 },
2082 'DDDD': function(v) {
2083 parser.FIND.call(this, v, weekDaysFull);
2084 },
2085 'DAY': function(v) {
2086 parser['DDDD'].call(this, v);
2087 },
2088 'HH12': function(v, two) {
2089 var test = false;
2090 if (parseInt(v) >= 0 && parseInt(v) < 10) {
2091 if (isBlank(this.values[this.index])) {
2092 if (parseInt(v) > 1 && parseInt(v) < 10) {
2093 if (two) {
2094 v = 0 + v;
2095 }
2096 this.date[3] = this.values[this.index] = v;
2097 this.index++;
2098 } else if (parseInt(v) < 10) {
2099 this.values[this.index] = v;
2100 }
2101 } else {
2102 if (this.values[this.index] == 1 && parseInt(v) < 3) {
2103 this.date[3] = this.values[this.index] += v;
2104 this.index++;
2105 } else if (this.values[this.index] < 1 && parseInt(v) < 10) {
2106 this.date[3] = this.values[this.index] += v;
2107 this.index++;
2108 } else {
2109 var test = true;
2110 }
2111 }
2112 } else {
2113 var test = true;
2114 }
2115
2116 // Re-test
2117 if (test == true) {
2118 var t = parseInt(this.values[this.index]);
2119 if (t >= 0 && t <= 12) {
2120 this.date[3] = this.values[this.index];
2121 this.index++;
2122 // Repeat the character
2123 this.position--;
2124 }
2125 }
2126 },
2127 'HH24': function(v, two) {
2128 var test = false;
2129 if (parseInt(v) >= 0 && parseInt(v) < 10) {
2130 if (this.values[this.index] == null || this.values[this.index] == '') {
2131 if (parseInt(v) > 2 && parseInt(v) < 10) {
2132 if (two) {
2133 v = 0 + v;
2134 }
2135 this.date[3] = this.values[this.index] = v;
2136 this.index++;
2137 } else if (parseInt(v) < 10) {
2138 this.values[this.index] = v;
2139 }
2140 } else {
2141 if (this.values[this.index] == 2 && parseInt(v) < 4) {
2142 if (! two && this.values[this.index] === '0') {
2143 this.values[this.index] = '';
2144 }
2145 this.date[3] = this.values[this.index] += v;
2146 this.index++;
2147 } else if (this.values[this.index] < 2 && parseInt(v) < 10) {
2148 if (! two && this.values[this.index] === '0') {
2149 this.values[this.index] = '';
2150 }
2151 this.date[3] = this.values[this.index] += v;
2152 this.index++;
2153 } else {
2154 var test = true;
2155 }
2156 }
2157 } else {
2158 var test = true;
2159 }
2160
2161 // Re-test
2162 if (test == true) {
2163 var t = parseInt(this.values[this.index]);
2164 if (t >= 0 && t < 24) {
2165 this.date[3] = this.values[this.index];
2166 this.index++;
2167 // Repeat the character
2168 this.position--;
2169 }
2170 }
2171 },
2172 'HH': function(v) {
2173 parser['HH24'].call(this, v, 1);
2174 },
2175 'H': function(v) {
2176 parser['HH24'].call(this, v, 0);
2177 },
2178 '\\[H\\]': function(v) {
2179 if (this.values[this.index] == undefined) {
2180 this.values[this.index] = '';
2181 }
2182 if (v.match(/[0-9]/g)) {
2183 this.date[3] = this.values[this.index] += v;
2184 } else {
2185 if (this.values[this.index].match(/[0-9]/g)) {
2186 this.date[3] = this.values[this.index];
2187 this.index++;
2188 // Repeat the character
2189 this.position--;
2190 }
2191 }
2192 },
2193 'N60': function(v, i) {
2194 if (this.values[this.index] == null || this.values[this.index] == '') {
2195 if (parseInt(v) > 5 && parseInt(v) < 10) {
2196 this.date[i] = this.values[this.index] = '0' + v;
2197 this.index++;
2198 } else if (parseInt(v) < 10) {
2199 this.values[this.index] = v;
2200 }
2201 } else {
2202 if (parseInt(v) < 10) {
2203 this.date[i] = this.values[this.index] += v;
2204 this.index++;
2205 }
2206 }
2207 },
2208 'MI': function(v) {
2209 parser.N60.call(this, v, 4);
2210 },
2211 'SS': function(v) {
2212 parser.N60.call(this, v, 5);
2213 },
2214 'AM/PM': function(v) {
2215 if (typeof(this.values[this.index]) === 'undefined') {
2216 this.values[this.index] = '';
2217 }
2218
2219 if (this.values[this.index] === '') {
2220 if (v.match(/a/i) && this.date[3] < 13) {
2221 this.values[this.index] += 'A';
2222 } else if (v.match(/p/i)) {
2223 this.values[this.index] += 'P';
2224 }
2225 } else if (this.values[this.index] === 'A' || this.values[this.index] === 'P') {
2226 this.values[this.index] += 'M';
2227 this.index++;
2228 }
2229 },
2230 'WD': function(v) {
2231 if (typeof(this.values[this.index]) === 'undefined') {
2232 this.values[this.index] = '';
2233 }
2234 if (parseInt(v) >= 0 && parseInt(v) < 7) {
2235 this.values[this.index] = v;
2236 }
2237 if (this.values[this.index].length == 1) {
2238 this.index++;
2239 }
2240 },
2241 '0{1}(.{1}0+)?': function(v) {
2242 // Get decimal
2243 var decimal = getDecimal.call(this);
2244 // Negative number
2245 var neg = false;
2246 // Create if is blank
2247 if (isBlank(this.values[this.index])) {
2248 this.values[this.index] = '';
2249 } else {
2250 if (this.values[this.index] == '-') {
2251 neg = true;
2252 }
2253 }
2254 var current = ParseValue.call(this, this.values[this.index], decimal);
2255 if (current) {
2256 this.values[this.index] = current.join(decimal);
2257 }
2258 // New entry
2259 if (parseInt(v) >= 0 && parseInt(v) < 10) {
2260 // Replace the zero for a number
2261 if (this.values[this.index] == '0' && v > 0) {
2262 this.values[this.index] = '';
2263 } else if (this.values[this.index] == '-0' && v > 0) {
2264 this.values[this.index] = '-';
2265 }
2266 // Don't add up zeros because does not mean anything here
2267 if ((this.values[this.index] != '0' && this.values[this.index] != '-0') || v == decimal) {
2268 this.values[this.index] += v;
2269 }
2270 } else if (decimal && v == decimal) {
2271 if (this.values[this.index].indexOf(decimal) == -1) {
2272 if (! this.values[this.index]) {
2273 this.values[this.index] = '0';
2274 }
2275 this.values[this.index] += v;
2276 }
2277 } else if (v == '-') {
2278 // Negative signed
2279 neg = true;
2280 }
2281
2282 if (neg === true && this.values[this.index][0] !== '-') {
2283 this.values[this.index] = '-' + this.values[this.index];
2284 }
2285 },
2286 '0{1}(.{1}0+)?E{1}\\+0+': function(v) {
2287 parser['0{1}(.{1}0+)?'].call(this, v);
2288 },
2289 '0{1}(.{1}0+)?%': function(v) {
2290 parser['0{1}(.{1}0+)?'].call(this, v);
2291
2292 if (this.values[this.index].match(/[\-0-9]/g)) {
2293 if (this.values[this.index] && this.values[this.index].indexOf('%') == -1) {
2294 this.values[this.index] += '%';
2295 }
2296 } else {
2297 this.values[this.index] = '';
2298 }
2299 },
2300 '#(.{1})##0?(.{1}0+)?( ?;(.*)?)?': function(v) {
2301 // Parse number
2302 parser['0{1}(.{1}0+)?'].call(this, v);
2303 // Get decimal
2304 var decimal = getDecimal.call(this);
2305 // Get separator
2306 var separator = this.tokens[this.index].substr(1,1);
2307 // Negative
2308 var negative = this.values[this.index][0] === '-' ? true : false;
2309 // Current value
2310 var current = ParseValue.call(this, this.values[this.index], decimal);
2311
2312 // Get main and decimal parts
2313 if (current !== '') {
2314 // Format number
2315 var n = current[0].match(/[0-9]/g);
2316 if (n) {
2317 // Format
2318 n = n.join('');
2319 var t = [];
2320 var s = 0;
2321 for (var j = n.length - 1; j >= 0 ; j--) {
2322 t.push(n[j]);
2323 s++;
2324 if (! (s % 3)) {
2325 t.push(separator);
2326 }
2327 }
2328 t = t.reverse();
2329 current[0] = t.join('');
2330 if (current[0].substr(0,1) == separator) {
2331 current[0] = current[0].substr(1);
2332 }
2333 } else {
2334 current[0] = '';
2335 }
2336
2337 // Value
2338 this.values[this.index] = current.join(decimal);
2339
2340 // Negative
2341 if (negative) {
2342 this.values[this.index] = '-' + this.values[this.index];
2343 }
2344 }
2345 },
2346 '0': function(v) {
2347 if (v.match(/[0-9]/g)) {
2348 this.values[this.index] = v;
2349 this.index++;
2350 }
2351 },
2352 '[0-9a-zA-Z$]+': function(v) {
2353 if (isBlank(this.values[this.index])) {
2354 this.values[this.index] = '';
2355 }
2356 var t = this.tokens[this.index];
2357 var s = this.values[this.index];
2358 var i = s.length;
2359
2360 if (t[i] == v) {
2361 this.values[this.index] += v;
2362
2363 if (this.values[this.index] == t) {
2364 this.index++;
2365 }
2366 } else {
2367 this.values[this.index] = t;
2368 this.index++;
2369
2370 if (v.match(/[\-0-9]/g)) {
2371 // Repeat the character
2372 this.position--;
2373 }
2374 }
2375 },
2376 'A': function(v) {
2377 if (v.match(/[a-zA-Z]/gi)) {
2378 this.values[this.index] = v;
2379 this.index++;
2380 }
2381 },
2382 '.': function(v) {
2383 parser['[0-9a-zA-Z$]+'].call(this, v);
2384 },
2385 '@': function(v) {
2386 if (isBlank(this.values[this.index])) {
2387 this.values[this.index] = '';
2388 }
2389 this.values[this.index] += v;
2390 }
2391 }
2392
2393 /**
2394 * Get the tokens in the mask string
2395 */
2396 var getTokens = function(str) {
2397 if (this.type == 'general') {
2398 var t = [].concat(tokens.general);
2399 } else {
2400 var t = [].concat(tokens.currency, tokens.datetime, tokens.percentage, tokens.scientific, tokens.numeric, tokens.text, tokens.general);
2401 }
2402 // Expression to extract all tokens from the string
2403 var e = new RegExp(t.join('|'), 'gi');
2404 // Extract
2405 return str.match(e);
2406 }
2407
2408 /**
2409 * Get the method of one given token
2410 */
2411 var getMethod = function(str) {
2412 if (! this.type) {
2413 var types = Object.keys(tokens);
2414 } else if (this.type == 'text') {
2415 var types = [ 'text' ];
2416 } else if (this.type == 'general') {
2417 var types = [ 'general' ];
2418 } else if (this.type == 'datetime') {
2419 var types = [ 'numeric', 'datetime', 'general' ];
2420 } else {
2421 var types = [ 'currency', 'percentage', 'scientific', 'numeric', 'general' ];
2422 }
2423
2424 // Found
2425 for (var i = 0; i < types.length; i++) {
2426 var type = types[i];
2427 for (var j = 0; j < tokens[type].length; j++) {
2428 var e = new RegExp(tokens[type][j], 'gi');
2429 var r = str.match(e);
2430 if (r) {
2431 return { type: type, method: tokens[type][j] }
2432 }
2433 }
2434 }
2435 }
2436
2437 /**
2438 * Identify each method for each token
2439 */
2440 var getMethods = function(t) {
2441 var result = [];
2442 for (var i = 0; i < t.length; i++) {
2443 var m = getMethod.call(this, t[i]);
2444 if (m) {
2445 result.push(m.method);
2446 } else {
2447 result.push(null);
2448 }
2449 }
2450
2451 // Compatibility with excel
2452 for (var i = 0; i < result.length; i++) {
2453 if (result[i] == 'MM') {
2454 // Not a month, correct to minutes
2455 if (result[i-1] && result[i-1].indexOf('H') >= 0) {
2456 result[i] = 'MI';
2457 } else if (result[i-2] && result[i-2].indexOf('H') >= 0) {
2458 result[i] = 'MI';
2459 } else if (result[i+1] && result[i+1].indexOf('S') >= 0) {
2460 result[i] = 'MI';
2461 } else if (result[i+2] && result[i+2].indexOf('S') >= 0) {
2462 result[i] = 'MI';
2463 }
2464 }
2465 }
2466
2467 return result;
2468 }
2469
2470 /**
2471 * Get the type for one given token
2472 */
2473 var getType = function(str) {
2474 var m = getMethod.call(this, str);
2475 if (m) {
2476 var type = m.type;
2477 }
2478
2479 if (type) {
2480 var numeric = 0;
2481 // Make sure the correct type
2482 var t = getTokens.call(this, str);
2483 for (var i = 0; i < t.length; i++) {
2484 m = getMethod.call(this, t[i]);
2485 if (m && isNumeric(m.type)) {
2486 numeric++;
2487 }
2488 }
2489 if (numeric > 1) {
2490 type = 'general';
2491 }
2492 }
2493
2494 return type;
2495 }
2496
2497 /**
2498 * Parse character per character using the detected tokens in the mask
2499 */
2500 var parse = function() {
2501 // Parser method for this position
2502 if (typeof(parser[this.methods[this.index]]) == 'function') {
2503 parser[this.methods[this.index]].call(this, this.value[this.position]);
2504 this.position++;
2505 } else {
2506 this.values[this.index] = this.tokens[this.index];
2507 this.index++;
2508 }
2509 }
2510
2511 var toPlainString = function(num) {
2512 return (''+ +num).replace(/(-?)(\d*)\.?(\d*)e([+-]\d+)/,
2513 function(a,b,c,d,e) {
2514 return e < 0
2515 ? b + '0.' + Array(1-e-c.length).join(0) + c + d
2516 : b + c + d + Array(e-d.length+1).join(0);
2517 });
2518 }
2519
2520 /**
2521 * Mask function
2522 * @param {mixed|string} JS input or a string to be parsed
2523 * @param {object|string} When the first param is a string, the second is the mask or object with the mask options
2524 */
2525 var obj = function(e, config, returnObject) {
2526 // Options
2527 var r = null;
2528 var t = null;
2529 var o = {
2530 // Element
2531 input: null,
2532 // Current value
2533 value: null,
2534 // Mask options
2535 options: {},
2536 // New values for each token found
2537 values: [],
2538 // Token position
2539 index: 0,
2540 // Character position
2541 position: 0,
2542 // Date raw values
2543 date: [0,0,0,0,0,0],
2544 // Raw number for the numeric values
2545 number: 0,
2546 }
2547
2548 // This is a JavaScript Event
2549 if (typeof(e) == 'object') {
2550 // Element
2551 o.input = e.target;
2552 // Current value
2553 o.value = Value.call(e.target);
2554 // Current caret position
2555 o.caret = Caret.call(e.target);
2556 // Mask
2557 if (t = e.target.getAttribute('data-mask')) {
2558 o.mask = t;
2559 }
2560 // Type
2561 if (t = e.target.getAttribute('data-type')) {
2562 o.type = t;
2563 }
2564 // Options
2565 if (e.target.mask) {
2566 if (e.target.mask.options) {
2567 o.options = e.target.mask.options;
2568 }
2569 if (e.target.mask.locale) {
2570 o.locale = e.target.mask.locale;
2571 }
2572 } else {
2573 // Locale
2574 if (t = e.target.getAttribute('data-locale')) {
2575 o.locale = t;
2576 if (o.mask) {
2577 o.options.style = o.mask;
2578 }
2579 }
2580 }
2581 // Extra configuration
2582 if (e.target.attributes && e.target.attributes.length) {
2583 for (var i = 0; i < e.target.attributes.length; i++) {
2584 var k = e.target.attributes[i].name;
2585 var v = e.target.attributes[i].value;
2586 if (k.substr(0,4) == 'data') {
2587 o.options[k.substr(5)] = v;
2588 }
2589 }
2590 }
2591 } else {
2592 // Options
2593 if (typeof(config) == 'string') {
2594 // Mask
2595 o.mask = config;
2596 } else {
2597 // Mask
2598 var k = Object.keys(config);
2599 for (var i = 0; i < k.length; i++) {
2600 o[k[i]] = config[k[i]];
2601 }
2602 }
2603
2604 if (typeof(e) === 'number') {
2605 // Get decimal
2606 getDecimal.call(o, o.mask);
2607 // Replace to the correct decimal
2608 e = (''+e).replace('.', o.options.decimal);
2609 }
2610
2611 // Current
2612 o.value = e;
2613
2614 if (o.input) {
2615 // Value
2616 Value.call(o.input, e);
2617 // Focus
2618 helpers.focus(o.input);
2619 // Caret
2620 o.caret = Caret.call(o.input);
2621 }
2622 }
2623
2624 // Mask detected start the process
2625 if (! isFormula(o.value) && (o.mask || o.locale)) {
2626 // Compatibility fixes
2627 if (o.mask) {
2628 // Remove []
2629 o.mask = o.mask.replace(new RegExp(/\[h]/),'|h|');
2630 o.mask = o.mask.replace(new RegExp(/\[.*?\]/),'');
2631 o.mask = o.mask.replace(new RegExp(/\|h\|/),'[h]');
2632 if (o.mask.indexOf(';') !== -1) {
2633 var t = o.mask.split(';');
2634 o.mask = t[0];
2635 }
2636 // Excel mask TODO: Improve
2637 if (o.mask.indexOf('##') !== -1) {
2638 var d = o.mask.split(';');
2639 if (d[0]) {
2640 if (typeof(e) == 'object') {
2641 d[0] = d[0].replace(new RegExp(/_\)/g), '');
2642 d[0] = d[0].replace(new RegExp(/_\(/g), '');
2643 }
2644 d[0] = d[0].replace('*', '\t');
2645 d[0] = d[0].replace(new RegExp(/_-/g), '');
2646 d[0] = d[0].replace(new RegExp(/_/g), '');
2647 d[0] = d[0].replace(new RegExp(/"/g), '');
2648 d[0] = d[0].replace('##0.###','##0.000');
2649 d[0] = d[0].replace('##0.##','##0.00');
2650 d[0] = d[0].replace('##0.#','##0.0');
2651 d[0] = d[0].replace('##0,###','##0,000');
2652 d[0] = d[0].replace('##0,##','##0,00');
2653 d[0] = d[0].replace('##0,#','##0,0');
2654 }
2655 o.mask = d[0];
2656 }
2657 // Remove back slashes
2658 if (o.mask.indexOf('\\') !== -1) {
2659 var d = o.mask.split(';');
2660 d[0] = d[0].replace(new RegExp(/\\/g), '');
2661 o.mask = d[0];
2662 }
2663 // Get type
2664 if (! o.type) {
2665 o.type = getType.call(o, o.mask);
2666 }
2667 // Get tokens
2668 o.tokens = getTokens.call(o, o.mask);
2669 }
2670
2671 // On new input
2672 if (typeof(e) !== 'object' || ! e.inputType || ! e.inputType.indexOf('insert') || ! e.inputType.indexOf('delete')) {
2673 // Start transformation
2674 if (o.locale) {
2675 if (o.input) {
2676 Format.call(o, o.input, e);
2677 } else {
2678 var newValue = FormatValue.call(o, o.value);
2679 }
2680 } else {
2681 // Get tokens
2682 o.methods = getMethods.call(o, o.tokens);
2683 o.event = e;
2684
2685 // Go through all tokes
2686 while (o.position < o.value.length && typeof(o.tokens[o.index]) !== 'undefined') {
2687 // Get the appropriate parser
2688 parse.call(o);
2689 }
2690
2691 // New value
2692 var newValue = o.values.join('');
2693
2694 // Add tokens to the end of string only if string is not empty
2695 if (isNumeric(o.type) && newValue !== '') {
2696 // Complement things in the end of the mask
2697 while (typeof(o.tokens[o.index]) !== 'undefined') {
2698 var t = getMethod.call(o, o.tokens[o.index]);
2699 if (t && t.type == 'general') {
2700 o.values[o.index] = o.tokens[o.index];
2701 }
2702 o.index++;
2703 }
2704
2705 var adjustNumeric = true;
2706 } else {
2707 var adjustNumeric = false;
2708 }
2709
2710 // New value
2711 newValue = o.values.join('');
2712
2713 // Reset value
2714 if (o.input) {
2715 t = newValue.length - o.value.length;
2716 if (t > 0) {
2717 var caret = o.caret + t;
2718 } else {
2719 var caret = o.caret;
2720 }
2721 Value.call(o.input, newValue, caret, adjustNumeric);
2722 }
2723 }
2724 }
2725
2726 // Update raw data
2727 if (o.input) {
2728 var label = null;
2729 if (isNumeric(o.type)) {
2730 let v = Value.call(o.input);
2731 // Extract the number
2732 o.number = Extract.call(o, v);
2733 // Keep the raw data as a property of the tag
2734 if (o.type == 'percentage' && (''+v).indexOf('%') !== -1) {
2735 label = obj.adjustPrecision(o.number / 100);
2736 } else {
2737 label = o.number;
2738 }
2739 } else if (o.type == 'datetime') {
2740 label = getDate.call(o);
2741
2742 if (o.date[0] && o.date[1] && o.date[2]) {
2743 o.input.setAttribute('data-completed', true);
2744 }
2745 }
2746
2747 if (label) {
2748 o.input.setAttribute('data-value', label);
2749 }
2750 }
2751
2752 if (newValue !== undefined) {
2753 if (returnObject) {
2754 return o;
2755 } else {
2756 return newValue;
2757 }
2758 }
2759 }
2760 }
2761
2762 obj.adjustPrecision = function(num) {
2763 if (typeof num === 'number' && !Number.isInteger(num)) {
2764 const v = num.toString().split('.');
2765
2766 if (v[1] && v[1].length > 10) {
2767 let t0 = 0;
2768 const t1 = v[1][v[1].length - 2];
2769
2770 if (t1 == 0 || t1 == 9) {
2771 for (let i = v[1].length - 2; i > 0; i--) {
2772 if (t0 >= 0 && v[1][i] == t1) {
2773 t0++;
2774 if (t0 > 6) {
2775 break;
2776 }
2777 } else {
2778 t0 = 0;
2779 break;
2780 }
2781 }
2782
2783 if (t0) {
2784 return parseFloat(parseFloat(num).toFixed(v[1].length - 1));
2785 }
2786 }
2787 }
2788 }
2789
2790 return num;
2791 }
2792
2793 // Get the type of the mask
2794 obj.getType = getType;
2795
2796 // Extract the tokens from a mask
2797 obj.prepare = function(str, o) {
2798 if (! o) {
2799 o = {};
2800 }
2801 return getTokens.call(o, str);
2802 }
2803
2804 /**
2805 * Apply the mask to a element (legacy)
2806 */
2807 obj.apply = function(e) {
2808 var v = Value.call(e.target);
2809 if (e.key.length == 1) {
2810 v += e.key;
2811 }
2812 Value.call(e.target, obj(v, e.target.getAttribute('data-mask')));
2813 }
2814
2815 /**
2816 * Legacy support
2817 */
2818 obj.run = function(value, mask, decimal) {
2819 return obj(value, { mask: mask, decimal: decimal });
2820 }
2821
2822 /**
2823 * Extract number from masked string
2824 */
2825 obj.extract = function(v, options, returnObject) {
2826 if (isBlank(v)) {
2827 return v;
2828 }
2829 if (typeof(options) != 'object') {
2830 return v;
2831 } else {
2832 options = Object.assign({}, options);
2833
2834 if (! options.options) {
2835 options.options = {};
2836 }
2837 }
2838
2839 // Compatibility
2840 if (! options.mask && options.format) {
2841 options.mask = options.format;
2842 }
2843
2844 // Remove []
2845 if (options.mask) {
2846 if (options.mask.indexOf(';') !== -1) {
2847 var t = options.mask.split(';');
2848 options.mask = t[0];
2849 }
2850 options.mask = options.mask.replace(new RegExp(/\[h]/),'|h|');
2851 options.mask = options.mask.replace(new RegExp(/\[.*?\]/),'');
2852 options.mask = options.mask.replace(new RegExp(/\|h\|/),'[h]');
2853 }
2854
2855 // Get decimal
2856 getDecimal.call(options, options.mask);
2857
2858 var type = null;
2859 var value = null;
2860
2861 if (options.type == 'percent' || options.options.style == 'percent') {
2862 type = 'percentage';
2863 } else if (options.mask) {
2864 type = getType.call(options, options.mask);
2865 }
2866
2867 if (type === 'text') {
2868 var o = {};
2869 value = v;
2870 } else if (type === 'general') {
2871 var o = obj(v, options, true);
2872
2873 value = v;
2874 } else if (type === 'datetime') {
2875 if (v instanceof Date) {
2876 v = obj.getDateString(v, options.mask);
2877 }
2878
2879 var o = obj(v, options, true);
2880
2881 if (helpers.isNumeric(v)) {
2882 value = v;
2883 } else {
2884 value = extractDate.call(o);
2885 }
2886 } else if (type === 'scientific') {
2887 value = v;
2888 if (typeof(v) === 'string') {
2889 value = Number(value);
2890 }
2891 var o = options;
2892 } else {
2893 value = Extract.call(options, v);
2894 // Percentage
2895 if (type === 'percentage' && (''+v).indexOf('%') !== -1) {
2896 value /= 100;
2897 }
2898 var o = options;
2899 }
2900
2901 o.value = value;
2902
2903 if (! o.type && type) {
2904 o.type = type;
2905 }
2906
2907 if (returnObject) {
2908 return o;
2909 } else {
2910 return value;
2911 }
2912 }
2913
2914 /**
2915 * Render
2916 */
2917 obj.render = function(value, options, fullMask, strict) {
2918 if (isBlank(value)) {
2919 return value;
2920 }
2921
2922 if (typeof(options) != 'object') {
2923 return value;
2924 } else {
2925 options = Object.assign({}, options);
2926
2927 if (! options.options) {
2928 options.options = {};
2929 }
2930 }
2931
2932 // Compatibility
2933 if (! options.mask && options.format) {
2934 options.mask = options.format;
2935 }
2936
2937 // Remove []
2938 if (options.mask) {
2939 if (options.mask.indexOf(';') !== -1) {
2940 var t = options.mask.split(';');
2941 if (! fullMask) {
2942 t[0] = t[0].replace(new RegExp(/_\)/g), '');
2943 t[0] = t[0].replace(new RegExp(/_\(/g), '');
2944 }
2945 options.mask = t[0];
2946 }
2947 options.mask = options.mask.replace(new RegExp(/\[h]/),'|h|');
2948 options.mask = options.mask.replace(new RegExp(/\[.*?\]/),'');
2949 options.mask = options.mask.replace(new RegExp(/\|h\|/),'[h]');
2950 }
2951
2952 var type = null;
2953 if (options.type == 'percent' || options.options.style == 'percent') {
2954 type = 'percentage';
2955 } else if (options.mask) {
2956 type = getType.call(options, options.mask);
2957 } else if (value instanceof Date) {
2958 type = 'datetime';
2959 }
2960
2961 // Fill with blanks
2962 var fillWithBlanks = false;
2963
2964 if (type =='datetime' || options.type == 'calendar') {
2965 var t = obj.getDateString(value, options.mask);
2966 if (t) {
2967 value = t;
2968 }
2969 if (options.mask && fullMask) {
2970 fillWithBlanks = true;
2971 }
2972 } else if (type === 'text') {
2973 // Parse number
2974 if (typeof(value) === 'number') {
2975 value = value.toString();
2976 }
2977 } else {
2978 // Parse number
2979 if (typeof(value) === 'string' && jSuites.isNumeric(value)) {
2980 value = Number(value);
2981 }
2982 // Percentage
2983 if (type === 'percentage') {
2984 value = obj.adjustPrecision(value*100);
2985 }
2986
2987 // Number of decimal places
2988 if (typeof(value) === 'number') {
2989 var t = null;
2990 if (options.mask && fullMask) {
2991 var d = getDecimal.call(options, options.mask);
2992 if (type === 'scientific') {
2993 if (options.mask.indexOf(d) !== -1) {
2994 let exp = options.mask.split('E');
2995 exp = exp[0].split(d);
2996 exp = ('' + exp[1].match(/[0-9]+/g))
2997 exp = exp.length;
2998 t = value.toExponential(exp);
2999 } else {
3000 t = value.toExponential(0);
3001 }
3002 } else {
3003 if (options.mask.indexOf(d) !== -1) {
3004 d = options.mask.split(d);
3005 d = (''+d[1].match(/[0-9]+/g))
3006 d = d.length;
3007 t = value.toFixed(d);
3008 let n = value.toString().split('.');
3009 let fraction = n[1];
3010 if (fraction && fraction.length > d && fraction[fraction.length-1] === '5') {
3011 t = parseFloat(n[0] + '.' + fraction + '1').toFixed(d);
3012 }
3013 } else {
3014 t = value.toFixed(0);
3015 }
3016
3017 // Handle scientific notation
3018 if ((''+t).indexOf('e') !== -1) {
3019 t = toPlainString(t);
3020 }
3021 }
3022 } else if (options.locale && fullMask) {
3023 // Append zeros
3024 var d = (''+value).split('.');
3025 if (options.options) {
3026 if (typeof(d[1]) === 'undefined') {
3027 d[1] = '';
3028 }
3029 var len = d[1].length;
3030 if (options.options.minimumFractionDigits > len) {
3031 for (var i = 0; i < options.options.minimumFractionDigits - len; i++) {
3032 d[1] += '0';
3033 }
3034 }
3035 }
3036 if (! d[1].length) {
3037 t = d[0]
3038 } else {
3039 t = d.join('.');
3040 }
3041 var len = d[1].length;
3042 if (options.options && options.options.maximumFractionDigits < len) {
3043 t = parseFloat(t).toFixed(options.options.maximumFractionDigits);
3044 }
3045 } else {
3046 t = toPlainString(value);
3047 }
3048
3049 if (t !== null) {
3050 value = t;
3051 // Get decimal
3052 getDecimal.call(options, options.mask);
3053 // Replace to the correct decimal
3054 if (options.options.decimal) {
3055 value = value.replace('.', options.options.decimal);
3056 }
3057 }
3058 } else {
3059 if (options.mask && fullMask) {
3060 fillWithBlanks = true;
3061 }
3062 }
3063 }
3064
3065 if (fillWithBlanks) {
3066 var s = options.mask.length - value.length;
3067 if (s > 0) {
3068 for (var i = 0; i < s; i++) {
3069 value += ' ';
3070 }
3071 }
3072 }
3073
3074 if (type === 'scientific') {
3075 if (! fullMask) {
3076 value = toPlainString(value);
3077 } else {
3078 return value;
3079 }
3080 }
3081
3082 if (type === 'numeric' && strict === false && typeof(value) === 'string') {
3083 return value;
3084 }
3085
3086 value = obj(value, options);
3087
3088 // Numeric mask, number of zeros
3089 if (fullMask && type === 'numeric') {
3090 var maskZeros = options.mask.match(new RegExp(/^[0]+$/gm));
3091 if (maskZeros && maskZeros.length === 1) {
3092 var maskLength = maskZeros[0].length;
3093 if (maskLength > 3) {
3094 value = '' + value;
3095 while (value.length < maskLength) {
3096 value = '0' + value;
3097 }
3098 }
3099 }
3100 }
3101
3102 return value;
3103 }
3104
3105 obj.set = function(e, m) {
3106 if (m) {
3107 e.setAttribute('data-mask', m);
3108 // Reset the value
3109 var event = new Event('input', {
3110 bubbles: true,
3111 cancelable: true,
3112 });
3113 e.dispatchEvent(event);
3114 }
3115 }
3116
3117 // Helper to extract date from a string
3118 obj.extractDateFromString = function (date, format) {
3119 var o = obj(date, { mask: format }, true);
3120
3121 // Check if in format Excel (Need difference with format date or type detected is numeric)
3122 if (date > 0 && Number(date) == date && (o.values.join("") !== o.value || o.type == "numeric")) {
3123 var d = new Date(Math.round((date - 25569) * 86400 * 1000));
3124 return d.getFullYear() + "-" + helpers.two(d.getMonth()) + "-" + helpers.two(d.getDate()) + ' 00:00:00';
3125 }
3126
3127 var complete = false;
3128
3129 if (o.values && o.values.length === o.tokens.length && o.values[o.values.length - 1].length >= o.tokens[o.tokens.length - 1].length) {
3130 complete = true;
3131 }
3132
3133 if (o.date[0] && o.date[1] && (o.date[2] || complete)) {
3134 if (!o.date[2]) {
3135 o.date[2] = 1;
3136 }
3137
3138 return o.date[0] + '-' + helpers.two(o.date[1]) + '-' + helpers.two(o.date[2]) + ' ' + helpers.two(o.date[3]) + ':' + helpers.two(o.date[4]) + ':' + helpers.two(o.date[5]);
3139 }
3140
3141 return '';
3142 }
3143
3144 // Helper to convert date into string
3145 obj.getDateString = function (value, options) {
3146 if (!options) {
3147 var options = {};
3148 }
3149
3150 // Labels
3151 if (options && typeof (options) == 'object') {
3152 if (options.format) {
3153 var format = options.format;
3154 } else if (options.mask) {
3155 var format = options.mask;
3156 }
3157 } else {
3158 var format = options;
3159 }
3160
3161 if (!format) {
3162 format = 'YYYY-MM-DD';
3163 }
3164
3165 // Convert to number of hours
3166 if (format.indexOf('[h]') >= 0) {
3167 var result = 0;
3168 if (value && helpers.isNumeric(value)) {
3169 result = parseFloat(24 * Number(value));
3170 if (format.indexOf('mm') >= 0) {
3171 var h = ('' + result).split('.');
3172 if (h[1]) {
3173 var d = 60 * parseFloat('0.' + h[1])
3174 d = parseFloat(d.toFixed(2));
3175 } else {
3176 var d = 0;
3177 }
3178 result = parseInt(h[0]) + ':' + helpers.two(d);
3179 }
3180 }
3181 return result;
3182 }
3183
3184 // Date instance
3185 if (value instanceof Date) {
3186 value = helpers_date.now(value);
3187 } else if (value && helpers.isNumeric(value)) {
3188 value = helpers_date.numToDate(value);
3189 }
3190
3191 // Tokens
3192 var tokens = ['DAY', 'WD', 'DDDD', 'DDD', 'DD', 'D', 'Q', 'HH24', 'HH12', 'HH', 'H', 'AM/PM', 'MI', 'SS', 'MS', 'YYYY', 'YYY', 'YY', 'Y', 'MONTH', 'MON', 'MMMMM', 'MMMM', 'MMM', 'MM', 'M', '.'];
3193
3194 // Expression to extract all tokens from the string
3195 var e = new RegExp(tokens.join('|'), 'gi');
3196 // Extract
3197 var t = format.match(e);
3198
3199 // Compatibility with excel
3200 for (var i = 0; i < t.length; i++) {
3201 if (t[i].toUpperCase() == 'MM') {
3202 // Not a month, correct to minutes
3203 if (t[i - 1] && t[i - 1].toUpperCase().indexOf('H') >= 0) {
3204 t[i] = 'mi';
3205 } else if (t[i - 2] && t[i - 2].toUpperCase().indexOf('H') >= 0) {
3206 t[i] = 'mi';
3207 } else if (t[i + 1] && t[i + 1].toUpperCase().indexOf('S') >= 0) {
3208 t[i] = 'mi';
3209 } else if (t[i + 2] && t[i + 2].toUpperCase().indexOf('S') >= 0) {
3210 t[i] = 'mi';
3211 }
3212 }
3213 }
3214
3215 // Object
3216 var o = {
3217 tokens: t
3218 }
3219
3220 // Value
3221 if (value) {
3222 var d = '' + value;
3223 var splitStr = (d.indexOf('T') !== -1) ? 'T' : ' ';
3224 d = d.split(splitStr);
3225
3226 var h = 0;
3227 var m = 0;
3228 var s = 0;
3229
3230 if (d[1]) {
3231 h = d[1].split(':');
3232 m = h[1] ? h[1] : 0;
3233 s = h[2] ? h[2] : 0;
3234 h = h[0] ? h[0] : 0;
3235 }
3236
3237 d = d[0].split('-');
3238
3239 let day = new Date(d[0], d[1], 0).getDate();
3240
3241 if (d[0] && d[1] && d[2] && d[0] > 0 && d[1] > 0 && d[1] < 13 && d[2] > 0 && d[2] <= day) {
3242
3243 // Data
3244 o.data = [d[0], d[1], d[2], h, m, s];
3245
3246 // Value
3247 o.value = [];
3248
3249 // Calendar instance
3250 var calendar = new Date(o.data[0], o.data[1] - 1, o.data[2], o.data[3], o.data[4], o.data[5]);
3251
3252 // Get method
3253 var get = function (i) {
3254 // Token
3255 var t = this.tokens[i];
3256 // Case token
3257 var s = t.toUpperCase();
3258 var v = null;
3259
3260 if (s === 'YYYY') {
3261 v = this.data[0];
3262 } else if (s === 'YYY') {
3263 v = this.data[0].substring(1, 4);
3264 } else if (s === 'YY') {
3265 v = this.data[0].substring(2, 4);
3266 } else if (s === 'Y') {
3267 v = this.data[0].substring(3, 4);
3268 } else if (t === 'MON') {
3269 v = helpers_date.months[calendar.getMonth()].substr(0, 3).toUpperCase();
3270 } else if (t === 'mon') {
3271 v = helpers_date.months[calendar.getMonth()].substr(0, 3).toLowerCase();
3272 } else if (t === 'MONTH') {
3273 v = helpers_date.months[calendar.getMonth()].toUpperCase();
3274 } else if (t === 'month') {
3275 v = helpers_date.months[calendar.getMonth()].toLowerCase();
3276 } else if (s === 'MMMMM') {
3277 v = helpers_date.months[calendar.getMonth()].substr(0, 1);
3278 } else if (s === 'MMMM' || t === 'Month') {
3279 v = helpers_date.months[calendar.getMonth()];
3280 } else if (s === 'MMM' || t == 'Mon') {
3281 v = helpers_date.months[calendar.getMonth()].substr(0, 3);
3282 } else if (s === 'MM') {
3283 v = helpers.two(this.data[1]);
3284 } else if (s === 'M') {
3285 v = calendar.getMonth() + 1;
3286 } else if (t === 'DAY') {
3287 v = helpers_date.weekdays[calendar.getDay()].toUpperCase();
3288 } else if (t === 'day') {
3289 v = helpers_date.weekdays[calendar.getDay()].toLowerCase();
3290 } else if (s === 'DDDD' || t == 'Day') {
3291 v = helpers_date.weekdays[calendar.getDay()];
3292 } else if (s === 'DDD') {
3293 v = helpers_date.weekdays[calendar.getDay()].substr(0, 3);
3294 } else if (s === 'DD') {
3295 v = helpers.two(this.data[2]);
3296 } else if (s === 'D') {
3297 v = parseInt(this.data[2]);
3298 } else if (s === 'Q') {
3299 v = Math.floor((calendar.getMonth() + 3) / 3);
3300 } else if (s === 'HH24' || s === 'HH') {
3301 v = this.data[3];
3302 if (v > 12 && this.tokens.indexOf('am/pm') !== -1) {
3303 v -= 12;
3304 }
3305 v = helpers.two(v);
3306 } else if (s === 'HH12') {
3307 if (this.data[3] > 12) {
3308 v = helpers.two(this.data[3] - 12);
3309 } else {
3310 v = helpers.two(this.data[3]);
3311 }
3312 } else if (s === 'H') {
3313 v = this.data[3];
3314 if (v > 12 && this.tokens.indexOf('am/pm') !== -1) {
3315 v -= 12;
3316 v = helpers.two(v);
3317 }
3318 } else if (s === 'MI') {
3319 v = helpers.two(this.data[4]);
3320 } else if (s === 'SS') {
3321 v = helpers.two(this.data[5]);
3322 } else if (s === 'MS') {
3323 v = calendar.getMilliseconds();
3324 } else if (s === 'AM/PM') {
3325 if (this.data[3] >= 12) {
3326 v = 'PM';
3327 } else {
3328 v = 'AM';
3329 }
3330 } else if (s === 'WD') {
3331 v = helpers_date.weekdays[calendar.getDay()];
3332 }
3333
3334 if (v === null) {
3335 this.value[i] = this.tokens[i];
3336 } else {
3337 this.value[i] = v;
3338 }
3339 }
3340
3341 for (var i = 0; i < o.tokens.length; i++) {
3342 get.call(o, i);
3343 }
3344 // Put pieces together
3345 value = o.value.join('');
3346 } else {
3347 value = '';
3348 }
3349 }
3350
3351 return value;
3352 }
3353
3354 return obj;
3355}
3356
3357/* harmony default export */ var mask = (Mask());
3358
3359;// CONCATENATED MODULE: ./src/plugins/calendar.js
3360
3361
3362
3363
3364
3365
3366
3367function Calendar() {
3368 var Component = (function (el, options) {
3369 // Already created, update options
3370 if (el.calendar) {
3371 return el.calendar.setOptions(options, true);
3372 }
3373
3374 // New instance
3375 var obj = {type: 'calendar'};
3376 obj.options = {};
3377
3378 // Date
3379 obj.date = null;
3380
3381 /**
3382 * Update options
3383 */
3384 obj.setOptions = function (options, reset) {
3385 // Default configuration
3386 var defaults = {
3387 // Render type: [ default | year-month-picker ]
3388 type: 'default',
3389 // Restrictions
3390 validRange: null,
3391 // Starting weekday - 0 for sunday, 6 for saturday
3392 startingDay: null,
3393 // Date format
3394 format: 'DD/MM/YYYY',
3395 // Allow keyboard date entry
3396 readonly: true,
3397 // Today is default
3398 today: false,
3399 // Show timepicker
3400 time: false,
3401 // Show the reset button
3402 resetButton: true,
3403 // Placeholder
3404 placeholder: '',
3405 // Translations can be done here
3406 months: helpers_date.monthsShort,
3407 monthsFull: helpers_date.months,
3408 weekdays: helpers_date.weekdays,
3409 textDone: dictionary.translate('Done'),
3410 textReset: dictionary.translate('Reset'),
3411 textUpdate: dictionary.translate('Update'),
3412 // Value
3413 value: null,
3414 // Fullscreen (this is automatic set for screensize < 800)
3415 fullscreen: false,
3416 // Create the calendar closed as default
3417 opened: false,
3418 // Events
3419 onopen: null,
3420 onclose: null,
3421 onchange: null,
3422 onupdate: null,
3423 // Internal mode controller
3424 mode: null,
3425 position: null,
3426 // Data type
3427 dataType: null,
3428 // Controls
3429 controls: true,
3430 // Auto select
3431 autoSelect: true,
3432 }
3433
3434 // Loop through our object
3435 for (var property in defaults) {
3436 if (options && options.hasOwnProperty(property)) {
3437 obj.options[property] = options[property];
3438 } else {
3439 if (typeof (obj.options[property]) == 'undefined' || reset === true) {
3440 obj.options[property] = defaults[property];
3441 }
3442 }
3443 }
3444
3445 // Reset button
3446 if (obj.options.resetButton == false) {
3447 calendarReset.style.display = 'none';
3448 } else {
3449 calendarReset.style.display = '';
3450 }
3451
3452 // Readonly
3453 if (obj.options.readonly) {
3454 el.setAttribute('readonly', 'readonly');
3455 } else {
3456 el.removeAttribute('readonly');
3457 }
3458
3459 // Placeholder
3460 if (obj.options.placeholder) {
3461 el.setAttribute('placeholder', obj.options.placeholder);
3462 } else {
3463 el.removeAttribute('placeholder');
3464 }
3465
3466 if (helpers.isNumeric(obj.options.value) && obj.options.value > 0) {
3467 obj.options.value = Component.numToDate(obj.options.value);
3468 // Data type numeric
3469 obj.options.dataType = 'numeric';
3470 }
3471
3472 // Texts
3473 calendarReset.innerHTML = obj.options.textReset;
3474 calendarConfirm.innerHTML = obj.options.textDone;
3475 calendarControlsUpdateButton.innerHTML = obj.options.textUpdate;
3476
3477 // Define mask
3478 if (obj.options.format) {
3479 el.setAttribute('data-mask', obj.options.format.toLowerCase());
3480 }
3481
3482 // Value
3483 if (!obj.options.value && obj.options.today) {
3484 var value = Component.now();
3485 } else {
3486 var value = obj.options.value;
3487 }
3488
3489 // Set internal date
3490 if (value) {
3491 // Force the update
3492 obj.options.value = null;
3493 // New value
3494 obj.setValue(value);
3495 }
3496
3497 return obj;
3498 }
3499
3500 /**
3501 * Open the calendar
3502 */
3503 obj.open = function (value) {
3504 if (!calendar.classList.contains('jcalendar-focus')) {
3505 if (!calendar.classList.contains('jcalendar-inline')) {
3506 // Current
3507 Component.current = obj;
3508 // Start tracking
3509 tracking(obj, true);
3510 // Create the days
3511 obj.getDays();
3512 // Render months
3513 if (obj.options.type == 'year-month-picker') {
3514 obj.getMonths();
3515 }
3516 // Get time
3517 if (obj.options.time) {
3518 calendarSelectHour.value = obj.date[3];
3519 calendarSelectMin.value = obj.date[4];
3520 }
3521
3522 // Show calendar
3523 calendar.classList.add('jcalendar-focus');
3524
3525 // Get the position of the corner helper
3526 if (helpers.getWindowWidth() < 800 || obj.options.fullscreen) {
3527 calendar.classList.add('jcalendar-fullsize');
3528 // Animation
3529 animation.slideBottom(calendarContent, 1);
3530 } else {
3531 calendar.classList.remove('jcalendar-fullsize');
3532
3533 var rect = el.getBoundingClientRect();
3534 var rectContent = calendarContent.getBoundingClientRect();
3535
3536 if (obj.options.position) {
3537 calendarContainer.style.position = 'fixed';
3538 if (window.innerHeight < rect.bottom + rectContent.height) {
3539 calendarContainer.style.top = (rect.top - (rectContent.height + 2)) + 'px';
3540 } else {
3541 calendarContainer.style.top = (rect.top + rect.height + 2) + 'px';
3542 }
3543 calendarContainer.style.left = rect.left + 'px';
3544 } else {
3545 if (window.innerHeight < rect.bottom + rectContent.height) {
3546 var d = -1 * (rect.height + rectContent.height + 2);
3547 if (d + rect.top < 0) {
3548 d = -1 * (rect.top + rect.height);
3549 }
3550 calendarContainer.style.top = d + 'px';
3551 } else {
3552 calendarContainer.style.top = 2 + 'px';
3553 }
3554
3555 if (window.innerWidth < rect.left + rectContent.width) {
3556 var d = window.innerWidth - (rect.left + rectContent.width + 20);
3557 calendarContainer.style.left = d + 'px';
3558 } else {
3559 calendarContainer.style.left = '0px';
3560 }
3561 }
3562 }
3563
3564 // Events
3565 if (typeof (obj.options.onopen) == 'function') {
3566 obj.options.onopen(el);
3567 }
3568 }
3569 }
3570 }
3571
3572 obj.close = function (ignoreEvents, update) {
3573 if (obj.options.autoSelect !== true && typeof(update) === 'undefined') {
3574 update = false;
3575 }
3576 if (calendar.classList.contains('jcalendar-focus')) {
3577 if (update !== false) {
3578 var element = calendar.querySelector('.jcalendar-selected');
3579
3580 if (typeof (update) == 'string') {
3581 var value = update;
3582 } else if (!element || element.classList.contains('jcalendar-disabled')) {
3583 var value = obj.options.value
3584 } else {
3585 var value = obj.getValue();
3586 }
3587
3588 obj.setValue(value);
3589 } else {
3590 let value = obj.options.value || '';
3591 obj.options.value = null;
3592 obj.setValue(value)
3593 }
3594
3595 // Events
3596 if (!ignoreEvents && typeof (obj.options.onclose) == 'function') {
3597 obj.options.onclose(el);
3598 }
3599 // Hide
3600 calendar.classList.remove('jcalendar-focus');
3601 // Stop tracking
3602 tracking(obj, false);
3603 // Current
3604 Component.current = null;
3605 }
3606
3607 return obj.options.value;
3608 }
3609
3610 obj.prev = function () {
3611 // Check if the visualization is the days picker or years picker
3612 if (obj.options.mode == 'years') {
3613 obj.date[0] = obj.date[0] - 12;
3614
3615 // Update picker table of days
3616 obj.getYears();
3617 } else if (obj.options.mode == 'months') {
3618 obj.date[0] = parseInt(obj.date[0]) - 1;
3619 // Update picker table of months
3620 obj.getMonths();
3621 } else {
3622 // Go to the previous month
3623 if (obj.date[1] < 2) {
3624 obj.date[0] = obj.date[0] - 1;
3625 obj.date[1] = 12;
3626 } else {
3627 obj.date[1] = obj.date[1] - 1;
3628 }
3629
3630 // Update picker table of days
3631 obj.getDays();
3632 }
3633 }
3634
3635 obj.next = function () {
3636 // Check if the visualization is the days picker or years picker
3637 if (obj.options.mode == 'years') {
3638 obj.date[0] = parseInt(obj.date[0]) + 12;
3639
3640 // Update picker table of days
3641 obj.getYears();
3642 } else if (obj.options.mode == 'months') {
3643 obj.date[0] = parseInt(obj.date[0]) + 1;
3644 // Update picker table of months
3645 obj.getMonths();
3646 } else {
3647 // Go to the previous month
3648 if (obj.date[1] > 11) {
3649 obj.date[0] = parseInt(obj.date[0]) + 1;
3650 obj.date[1] = 1;
3651 } else {
3652 obj.date[1] = parseInt(obj.date[1]) + 1;
3653 }
3654
3655 // Update picker table of days
3656 obj.getDays();
3657 }
3658 }
3659
3660 /**
3661 * Set today
3662 */
3663 obj.setToday = function () {
3664 // Today
3665 var value = new Date().toISOString().substr(0, 10);
3666 // Change value
3667 obj.setValue(value);
3668 // Value
3669 return value;
3670 }
3671
3672 obj.setValue = function (val) {
3673 if (!val) {
3674 val = '' + val;
3675 }
3676 // Values
3677 var newValue = val;
3678 var oldValue = obj.options.value;
3679
3680 if (oldValue != newValue) {
3681 // Set label
3682 if (!newValue) {
3683 obj.date = null;
3684 var val = '';
3685 el.classList.remove('jcalendar_warning');
3686 el.title = '';
3687 } else {
3688 var value = obj.setLabel(newValue, obj.options);
3689 var date = newValue.split(' ');
3690 if (!date[1]) {
3691 date[1] = '00:00:00';
3692 }
3693 var time = date[1].split(':')
3694 var date = date[0].split('-');
3695 var y = parseInt(date[0]);
3696 var m = parseInt(date[1]);
3697 var d = parseInt(date[2]);
3698 var h = parseInt(time[0]);
3699 var i = parseInt(time[1]);
3700 obj.date = [y, m, d, h, i, 0];
3701 var val = obj.setLabel(newValue, obj.options);
3702
3703 // Current selection day
3704 var current = Component.now(new Date(y, m - 1, d), true);
3705
3706 // Available ranges
3707 if (obj.options.validRange) {
3708 if (!obj.options.validRange[0] || current >= obj.options.validRange[0]) {
3709 var test1 = true;
3710 } else {
3711 var test1 = false;
3712 }
3713
3714 if (!obj.options.validRange[1] || current <= obj.options.validRange[1]) {
3715 var test2 = true;
3716 } else {
3717 var test2 = false;
3718 }
3719
3720 if (!(test1 && test2)) {
3721 el.classList.add('jcalendar_warning');
3722 el.title = dictionary.translate('Date outside the valid range');
3723 } else {
3724 el.classList.remove('jcalendar_warning');
3725 el.title = '';
3726 }
3727 } else {
3728 el.classList.remove('jcalendar_warning');
3729 el.title = '';
3730 }
3731 }
3732
3733 // New value
3734 obj.options.value = newValue;
3735
3736 if (typeof (obj.options.onchange) == 'function') {
3737 obj.options.onchange(el, newValue, oldValue);
3738 }
3739
3740 // Lemonade JS
3741 if (el.value != val) {
3742 el.value = val;
3743 if (typeof (el.oninput) == 'function') {
3744 el.oninput({
3745 type: 'input',
3746 target: el,
3747 value: el.value
3748 });
3749 }
3750 }
3751 }
3752
3753 if (obj.date) {
3754 obj.getDays();
3755 // Render months
3756 if (obj.options.type == 'year-month-picker') {
3757 obj.getMonths();
3758 }
3759 }
3760 }
3761
3762 obj.getValue = function () {
3763 if (obj.date) {
3764 if (obj.options.time) {
3765 return helpers.two(obj.date[0]) + '-' + helpers.two(obj.date[1]) + '-' + helpers.two(obj.date[2]) + ' ' + helpers.two(obj.date[3]) + ':' + helpers.two(obj.date[4]) + ':' + helpers.two(0);
3766 } else {
3767 return helpers.two(obj.date[0]) + '-' + helpers.two(obj.date[1]) + '-' + helpers.two(obj.date[2]) + ' ' + helpers.two(0) + ':' + helpers.two(0) + ':' + helpers.two(0);
3768 }
3769 } else {
3770 return "";
3771 }
3772 }
3773
3774 /**
3775 * Calendar
3776 */
3777 obj.update = function (element, v) {
3778 if (element.classList.contains('jcalendar-disabled')) {
3779 // Do nothing
3780 } else {
3781 var elements = calendar.querySelector('.jcalendar-selected');
3782 if (elements) {
3783 elements.classList.remove('jcalendar-selected');
3784 }
3785 element.classList.add('jcalendar-selected');
3786
3787 if (element.classList.contains('jcalendar-set-month')) {
3788 obj.date[1] = v;
3789 obj.date[2] = 1; // first day of the month
3790 } else {
3791 obj.date[2] = element.innerText;
3792 }
3793
3794 if (!obj.options.time) {
3795 obj.close(null, true);
3796 } else {
3797 obj.date[3] = calendarSelectHour.value;
3798 obj.date[4] = calendarSelectMin.value;
3799 }
3800 }
3801
3802 // Update
3803 updateActions();
3804 }
3805
3806 /**
3807 * Set to blank
3808 */
3809 obj.reset = function () {
3810 // Close calendar
3811 obj.setValue('');
3812 obj.date = null;
3813 obj.close(false, false);
3814 }
3815
3816 /**
3817 * Get calendar days
3818 */
3819 obj.getDays = function () {
3820 // Mode
3821 obj.options.mode = 'days';
3822
3823 // Setting current values in case of NULLs
3824 var date = new Date();
3825
3826 // Current selection
3827 var year = obj.date && helpers.isNumeric(obj.date[0]) ? obj.date[0] : parseInt(date.getFullYear());
3828 var month = obj.date && helpers.isNumeric(obj.date[1]) ? obj.date[1] : parseInt(date.getMonth()) + 1;
3829 var day = obj.date && helpers.isNumeric(obj.date[2]) ? obj.date[2] : parseInt(date.getDate());
3830 var hour = obj.date && helpers.isNumeric(obj.date[3]) ? obj.date[3] : parseInt(date.getHours());
3831 var min = obj.date && helpers.isNumeric(obj.date[4]) ? obj.date[4] : parseInt(date.getMinutes());
3832
3833 // Selection container
3834 obj.date = [year, month, day, hour, min, 0];
3835
3836 // Update title
3837 calendarLabelYear.innerHTML = year;
3838 calendarLabelMonth.innerHTML = obj.options.months[month - 1];
3839
3840 // Current month and Year
3841 var isCurrentMonthAndYear = (date.getMonth() == month - 1) && (date.getFullYear() == year) ? true : false;
3842 var currentDay = date.getDate();
3843
3844 // Number of days in the month
3845 var date = new Date(year, month, 0, 0, 0);
3846 var numberOfDays = date.getDate();
3847
3848 // First day
3849 var date = new Date(year, month - 1, 0, 0, 0);
3850 var firstDay = date.getDay() + 1;
3851
3852 // Index value
3853 var index = obj.options.startingDay || 0;
3854
3855 // First of day relative to the starting calendar weekday
3856 firstDay = firstDay - index;
3857
3858 // Reset table
3859 calendarBody.innerHTML = '';
3860
3861 // Weekdays Row
3862 var row = document.createElement('tr');
3863 row.setAttribute('align', 'center');
3864 calendarBody.appendChild(row);
3865
3866 // Create weekdays row
3867 for (var i = 0; i < 7; i++) {
3868 var cell = document.createElement('td');
3869 cell.classList.add('jcalendar-weekday')
3870 cell.innerHTML = obj.options.weekdays[index].substr(0, 1);
3871 row.appendChild(cell);
3872 // Next week day
3873 index++;
3874 // Restart index
3875 if (index > 6) {
3876 index = 0;
3877 }
3878 }
3879
3880 // Index of days
3881 var index = 0;
3882 var d = 0;
3883
3884 // Calendar table
3885 for (var j = 0; j < 6; j++) {
3886 // Reset cells container
3887 var row = document.createElement('tr');
3888 row.setAttribute('align', 'center');
3889 row.style.height = '34px';
3890
3891 // Create cells
3892 for (var i = 0; i < 7; i++) {
3893 // Create cell
3894 var cell = document.createElement('td');
3895 cell.classList.add('jcalendar-set-day');
3896
3897 if (index >= firstDay && index < (firstDay + numberOfDays)) {
3898 // Day cell
3899 d++;
3900 cell.innerHTML = d;
3901
3902 // Selected
3903 if (d == day) {
3904 cell.classList.add('jcalendar-selected');
3905 }
3906
3907 // Current selection day is today
3908 if (isCurrentMonthAndYear && currentDay == d) {
3909 cell.style.fontWeight = 'bold';
3910 }
3911
3912 // Current selection day
3913 var current = Component.now(new Date(year, month - 1, d), true);
3914
3915 // Available ranges
3916 if (obj.options.validRange) {
3917 if (!obj.options.validRange[0] || current >= obj.options.validRange[0]) {
3918 var test1 = true;
3919 } else {
3920 var test1 = false;
3921 }
3922
3923 if (!obj.options.validRange[1] || current <= obj.options.validRange[1]) {
3924 var test2 = true;
3925 } else {
3926 var test2 = false;
3927 }
3928
3929 if (!(test1 && test2)) {
3930 cell.classList.add('jcalendar-disabled');
3931 }
3932 }
3933 }
3934 // Day cell
3935 row.appendChild(cell);
3936 // Index
3937 index++;
3938 }
3939
3940 // Add cell to the calendar body
3941 calendarBody.appendChild(row);
3942 }
3943
3944 // Show time controls
3945 if (obj.options.time) {
3946 calendarControlsTime.style.display = '';
3947 } else {
3948 calendarControlsTime.style.display = 'none';
3949 }
3950
3951 // Update
3952 updateActions();
3953 }
3954
3955 obj.getMonths = function () {
3956 // Mode
3957 obj.options.mode = 'months';
3958
3959 // Loading month labels
3960 var months = obj.options.months;
3961
3962 // Value
3963 var value = obj.options.value;
3964
3965 // Current date
3966 var date = new Date();
3967 var currentYear = parseInt(date.getFullYear());
3968 var currentMonth = parseInt(date.getMonth()) + 1;
3969 var selectedYear = obj.date && helpers.isNumeric(obj.date[0]) ? obj.date[0] : currentYear;
3970 var selectedMonth = obj.date && helpers.isNumeric(obj.date[1]) ? obj.date[1] : currentMonth;
3971
3972 // Update title
3973 calendarLabelYear.innerHTML = obj.date[0];
3974 calendarLabelMonth.innerHTML = months[selectedMonth - 1];
3975
3976 // Table
3977 var table = document.createElement('table');
3978 table.setAttribute('width', '100%');
3979
3980 // Row
3981 var row = null;
3982
3983 // Calendar table
3984 for (var i = 0; i < 12; i++) {
3985 if (!(i % 4)) {
3986 // Reset cells container
3987 var row = document.createElement('tr');
3988 row.setAttribute('align', 'center');
3989 table.appendChild(row);
3990 }
3991
3992 // Create cell
3993 var cell = document.createElement('td');
3994 cell.classList.add('jcalendar-set-month');
3995 cell.setAttribute('data-value', i + 1);
3996 cell.innerText = months[i];
3997
3998 if (obj.options.validRange) {
3999 var current = selectedYear + '-' + helpers.two(i + 1);
4000 if (!obj.options.validRange[0] || current >= obj.options.validRange[0].substr(0, 7)) {
4001 var test1 = true;
4002 } else {
4003 var test1 = false;
4004 }
4005
4006 if (!obj.options.validRange[1] || current <= obj.options.validRange[1].substr(0, 7)) {
4007 var test2 = true;
4008 } else {
4009 var test2 = false;
4010 }
4011
4012 if (!(test1 && test2)) {
4013 cell.classList.add('jcalendar-disabled');
4014 }
4015 }
4016
4017 if (i + 1 == selectedMonth) {
4018 cell.classList.add('jcalendar-selected');
4019 }
4020
4021 if (currentYear == selectedYear && i + 1 == currentMonth) {
4022 cell.style.fontWeight = 'bold';
4023 }
4024
4025 row.appendChild(cell);
4026 }
4027
4028 calendarBody.innerHTML = '<tr><td colspan="7"></td></tr>';
4029 calendarBody.children[0].children[0].appendChild(table);
4030
4031 // Update
4032 updateActions();
4033 }
4034
4035 obj.getYears = function () {
4036 // Mode
4037 obj.options.mode = 'years';
4038
4039 // Current date
4040 var date = new Date();
4041 var currentYear = date.getFullYear();
4042 var selectedYear = obj.date && helpers.isNumeric(obj.date[0]) ? obj.date[0] : parseInt(date.getFullYear());
4043
4044 // Array of years
4045 var y = [];
4046 for (var i = 0; i < 25; i++) {
4047 y[i] = parseInt(obj.date[0]) + (i - 12);
4048 }
4049
4050 // Assembling the year tables
4051 var table = document.createElement('table');
4052 table.setAttribute('width', '100%');
4053
4054 for (var i = 0; i < 25; i++) {
4055 if (!(i % 5)) {
4056 // Reset cells container
4057 var row = document.createElement('tr');
4058 row.setAttribute('align', 'center');
4059 table.appendChild(row);
4060 }
4061
4062 // Create cell
4063 var cell = document.createElement('td');
4064 cell.classList.add('jcalendar-set-year');
4065 cell.innerText = y[i];
4066
4067 if (selectedYear == y[i]) {
4068 cell.classList.add('jcalendar-selected');
4069 }
4070
4071 if (currentYear == y[i]) {
4072 cell.style.fontWeight = 'bold';
4073 }
4074
4075 row.appendChild(cell);
4076 }
4077
4078 calendarBody.innerHTML = '<tr><td colspan="7"></td></tr>';
4079 calendarBody.firstChild.firstChild.appendChild(table);
4080
4081 // Update
4082 updateActions();
4083 }
4084
4085 obj.setLabel = function (value, mixed) {
4086 return Component.getDateString(value, mixed);
4087 }
4088
4089 obj.fromFormatted = function (value, format) {
4090 return Component.extractDateFromString(value, format);
4091 }
4092
4093 var mouseUpControls = function (e) {
4094 var element = helpers.findElement(e.target, 'jcalendar-container');
4095 if (element) {
4096 var action = e.target.className;
4097
4098 // Object id
4099 if (action == 'jcalendar-prev') {
4100 obj.prev();
4101 } else if (action == 'jcalendar-next') {
4102 obj.next();
4103 } else if (action == 'jcalendar-month') {
4104 obj.getMonths();
4105 } else if (action == 'jcalendar-year') {
4106 obj.getYears();
4107 } else if (action == 'jcalendar-set-year') {
4108 obj.date[0] = e.target.innerText;
4109 if (obj.options.type == 'year-month-picker') {
4110 obj.getMonths();
4111 } else {
4112 obj.getDays();
4113 }
4114 } else if (e.target.classList.contains('jcalendar-set-month')) {
4115 var month = parseInt(e.target.getAttribute('data-value'));
4116 if (obj.options.type == 'year-month-picker') {
4117 obj.update(e.target, month);
4118 } else {
4119 obj.date[1] = month;
4120 obj.getDays();
4121 }
4122 } else if (action == 'jcalendar-confirm' || action == 'jcalendar-update' || action == 'jcalendar-close') {
4123 obj.close(null, true);
4124 } else if (action == 'jcalendar-backdrop') {
4125 obj.close(false, false);
4126 } else if (action == 'jcalendar-reset') {
4127 obj.reset();
4128 } else if (e.target.classList.contains('jcalendar-set-day') && e.target.innerText) {
4129 obj.update(e.target);
4130 }
4131 } else {
4132 obj.close(false, false);
4133 }
4134 }
4135
4136 var keyUpControls = function (e) {
4137 if (e.target.value && e.target.value.length > 3) {
4138 var test = Component.extractDateFromString(e.target.value, obj.options.format);
4139 if (test) {
4140 obj.setValue(test);
4141 }
4142 }
4143 }
4144
4145 // Update actions button
4146 var updateActions = function () {
4147 var currentDay = calendar.querySelector('.jcalendar-selected');
4148
4149 if (currentDay && currentDay.classList.contains('jcalendar-disabled')) {
4150 calendarControlsUpdateButton.setAttribute('disabled', 'disabled');
4151 calendarSelectHour.setAttribute('disabled', 'disabled');
4152 calendarSelectMin.setAttribute('disabled', 'disabled');
4153 } else {
4154 calendarControlsUpdateButton.removeAttribute('disabled');
4155 calendarSelectHour.removeAttribute('disabled');
4156 calendarSelectMin.removeAttribute('disabled');
4157 }
4158
4159 // Event
4160 if (typeof (obj.options.onupdate) == 'function') {
4161 obj.options.onupdate(el, obj.getValue());
4162 }
4163 }
4164
4165 var calendar = null;
4166 var calendarReset = null;
4167 var calendarConfirm = null;
4168 var calendarContainer = null;
4169 var calendarContent = null;
4170 var calendarLabelYear = null;
4171 var calendarLabelMonth = null;
4172 var calendarTable = null;
4173 var calendarBody = null;
4174
4175 var calendarControls = null;
4176 var calendarControlsTime = null;
4177 var calendarControlsUpdate = null;
4178 var calendarControlsUpdateButton = null;
4179 var calendarSelectHour = null;
4180 var calendarSelectMin = null;
4181
4182 var init = function () {
4183 // Get value from initial element if that is an input
4184 if (el.tagName == 'INPUT' && el.value) {
4185 options.value = el.value;
4186 }
4187
4188 // Calendar DOM elements
4189 calendarReset = document.createElement('div');
4190 calendarReset.className = 'jcalendar-reset';
4191
4192 calendarConfirm = document.createElement('div');
4193 calendarConfirm.className = 'jcalendar-confirm';
4194
4195 calendarControls = document.createElement('div');
4196 calendarControls.className = 'jcalendar-controls'
4197 calendarControls.style.borderBottom = '1px solid #ddd';
4198 calendarControls.appendChild(calendarReset);
4199 calendarControls.appendChild(calendarConfirm);
4200
4201 calendarContainer = document.createElement('div');
4202 calendarContainer.className = 'jcalendar-container';
4203 calendarContent = document.createElement('div');
4204 calendarContent.className = 'jcalendar-content';
4205 calendarContainer.appendChild(calendarContent);
4206
4207 // Main element
4208 if (el.tagName == 'DIV') {
4209 calendar = el;
4210 calendar.classList.add('jcalendar-inline');
4211 } else {
4212 // Add controls to the screen
4213 calendarContent.appendChild(calendarControls);
4214
4215 calendar = document.createElement('div');
4216 calendar.className = 'jcalendar';
4217 }
4218 calendar.classList.add('jcalendar-container');
4219 calendar.appendChild(calendarContainer);
4220
4221 // Table container
4222 var calendarTableContainer = document.createElement('div');
4223 calendarTableContainer.className = 'jcalendar-table';
4224 calendarContent.appendChild(calendarTableContainer);
4225
4226 // Previous button
4227 var calendarHeaderPrev = document.createElement('td');
4228 calendarHeaderPrev.setAttribute('colspan', '2');
4229 calendarHeaderPrev.className = 'jcalendar-prev';
4230
4231 // Header with year and month
4232 calendarLabelYear = document.createElement('span');
4233 calendarLabelYear.className = 'jcalendar-year';
4234 calendarLabelMonth = document.createElement('span');
4235 calendarLabelMonth.className = 'jcalendar-month';
4236
4237 var calendarHeaderTitle = document.createElement('td');
4238 calendarHeaderTitle.className = 'jcalendar-header';
4239 calendarHeaderTitle.setAttribute('colspan', '3');
4240 calendarHeaderTitle.appendChild(calendarLabelMonth);
4241 calendarHeaderTitle.appendChild(calendarLabelYear);
4242
4243 var calendarHeaderNext = document.createElement('td');
4244 calendarHeaderNext.setAttribute('colspan', '2');
4245 calendarHeaderNext.className = 'jcalendar-next';
4246
4247 var calendarHeader = document.createElement('thead');
4248 var calendarHeaderRow = document.createElement('tr');
4249 calendarHeaderRow.appendChild(calendarHeaderPrev);
4250 calendarHeaderRow.appendChild(calendarHeaderTitle);
4251 calendarHeaderRow.appendChild(calendarHeaderNext);
4252 calendarHeader.appendChild(calendarHeaderRow);
4253
4254 calendarTable = document.createElement('table');
4255 calendarBody = document.createElement('tbody');
4256 calendarTable.setAttribute('cellpadding', '0');
4257 calendarTable.setAttribute('cellspacing', '0');
4258 calendarTable.appendChild(calendarHeader);
4259 calendarTable.appendChild(calendarBody);
4260 calendarTableContainer.appendChild(calendarTable);
4261
4262 calendarSelectHour = document.createElement('select');
4263 calendarSelectHour.className = 'jcalendar-select';
4264 calendarSelectHour.onchange = function () {
4265 obj.date[3] = this.value;
4266
4267 // Event
4268 if (typeof (obj.options.onupdate) == 'function') {
4269 obj.options.onupdate(el, obj.getValue());
4270 }
4271 }
4272
4273 for (var i = 0; i < 24; i++) {
4274 var element = document.createElement('option');
4275 element.value = i;
4276 element.innerHTML = helpers.two(i);
4277 calendarSelectHour.appendChild(element);
4278 }
4279
4280 calendarSelectMin = document.createElement('select');
4281 calendarSelectMin.className = 'jcalendar-select';
4282 calendarSelectMin.onchange = function () {
4283 obj.date[4] = this.value;
4284
4285 // Event
4286 if (typeof (obj.options.onupdate) == 'function') {
4287 obj.options.onupdate(el, obj.getValue());
4288 }
4289 }
4290
4291 for (var i = 0; i < 60; i++) {
4292 var element = document.createElement('option');
4293 element.value = i;
4294 element.innerHTML = helpers.two(i);
4295 calendarSelectMin.appendChild(element);
4296 }
4297
4298 // Footer controls
4299 var calendarControlsFooter = document.createElement('div');
4300 calendarControlsFooter.className = 'jcalendar-controls';
4301
4302 calendarControlsTime = document.createElement('div');
4303 calendarControlsTime.className = 'jcalendar-time';
4304 calendarControlsTime.style.maxWidth = '140px';
4305 calendarControlsTime.appendChild(calendarSelectHour);
4306 calendarControlsTime.appendChild(calendarSelectMin);
4307
4308 calendarControlsUpdateButton = document.createElement('button');
4309 calendarControlsUpdateButton.setAttribute('type', 'button');
4310 calendarControlsUpdateButton.className = 'jcalendar-update';
4311
4312 calendarControlsUpdate = document.createElement('div');
4313 calendarControlsUpdate.style.flexGrow = '10';
4314 calendarControlsUpdate.appendChild(calendarControlsUpdateButton);
4315 calendarControlsFooter.appendChild(calendarControlsTime);
4316
4317 // Only show the update button for input elements
4318 if (el.tagName == 'INPUT') {
4319 calendarControlsFooter.appendChild(calendarControlsUpdate);
4320 }
4321
4322 calendarContent.appendChild(calendarControlsFooter);
4323
4324 var calendarBackdrop = document.createElement('div');
4325 calendarBackdrop.className = 'jcalendar-backdrop';
4326 calendar.appendChild(calendarBackdrop);
4327
4328 // Handle events
4329 el.addEventListener("keyup", keyUpControls);
4330
4331 // Add global events
4332 calendar.addEventListener("swipeleft", function (e) {
4333 animation.slideLeft(calendarTable, 0, function () {
4334 obj.next();
4335 animation.slideRight(calendarTable, 1);
4336 });
4337 e.preventDefault();
4338 e.stopPropagation();
4339 });
4340
4341 calendar.addEventListener("swiperight", function (e) {
4342 animation.slideRight(calendarTable, 0, function () {
4343 obj.prev();
4344 animation.slideLeft(calendarTable, 1);
4345 });
4346 e.preventDefault();
4347 e.stopPropagation();
4348 });
4349
4350 if ('ontouchend' in document.documentElement === true) {
4351 calendar.addEventListener("touchend", mouseUpControls);
4352 el.addEventListener("touchend", obj.open);
4353 } else {
4354 calendar.addEventListener("mouseup", mouseUpControls);
4355 el.addEventListener("mouseup", obj.open);
4356 }
4357
4358 // Global controls
4359 if (!Component.hasEvents) {
4360 // Execute only one time
4361 Component.hasEvents = true;
4362 // Enter and Esc
4363 document.addEventListener("keydown", Component.keydown);
4364 }
4365
4366 // Set configuration
4367 obj.setOptions(options);
4368
4369 // Append element to the DOM
4370 if (el.tagName == 'INPUT') {
4371 el.parentNode.insertBefore(calendar, el.nextSibling);
4372 // Add properties
4373 el.setAttribute('autocomplete', 'off');
4374 // Element
4375 el.classList.add('jcalendar-input');
4376 // Value
4377 el.value = obj.setLabel(obj.getValue(), obj.options);
4378 } else {
4379 // Get days
4380 obj.getDays();
4381 // Hour
4382 if (obj.options.time) {
4383 calendarSelectHour.value = obj.date[3];
4384 calendarSelectMin.value = obj.date[4];
4385 }
4386 }
4387
4388 // Default opened
4389 if (obj.options.opened == true) {
4390 obj.open();
4391 }
4392
4393 // Controls
4394 if (obj.options.controls == false) {
4395 calendarContainer.classList.add('jcalendar-hide-controls');
4396 }
4397
4398 // Change method
4399 el.change = obj.setValue;
4400
4401 // Global generic value handler
4402 el.val = function (val) {
4403 if (val === undefined) {
4404 return obj.getValue();
4405 } else {
4406 obj.setValue(val);
4407 }
4408 }
4409
4410 // Keep object available from the node
4411 el.calendar = calendar.calendar = obj;
4412 }
4413
4414 init();
4415
4416 return obj;
4417 });
4418
4419 Component.keydown = function (e) {
4420 var calendar = null;
4421 if (calendar = Component.current) {
4422 if (e.which == 13) {
4423 // ENTER
4424 calendar.close(false, true);
4425 } else if (e.which == 27) {
4426 // ESC
4427 calendar.close(false, false);
4428 }
4429 }
4430 }
4431
4432 Component.prettify = function (d, texts) {
4433 if (!texts) {
4434 var texts = {
4435 justNow: 'Just now',
4436 xMinutesAgo: '{0}m ago',
4437 xHoursAgo: '{0}h ago',
4438 xDaysAgo: '{0}d ago',
4439 xWeeksAgo: '{0}w ago',
4440 xMonthsAgo: '{0} mon ago',
4441 xYearsAgo: '{0}y ago',
4442 }
4443 }
4444
4445 if (d.indexOf('GMT') === -1 && d.indexOf('Z') === -1) {
4446 d += ' GMT';
4447 }
4448
4449 var d1 = new Date();
4450 var d2 = new Date(d);
4451 var total = parseInt((d1 - d2) / 1000 / 60);
4452
4453 String.prototype.format = function (o) {
4454 return this.replace('{0}', o);
4455 }
4456
4457 if (total == 0) {
4458 var text = texts.justNow;
4459 } else if (total < 90) {
4460 var text = texts.xMinutesAgo.format(total);
4461 } else if (total < 1440) { // One day
4462 var text = texts.xHoursAgo.format(Math.round(total / 60));
4463 } else if (total < 20160) { // 14 days
4464 var text = texts.xDaysAgo.format(Math.round(total / 1440));
4465 } else if (total < 43200) { // 30 days
4466 var text = texts.xWeeksAgo.format(Math.round(total / 10080));
4467 } else if (total < 1036800) { // 24 months
4468 var text = texts.xMonthsAgo.format(Math.round(total / 43200));
4469 } else { // 24 months+
4470 var text = texts.xYearsAgo.format(Math.round(total / 525600));
4471 }
4472
4473 return text;
4474 }
4475
4476 Component.prettifyAll = function () {
4477 var elements = document.querySelectorAll('.prettydate');
4478 for (var i = 0; i < elements.length; i++) {
4479 if (elements[i].getAttribute('data-date')) {
4480 elements[i].innerHTML = Component.prettify(elements[i].getAttribute('data-date'));
4481 } else {
4482 if (elements[i].innerHTML) {
4483 elements[i].setAttribute('title', elements[i].innerHTML);
4484 elements[i].setAttribute('data-date', elements[i].innerHTML);
4485 elements[i].innerHTML = Component.prettify(elements[i].innerHTML);
4486 }
4487 }
4488 }
4489 }
4490
4491 Component.now = helpers_date.now;
4492 Component.toArray = helpers_date.toArray;
4493 Component.dateToNum = helpers_date.dateToNum
4494 Component.numToDate = helpers_date.numToDate;
4495 Component.weekdays = helpers_date.weekdays;
4496 Component.months = helpers_date.months;
4497 Component.weekdaysShort = helpers_date.weekdaysShort;
4498 Component.monthsShort = helpers_date.monthsShort;
4499
4500 // Legacy shortcut
4501 Component.extractDateFromString = mask.extractDateFromString;
4502 Component.getDateString = mask.getDateString;
4503
4504 return Component;
4505}
4506
4507/* harmony default export */ var calendar = (Calendar());
4508;// CONCATENATED MODULE: ./src/plugins/palette.js
4509// More palettes https://coolors.co/ or https://gka.github.io/palettes/#/10|s|003790,005647,ffffe0|ffffe0,ff005e,93003a|1|1
4510
4511function Palette() {
4512
4513 var palette = {
4514 material: [
4515 ["#ffebee", "#fce4ec", "#f3e5f5", "#e8eaf6", "#e3f2fd", "#e0f7fa", "#e0f2f1", "#e8f5e9", "#f1f8e9", "#f9fbe7", "#fffde7", "#fff8e1", "#fff3e0", "#fbe9e7", "#efebe9", "#fafafa", "#eceff1"],
4516 ["#ffcdd2", "#f8bbd0", "#e1bee7", "#c5cae9", "#bbdefb", "#b2ebf2", "#b2dfdb", "#c8e6c9", "#dcedc8", "#f0f4c3", "#fff9c4", "#ffecb3", "#ffe0b2", "#ffccbc", "#d7ccc8", "#f5f5f5", "#cfd8dc"],
4517 ["#ef9a9a", "#f48fb1", "#ce93d8", "#9fa8da", "#90caf9", "#80deea", "#80cbc4", "#a5d6a7", "#c5e1a5", "#e6ee9c", "#fff59d", "#ffe082", "#ffcc80", "#ffab91", "#bcaaa4", "#eeeeee", "#b0bec5"],
4518 ["#e57373", "#f06292", "#ba68c8", "#7986cb", "#64b5f6", "#4dd0e1", "#4db6ac", "#81c784", "#aed581", "#dce775", "#fff176", "#ffd54f", "#ffb74d", "#ff8a65", "#a1887f", "#e0e0e0", "#90a4ae"],
4519 ["#ef5350", "#ec407a", "#ab47bc", "#5c6bc0", "#42a5f5", "#26c6da", "#26a69a", "#66bb6a", "#9ccc65", "#d4e157", "#ffee58", "#ffca28", "#ffa726", "#ff7043", "#8d6e63", "#bdbdbd", "#78909c"],
4520 ["#f44336", "#e91e63", "#9c27b0", "#3f51b5", "#2196f3", "#00bcd4", "#009688", "#4caf50", "#8bc34a", "#cddc39", "#ffeb3b", "#ffc107", "#ff9800", "#ff5722", "#795548", "#9e9e9e", "#607d8b"],
4521 ["#e53935", "#d81b60", "#8e24aa", "#3949ab", "#1e88e5", "#00acc1", "#00897b", "#43a047", "#7cb342", "#c0ca33", "#fdd835", "#ffb300", "#fb8c00", "#f4511e", "#6d4c41", "#757575", "#546e7a"],
4522 ["#d32f2f", "#c2185b", "#7b1fa2", "#303f9f", "#1976d2", "#0097a7", "#00796b", "#388e3c", "#689f38", "#afb42b", "#fbc02d", "#ffa000", "#f57c00", "#e64a19", "#5d4037", "#616161", "#455a64"],
4523 ["#c62828", "#ad1457", "#6a1b9a", "#283593", "#1565c0", "#00838f", "#00695c", "#2e7d32", "#558b2f", "#9e9d24", "#f9a825", "#ff8f00", "#ef6c00", "#d84315", "#4e342e", "#424242", "#37474f"],
4524 ["#b71c1c", "#880e4f", "#4a148c", "#1a237e", "#0d47a1", "#006064", "#004d40", "#1b5e20", "#33691e", "#827717", "#f57f17", "#ff6f00", "#e65100", "#bf360c", "#3e2723", "#212121", "#263238"],
4525 ],
4526 fire: [
4527 ["0b1a6d", "840f38", "b60718", "de030b", "ff0c0c", "fd491c", "fc7521", "faa331", "fbb535", "ffc73a"],
4528 ["071147", "5f0b28", "930513", "be0309", "ef0000", "fa3403", "fb670b", "f9991b", "faad1e", "ffc123"],
4529 ["03071e", "370617", "6a040f", "9d0208", "d00000", "dc2f02", "e85d04", "f48c06", "faa307", "ffba08"],
4530 ["020619", "320615", "61040d", "8c0207", "bc0000", "c82a02", "d05203", "db7f06", "e19405", "efab00"],
4531 ["020515", "2d0513", "58040c", "7f0206", "aa0000", "b62602", "b94903", "c57205", "ca8504", "d89b00"],
4532 ],
4533 baby: [
4534 ["eddcd2", "fff1e6", "fde2e4", "fad2e1", "c5dedd", "dbe7e4", "f0efeb", "d6e2e9", "bcd4e6", "99c1de"],
4535 ["e1c4b3", "ffd5b5", "fab6ba", "f5a8c4", "aacecd", "bfd5cf", "dbd9d0", "baceda", "9dc0db", "7eb1d5"],
4536 ["daa990", "ffb787", "f88e95", "f282a9", "8fc4c3", "a3c8be", "cec9b3", "9dbcce", "82acd2", "649dcb"],
4537 ["d69070", "ff9c5e", "f66770", "f05f8f", "74bbb9", "87bfae", "c5b993", "83aac3", "699bca", "4d89c2"],
4538 ["c97d5d", "f58443", "eb4d57", "e54a7b", "66a9a7", "78ae9c", "b5a67e", "7599b1", "5c88b7", "4978aa"],
4539 ],
4540 chart: [
4541 ['#C1D37F', '#4C5454', '#FFD275', '#66586F', '#D05D5B', '#C96480', '#95BF8F', '#6EA240', '#0F0F0E', '#EB8258', '#95A3B3', '#995D81'],
4542 ],
4543 }
4544
4545 var Component = function (o) {
4546 // Otherwise get palette value
4547 if (palette[o]) {
4548 return palette[o];
4549 } else {
4550 return palette.material;
4551 }
4552 }
4553
4554 Component.get = function (o) {
4555 // Otherwise get palette value
4556 if (palette[o]) {
4557 return palette[o];
4558 } else {
4559 return palette;
4560 }
4561 }
4562
4563 Component.set = function (o, v) {
4564 palette[o] = v;
4565 }
4566
4567 return Component;
4568}
4569
4570/* harmony default export */ var palette = (Palette());
4571;// CONCATENATED MODULE: ./src/plugins/tabs.js
4572
4573
4574
4575
4576function Tabs(el, options) {
4577 var obj = {};
4578 obj.options = {};
4579
4580 // Default configuration
4581 var defaults = {
4582 data: [],
4583 position: null,
4584 allowCreate: false,
4585 allowChangePosition: false,
4586 onclick: null,
4587 onload: null,
4588 onchange: null,
4589 oncreate: null,
4590 ondelete: null,
4591 onbeforecreate: null,
4592 onchangeposition: null,
4593 animation: false,
4594 hideHeaders: false,
4595 padding: null,
4596 palette: null,
4597 maxWidth: null,
4598 }
4599
4600 // Loop through the initial configuration
4601 for (var property in defaults) {
4602 if (options && options.hasOwnProperty(property)) {
4603 obj.options[property] = options[property];
4604 } else {
4605 obj.options[property] = defaults[property];
4606 }
4607 }
4608
4609 // Class
4610 el.classList.add('jtabs');
4611
4612 var prev = null;
4613 var next = null;
4614 var border = null;
4615
4616 // Helpers
4617 const setBorder = function(index) {
4618 if (obj.options.animation) {
4619 setTimeout(function() {
4620 let rect = obj.headers.children[index].getBoundingClientRect();
4621
4622 if (obj.options.palette === 'modern') {
4623 border.style.width = rect.width - 4 + 'px';
4624 border.style.left = obj.headers.children[index].offsetLeft + 2 + 'px';
4625 } else {
4626 border.style.width = rect.width + 'px';
4627 border.style.left = obj.headers.children[index].offsetLeft + 'px';
4628 }
4629
4630 if (obj.options.position === 'bottom') {
4631 border.style.top = '0px';
4632 } else {
4633 border.style.bottom = '0px';
4634 }
4635 }, 50);
4636 }
4637 }
4638
4639 var updateControls = function(x) {
4640 if (typeof(obj.headers.scrollTo) == 'function') {
4641 obj.headers.scrollTo({
4642 left: x,
4643 behavior: 'smooth',
4644 });
4645 } else {
4646 obj.headers.scrollLeft = x;
4647 }
4648
4649 if (x <= 1) {
4650 prev.classList.add('disabled');
4651 } else {
4652 prev.classList.remove('disabled');
4653 }
4654
4655 if (x >= obj.headers.scrollWidth - obj.headers.offsetWidth) {
4656 next.classList.add('disabled');
4657 } else {
4658 next.classList.remove('disabled');
4659 }
4660
4661 if (obj.headers.scrollWidth <= obj.headers.offsetWidth) {
4662 prev.style.display = 'none';
4663 next.style.display = 'none';
4664 } else {
4665 prev.style.display = '';
4666 next.style.display = '';
4667 }
4668 }
4669
4670 obj.setBorder = setBorder;
4671
4672 // Set value
4673 obj.open = function(index) {
4674 // This is to force safari to update the children
4675 const items = Array.from(obj.content.children);
4676 if (! obj.content.children[index]) {
4677 return;
4678 }
4679
4680 var previous = null;
4681 for (var i = 0; i < obj.headers.children.length; i++) {
4682 if (obj.headers.children[i].classList.contains('jtabs-selected')) {
4683 // Current one
4684 previous = i;
4685 }
4686 // Remote selected
4687 obj.headers.children[i].classList.remove('jtabs-selected');
4688 obj.headers.children[i].removeAttribute('aria-selected')
4689 if (obj.content.children[i]) {
4690 obj.content.children[i].classList.remove('jtabs-selected');
4691 }
4692 }
4693
4694 obj.headers.children[index].classList.add('jtabs-selected');
4695 obj.headers.children[index].setAttribute('aria-selected', 'true')
4696
4697 if (obj.content.children[index]) {
4698 obj.content.children[index].classList.add('jtabs-selected');
4699 }
4700
4701 if (previous != index && typeof(obj.options.onchange) == 'function') {
4702 if (obj.content.children[index]) {
4703 obj.options.onchange(el, obj, index, obj.headers.children[index], obj.content.children[index]);
4704 }
4705 }
4706
4707 // Hide
4708 if (obj.options.hideHeaders == true && (obj.headers.children.length < 3 && obj.options.allowCreate == false)) {
4709 obj.headers.parentNode.style.display = 'none';
4710 } else {
4711 obj.headers.parentNode.style.display = '';
4712
4713 var x1 = obj.headers.children[index].offsetLeft;
4714 var x2 = x1 + obj.headers.children[index].offsetWidth;
4715 var r1 = obj.headers.scrollLeft;
4716 var r2 = r1 + obj.headers.offsetWidth;
4717
4718 if (! (r1 <= x1 && r2 >= x2)) {
4719 // Out of the viewport
4720 updateControls(x1 - 1);
4721 }
4722
4723 // Set border
4724 setBorder(index);
4725 }
4726 }
4727
4728 obj.selectIndex = function(a) {
4729 var index = Array.prototype.indexOf.call(obj.headers.children, a);
4730 if (index >= 0) {
4731 obj.open(index);
4732 }
4733
4734 return index;
4735 }
4736
4737 obj.rename = function(i, title) {
4738 if (! title) {
4739 title = prompt('New title', obj.headers.children[i].innerText);
4740 }
4741 obj.headers.children[i].innerText = title;
4742 setBorder(obj.getActive());
4743 }
4744
4745 obj.create = function(title, url) {
4746 if (typeof(obj.options.onbeforecreate) == 'function') {
4747 var ret = obj.options.onbeforecreate(el, title);
4748 if (ret === false) {
4749 return false;
4750 } else {
4751 title = ret;
4752 }
4753 }
4754
4755 var div = obj.appendElement(title);
4756
4757 if (typeof(obj.options.oncreate) == 'function') {
4758 obj.options.oncreate(el, div)
4759 }
4760
4761 setBorder(obj.getActive());
4762
4763 return div;
4764 }
4765
4766 obj.remove = function(index) {
4767 return obj.deleteElement(index);
4768 }
4769
4770 obj.nextNumber = function() {
4771 var num = 0;
4772 for (var i = 0; i < obj.headers.children.length; i++) {
4773 var tmp = obj.headers.children[i].innerText.match(/[0-9].*/);
4774 if (tmp > num) {
4775 num = parseInt(tmp);
4776 }
4777 }
4778 if (! num) {
4779 num = 1;
4780 } else {
4781 num++;
4782 }
4783
4784 return num;
4785 }
4786
4787 obj.deleteElement = function(index) {
4788 let current = obj.getActive();
4789
4790 if (! obj.headers.children[index]) {
4791 return false;
4792 } else {
4793 obj.headers.removeChild(obj.headers.children[index]);
4794 obj.content.removeChild(obj.content.children[index]);
4795 }
4796
4797 if (current === index) {
4798 obj.open(0);
4799 } else {
4800 let current = obj.getActive() || 0;
4801 setBorder(current);
4802 }
4803
4804 if (typeof(obj.options.ondelete) == 'function') {
4805 obj.options.ondelete(el, index)
4806 }
4807 }
4808
4809 obj.appendElement = function(title, cb, openTab, position) {
4810 if (! title) {
4811 var title = prompt('Title?', '');
4812 }
4813
4814 if (title) {
4815 let headerId = helpers.guid();
4816 let contentId = helpers.guid();
4817 // Add content
4818 var div = document.createElement('div');
4819 div.setAttribute('id', contentId);
4820 div.setAttribute('role', 'tabpanel');
4821 div.setAttribute('aria-labelledby', headerId);
4822
4823 // Add headers
4824 var h = document.createElement('div');
4825 h.setAttribute('id', headerId);
4826 h.setAttribute('role', 'tab');
4827 h.setAttribute('aria-controls', contentId);
4828
4829 h.textContent = title;
4830 h.content = div;
4831
4832 if (typeof(position) === 'undefined') {
4833 obj.content.appendChild(div);
4834 obj.headers.insertBefore(h, obj.headers.lastChild);
4835 } else {
4836 let r = obj.content.children[position];
4837 if (r) {
4838 obj.content.insertBefore(div, r);
4839 } else {
4840 obj.content.appendChild(div);
4841 }
4842 r = obj.headers.children[position] || obj.headers.lastChild;
4843 obj.headers.insertBefore(h, r);
4844 }
4845
4846 // Sortable
4847 if (obj.options.allowChangePosition) {
4848 h.setAttribute('draggable', 'true');
4849 }
4850
4851 // Open new tab
4852 if (openTab !== false) {
4853 // Open new tab
4854 obj.selectIndex(h);
4855 }
4856
4857 // Callback
4858 if (typeof(cb) == 'function') {
4859 cb(div, h);
4860 }
4861
4862 // Return element
4863 return div;
4864 }
4865 }
4866
4867 obj.getActive = function() {
4868 for (var i = 0; i < obj.headers.children.length; i++) {
4869 if (obj.headers.children[i].classList.contains('jtabs-selected')) {
4870 return i;
4871 }
4872 }
4873 return false;
4874 }
4875
4876 obj.updateContent = function(position, newContent) {
4877 if (typeof newContent !== 'string') {
4878 var contentItem = newContent;
4879 } else {
4880 var contentItem = document.createElement('div');
4881 contentItem.innerHTML = newContent;
4882 }
4883
4884 if (obj.content.children[position].classList.contains('jtabs-selected')) {
4885 newContent.classList.add('jtabs-selected');
4886 }
4887
4888 obj.content.replaceChild(newContent, obj.content.children[position]);
4889
4890 setBorder();
4891 }
4892
4893 obj.updatePosition = function(f, t, ignoreEvents, openTab) {
4894 // Ondrop update position of content
4895 if (f > t) {
4896 obj.content.insertBefore(obj.content.children[f], obj.content.children[t]);
4897 } else {
4898 obj.content.insertBefore(obj.content.children[f], obj.content.children[t].nextSibling);
4899 }
4900
4901 // Open destination tab
4902 if (openTab !== false) {
4903 obj.open(t);
4904 } else {
4905 const activeIndex = obj.getActive();
4906
4907 if (t < activeIndex) {
4908 obj.setBorder(activeIndex);
4909 }
4910 }
4911
4912 // Call event
4913 if (! ignoreEvents && typeof(obj.options.onchangeposition) == 'function') {
4914 obj.options.onchangeposition(obj.headers, f, t);
4915 }
4916 }
4917
4918 obj.move = function(f, t, ignoreEvents, openTab) {
4919 if (f > t) {
4920 obj.headers.insertBefore(obj.headers.children[f], obj.headers.children[t]);
4921 } else {
4922 obj.headers.insertBefore(obj.headers.children[f], obj.headers.children[t].nextSibling);
4923 }
4924
4925 obj.updatePosition(f, t, ignoreEvents, openTab);
4926 }
4927
4928 obj.setBorder = setBorder;
4929
4930 obj.init = function() {
4931 el.textContent = '';
4932
4933 // Make sure the component is blank
4934 obj.headers = document.createElement('div');
4935 obj.content = document.createElement('div');
4936 obj.headers.classList.add('jtabs-headers');
4937 obj.headers.setAttribute('role', 'tablist');
4938 obj.content.classList.add('jtabs-content');
4939 obj.content.setAttribute('role', 'region');
4940 obj.content.setAttribute('aria-label', 'Tab Panels');
4941
4942 if (obj.options.palette) {
4943 el.classList.add('jtabs-modern');
4944 } else {
4945 el.classList.remove('jtabs-modern');
4946 }
4947
4948 // Padding
4949 if (obj.options.padding) {
4950 obj.content.style.padding = parseInt(obj.options.padding) + 'px';
4951 }
4952
4953 // Header
4954 var header = document.createElement('div');
4955 header.className = 'jtabs-headers-container';
4956 header.appendChild(obj.headers);
4957 if (obj.options.maxWidth) {
4958 header.style.maxWidth = parseInt(obj.options.maxWidth) + 'px';
4959 }
4960
4961 // Controls
4962 var controls = document.createElement('div');
4963 controls.className = 'jtabs-controls';
4964 controls.setAttribute('draggable', 'false');
4965 header.appendChild(controls);
4966
4967 // Append DOM elements
4968 if (obj.options.position == 'bottom') {
4969 el.appendChild(obj.content);
4970 el.appendChild(header);
4971 } else {
4972 el.appendChild(header);
4973 el.appendChild(obj.content);
4974 }
4975
4976 // New button
4977 if (obj.options.allowCreate == true) {
4978 var add = document.createElement('div');
4979 add.className = 'jtabs-add';
4980 add.onclick = function() {
4981 obj.create();
4982 }
4983 controls.appendChild(add);
4984 }
4985
4986 prev = document.createElement('div');
4987 prev.className = 'jtabs-prev';
4988 prev.onclick = function() {
4989 updateControls(obj.headers.scrollLeft - obj.headers.offsetWidth);
4990 }
4991 controls.appendChild(prev);
4992
4993 next = document.createElement('div');
4994 next.className = 'jtabs-next';
4995 next.onclick = function() {
4996 updateControls(obj.headers.scrollLeft + obj.headers.offsetWidth);
4997 }
4998 controls.appendChild(next);
4999
5000 // Data
5001 for (var i = 0; i < obj.options.data.length; i++) {
5002 // Title
5003 if (obj.options.data[i].titleElement) {
5004 var headerItem = obj.options.data[i].titleElement;
5005 } else {
5006 var headerItem = document.createElement('div');
5007 }
5008 // Icon
5009 if (obj.options.data[i].icon) {
5010 var iconContainer = document.createElement('div');
5011 var icon = document.createElement('i');
5012 icon.classList.add('material-icons');
5013 icon.textContent = obj.options.data[i].icon;
5014 iconContainer.appendChild(icon);
5015 headerItem.appendChild(iconContainer);
5016 }
5017 // Title
5018 if (obj.options.data[i].title) {
5019 var title = document.createTextNode(obj.options.data[i].title);
5020 headerItem.appendChild(title);
5021 }
5022 // Width
5023 if (obj.options.data[i].width) {
5024 headerItem.style.width = obj.options.data[i].width;
5025 }
5026 // Content
5027 if (obj.options.data[i].contentElement) {
5028 var contentItem = obj.options.data[i].contentElement;
5029 } else {
5030 var contentItem = document.createElement('div');
5031 contentItem.innerHTML = obj.options.data[i].content;
5032 }
5033 obj.headers.appendChild(headerItem);
5034 obj.content.appendChild(contentItem);
5035 }
5036
5037 // Animation
5038 border = document.createElement('div');
5039 border.className = 'jtabs-border';
5040 obj.headers.appendChild(border);
5041
5042 if (obj.options.animation) {
5043 el.classList.add('jtabs-animation');
5044 }
5045
5046 // Events
5047 obj.headers.addEventListener("click", function(e) {
5048 if (e.target.parentNode.classList.contains('jtabs-headers')) {
5049 var target = e.target;
5050 } else {
5051 if (e.target.tagName == 'I') {
5052 var target = e.target.parentNode.parentNode;
5053 } else {
5054 var target = e.target.parentNode;
5055 }
5056 }
5057
5058 var index = obj.selectIndex(target);
5059
5060 if (typeof(obj.options.onclick) == 'function') {
5061 obj.options.onclick(el, obj, index, obj.headers.children[index], obj.content.children[index]);
5062 }
5063 });
5064
5065 obj.headers.addEventListener("contextmenu", function(e) {
5066 obj.selectIndex(e.target);
5067 });
5068
5069 if (obj.headers.children.length) {
5070 // Open first tab
5071 obj.open(0);
5072 }
5073
5074 // Update controls
5075 updateControls(0);
5076
5077 if (obj.options.allowChangePosition == true) {
5078 Sorting(obj.headers, {
5079 direction: 1,
5080 ondrop: function(a,b,c) {
5081 obj.updatePosition(b,c);
5082 },
5083 });
5084 }
5085
5086 if (typeof(obj.options.onload) == 'function') {
5087 obj.options.onload(el, obj);
5088 }
5089 }
5090
5091 // Loading existing nodes as the data
5092 if (el.children[0] && el.children[0].children.length) {
5093 // Create from existing elements
5094 for (var i = 0; i < el.children[0].children.length; i++) {
5095 var item = obj.options.data && obj.options.data[i] ? obj.options.data[i] : {};
5096
5097 if (el.children[1] && el.children[1].children[i]) {
5098 item.titleElement = el.children[0].children[i];
5099 item.contentElement = el.children[1].children[i];
5100 } else {
5101 item.contentElement = el.children[0].children[i];
5102 }
5103
5104 obj.options.data[i] = item;
5105 }
5106 }
5107
5108 // Remote controller flag
5109 var loadingRemoteData = false;
5110
5111 // Create from data
5112 if (obj.options.data) {
5113 // Append children
5114 for (var i = 0; i < obj.options.data.length; i++) {
5115 if (obj.options.data[i].url) {
5116 ajax({
5117 url: obj.options.data[i].url,
5118 type: 'GET',
5119 dataType: 'text/html',
5120 index: i,
5121 success: function(result) {
5122 obj.options.data[this.index].content = result;
5123 },
5124 complete: function() {
5125 obj.init();
5126 }
5127 });
5128
5129 // Flag loading
5130 loadingRemoteData = true;
5131 }
5132 }
5133 }
5134
5135 if (! loadingRemoteData) {
5136 obj.init();
5137 }
5138
5139 el.tabs = obj;
5140
5141 return obj;
5142}
5143;// CONCATENATED MODULE: ./src/plugins/color.js
5144
5145
5146
5147
5148
5149
5150function Color(el, options) {
5151 // Already created, update options
5152 if (el.color) {
5153 return el.color.setOptions(options, true);
5154 }
5155
5156 // New instance
5157 var obj = { type: 'color' };
5158 obj.options = {};
5159
5160 var container = null;
5161 var backdrop = null;
5162 var content = null;
5163 var resetButton = null;
5164 var closeButton = null;
5165 var tabs = null;
5166 var jsuitesTabs = null;
5167
5168 /**
5169 * Update options
5170 */
5171 obj.setOptions = function(options, reset) {
5172 /**
5173 * @typedef {Object} defaults
5174 * @property {(string|Array)} value - Initial value of the compontent
5175 * @property {string} placeholder - The default instruction text on the element
5176 * @property {requestCallback} onchange - Method to be execute after any changes on the element
5177 * @property {requestCallback} onclose - Method to be execute when the element is closed
5178 * @property {string} doneLabel - Label for button done
5179 * @property {string} resetLabel - Label for button reset
5180 * @property {string} resetValue - Value for button reset
5181 * @property {Bool} showResetButton - Active or note for button reset - default false
5182 */
5183 var defaults = {
5184 placeholder: '',
5185 value: null,
5186 onopen: null,
5187 onclose: null,
5188 onchange: null,
5189 closeOnChange: true,
5190 palette: null,
5191 position: null,
5192 doneLabel: 'Done',
5193 resetLabel: 'Reset',
5194 fullscreen: false,
5195 opened: false,
5196 }
5197
5198 if (! options) {
5199 options = {};
5200 }
5201
5202 if (options && ! options.palette) {
5203 // Default palette
5204 options.palette = palette();
5205 }
5206
5207 // Loop through our object
5208 for (var property in defaults) {
5209 if (options && options.hasOwnProperty(property)) {
5210 obj.options[property] = options[property];
5211 } else {
5212 if (typeof(obj.options[property]) == 'undefined' || reset === true) {
5213 obj.options[property] = defaults[property];
5214 }
5215 }
5216 }
5217
5218 // Update the text of the controls, if they have already been created
5219 if (resetButton) {
5220 resetButton.innerHTML = obj.options.resetLabel;
5221 }
5222 if (closeButton) {
5223 closeButton.innerHTML = obj.options.doneLabel;
5224 }
5225
5226 // Update the pallete
5227 if (obj.options.palette && jsuitesTabs) {
5228 jsuitesTabs.updateContent(0, table());
5229 }
5230
5231 // Value
5232 if (typeof obj.options.value === 'string') {
5233 el.value = obj.options.value;
5234 if (el.tagName === 'INPUT') {
5235 el.style.color = el.value;
5236 el.style.backgroundColor = el.value;
5237 }
5238 }
5239
5240 // Placeholder
5241 if (obj.options.placeholder) {
5242 el.setAttribute('placeholder', obj.options.placeholder);
5243 } else {
5244 if (el.getAttribute('placeholder')) {
5245 el.removeAttribute('placeholder');
5246 }
5247 }
5248
5249 return obj;
5250 }
5251
5252 obj.select = function(color) {
5253 // Remove current selected mark
5254 var selected = container.querySelector('.jcolor-selected');
5255 if (selected) {
5256 selected.classList.remove('jcolor-selected');
5257 }
5258
5259 // Mark cell as selected
5260 if (obj.values[color]) {
5261 obj.values[color].classList.add('jcolor-selected');
5262 }
5263
5264 obj.options.value = color;
5265 }
5266
5267 /**
5268 * Open color pallete
5269 */
5270 obj.open = function() {
5271 if (! container.classList.contains('jcolor-focus')) {
5272 // Start tracking
5273 tracking(obj, true);
5274
5275 // Show color picker
5276 container.classList.add('jcolor-focus');
5277
5278 // Select current color
5279 if (obj.options.value) {
5280 obj.select(obj.options.value);
5281 }
5282
5283 // Reset margin
5284 content.style.marginTop = '';
5285 content.style.marginLeft = '';
5286
5287 var rectContent = content.getBoundingClientRect();
5288 var availableWidth = helpers.getWindowWidth();
5289 var availableHeight = helpers.getWindowHeight();
5290
5291 if (availableWidth < 800 || obj.options.fullscreen == true) {
5292 content.classList.add('jcolor-fullscreen');
5293 animation.slideBottom(content, 1);
5294 backdrop.style.display = 'block';
5295 } else {
5296 if (content.classList.contains('jcolor-fullscreen')) {
5297 content.classList.remove('jcolor-fullscreen');
5298 backdrop.style.display = '';
5299 }
5300
5301 if (obj.options.position) {
5302 content.style.position = 'fixed';
5303 } else {
5304 content.style.position = '';
5305 }
5306
5307 if (rectContent.left + rectContent.width > availableWidth) {
5308 content.style.marginLeft = -1 * (rectContent.left + rectContent.width - (availableWidth - 20)) + 'px';
5309 }
5310 if (rectContent.top + rectContent.height > availableHeight) {
5311 content.style.marginTop = -1 * (rectContent.top + rectContent.height - (availableHeight - 20)) + 'px';
5312 }
5313 }
5314
5315
5316 if (typeof(obj.options.onopen) == 'function') {
5317 obj.options.onopen(el, obj);
5318 }
5319
5320 jsuitesTabs.setBorder(jsuitesTabs.getActive());
5321
5322 // Update sliders
5323 if (obj.options.value) {
5324 var rgb = HexToRgb(obj.options.value);
5325
5326 rgbInputs.forEach(function(rgbInput, index) {
5327 rgbInput.value = rgb[index];
5328 rgbInput.dispatchEvent(new Event('input'));
5329 });
5330 }
5331 }
5332 }
5333
5334 /**
5335 * Close color pallete
5336 */
5337 obj.close = function(ignoreEvents) {
5338 if (container.classList.contains('jcolor-focus')) {
5339 // Remove focus
5340 container.classList.remove('jcolor-focus');
5341 // Make sure backdrop is hidden
5342 backdrop.style.display = '';
5343 // Call related events
5344 if (! ignoreEvents && typeof(obj.options.onclose) == 'function') {
5345 obj.options.onclose(el, obj);
5346 }
5347 // Stop the object
5348 tracking(obj, false);
5349 }
5350
5351 return obj.options.value;
5352 }
5353
5354 /**
5355 * Set value
5356 */
5357 obj.setValue = function(color) {
5358 if (! color) {
5359 color = '';
5360 }
5361
5362 if (color != obj.options.value) {
5363 obj.options.value = color;
5364 slidersResult = color;
5365
5366 // Remove current selecded mark
5367 obj.select(color);
5368
5369 // Onchange
5370 if (typeof(obj.options.onchange) == 'function') {
5371 obj.options.onchange(el, color, obj);
5372 }
5373
5374 // Changes
5375 if (el.value != obj.options.value) {
5376 // Set input value
5377 el.value = obj.options.value;
5378 if (el.tagName === 'INPUT') {
5379 el.style.color = el.value;
5380 el.style.backgroundColor = el.value;
5381 }
5382
5383 // Element onchange native
5384 if (typeof(el.oninput) == 'function') {
5385 el.oninput({
5386 type: 'input',
5387 target: el,
5388 value: el.value
5389 });
5390 }
5391 }
5392
5393 if (obj.options.closeOnChange == true) {
5394 obj.close();
5395 }
5396 }
5397 }
5398
5399 /**
5400 * Get value
5401 */
5402 obj.getValue = function() {
5403 return obj.options.value;
5404 }
5405
5406 var backdropClickControl = false;
5407
5408 // Converts a number in decimal to hexadecimal
5409 var decToHex = function(num) {
5410 var hex = num.toString(16);
5411 return hex.length === 1 ? "0" + hex : hex;
5412 }
5413
5414 // Converts a color in rgb to hexadecimal
5415 var rgbToHex = function(r, g, b) {
5416 return "#" + decToHex(r) + decToHex(g) + decToHex(b);
5417 }
5418
5419 // Converts a number in hexadecimal to decimal
5420 var hexToDec = function(hex) {
5421 return parseInt('0x' + hex);
5422 }
5423
5424 // Converts a color in hexadecimal to rgb
5425 var HexToRgb = function(hex) {
5426 return [hexToDec(hex.substr(1, 2)), hexToDec(hex.substr(3, 2)), hexToDec(hex.substr(5, 2))]
5427 }
5428
5429 var table = function() {
5430 // Content of the first tab
5431 var tableContainer = document.createElement('div');
5432 tableContainer.className = 'jcolor-grid';
5433
5434 // Cells
5435 obj.values = [];
5436
5437 // Table pallete
5438 var t = document.createElement('table');
5439 t.setAttribute('cellpadding', '7');
5440 t.setAttribute('cellspacing', '0');
5441
5442 for (var j = 0; j < obj.options.palette.length; j++) {
5443 var tr = document.createElement('tr');
5444 for (var i = 0; i < obj.options.palette[j].length; i++) {
5445 var td = document.createElement('td');
5446 var color = obj.options.palette[j][i];
5447 if (color.length < 7 && color.substr(0,1) !== '#') {
5448 color = '#' + color;
5449 }
5450 td.style.backgroundColor = color;
5451 td.setAttribute('data-value', color);
5452 td.innerHTML = '';
5453 tr.appendChild(td);
5454
5455 // Selected color
5456 if (obj.options.value == color) {
5457 td.classList.add('jcolor-selected');
5458 }
5459
5460 // Possible values
5461 obj.values[color] = td;
5462 }
5463 t.appendChild(tr);
5464 }
5465
5466 // Append to the table
5467 tableContainer.appendChild(t);
5468
5469 return tableContainer;
5470 }
5471
5472 // Canvas where the image will be rendered
5473 var canvas = document.createElement('canvas');
5474 canvas.width = 200;
5475 canvas.height = 160;
5476 var context = canvas.getContext("2d");
5477
5478 var resizeCanvas = function() {
5479 // Specifications necessary to correctly obtain colors later in certain positions
5480 var m = tabs.firstChild.getBoundingClientRect();
5481 canvas.width = m.width - 14;
5482 gradient()
5483 }
5484
5485 var gradient = function() {
5486 var g = context.createLinearGradient(0, 0, canvas.width, 0);
5487 // Create color gradient
5488 g.addColorStop(0, "rgb(255,0,0)");
5489 g.addColorStop(0.15, "rgb(255,0,255)");
5490 g.addColorStop(0.33, "rgb(0,0,255)");
5491 g.addColorStop(0.49, "rgb(0,255,255)");
5492 g.addColorStop(0.67, "rgb(0,255,0)");
5493 g.addColorStop(0.84, "rgb(255,255,0)");
5494 g.addColorStop(1, "rgb(255,0,0)");
5495 context.fillStyle = g;
5496 context.fillRect(0, 0, canvas.width, canvas.height);
5497 g = context.createLinearGradient(0, 0, 0, canvas.height);
5498 g.addColorStop(0, "rgba(255,255,255,1)");
5499 g.addColorStop(0.5, "rgba(255,255,255,0)");
5500 g.addColorStop(0.5, "rgba(0,0,0,0)");
5501 g.addColorStop(1, "rgba(0,0,0,1)");
5502 context.fillStyle = g;
5503 context.fillRect(0, 0, canvas.width, canvas.height);
5504 }
5505
5506 var hsl = function() {
5507 var element = document.createElement('div');
5508 element.className = "jcolor-hsl";
5509
5510 var point = document.createElement('div');
5511 point.className = 'jcolor-point';
5512
5513 var div = document.createElement('div');
5514 div.appendChild(canvas);
5515 div.appendChild(point);
5516 element.appendChild(div);
5517
5518 // Moves the marquee point to the specified position
5519 var update = function(buttons, x, y) {
5520 if (buttons === 1) {
5521 var rect = element.getBoundingClientRect();
5522 var left = x - rect.left;
5523 var top = y - rect.top;
5524 if (left < 0) {
5525 left = 0;
5526 }
5527 if (top < 0) {
5528 top = 0;
5529 }
5530 if (left > rect.width) {
5531 left = rect.width;
5532 }
5533 if (top > rect.height) {
5534 top = rect.height;
5535 }
5536 point.style.left = left + 'px';
5537 point.style.top = top + 'px';
5538 var pixel = context.getImageData(left, top, 1, 1).data;
5539 slidersResult = rgbToHex(pixel[0], pixel[1], pixel[2]);
5540 }
5541 }
5542
5543 // Applies the point's motion function to the div that contains it
5544 element.addEventListener('mousedown', function(e) {
5545 update(e.buttons, e.clientX, e.clientY);
5546 });
5547
5548 element.addEventListener('mousemove', function(e) {
5549 update(e.buttons, e.clientX, e.clientY);
5550 });
5551
5552 element.addEventListener('touchmove', function(e) {
5553 update(1, e.changedTouches[0].clientX, e.changedTouches[0].clientY);
5554 });
5555
5556 return element;
5557 }
5558
5559 var slidersResult = '';
5560
5561 var rgbInputs = [];
5562
5563 var changeInputColors = function() {
5564 if (slidersResult !== '') {
5565 for (var j = 0; j < rgbInputs.length; j++) {
5566 var currentColor = HexToRgb(slidersResult);
5567
5568 currentColor[j] = 0;
5569
5570 var newGradient = 'linear-gradient(90deg, rgb(';
5571 newGradient += currentColor.join(', ');
5572 newGradient += '), rgb(';
5573
5574 currentColor[j] = 255;
5575
5576 newGradient += currentColor.join(', ');
5577 newGradient += '))';
5578
5579 rgbInputs[j].style.backgroundImage = newGradient;
5580 }
5581 }
5582 }
5583
5584 var sliders = function() {
5585 // Content of the third tab
5586 var slidersElement = document.createElement('div');
5587 slidersElement.className = 'jcolor-sliders';
5588
5589 var slidersBody = document.createElement('div');
5590
5591 // Creates a range-type input with the specified name
5592 var createSliderInput = function(name) {
5593 var inputContainer = document.createElement('div');
5594 inputContainer.className = 'jcolor-sliders-input-container';
5595
5596 var label = document.createElement('label');
5597 label.innerText = name;
5598
5599 var subContainer = document.createElement('div');
5600 subContainer.className = 'jcolor-sliders-input-subcontainer';
5601
5602 var input = document.createElement('input');
5603 input.type = 'range';
5604 input.min = 0;
5605 input.max = 255;
5606 input.value = 0;
5607
5608 input.setAttribute('aria-label', "Color value");
5609 input.setAttribute('aria-valuemin', "0");
5610 input.setAttribute('aria-valuemax', "255");
5611 input.setAttribute('aria-valuenow', "0");
5612
5613 inputContainer.appendChild(label);
5614 subContainer.appendChild(input);
5615
5616 var value = document.createElement('div');
5617 value.innerText = input.value;
5618
5619 input.addEventListener('input', function() {
5620 value.innerText = input.value;
5621 });
5622
5623 subContainer.appendChild(value);
5624 inputContainer.appendChild(subContainer);
5625
5626 slidersBody.appendChild(inputContainer);
5627
5628 return input;
5629 }
5630
5631 // Creates red, green and blue inputs
5632 rgbInputs = [
5633 createSliderInput('Red'),
5634 createSliderInput('Green'),
5635 createSliderInput('Blue'),
5636 ];
5637
5638 slidersElement.appendChild(slidersBody);
5639
5640 // Element that prints the current color
5641 var slidersResultColor = document.createElement('div');
5642 slidersResultColor.className = 'jcolor-sliders-final-color';
5643
5644 var resultElement = document.createElement('div');
5645 resultElement.style.visibility = 'hidden';
5646 resultElement.innerText = 'a';
5647 slidersResultColor.appendChild(resultElement)
5648
5649 // Update the element that prints the current color
5650 var updateResult = function() {
5651 var resultColor = rgbToHex(parseInt(rgbInputs[0].value), parseInt(rgbInputs[1].value), parseInt(rgbInputs[2].value));
5652
5653 resultElement.innerText = resultColor;
5654 resultElement.style.color = resultColor;
5655 resultElement.style.removeProperty('visibility');
5656
5657 slidersResult = resultColor;
5658 }
5659
5660 // Apply the update function to color inputs
5661 rgbInputs.forEach(function(rgbInput) {
5662 rgbInput.addEventListener('input', function() {
5663 updateResult();
5664 changeInputColors();
5665 });
5666 });
5667
5668 slidersElement.appendChild(slidersResultColor);
5669
5670 return slidersElement;
5671 }
5672
5673 var init = function() {
5674 // Initial options
5675 obj.setOptions(options);
5676
5677 // Add a proper input tag when the element is an input
5678 if (el.tagName == 'INPUT') {
5679 el.classList.add('jcolor-input');
5680 el.readOnly = true;
5681 }
5682
5683 // Table container
5684 container = document.createElement('div');
5685 container.className = 'jcolor';
5686
5687 // Table container
5688 backdrop = document.createElement('div');
5689 backdrop.className = 'jcolor-backdrop';
5690 container.appendChild(backdrop);
5691
5692 // Content
5693 content = document.createElement('div');
5694 content.className = 'jcolor-content';
5695
5696 // Controls
5697 var controls = document.createElement('div');
5698 controls.className = 'jcolor-controls';
5699 content.appendChild(controls);
5700
5701 // Reset button
5702 resetButton = document.createElement('div');
5703 resetButton.className = 'jcolor-reset';
5704 resetButton.innerHTML = obj.options.resetLabel;
5705 controls.appendChild(resetButton);
5706
5707 // Close button
5708 closeButton = document.createElement('div');
5709 closeButton.className = 'jcolor-close';
5710 closeButton.innerHTML = obj.options.doneLabel;
5711 controls.appendChild(closeButton);
5712
5713 // Element that will be used to create the tabs
5714 tabs = document.createElement('div');
5715 content.appendChild(tabs);
5716
5717 // Starts the jSuites tabs component
5718 jsuitesTabs = Tabs(tabs, {
5719 animation: true,
5720 data: [
5721 {
5722 title: 'Grid',
5723 contentElement: table(),
5724 },
5725 {
5726 title: 'Spectrum',
5727 contentElement: hsl(),
5728 },
5729 {
5730 title: 'Sliders',
5731 contentElement: sliders(),
5732 }
5733 ],
5734 onchange: function(element, instance, index) {
5735 if (index === 1) {
5736 resizeCanvas();
5737 } else {
5738 var color = slidersResult !== '' ? slidersResult : obj.getValue();
5739
5740 if (index === 2 && color) {
5741 var rgb = HexToRgb(color);
5742
5743 rgbInputs.forEach(function(rgbInput, index) {
5744 rgbInput.value = rgb[index];
5745 rgbInput.dispatchEvent(new Event('input'));
5746 });
5747 }
5748 }
5749 },
5750 palette: 'modern',
5751 });
5752
5753 container.appendChild(content);
5754
5755 // Insert picker after the element
5756 if (el.tagName == 'INPUT') {
5757 el.parentNode.insertBefore(container, el.nextSibling);
5758 } else {
5759 el.appendChild(container);
5760 }
5761
5762 container.addEventListener("click", function(e) {
5763 if (e.target.tagName == 'TD') {
5764 var value = e.target.getAttribute('data-value');
5765 if (value) {
5766 obj.setValue(value);
5767 }
5768 } else if (e.target.classList.contains('jcolor-reset')) {
5769 obj.setValue('');
5770 obj.close();
5771 } else if (e.target.classList.contains('jcolor-close')) {
5772 if (jsuitesTabs.getActive() > 0) {
5773 obj.setValue(slidersResult);
5774 }
5775 obj.close();
5776 } else if (e.target.classList.contains('jcolor-backdrop')) {
5777 obj.close();
5778 } else {
5779 obj.open();
5780 }
5781 });
5782
5783 /**
5784 * If element is focus open the picker
5785 */
5786 el.addEventListener("mouseup", function(e) {
5787 obj.open();
5788 });
5789
5790 // If the picker is open on the spectrum tab, it changes the canvas size when the window size is changed
5791 window.addEventListener('resize', function() {
5792 if (container.classList.contains('jcolor-focus') && jsuitesTabs.getActive() == 1) {
5793 resizeCanvas();
5794 }
5795 });
5796
5797 // Default opened
5798 if (obj.options.opened == true) {
5799 obj.open();
5800 }
5801
5802 // Change
5803 el.change = obj.setValue;
5804
5805 // Global generic value handler
5806 el.val = function(val) {
5807 if (val === undefined) {
5808 return obj.getValue();
5809 } else {
5810 obj.setValue(val);
5811 }
5812 }
5813
5814 // Keep object available from the node
5815 el.color = obj;
5816
5817 // Container shortcut
5818 container.color = obj;
5819 }
5820
5821 obj.toHex = function(rgb) {
5822 var hex = function(x) {
5823 return ("0" + parseInt(x).toString(16)).slice(-2);
5824 }
5825 if (rgb) {
5826 if (/^#[0-9A-F]{6}$/i.test(rgb)) {
5827 return rgb;
5828 } else {
5829 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
5830 if (rgb && rgb.length) {
5831 return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
5832 } else {
5833 return "";
5834 }
5835 }
5836 }
5837 }
5838
5839 init();
5840
5841 return obj;
5842}
5843;// CONCATENATED MODULE: ./src/plugins/contextmenu.js
5844
5845
5846
5847function Contextmenu() {
5848
5849 var Component = function(el, options) {
5850 // New instance
5851 var obj = {type: 'contextmenu'};
5852 obj.options = {};
5853
5854 // Default configuration
5855 var defaults = {
5856 items: null,
5857 onclick: null,
5858 };
5859
5860 // Loop through our object
5861 for (var property in defaults) {
5862 if (options && options.hasOwnProperty(property)) {
5863 obj.options[property] = options[property];
5864 } else {
5865 obj.options[property] = defaults[property];
5866 }
5867 }
5868
5869 // Class definition
5870 el.classList.add('jcontextmenu');
5871
5872 /**
5873 * Open contextmenu
5874 */
5875 obj.open = function (e, items) {
5876 if (items) {
5877 // Update content
5878 obj.options.items = items;
5879 // Create items
5880 obj.create(items);
5881 }
5882
5883 // Close current contextmenu
5884 if (Component.current) {
5885 Component.current.close();
5886 }
5887
5888 // Add to the opened components monitor
5889 tracking(obj, true);
5890
5891 // Show context menu
5892 el.classList.add('jcontextmenu-focus');
5893
5894 // Current
5895 Component.current = obj;
5896
5897 // Coordinates
5898 if ((obj.options.items && obj.options.items.length > 0) || el.children.length) {
5899 if (e.target) {
5900 if (e.changedTouches && e.changedTouches[0]) {
5901 x = e.changedTouches[0].clientX;
5902 y = e.changedTouches[0].clientY;
5903 } else {
5904 var x = e.clientX;
5905 var y = e.clientY;
5906 }
5907 } else {
5908 var x = e.x;
5909 var y = e.y;
5910 }
5911
5912 var rect = el.getBoundingClientRect();
5913
5914 if (window.innerHeight < y + rect.height) {
5915 var h = y - rect.height;
5916 if (h < 0) {
5917 h = 0;
5918 }
5919 el.style.top = h + 'px';
5920 } else {
5921 el.style.top = y + 'px';
5922 }
5923
5924 if (window.innerWidth < x + rect.width) {
5925 if (x - rect.width > 0) {
5926 el.style.left = (x - rect.width) + 'px';
5927 } else {
5928 el.style.left = '10px';
5929 }
5930 } else {
5931 el.style.left = x + 'px';
5932 }
5933 }
5934 }
5935
5936 obj.isOpened = function () {
5937 return el.classList.contains('jcontextmenu-focus') ? true : false;
5938 }
5939
5940 /**
5941 * Close menu
5942 */
5943 obj.close = function () {
5944 if (el.classList.contains('jcontextmenu-focus')) {
5945 el.classList.remove('jcontextmenu-focus');
5946 }
5947 tracking(obj, false);
5948 }
5949
5950 /**
5951 * Create items based on the declared objectd
5952 * @param {object} items - List of object
5953 */
5954 obj.create = function (items) {
5955 // Update content
5956 el.innerHTML = '';
5957
5958 // Add header contextmenu
5959 var itemHeader = createHeader();
5960 el.appendChild(itemHeader);
5961
5962 // Append items
5963 for (var i = 0; i < items.length; i++) {
5964 var itemContainer = createItemElement(items[i]);
5965 el.appendChild(itemContainer);
5966 }
5967 }
5968
5969 /**
5970 * createHeader for context menu
5971 * @private
5972 * @returns {HTMLElement}
5973 */
5974 function createHeader() {
5975 var header = document.createElement('div');
5976 header.classList.add("header");
5977 header.addEventListener("click", function (e) {
5978 e.preventDefault();
5979 e.stopPropagation();
5980 });
5981 var title = document.createElement('a');
5982 title.classList.add("title");
5983 title.innerHTML = dictionary.translate("Menu");
5984
5985 header.appendChild(title);
5986
5987 var closeButton = document.createElement('a');
5988 closeButton.classList.add("close");
5989 closeButton.innerHTML = dictionary.translate("close");
5990 closeButton.addEventListener("click", function (e) {
5991 obj.close();
5992 });
5993
5994 header.appendChild(closeButton);
5995
5996 return header;
5997 }
5998
5999 /**
6000 * Private function for create a new Item element
6001 * @param {type} item
6002 * @returns {jsuitesL#15.jSuites.contextmenu.createItemElement.itemContainer}
6003 */
6004 function createItemElement(item) {
6005 if (item.type && (item.type == 'line' || item.type == 'divisor')) {
6006 var itemContainer = document.createElement('hr');
6007 } else {
6008 var itemContainer = document.createElement('div');
6009 var itemText = document.createElement('a');
6010 itemText.innerHTML = item.title;
6011
6012 if (item.tooltip) {
6013 itemContainer.setAttribute('title', item.tooltip);
6014 }
6015
6016 if (item.icon) {
6017 itemContainer.setAttribute('data-icon', item.icon);
6018 }
6019
6020 if (item.id) {
6021 itemContainer.id = item.id;
6022 }
6023
6024 if (item.disabled) {
6025 itemContainer.className = 'jcontextmenu-disabled';
6026 } else if (item.onclick) {
6027 let method = item.onclick;
6028 itemContainer.addEventListener("mousedown", function (e) {
6029 e.preventDefault();
6030 });
6031 itemContainer.addEventListener("mouseup", function (e) {
6032 method(this, e);
6033 });
6034 }
6035 itemContainer.appendChild(itemText);
6036
6037 if (item.submenu) {
6038 var itemIconSubmenu = document.createElement('span');
6039 itemIconSubmenu.innerHTML = "&#9658;";
6040 itemContainer.appendChild(itemIconSubmenu);
6041 itemContainer.classList.add('jcontexthassubmenu');
6042 var el_submenu = document.createElement('div');
6043 // Class definition
6044 el_submenu.classList.add('jcontextmenu');
6045 // Focusable
6046 el_submenu.setAttribute('tabindex', '900');
6047
6048 // Append items
6049 var submenu = item.submenu;
6050 for (var i = 0; i < submenu.length; i++) {
6051 var itemContainerSubMenu = createItemElement(submenu[i]);
6052 el_submenu.appendChild(itemContainerSubMenu);
6053 }
6054
6055 itemContainer.appendChild(el_submenu);
6056
6057 // Submenu positioning logic:
6058 // Case 1: Default (enough space to the right) - submenu opens to the right of the parent menu item.
6059 // Case 2: Not enough space to the right, but enough to the left - submenu opens to the left of the parent menu item.
6060 // Case 3: Not enough space on either side (e.g., very narrow viewport) - submenu opens below the parent menu item.
6061 itemContainer.addEventListener('mouseenter', function () {
6062 // Reset to default
6063 el_submenu.style.left = '';
6064 el_submenu.style.right = '';
6065 el_submenu.style.minWidth = itemContainer.offsetWidth + 'px';
6066
6067 // Temporarily show submenu to measure
6068 el_submenu.style.display = 'block';
6069 el_submenu.style.opacity = '0';
6070 el_submenu.style.pointerEvents = 'none';
6071
6072 // Use getBoundingClientRect to determine position
6073 var parentRect = itemContainer.getBoundingClientRect();
6074 var submenuRect = el_submenu.getBoundingClientRect();
6075 var viewportWidth = window.innerWidth || document.documentElement.clientWidth;
6076
6077 // Calculate the right edge if rendered to the right
6078 var rightEdge = parentRect.right + submenuRect.width;
6079 var leftEdge = parentRect.left - submenuRect.width;
6080
6081 // If rendering to the right would overflow, render to the left
6082 if (rightEdge > viewportWidth && leftEdge >= 0) {
6083 el_submenu.style.left = 'auto';
6084 el_submenu.style.right = '99%';
6085 }
6086 // If both right and left would overflow, render to the right of the left border (worst case)
6087 else if (rightEdge > viewportWidth && leftEdge < 0) {
6088 el_submenu.style.left = '32px';
6089 el_submenu.style.right = 'auto';
6090 el_submenu.style.top = '100%';
6091 }
6092 // Default: render to the right
6093 else {
6094 el_submenu.style.left = '99%';
6095 el_submenu.style.right = 'auto';
6096 }
6097
6098 // Restore visibility
6099 el_submenu.style.opacity = '';
6100 el_submenu.style.pointerEvents = '';
6101 el_submenu.style.display = '';
6102 });
6103
6104 // Also reset submenu position on mouseleave to avoid stale styles
6105 itemContainer.addEventListener('mouseleave', function () {
6106 el_submenu.style.left = '';
6107 el_submenu.style.right = '';
6108 el_submenu.style.minWidth = '';
6109 });
6110 } else if (item.shortcut) {
6111 var itemShortCut = document.createElement('span');
6112 itemShortCut.innerHTML = item.shortcut;
6113 itemContainer.appendChild(itemShortCut);
6114 }
6115 }
6116 return itemContainer;
6117 }
6118
6119 if (typeof (obj.options.onclick) == 'function') {
6120 el.addEventListener('click', function (e) {
6121 obj.options.onclick(obj, e);
6122 });
6123 }
6124
6125 // Create items
6126 if (obj.options.items) {
6127 obj.create(obj.options.items);
6128 }
6129
6130 window.addEventListener("mousewheel", function () {
6131 obj.close();
6132 });
6133
6134 el.contextmenu = obj;
6135
6136 return obj;
6137 }
6138
6139 return Component;
6140}
6141
6142/* harmony default export */ var contextmenu = (Contextmenu());
6143;// CONCATENATED MODULE: ./src/plugins/dropdown.js
6144
6145
6146
6147
6148
6149
6150
6151function Dropdown() {
6152
6153 var Component = (function (el, options) {
6154 // Already created, update options
6155 if (el.dropdown) {
6156 return el.dropdown.setOptions(options, true);
6157 }
6158
6159 // New instance
6160 var obj = {type: 'dropdown'};
6161 obj.options = {};
6162
6163 // Success
6164 var success = function (data, val) {
6165 // Set data
6166 if (data && data.length) {
6167 // Sort
6168 if (obj.options.sortResults !== false) {
6169 if (typeof obj.options.sortResults == "function") {
6170 data.sort(obj.options.sortResults);
6171 } else {
6172 data.sort(sortData);
6173 }
6174 }
6175
6176 obj.setData(data);
6177 }
6178
6179 // Onload method
6180 if (typeof (obj.options.onload) == 'function') {
6181 obj.options.onload(el, obj, data, val);
6182 }
6183
6184 // Set value
6185 if (val) {
6186 applyValue(val);
6187 }
6188
6189 // Component value
6190 if (val === undefined || val === null) {
6191 obj.options.value = '';
6192 }
6193 el.value = obj.options.value;
6194
6195 // Open dropdown
6196 if (obj.options.opened == true) {
6197 obj.open();
6198 }
6199 }
6200
6201
6202 // Default sort
6203 var sortData = function (itemA, itemB) {
6204 var testA, testB;
6205 if (typeof itemA == "string") {
6206 testA = itemA;
6207 } else {
6208 if (itemA.text) {
6209 testA = itemA.text;
6210 } else if (itemA.name) {
6211 testA = itemA.name;
6212 }
6213 }
6214
6215 if (typeof itemB == "string") {
6216 testB = itemB;
6217 } else {
6218 if (itemB.text) {
6219 testB = itemB.text;
6220 } else if (itemB.name) {
6221 testB = itemB.name;
6222 }
6223 }
6224
6225 if (typeof testA == "string" || typeof testB == "string") {
6226 if (typeof testA != "string") {
6227 testA = "" + testA;
6228 }
6229 if (typeof testB != "string") {
6230 testB = "" + testB;
6231 }
6232 return testA.localeCompare(testB);
6233 } else {
6234 return testA - testB;
6235 }
6236 }
6237
6238 /**
6239 * Reset the options for the dropdown
6240 */
6241 var resetValue = function () {
6242 // Reset value container
6243 obj.value = {};
6244 // Remove selected
6245 for (var i = 0; i < obj.items.length; i++) {
6246 if (obj.items[i].selected == true) {
6247 if (obj.items[i].element) {
6248 obj.items[i].element.classList.remove('jdropdown-selected')
6249 }
6250 obj.items[i].selected = null;
6251 }
6252 }
6253 // Reset options
6254 obj.options.value = '';
6255 // Reset value
6256 el.value = '';
6257 }
6258
6259 /**
6260 * Apply values to the dropdown
6261 */
6262 var applyValue = function (values) {
6263 // Reset the current values
6264 resetValue();
6265
6266 // Read values
6267 if (values !== null) {
6268 if (!values) {
6269 if (typeof (obj.value['']) !== 'undefined') {
6270 obj.value[''] = '';
6271 }
6272 } else {
6273 if (!Array.isArray(values)) {
6274 values = ('' + values).split(';');
6275 }
6276 for (var i = 0; i < values.length; i++) {
6277 obj.value[values[i]] = '';
6278 }
6279 }
6280 }
6281
6282 // Update the DOM
6283 for (var i = 0; i < obj.items.length; i++) {
6284 if (typeof (obj.value[Value(i)]) !== 'undefined') {
6285 if (obj.items[i].element) {
6286 obj.items[i].element.classList.add('jdropdown-selected')
6287 }
6288 obj.items[i].selected = true;
6289
6290 // Keep label
6291 obj.value[Value(i)] = Text(i);
6292 }
6293 }
6294
6295 // Global value
6296 obj.options.value = Object.keys(obj.value).join(';');
6297
6298 // Update labels
6299 obj.header.value = obj.getText();
6300 }
6301
6302 // Get the value of one item
6303 var Value = function (k, v) {
6304 // Legacy purposes
6305 if (!obj.options.format) {
6306 var property = 'value';
6307 } else {
6308 var property = 'id';
6309 }
6310
6311 if (obj.items[k]) {
6312 if (v !== undefined) {
6313 return obj.items[k].data[property] = v;
6314 } else {
6315 return obj.items[k].data[property];
6316 }
6317 }
6318
6319 return '';
6320 }
6321
6322 // Get the label of one item
6323 var Text = function (k, v) {
6324 // Legacy purposes
6325 if (!obj.options.format) {
6326 var property = 'text';
6327 } else {
6328 var property = 'name';
6329 }
6330
6331 if (obj.items[k]) {
6332 if (v !== undefined) {
6333 return obj.items[k].data[property] = v;
6334 } else {
6335 return obj.items[k].data[property];
6336 }
6337 }
6338
6339 return '';
6340 }
6341
6342 var getValue = function () {
6343 return Object.keys(obj.value);
6344 }
6345
6346 var getText = function () {
6347 var data = [];
6348 var k = Object.keys(obj.value);
6349 for (var i = 0; i < k.length; i++) {
6350 data.push(obj.value[k[i]]);
6351 }
6352 return data;
6353 }
6354
6355 obj.setOptions = function (options, reset) {
6356 if (!options) {
6357 options = {};
6358 }
6359
6360 // Default configuration
6361 var defaults = {
6362 url: null,
6363 data: [],
6364 format: 0,
6365 multiple: false,
6366 autocomplete: false,
6367 remoteSearch: false,
6368 lazyLoading: false,
6369 type: null,
6370 width: null,
6371 maxWidth: null,
6372 opened: false,
6373 value: null,
6374 placeholder: '',
6375 newOptions: false,
6376 position: false,
6377 onchange: null,
6378 onload: null,
6379 onopen: null,
6380 onclose: null,
6381 onfocus: null,
6382 onblur: null,
6383 oninsert: null,
6384 onbeforeinsert: null,
6385 onsearch: null,
6386 onbeforesearch: null,
6387 sortResults: false,
6388 autofocus: false,
6389 prompt: null,
6390 allowEmpty: true,
6391 }
6392
6393 // Loop through our object
6394 for (var property in defaults) {
6395 if (options && options.hasOwnProperty(property)) {
6396 obj.options[property] = options[property];
6397 } else {
6398 if (typeof (obj.options[property]) == 'undefined' || reset === true) {
6399 obj.options[property] = defaults[property];
6400 }
6401 }
6402 }
6403
6404 // Force autocomplete search
6405 if (obj.options.remoteSearch == true || obj.options.type === 'searchbar') {
6406 obj.options.autocomplete = true;
6407 }
6408
6409 // New options
6410 if (obj.options.newOptions == true) {
6411 obj.header.classList.add('jdropdown-add');
6412 } else {
6413 obj.header.classList.remove('jdropdown-add');
6414 }
6415
6416 // Autocomplete
6417 if (obj.options.autocomplete == true) {
6418 obj.header.removeAttribute('readonly');
6419 } else {
6420 obj.header.setAttribute('readonly', 'readonly');
6421 }
6422
6423 // Place holder
6424 if (obj.options.placeholder) {
6425 obj.header.setAttribute('placeholder', obj.options.placeholder);
6426 } else {
6427 obj.header.removeAttribute('placeholder');
6428 }
6429
6430 // Remove specific dropdown typing to add again
6431 el.classList.remove('jdropdown-searchbar');
6432 el.classList.remove('jdropdown-picker');
6433 el.classList.remove('jdropdown-list');
6434
6435 if (obj.options.type == 'searchbar') {
6436 el.classList.add('jdropdown-searchbar');
6437 } else if (obj.options.type == 'list') {
6438 el.classList.add('jdropdown-list');
6439 } else if (obj.options.type == 'picker') {
6440 el.classList.add('jdropdown-picker');
6441 } else {
6442 if (helpers.getWindowWidth() < 800) {
6443 if (obj.options.autocomplete) {
6444 el.classList.add('jdropdown-searchbar');
6445 obj.options.type = 'searchbar';
6446 } else {
6447 el.classList.add('jdropdown-picker');
6448 obj.options.type = 'picker';
6449 }
6450 } else {
6451 if (obj.options.width) {
6452 el.style.width = obj.options.width;
6453 el.style.minWidth = obj.options.width;
6454 } else {
6455 el.style.removeProperty('width');
6456 el.style.removeProperty('min-width');
6457 }
6458
6459 el.classList.add('jdropdown-default');
6460 obj.options.type = 'default';
6461 }
6462 }
6463
6464 // Close button
6465 if (obj.options.type == 'searchbar') {
6466 containerHeader.appendChild(closeButton);
6467 } else {
6468 container.insertBefore(closeButton, container.firstChild);
6469 }
6470
6471 // Load the content
6472 if (obj.options.url && !options.data) {
6473 ajax({
6474 url: obj.options.url,
6475 method: 'GET',
6476 dataType: 'json',
6477 success: function (data) {
6478 if (data) {
6479 success(data, obj.options.value);
6480 }
6481 }
6482 });
6483 } else {
6484 success(obj.options.data, obj.options.value);
6485 }
6486
6487 // Return the instance
6488 return obj;
6489 }
6490
6491 // Helpers
6492 var containerHeader = null;
6493 var container = null;
6494 var content = null;
6495 var closeButton = null;
6496 var resetButton = null;
6497 var backdrop = null;
6498
6499 var keyTimer = null;
6500
6501 /**
6502 * Init dropdown
6503 */
6504 var init = function () {
6505 // Do not accept null
6506 if (!options) {
6507 options = {};
6508 }
6509
6510 // If the element is a SELECT tag, create a configuration object
6511 if (el.tagName == 'SELECT') {
6512 var ret = Component.extractFromDom(el, options);
6513 el = ret.el;
6514 options = ret.options;
6515 }
6516
6517 // Place holder
6518 if (!options.placeholder && el.getAttribute('placeholder')) {
6519 options.placeholder = el.getAttribute('placeholder');
6520 }
6521
6522 // Value container
6523 obj.value = {};
6524 // Containers
6525 obj.items = [];
6526 obj.groups = [];
6527 // Search options
6528 obj.search = '';
6529 obj.results = null;
6530
6531 // Create dropdown
6532 el.classList.add('jdropdown');
6533
6534 // Header container
6535 containerHeader = document.createElement('div');
6536 containerHeader.className = 'jdropdown-container-header';
6537
6538 // Header
6539 obj.header = document.createElement('input');
6540 obj.header.className = 'jdropdown-header jss_object';
6541 obj.header.type = 'text';
6542 obj.header.setAttribute('autocomplete', 'off');
6543 obj.header.onfocus = function () {
6544 if (typeof (obj.options.onfocus) == 'function') {
6545 obj.options.onfocus(el);
6546 }
6547 }
6548
6549 obj.header.onblur = function () {
6550 if (typeof (obj.options.onblur) == 'function') {
6551 obj.options.onblur(el);
6552 }
6553 }
6554
6555 obj.header.onkeyup = function (e) {
6556 if (obj.options.autocomplete == true && !keyTimer) {
6557 if (obj.search != obj.header.value.trim()) {
6558 keyTimer = setTimeout(function () {
6559 obj.find(obj.header.value.trim());
6560 keyTimer = null;
6561 }, 400);
6562 }
6563
6564 if (!el.classList.contains('jdropdown-focus')) {
6565 obj.open();
6566 }
6567 } else {
6568 if (!obj.options.autocomplete) {
6569 obj.next(e.key);
6570 }
6571 }
6572 }
6573
6574 // Global controls
6575 if (!Component.hasEvents) {
6576 // Execute only one time
6577 Component.hasEvents = true;
6578 // Enter and Esc
6579 document.addEventListener("keydown", Component.keydown);
6580 }
6581
6582 // Container
6583 container = document.createElement('div');
6584 container.className = 'jdropdown-container';
6585
6586 // Dropdown content
6587 content = document.createElement('div');
6588 content.className = 'jdropdown-content';
6589
6590 // Close button
6591 closeButton = document.createElement('div');
6592 closeButton.className = 'jdropdown-close';
6593 closeButton.textContent = 'Done';
6594
6595 // Reset button
6596 resetButton = document.createElement('div');
6597 resetButton.className = 'jdropdown-reset';
6598 resetButton.textContent = 'x';
6599 resetButton.onclick = function () {
6600 obj.reset();
6601 obj.close();
6602 }
6603
6604 // Create backdrop
6605 backdrop = document.createElement('div');
6606 backdrop.className = 'jdropdown-backdrop';
6607
6608 // Append elements
6609 containerHeader.appendChild(obj.header);
6610
6611 container.appendChild(content);
6612 el.appendChild(containerHeader);
6613 el.appendChild(container);
6614 el.appendChild(backdrop);
6615
6616 // Set the otiptions
6617 obj.setOptions(options);
6618
6619 if ('ontouchsend' in document.documentElement === true) {
6620 el.addEventListener('touchsend', Component.mouseup);
6621 } else {
6622 el.addEventListener('mouseup', Component.mouseup);
6623 }
6624
6625 // Lazyloading
6626 if (obj.options.lazyLoading == true) {
6627 LazyLoading(content, {
6628 loadUp: obj.loadUp,
6629 loadDown: obj.loadDown,
6630 });
6631 }
6632
6633 content.onwheel = function (e) {
6634 e.stopPropagation();
6635 }
6636
6637 // Change method
6638 el.change = obj.setValue;
6639
6640 // Global generic value handler
6641 el.val = function (val) {
6642 if (val === undefined) {
6643 return obj.getValue(obj.options.multiple ? true : false);
6644 } else {
6645 obj.setValue(val);
6646 }
6647 }
6648
6649 // Keep object available from the node
6650 el.dropdown = obj;
6651 }
6652
6653 /**
6654 * Get the current remote source of data URL
6655 */
6656 obj.getUrl = function () {
6657 return obj.options.url;
6658 }
6659
6660 /**
6661 * Set the new data from a remote source
6662 * @param {string} url - url from the remote source
6663 * @param {function} callback - callback when the data is loaded
6664 */
6665 obj.setUrl = function (url, callback) {
6666 obj.options.url = url;
6667
6668 ajax({
6669 url: obj.options.url,
6670 method: 'GET',
6671 dataType: 'json',
6672 success: function (data) {
6673 obj.setData(data);
6674 // Callback
6675 if (typeof (callback) == 'function') {
6676 callback(obj);
6677 }
6678 }
6679 });
6680 }
6681
6682 /**
6683 * Set ID for one item
6684 */
6685 obj.setId = function (item, v) {
6686 // Legacy purposes
6687 if (!obj.options.format) {
6688 var property = 'value';
6689 } else {
6690 var property = 'id';
6691 }
6692
6693 if (typeof (item) == 'object') {
6694 item[property] = v;
6695 } else {
6696 obj.items[item].data[property] = v;
6697 }
6698 }
6699
6700 const add = function(title, id) {
6701 if (! title) {
6702 let current = obj.options.autocomplete == true ? obj.header.value : '';
6703 title = prompt(dictionary.translate('Add A New Option'), current);
6704 if (! title) {
6705 return false;
6706 }
6707 }
6708
6709 // Id
6710 if (! id) {
6711 id = helpers.guid();
6712 }
6713
6714 // Create new item
6715 if (!obj.options.format) {
6716 var item = {
6717 value: id,
6718 text: title,
6719 }
6720 } else {
6721 var item = {
6722 id: id,
6723 name: title,
6724 }
6725 }
6726
6727 // Callback
6728 if (typeof (obj.options.onbeforeinsert) == 'function') {
6729 let ret = obj.options.onbeforeinsert(obj, item);
6730 if (ret === false) {
6731 return false;
6732 } else if (ret) {
6733 item = ret;
6734 }
6735 }
6736
6737 // Add item to the main list
6738 obj.options.data.push(item);
6739
6740 // Create DOM
6741 var newItem = obj.createItem(item);
6742
6743 // Append DOM to the list
6744 content.appendChild(newItem.element);
6745
6746 // Callback
6747 if (typeof (obj.options.oninsert) == 'function') {
6748 obj.options.oninsert(obj, item, newItem);
6749 }
6750
6751 // Show content
6752 if (content.style.display == 'none') {
6753 content.style.display = '';
6754 }
6755
6756 // Search?
6757 if (obj.results) {
6758 obj.results.push(newItem);
6759 }
6760
6761 return item;
6762 }
6763
6764 /**
6765 * Add a new item
6766 * @param {string} title - title of the new item
6767 * @param {string} id - value/id of the new item
6768 */
6769 obj.add = function (title, id) {
6770 if (typeof (obj.options.prompt) == 'function') {
6771 return obj.options.prompt.call(obj, add);
6772 }
6773 return add(title, id);
6774 }
6775
6776 /**
6777 * Create a new item
6778 */
6779 obj.createItem = function (data, group, groupName) {
6780 // Keep the correct source of data
6781 if (!obj.options.format) {
6782 if (!data.value && data.id !== undefined) {
6783 data.value = data.id;
6784 //delete data.id;
6785 }
6786 if (!data.text && data.name !== undefined) {
6787 data.text = data.name;
6788 //delete data.name;
6789 }
6790 } else {
6791 if (!data.id && data.value !== undefined) {
6792 data.id = data.value;
6793 //delete data.value;
6794 }
6795 if (!data.name && data.text !== undefined) {
6796 data.name = data.text
6797 //delete data.text;
6798 }
6799 }
6800
6801 // Create item
6802 var item = {};
6803 item.element = document.createElement('div');
6804 item.element.className = 'jdropdown-item';
6805 item.element.indexValue = obj.items.length;
6806 item.data = data;
6807
6808 // Groupd DOM
6809 if (group) {
6810 item.group = group;
6811 }
6812
6813 // Id
6814 if (data.id) {
6815 item.element.setAttribute('id', data.id);
6816 }
6817
6818 // Disabled
6819 if (data.disabled == true) {
6820 item.element.setAttribute('data-disabled', true);
6821 }
6822
6823 // Tooltip
6824 if (data.tooltip) {
6825 item.element.setAttribute('title', data.tooltip);
6826 }
6827
6828 // Image
6829 if (data.image) {
6830 var image = document.createElement('img');
6831 image.className = 'jdropdown-image';
6832 image.src = data.image;
6833 if (!data.title) {
6834 image.classList.add('jdropdown-image-small');
6835 }
6836 item.element.appendChild(image);
6837 } else if (data.icon) {
6838 var icon = document.createElement('span');
6839 icon.className = "jdropdown-icon material-icons";
6840 icon.innerText = data.icon;
6841 if (!data.title) {
6842 icon.classList.add('jdropdown-icon-small');
6843 }
6844 if (data.color) {
6845 icon.style.color = data.color;
6846 }
6847 item.element.appendChild(icon);
6848 } else if (data.color) {
6849 var color = document.createElement('div');
6850 color.className = 'jdropdown-color';
6851 color.style.backgroundColor = data.color;
6852 item.element.appendChild(color);
6853 }
6854
6855 // Set content
6856 if (!obj.options.format) {
6857 var text = data.text;
6858 } else {
6859 var text = data.name;
6860 }
6861
6862 var node = document.createElement('div');
6863 node.className = 'jdropdown-description';
6864 node.textContent = text || '&nbsp;';
6865
6866 // Title
6867 if (data.title) {
6868 var title = document.createElement('div');
6869 title.className = 'jdropdown-title';
6870 title.innerText = data.title;
6871 node.appendChild(title);
6872 }
6873
6874 // Set content
6875 if (!obj.options.format) {
6876 var val = data.value;
6877 } else {
6878 var val = data.id;
6879 }
6880
6881 // Value
6882 if (obj.value[val]) {
6883 item.element.classList.add('jdropdown-selected');
6884 item.selected = true;
6885 }
6886
6887 // Keep DOM accessible
6888 obj.items.push(item);
6889
6890 // Add node to item
6891 item.element.appendChild(node);
6892
6893 return item;
6894 }
6895
6896 obj.appendData = function (data) {
6897 // Create elements
6898 if (data.length) {
6899 // Helpers
6900 var items = [];
6901 var groups = [];
6902
6903 // Prepare data
6904 for (var i = 0; i < data.length; i++) {
6905 // Process groups
6906 if (data[i].group) {
6907 if (!groups[data[i].group]) {
6908 groups[data[i].group] = [];
6909 }
6910 groups[data[i].group].push(i);
6911 } else {
6912 items.push(i);
6913 }
6914 }
6915
6916 // Number of items counter
6917 var counter = 0;
6918
6919 // Groups
6920 var groupNames = Object.keys(groups);
6921
6922 // Append groups in case exists
6923 if (groupNames.length > 0) {
6924 for (var i = 0; i < groupNames.length; i++) {
6925 // Group container
6926 var group = document.createElement('div');
6927 group.className = 'jdropdown-group';
6928 // Group name
6929 var groupName = document.createElement('div');
6930 groupName.className = 'jdropdown-group-name';
6931 groupName.textContent = groupNames[i];
6932 // Group arrow
6933 var groupArrow = document.createElement('i');
6934 groupArrow.className = 'jdropdown-group-arrow jdropdown-group-arrow-down';
6935 groupName.appendChild(groupArrow);
6936 // Group items
6937 var groupContent = document.createElement('div');
6938 groupContent.className = 'jdropdown-group-items';
6939 for (var j = 0; j < groups[groupNames[i]].length; j++) {
6940 var item = obj.createItem(data[groups[groupNames[i]][j]], group, groupNames[i]);
6941
6942 if (obj.options.lazyLoading == false || counter < 200) {
6943 groupContent.appendChild(item.element);
6944 counter++;
6945 }
6946 }
6947 // Group itens
6948 group.appendChild(groupName);
6949 group.appendChild(groupContent);
6950 // Keep group DOM
6951 obj.groups.push(group);
6952 // Only add to the screen if children on the group
6953 if (groupContent.children.length > 0) {
6954 // Add DOM to the content
6955 content.appendChild(group);
6956 }
6957 }
6958 }
6959
6960 if (items.length) {
6961 for (var i = 0; i < items.length; i++) {
6962 var item = obj.createItem(data[items[i]]);
6963 if (obj.options.lazyLoading == false || counter < 200) {
6964 content.appendChild(item.element);
6965 counter++;
6966 }
6967 }
6968 }
6969 }
6970 }
6971
6972 obj.setData = function (data) {
6973 // Reset current value
6974 resetValue();
6975
6976 // Make sure the content container is blank
6977 content.textContent = '';
6978
6979 // Reset
6980 obj.header.value = '';
6981
6982 // Reset items and values
6983 obj.items = [];
6984
6985 // Prepare data
6986 if (data && data.length) {
6987 for (var i = 0; i < data.length; i++) {
6988 // Compatibility
6989 if (typeof (data[i]) != 'object') {
6990 // Correct format
6991 if (!obj.options.format) {
6992 data[i] = {
6993 value: data[i],
6994 text: data[i]
6995 }
6996 } else {
6997 data[i] = {
6998 id: data[i],
6999 name: data[i]
7000 }
7001 }
7002 }
7003 }
7004
7005 // Append data
7006 obj.appendData(data);
7007
7008 // Update data
7009 obj.options.data = data;
7010 } else {
7011 // Update data
7012 obj.options.data = [];
7013 }
7014
7015 obj.close();
7016 }
7017
7018 obj.getData = function () {
7019 return obj.options.data;
7020 }
7021
7022 /**
7023 * Get position of the item
7024 */
7025 obj.getPosition = function (val) {
7026 for (var i = 0; i < obj.items.length; i++) {
7027 if (Value(i) == val) {
7028 return i;
7029 }
7030 }
7031 return false;
7032 }
7033
7034 /**
7035 * Get dropdown current text
7036 */
7037 obj.getText = function (asArray) {
7038 // Get value
7039 var v = getText();
7040 // Return value
7041 if (asArray) {
7042 return v;
7043 } else {
7044 return v.join('; ');
7045 }
7046 }
7047
7048 /**
7049 * Get dropdown current value
7050 */
7051 obj.getValue = function (asArray) {
7052 // Get value
7053 var v = getValue();
7054 // Return value
7055 if (asArray) {
7056 return v;
7057 } else {
7058 return v.join(';');
7059 }
7060 }
7061
7062 /**
7063 * Change event
7064 */
7065 var change = function (oldValue) {
7066 // Lemonade JS
7067 if (el.value != obj.options.value) {
7068 el.value = obj.options.value;
7069 if (typeof (el.oninput) == 'function') {
7070 el.oninput({
7071 type: 'input',
7072 target: el,
7073 value: el.value
7074 });
7075 }
7076 }
7077
7078 // Events
7079 if (typeof (obj.options.onchange) == 'function') {
7080 obj.options.onchange(el, obj, oldValue, obj.options.value);
7081 }
7082 }
7083
7084 /**
7085 * Set value
7086 */
7087 obj.setValue = function (newValue) {
7088 // Current value
7089 var oldValue = obj.getValue();
7090 // New value
7091 if (Array.isArray(newValue)) {
7092 newValue = newValue.join(';')
7093 }
7094
7095 if (oldValue !== newValue) {
7096 // Set value
7097 applyValue(newValue);
7098
7099 // Change
7100 change(oldValue);
7101 }
7102 }
7103
7104 obj.resetSelected = function () {
7105 obj.setValue(null);
7106 }
7107
7108 obj.selectIndex = function (index, force) {
7109 // Make sure is a number
7110 var index = parseInt(index);
7111
7112 // Only select those existing elements
7113 if (obj.items && obj.items[index] && (force === true || obj.items[index].data.disabled !== true)) {
7114 // Reset cursor to a new position
7115 obj.setCursor(index, false);
7116
7117 // Behaviour
7118 if (!obj.options.multiple) {
7119 // Update value
7120 if (obj.items[index].selected) {
7121 if (obj.options.allowEmpty !== false) {
7122 obj.setValue(null);
7123 }
7124 } else {
7125 obj.setValue(Value(index));
7126 }
7127
7128 // Close component
7129 obj.close();
7130 } else {
7131 // Old value
7132 var oldValue = obj.options.value;
7133
7134 // Toggle option
7135 if (obj.items[index].selected) {
7136 obj.items[index].element.classList.remove('jdropdown-selected');
7137 obj.items[index].selected = false;
7138
7139 delete obj.value[Value(index)];
7140 } else {
7141 // Select element
7142 obj.items[index].element.classList.add('jdropdown-selected');
7143 obj.items[index].selected = true;
7144
7145 // Set value
7146 obj.value[Value(index)] = Text(index);
7147 }
7148
7149 // Global value
7150 obj.options.value = Object.keys(obj.value).join(';');
7151
7152 // Update labels for multiple dropdown
7153 if (obj.options.autocomplete == false) {
7154 obj.header.value = getText().join('; ');
7155 }
7156
7157 // Events
7158 change(oldValue);
7159 }
7160 }
7161 }
7162
7163 obj.selectItem = function (item) {
7164 obj.selectIndex(item.indexValue);
7165 }
7166
7167 var exists = function (k, result) {
7168 for (var j = 0; j < result.length; j++) {
7169 if (!obj.options.format) {
7170 if (result[j].value == k) {
7171 return true;
7172 }
7173 } else {
7174 if (result[j].id == k) {
7175 return true;
7176 }
7177 }
7178 }
7179 return false;
7180 }
7181
7182 obj.find = function (str) {
7183 if (obj.search == str.trim()) {
7184 return false;
7185 }
7186
7187 // Search term
7188 obj.search = str;
7189
7190 // Reset index
7191 obj.setCursor();
7192
7193 // Remove nodes from all groups
7194 if (obj.groups.length) {
7195 for (var i = 0; i < obj.groups.length; i++) {
7196 obj.groups[i].lastChild.textContent = '';
7197 }
7198 }
7199
7200 // Remove all nodes
7201 content.textContent = '';
7202
7203 // Remove current items in the remote search
7204 if (obj.options.remoteSearch == true) {
7205 // Reset results
7206 obj.results = null;
7207 // URL
7208 var url = obj.options.url;
7209
7210 // Ajax call
7211 let o = {
7212 url: url,
7213 method: 'GET',
7214 data: { q: str },
7215 dataType: 'json',
7216 success: function (result) {
7217 // Reset items
7218 obj.items = [];
7219
7220 // Add the current selected items to the results in case they are not there
7221 var current = Object.keys(obj.value);
7222 if (current.length) {
7223 for (var i = 0; i < current.length; i++) {
7224 if (!exists(current[i], result)) {
7225 if (!obj.options.format) {
7226 result.unshift({value: current[i], text: obj.value[current[i]]});
7227 } else {
7228 result.unshift({id: current[i], name: obj.value[current[i]]});
7229 }
7230 }
7231 }
7232 }
7233 // Append data
7234 obj.appendData(result);
7235 // Show or hide results
7236 if (!result.length) {
7237 content.style.display = 'none';
7238 } else {
7239 content.style.display = '';
7240 }
7241
7242 if (typeof(obj.options.onsearch) === 'function') {
7243 obj.options.onsearch(obj, result);
7244 }
7245 }
7246 }
7247
7248 if (typeof(obj.options.onbeforesearch) === 'function') {
7249 let ret = obj.options.onbeforesearch(obj, o);
7250 if (ret === false) {
7251 return;
7252 } else if (typeof(ret) === 'object') {
7253 o = ret;
7254 }
7255 }
7256
7257 // Remote search
7258 ajax(o);
7259 } else {
7260 // Search terms
7261 str = new RegExp(str, 'gi');
7262
7263 // Reset search
7264 var results = [];
7265
7266 // Append options
7267 for (var i = 0; i < obj.items.length; i++) {
7268 // Item label
7269 var label = Text(i);
7270 // Item title
7271 var title = obj.items[i].data.title || '';
7272 // Group name
7273 var groupName = obj.items[i].data.group || '';
7274 // Synonym
7275 var synonym = obj.items[i].data.synonym || '';
7276 if (synonym) {
7277 synonym = synonym.join(' ');
7278 }
7279
7280 if (str == null || obj.items[i].selected == true || label.toString().match(str) || title.match(str) || groupName.match(str) || synonym.match(str)) {
7281 results.push(obj.items[i]);
7282 }
7283 }
7284
7285 if (!results.length) {
7286 content.style.display = 'none';
7287
7288 // Results
7289 obj.results = null;
7290 } else {
7291 content.style.display = '';
7292
7293 // Results
7294 obj.results = results;
7295
7296 // Show 200 items at once
7297 var number = results.length || 0;
7298
7299 // Lazyloading
7300 if (obj.options.lazyLoading == true && number > 200) {
7301 number = 200;
7302 }
7303
7304 for (var i = 0; i < number; i++) {
7305 if (obj.results[i].group) {
7306 if (!obj.results[i].group.parentNode) {
7307 content.appendChild(obj.results[i].group);
7308 }
7309 obj.results[i].group.lastChild.appendChild(obj.results[i].element);
7310 } else {
7311 content.appendChild(obj.results[i].element);
7312 }
7313 }
7314 }
7315 }
7316
7317 // Auto focus
7318 if (obj.options.autofocus == true) {
7319 obj.first();
7320 }
7321 }
7322
7323 obj.open = function () {
7324 // Focus
7325 if (!el.classList.contains('jdropdown-focus')) {
7326 // Current dropdown
7327 Component.current = obj;
7328
7329 // Start tracking
7330 tracking(obj, true);
7331
7332 // Add focus
7333 el.classList.add('jdropdown-focus');
7334
7335 // Animation
7336 if (helpers.getWindowWidth() < 800) {
7337 if (obj.options.type == null || obj.options.type == 'picker') {
7338 animation.slideBottom(container, 1);
7339 }
7340 }
7341
7342 // Filter
7343 if (obj.options.autocomplete == true) {
7344 obj.header.value = obj.search;
7345 obj.header.focus();
7346 }
7347
7348 // Set cursor for the first or first selected element
7349 var k = getValue();
7350 if (k[0]) {
7351 var cursor = obj.getPosition(k[0]);
7352 if (cursor !== false) {
7353 obj.setCursor(cursor);
7354 }
7355 }
7356
7357 // Container Size
7358 if (!obj.options.type || obj.options.type == 'default') {
7359 var rect = el.getBoundingClientRect();
7360 var rectContainer = container.getBoundingClientRect();
7361
7362 if (obj.options.position) {
7363 container.style.position = 'fixed';
7364 if (window.innerHeight < rect.bottom + rectContainer.height) {
7365 container.style.top = '';
7366 container.style.bottom = (window.innerHeight - rect.top) + 1 + 'px';
7367 } else {
7368 container.style.top = rect.bottom + 'px';
7369 container.style.bottom = '';
7370 }
7371 container.style.left = rect.left + 'px';
7372 } else {
7373 if (window.innerHeight < rect.bottom + rectContainer.height) {
7374 container.style.top = '';
7375 container.style.bottom = rect.height + 1 + 'px';
7376 } else {
7377 container.style.top = '';
7378 container.style.bottom = '';
7379 }
7380 }
7381
7382 container.style.minWidth = rect.width + 'px';
7383
7384 if (obj.options.maxWidth) {
7385 container.style.maxWidth = obj.options.maxWidth;
7386 }
7387
7388 if (!obj.items.length && obj.options.autocomplete == true) {
7389 content.style.display = 'none';
7390 } else {
7391 content.style.display = '';
7392 }
7393 }
7394 }
7395
7396 // Events
7397 if (typeof (obj.options.onopen) == 'function') {
7398 obj.options.onopen(el);
7399 }
7400 }
7401
7402 obj.close = function (ignoreEvents) {
7403 if (el.classList.contains('jdropdown-focus')) {
7404 // Update labels
7405 obj.header.value = obj.getText();
7406 // Remove cursor
7407 obj.setCursor();
7408 // Events
7409 if (!ignoreEvents && typeof (obj.options.onclose) == 'function') {
7410 obj.options.onclose(el);
7411 }
7412 // Blur
7413 if (obj.header.blur) {
7414 obj.header.blur();
7415 }
7416 // Remove focus
7417 el.classList.remove('jdropdown-focus');
7418 // Start tracking
7419 tracking(obj, false);
7420 // Current dropdown
7421 Component.current = null;
7422 }
7423
7424 return obj.getValue();
7425 }
7426
7427 /**
7428 * Set cursor
7429 */
7430 obj.setCursor = function (index, setPosition) {
7431 // Remove current cursor
7432 if (obj.currentIndex != null) {
7433 // Remove visual cursor
7434 if (obj.items && obj.items[obj.currentIndex]) {
7435 obj.items[obj.currentIndex].element.classList.remove('jdropdown-cursor');
7436 }
7437 }
7438
7439 if (index == undefined) {
7440 obj.currentIndex = null;
7441 } else {
7442 index = parseInt(index);
7443
7444 // Cursor only for visible items
7445 if (obj.items[index].element.parentNode) {
7446 obj.items[index].element.classList.add('jdropdown-cursor');
7447 obj.currentIndex = index;
7448
7449 // Update scroll to the cursor element
7450 if (setPosition !== false && obj.items[obj.currentIndex].element) {
7451 var container = content.scrollTop;
7452 var element = obj.items[obj.currentIndex].element;
7453 content.scrollTop = element.offsetTop - element.scrollTop + element.clientTop - 95;
7454 }
7455 }
7456 }
7457 }
7458
7459 // Compatibility
7460 obj.resetCursor = obj.setCursor;
7461 obj.updateCursor = obj.setCursor;
7462
7463 /**
7464 * Reset cursor and selected items
7465 */
7466 obj.reset = function () {
7467 // Reset cursor
7468 obj.setCursor();
7469
7470 // Reset selected
7471 obj.setValue(null);
7472