jsuites 5.0.30 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/jsuites.js CHANGED
@@ -1377,1790 +1377,1790 @@ function Animation() {
1377
1377
 
1378
1378
  /* harmony default export */ var animation = (Animation());
1379
1379
  ;// CONCATENATED MODULE: ./src/plugins/mask.js
1380
-
1381
-
1382
-
1383
- function Mask() {
1384
- // Currency
1385
- var tokens = {
1386
- // Text
1387
- text: [ '@' ],
1388
- // Currency tokens
1389
- currency: [ '#(.{1})##0?(.{1}0+)?( ?;(.*)?)?', '#' ],
1390
- // Percentage
1391
- percentage: [ '0{1}(.{1}0+)?%' ],
1392
- // Number
1393
- numeric: [ '0{1}(.{1}0+)?' ],
1394
- // Data tokens
1395
- 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' ],
1396
- // Other
1397
- general: [ 'A', '0', '[0-9a-zA-Z\$]+', '.']
1398
- }
1399
-
1400
- var getDate = function() {
1401
- if (this.mask.toLowerCase().indexOf('[h]') !== -1) {
1402
- var m = 0;
1403
- if (this.date[4]) {
1404
- m = parseFloat(this.date[4] / 60);
1405
- }
1406
- var v = parseInt(this.date[3]) + m;
1407
- v /= 24;
1408
- } else if (! (this.date[0] && this.date[1] && this.date[2]) && (this.date[3] || this.date[4])) {
1409
- v = helpers.two(this.date[3]) + ':' + helpers.two(this.date[4]) + ':' + helpers.two(this.date[5])
1410
- } else {
1411
- if (this.date[0] && this.date[1] && ! this.date[2]) {
1412
- this.date[2] = 1;
1413
- }
1414
- v = helpers.two(this.date[0]) + '-' + helpers.two(this.date[1]) + '-' + helpers.two(this.date[2]);
1415
-
1416
- if (this.date[3] || this.date[4] || this.date[5]) {
1417
- v += ' ' + helpers.two(this.date[3]) + ':' + helpers.two(this.date[4]) + ':' + helpers.two(this.date[5]);
1418
- }
1419
- }
1420
-
1421
- return v;
1422
- }
1423
-
1424
- var extractDate = function() {
1425
- var v = '';
1426
- if (! (this.date[0] && this.date[1] && this.date[2]) && (this.date[3] || this.date[4])) {
1427
- if (this.mask.toLowerCase().indexOf('[h]') !== -1) {
1428
- v = parseInt(this.date[3]);
1429
- } else {
1430
- let h = parseInt(this.date[3]);
1431
- if (h < 13 && this.values.indexOf('PM') !== -1) {
1432
- v = (h+12) % 24;
1433
- } else {
1434
- v = h % 24;
1435
- }
1436
- }
1437
- if (this.date[4]) {
1438
- v += parseFloat(this.date[4] / 60);
1439
- }
1440
- if (this.date[5]) {
1441
- v += parseFloat(this.date[5] / 3600);
1442
- }
1443
- v /= 24;
1444
- } else if (this.date[0] || this.date[1] || this.date[2] || this.date[3] || this.date[4] || this.date[5]) {
1445
- if (this.date[0] && this.date[1] && ! this.date[2]) {
1446
- this.date[2] = 1;
1447
- }
1448
- var t = helpers_date.now(this.date);
1449
- v = helpers_date.dateToNum(t);
1450
- if (this.date[4]) {
1451
- v += parseFloat(this.date[4] / 60);
1452
- }
1453
- }
1454
-
1455
- if (isNaN(v)) {
1456
- v = '';
1457
- }
1458
-
1459
- return v;
1460
- }
1461
-
1462
- var isBlank = function(v) {
1463
- return v === null || v === '' || v === undefined ? true : false;
1464
- }
1465
-
1466
- var isFormula = function(value) {
1467
- var v = (''+value)[0];
1468
- return v == '=' ? true : false;
1469
- }
1470
-
1471
- var isNumeric = function(t) {
1472
- return t === 'currency' || t === 'percentage' || t === 'numeric' ? true : false;
1473
- }
1474
-
1475
- /**
1476
- * Get the decimal defined in the mask configuration
1477
- */
1478
- var getDecimal = function(v) {
1479
- if (v && Number(v) == v) {
1480
- return '.';
1481
- } else {
1482
- if (this.options.decimal) {
1483
- return this.options.decimal;
1484
- } else {
1485
- if (this.locale) {
1486
- var t = Intl.NumberFormat(this.locale).format(1.1);
1487
- return this.options.decimal = t[1];
1488
- } else {
1489
- if (! v) {
1490
- v = this.mask;
1491
- }
1492
- var e = new RegExp('0{1}(.{1})0+', 'ig');
1493
- var t = e.exec(v);
1494
- if (t && t[1] && t[1].length == 1) {
1495
- // Save decimal
1496
- this.options.decimal = t[1];
1497
- // Return decimal
1498
- return t[1];
1499
- } else {
1500
- // Did not find any decimal last resort the default
1501
- var e = new RegExp('#{1}(.{1})#+', 'ig');
1502
- var t = e.exec(v);
1503
- if (t && t[1] && t[1].length == 1) {
1504
- if (t[1] === ',') {
1505
- this.options.decimal = '.';
1506
- } else {
1507
- this.options.decimal = ',';
1508
- }
1509
- } else {
1510
- this.options.decimal = '1.1'.toLocaleString().substring(1,2);
1511
- }
1512
- }
1513
- }
1514
- }
1515
- }
1516
-
1517
- if (this.options.decimal) {
1518
- return this.options.decimal;
1519
- } else {
1520
- return null;
1521
- }
1522
- }
1523
-
1524
- var ParseValue = function(v, decimal) {
1525
- if (v == '') {
1526
- return '';
1527
- }
1528
-
1529
- // Get decimal
1530
- if (! decimal) {
1531
- decimal = getDecimal.call(this);
1532
- }
1533
-
1534
- // New value
1535
- v = (''+v).split(decimal);
1536
-
1537
- // Signal
1538
- var signal = v[0].match(/[-]+/g);
1539
- if (signal && signal.length) {
1540
- signal = true;
1541
- } else {
1542
- signal = false;
1543
- }
1544
-
1545
- v[0] = v[0].match(/[0-9]+/g);
1546
-
1547
- if (v[0]) {
1548
- if (signal) {
1549
- v[0].unshift('-');
1550
- }
1551
- v[0] = v[0].join('');
1552
- } else {
1553
- if (signal) {
1554
- v[0] = '-';
1555
- }
1556
- }
1557
-
1558
- if (v[0] || v[1]) {
1559
- if (v[1] !== undefined) {
1560
- v[1] = v[1].match(/[0-9]+/g);
1561
- if (v[1]) {
1562
- v[1] = v[1].join('');
1563
- } else {
1564
- v[1] = '';
1565
- }
1566
- }
1567
- } else {
1568
- return '';
1569
- }
1570
- return v;
1571
- }
1572
-
1573
- var FormatValue = function(v, event) {
1574
- if (v === '') {
1575
- return '';
1576
- }
1577
- // Get decimal
1578
- var d = getDecimal.call(this);
1579
- // Convert value
1580
- var o = this.options;
1581
- // Parse value
1582
- v = ParseValue.call(this, v);
1583
- if (v === '') {
1584
- return '';
1585
- }
1586
- var t = null;
1587
- // Temporary value
1588
- if (v[0]) {
1589
- if (o.style === 'percent') {
1590
- t = parseFloat(v[0]) / 100;
1591
- } else {
1592
- t = parseFloat(v[0] + '.1');
1593
- }
1594
- }
1595
-
1596
- if ((v[0] === '-' || v[0] === '-00') && ! v[1] && (event && event.inputType == "deleteContentBackward")) {
1597
- return '';
1598
- }
1599
-
1600
- var n = new Intl.NumberFormat(this.locale, o).format(t);
1601
- n = n.split(d);
1602
-
1603
- if (o.style === 'percent') {
1604
- if (n[0].indexOf('%') !== -1) {
1605
- n[0] = n[0].replace('%', '');
1606
- n[2] = '%';
1607
- }
1608
- }
1609
-
1610
- if (typeof(n[1]) !== 'undefined') {
1611
- var s = n[1].replace(/[0-9]*/g, '');
1612
- if (s) {
1613
- n[2] = s;
1614
- }
1615
- }
1616
-
1617
- if (v[1] !== undefined) {
1618
- n[1] = d + v[1];
1619
- } else {
1620
- n[1] = '';
1621
- }
1622
-
1623
- return n.join('');
1624
- }
1625
-
1626
- var Format = function(e, event) {
1627
- var v = Value.call(e);
1628
- if (! v) {
1629
- return;
1630
- }
1631
-
1632
- // Get decimal
1633
- var n = FormatValue.call(this, v, event);
1634
- var t = (n.length) - v.length;
1635
- var index = Caret.call(e) + t;
1636
- // Set value and update caret
1637
- Value.call(e, n, index, true);
1638
- }
1639
-
1640
- var Extract = function(v) {
1641
- // Keep the raw value
1642
- var current = ParseValue.call(this, v);
1643
- if (current) {
1644
- // Negative values
1645
- if (current[0] === '-') {
1646
- current[0] = '-0';
1647
- }
1648
- return parseFloat(current.join('.'));
1649
- }
1650
- return null;
1651
- }
1652
-
1653
- /**
1654
- * Caret getter and setter methods
1655
- */
1656
- var Caret = function(index, adjustNumeric) {
1657
- if (index === undefined) {
1658
- if (this.tagName == 'DIV') {
1659
- var pos = 0;
1660
- var s = window.getSelection();
1661
- if (s) {
1662
- if (s.rangeCount !== 0) {
1663
- var r = s.getRangeAt(0);
1664
- var p = r.cloneRange();
1665
- p.selectNodeContents(this);
1666
- p.setEnd(r.endContainer, r.endOffset);
1667
- pos = p.toString().length;
1668
- }
1669
- }
1670
- return pos;
1671
- } else {
1672
- return this.selectionStart;
1673
- }
1674
- } else {
1675
- // Get the current value
1676
- var n = Value.call(this);
1677
-
1678
- // Review the position
1679
- if (adjustNumeric) {
1680
- var p = null;
1681
- for (var i = 0; i < n.length; i++) {
1682
- if (n[i].match(/[\-0-9]/g) || n[i] === '.' || n[i] === ',') {
1683
- p = i;
1684
- }
1685
- }
1686
-
1687
- // If the string has no numbers
1688
- if (p === null) {
1689
- p = n.indexOf(' ');
1690
- }
1691
-
1692
- if (index >= p) {
1693
- index = p + 1;
1694
- }
1695
- }
1696
-
1697
- // Do not update caret
1698
- if (index > n.length) {
1699
- index = n.length;
1700
- }
1701
-
1702
- if (index) {
1703
- // Set caret
1704
- if (this.tagName == 'DIV') {
1705
- var s = window.getSelection();
1706
- var r = document.createRange();
1707
-
1708
- if (this.childNodes[0]) {
1709
- r.setStart(this.childNodes[0], index);
1710
- s.removeAllRanges();
1711
- s.addRange(r);
1712
- }
1713
- } else {
1714
- this.selectionStart = index;
1715
- this.selectionEnd = index;
1716
- }
1717
- }
1718
- }
1719
- }
1720
-
1721
- /**
1722
- * Value getter and setter method
1723
- */
1724
- var Value = function(v, updateCaret, adjustNumeric) {
1725
- if (this.tagName == 'DIV') {
1726
- if (v === undefined) {
1727
- var v = this.innerText;
1728
- if (this.value && this.value.length > v.length) {
1729
- v = this.value;
1730
- }
1731
- return v;
1732
- } else {
1733
- if (this.innerText !== v) {
1734
- this.innerText = v;
1735
-
1736
- if (updateCaret) {
1737
- Caret.call(this, updateCaret, adjustNumeric);
1738
- }
1739
- }
1740
- }
1741
- } else {
1742
- if (v === undefined) {
1743
- return this.value;
1744
- } else {
1745
- if (this.value !== v) {
1746
- this.value = v;
1747
- if (updateCaret) {
1748
- Caret.call(this, updateCaret, adjustNumeric);
1749
- }
1750
- }
1751
- }
1752
- }
1753
- }
1754
-
1755
- // Labels
1756
- var weekDaysFull = helpers_date.weekdays;
1757
- var weekDays = helpers_date.weekdaysShort;
1758
- var monthsFull = helpers_date.months;
1759
- var months = helpers_date.monthsShort;
1760
-
1761
- var parser = {
1762
- 'YEAR': function(v, s) {
1763
- var y = ''+new Date().getFullYear();
1764
-
1765
- if (typeof(this.values[this.index]) === 'undefined') {
1766
- this.values[this.index] = '';
1767
- }
1768
- if (parseInt(v) >= 0 && parseInt(v) <= 10) {
1769
- if (this.values[this.index].length < s) {
1770
- this.values[this.index] += v;
1771
- }
1772
- }
1773
- if (this.values[this.index].length == s) {
1774
- if (s == 2) {
1775
- var y = y.substr(0,2) + this.values[this.index];
1776
- } else if (s == 3) {
1777
- var y = y.substr(0,1) + this.values[this.index];
1778
- } else if (s == 4) {
1779
- var y = this.values[this.index];
1780
- }
1781
- this.date[0] = y;
1782
- this.index++;
1783
- }
1784
- },
1785
- 'YYYY': function(v) {
1786
- parser.YEAR.call(this, v, 4);
1787
- },
1788
- 'YYY': function(v) {
1789
- parser.YEAR.call(this, v, 3);
1790
- },
1791
- 'YY': function(v) {
1792
- parser.YEAR.call(this, v, 2);
1793
- },
1794
- 'FIND': function(v, a) {
1795
- if (isBlank(this.values[this.index])) {
1796
- this.values[this.index] = '';
1797
- }
1798
- if (this.event && this.event.inputType && this.event.inputType.indexOf('delete') > -1) {
1799
- this.values[this.index] += v;
1800
- return;
1801
- }
1802
- var pos = 0;
1803
- var count = 0;
1804
- var value = (this.values[this.index] + v).toLowerCase();
1805
- for (var i = 0; i < a.length; i++) {
1806
- if (a[i].toLowerCase().indexOf(value) == 0) {
1807
- pos = i;
1808
- count++;
1809
- }
1810
- }
1811
- if (count > 1) {
1812
- this.values[this.index] += v;
1813
- } else if (count == 1) {
1814
- // Jump number of chars
1815
- var t = (a[pos].length - this.values[this.index].length) - 1;
1816
- this.position += t;
1817
-
1818
- this.values[this.index] = a[pos];
1819
- this.index++;
1820
- return pos;
1821
- }
1822
- },
1823
- 'MMM': function(v) {
1824
- var ret = parser.FIND.call(this, v, months);
1825
- if (ret !== undefined) {
1826
- this.date[1] = ret + 1;
1827
- }
1828
- },
1829
- 'MON': function(v) {
1830
- parser['MMM'].call(this, v);
1831
- },
1832
- 'MMMM': function(v) {
1833
- var ret = parser.FIND.call(this, v, monthsFull);
1834
- if (ret !== undefined) {
1835
- this.date[1] = ret + 1;
1836
- }
1837
- },
1838
- 'MONTH': function(v) {
1839
- parser['MMMM'].call(this, v);
1840
- },
1841
- 'MMMMM': function(v) {
1842
- if (isBlank(this.values[this.index])) {
1843
- this.values[this.index] = '';
1844
- }
1845
- var pos = 0;
1846
- var count = 0;
1847
- var value = (this.values[this.index] + v).toLowerCase();
1848
- for (var i = 0; i < monthsFull.length; i++) {
1849
- if (monthsFull[i][0].toLowerCase().indexOf(value) == 0) {
1850
- this.values[this.index] = monthsFull[i][0];
1851
- this.date[1] = i + 1;
1852
- this.index++;
1853
- break;
1854
- }
1855
- }
1856
- },
1857
- 'MM': function(v) {
1858
- if (isBlank(this.values[this.index])) {
1859
- if (parseInt(v) > 1 && parseInt(v) < 10) {
1860
- this.date[1] = this.values[this.index] = '0' + v;
1861
- this.index++;
1862
- } else if (parseInt(v) < 2) {
1863
- this.values[this.index] = v;
1864
- }
1865
- } else {
1866
- if (this.values[this.index] == 1 && parseInt(v) < 3) {
1867
- this.date[1] = this.values[this.index] += v;
1868
- this.index++;
1869
- } else if (this.values[this.index] == 0 && parseInt(v) > 0 && parseInt(v) < 10) {
1870
- this.date[1] = this.values[this.index] += v;
1871
- this.index++;
1872
- }
1873
- }
1874
- },
1875
- 'M': function(v) {
1876
- var test = false;
1877
- if (parseInt(v) >= 0 && parseInt(v) < 10) {
1878
- if (isBlank(this.values[this.index])) {
1879
- this.values[this.index] = v;
1880
- if (v > 1) {
1881
- this.date[1] = this.values[this.index];
1882
- this.index++;
1883
- }
1884
- } else {
1885
- if (this.values[this.index] == 1 && parseInt(v) < 3) {
1886
- this.date[1] = this.values[this.index] += v;
1887
- this.index++;
1888
- } else if (this.values[this.index] == 0 && parseInt(v) > 0) {
1889
- this.date[1] = this.values[this.index] += v;
1890
- this.index++;
1891
- } else {
1892
- var test = true;
1893
- }
1894
- }
1895
- } else {
1896
- var test = true;
1897
- }
1898
-
1899
- // Re-test
1900
- if (test == true) {
1901
- var t = parseInt(this.values[this.index]);
1902
- if (t > 0 && t < 12) {
1903
- this.date[1] = this.values[this.index];
1904
- this.index++;
1905
- // Repeat the character
1906
- this.position--;
1907
- }
1908
- }
1909
- },
1910
- 'D': function(v) {
1911
- var test = false;
1912
- if (parseInt(v) >= 0 && parseInt(v) < 10) {
1913
- if (isBlank(this.values[this.index])) {
1914
- this.values[this.index] = v;
1915
- if (parseInt(v) > 3) {
1916
- this.date[2] = this.values[this.index];
1917
- this.index++;
1918
- }
1919
- } else {
1920
- if (this.values[this.index] == 3 && parseInt(v) < 2) {
1921
- this.date[2] = this.values[this.index] += v;
1922
- this.index++;
1923
- } else if (this.values[this.index] == 1 || this.values[this.index] == 2) {
1924
- this.date[2] = this.values[this.index] += v;
1925
- this.index++;
1926
- } else if (this.values[this.index] == 0 && parseInt(v) > 0) {
1927
- this.date[2] = this.values[this.index] += v;
1928
- this.index++;
1929
- } else {
1930
- var test = true;
1931
- }
1932
- }
1933
- } else {
1934
- var test = true;
1935
- }
1936
-
1937
- // Re-test
1938
- if (test == true) {
1939
- var t = parseInt(this.values[this.index]);
1940
- if (t > 0 && t < 32) {
1941
- this.date[2] = this.values[this.index];
1942
- this.index++;
1943
- // Repeat the character
1944
- this.position--;
1945
- }
1946
- }
1947
- },
1948
- 'DD': function(v) {
1949
- if (isBlank(this.values[this.index])) {
1950
- if (parseInt(v) > 3 && parseInt(v) < 10) {
1951
- this.date[2] = this.values[this.index] = '0' + v;
1952
- this.index++;
1953
- } else if (parseInt(v) < 10) {
1954
- this.values[this.index] = v;
1955
- }
1956
- } else {
1957
- if (this.values[this.index] == 3 && parseInt(v) < 2) {
1958
- this.date[2] = this.values[this.index] += v;
1959
- this.index++;
1960
- } else if ((this.values[this.index] == 1 || this.values[this.index] == 2) && parseInt(v) < 10) {
1961
- this.date[2] = this.values[this.index] += v;
1962
- this.index++;
1963
- } else if (this.values[this.index] == 0 && parseInt(v) > 0 && parseInt(v) < 10) {
1964
- this.date[2] = this.values[this.index] += v;
1965
- this.index++;
1966
- }
1967
- }
1968
- },
1969
- 'DDD': function(v) {
1970
- parser.FIND.call(this, v, weekDays);
1971
- },
1972
- 'DY': function(v) {
1973
- parser['DDD'].call(this, v);
1974
- },
1975
- 'DDDD': function(v) {
1976
- parser.FIND.call(this, v, weekDaysFull);
1977
- },
1978
- 'DAY': function(v) {
1979
- parser['DDDD'].call(this, v);
1980
- },
1981
- 'HH12': function(v, two) {
1982
- if (isBlank(this.values[this.index])) {
1983
- if (parseInt(v) > 1 && parseInt(v) < 10) {
1984
- if (two) {
1985
- v = 0 + v;
1986
- }
1987
- this.date[3] = this.values[this.index] = v;
1988
- this.index++;
1989
- } else if (parseInt(v) < 10) {
1990
- this.values[this.index] = v;
1991
- }
1992
- } else {
1993
- if (this.values[this.index] == 1 && parseInt(v) < 3) {
1994
- this.date[3] = this.values[this.index] += v;
1995
- this.index++;
1996
- } else if (this.values[this.index] < 1 && parseInt(v) < 10) {
1997
- this.date[3] = this.values[this.index] += v;
1998
- this.index++;
1999
- }
2000
- }
2001
- },
2002
- 'HH24': function(v, two) {
2003
- if (parseInt(v) >= 0 && parseInt(v) < 10) {
2004
- if (this.values[this.index] == null || this.values[this.index] == '') {
2005
- if (parseInt(v) > 2 && parseInt(v) < 10) {
2006
- if (two) {
2007
- v = 0 + v;
2008
- }
2009
- this.date[3] = this.values[this.index] = v;
2010
- this.index++;
2011
- } else if (parseInt(v) < 10) {
2012
- this.values[this.index] = v;
2013
- }
2014
- } else {
2015
- if (this.values[this.index] == 2 && parseInt(v) < 4) {
2016
- if (! two && this.values[this.index] === '0') {
2017
- this.values[this.index] = '';
2018
- }
2019
- this.date[3] = this.values[this.index] += v;
2020
- this.index++;
2021
- } else if (this.values[this.index] < 2 && parseInt(v) < 10) {
2022
- if (! two && this.values[this.index] === '0') {
2023
- this.values[this.index] = '';
2024
- }
2025
- this.date[3] = this.values[this.index] += v;
2026
- this.index++;
2027
- }
2028
- }
2029
- }
2030
- },
2031
- 'HH': function(v) {
2032
- parser['HH24'].call(this, v, 1);
2033
- },
2034
- 'H': function(v) {
2035
- parser['HH24'].call(this, v, 0);
2036
- },
2037
- '\\[H\\]': function(v) {
2038
- if (this.values[this.index] == undefined) {
2039
- this.values[this.index] = '';
2040
- }
2041
- if (v.match(/[0-9]/g)) {
2042
- this.date[3] = this.values[this.index] += v;
2043
- } else {
2044
- if (this.values[this.index].match(/[0-9]/g)) {
2045
- this.date[3] = this.values[this.index];
2046
- this.index++;
2047
- // Repeat the character
2048
- this.position--;
2049
- }
2050
- }
2051
- },
2052
- 'N60': function(v, i) {
2053
- if (this.values[this.index] == null || this.values[this.index] == '') {
2054
- if (parseInt(v) > 5 && parseInt(v) < 10) {
2055
- this.date[i] = this.values[this.index] = '0' + v;
2056
- this.index++;
2057
- } else if (parseInt(v) < 10) {
2058
- this.values[this.index] = v;
2059
- }
2060
- } else {
2061
- if (parseInt(v) < 10) {
2062
- this.date[i] = this.values[this.index] += v;
2063
- this.index++;
2064
- }
2065
- }
2066
- },
2067
- 'MI': function(v) {
2068
- parser.N60.call(this, v, 4);
2069
- },
2070
- 'SS': function(v) {
2071
- parser.N60.call(this, v, 5);
2072
- },
2073
- 'AM/PM': function(v) {
2074
- if (typeof(this.values[this.index]) === 'undefined') {
2075
- this.values[this.index] = '';
2076
- }
2077
-
2078
- if (this.values[this.index] === '') {
2079
- if (v.match(/a/i) && this.date[3] < 13) {
2080
- this.values[this.index] += 'A';
2081
- } else if (v.match(/p/i)) {
2082
- this.values[this.index] += 'P';
2083
- }
2084
- } else if (this.values[this.index] === 'A' || this.values[this.index] === 'P') {
2085
- this.values[this.index] += 'M';
2086
- this.index++;
2087
- }
2088
- },
2089
- 'WD': function(v) {
2090
- if (typeof(this.values[this.index]) === 'undefined') {
2091
- this.values[this.index] = '';
2092
- }
2093
- if (parseInt(v) >= 0 && parseInt(v) < 7) {
2094
- this.values[this.index] = v;
2095
- }
2096
- if (this.values[this.index].length == 1) {
2097
- this.index++;
2098
- }
2099
- },
2100
- '0{1}(.{1}0+)?': function(v) {
2101
- // Get decimal
2102
- var decimal = getDecimal.call(this);
2103
- // Negative number
2104
- var neg = false;
2105
- // Create if is blank
2106
- if (isBlank(this.values[this.index])) {
2107
- this.values[this.index] = '';
2108
- } else {
2109
- if (this.values[this.index] == '-') {
2110
- neg = true;
2111
- }
2112
- }
2113
- var current = ParseValue.call(this, this.values[this.index], decimal);
2114
- if (current) {
2115
- this.values[this.index] = current.join(decimal);
2116
- }
2117
- // New entry
2118
- if (parseInt(v) >= 0 && parseInt(v) < 10) {
2119
- // Replace the zero for a number
2120
- if (this.values[this.index] == '0' && v > 0) {
2121
- this.values[this.index] = '';
2122
- } else if (this.values[this.index] == '-0' && v > 0) {
2123
- this.values[this.index] = '-';
2124
- }
2125
- // Don't add up zeros because does not mean anything here
2126
- if ((this.values[this.index] != '0' && this.values[this.index] != '-0') || v == decimal) {
2127
- this.values[this.index] += v;
2128
- }
2129
- } else if (decimal && v == decimal) {
2130
- if (this.values[this.index].indexOf(decimal) == -1) {
2131
- if (! this.values[this.index]) {
2132
- this.values[this.index] = '0';
2133
- }
2134
- this.values[this.index] += v;
2135
- }
2136
- } else if (v == '-') {
2137
- // Negative signed
2138
- neg = true;
2139
- }
2140
-
2141
- if (neg === true && this.values[this.index][0] !== '-') {
2142
- this.values[this.index] = '-' + this.values[this.index];
2143
- }
2144
- },
2145
- '0{1}(.{1}0+)?%': function(v) {
2146
- parser['0{1}(.{1}0+)?'].call(this, v);
2147
-
2148
- if (this.values[this.index].match(/[\-0-9]/g)) {
2149
- if (this.values[this.index] && this.values[this.index].indexOf('%') == -1) {
2150
- this.values[this.index] += '%';
2151
- }
2152
- } else {
2153
- this.values[this.index] = '';
2154
- }
2155
- },
2156
- '#(.{1})##0?(.{1}0+)?( ?;(.*)?)?': function(v) {
2157
- // Parse number
2158
- parser['0{1}(.{1}0+)?'].call(this, v);
2159
- // Get decimal
2160
- var decimal = getDecimal.call(this);
2161
- // Get separator
2162
- var separator = this.tokens[this.index].substr(1,1);
2163
- // Negative
2164
- var negative = this.values[this.index][0] === '-' ? true : false;
2165
- // Current value
2166
- var current = ParseValue.call(this, this.values[this.index], decimal);
2167
-
2168
- // Get main and decimal parts
2169
- if (current !== '') {
2170
- // Format number
2171
- var n = current[0].match(/[0-9]/g);
2172
- if (n) {
2173
- // Format
2174
- n = n.join('');
2175
- var t = [];
2176
- var s = 0;
2177
- for (var j = n.length - 1; j >= 0 ; j--) {
2178
- t.push(n[j]);
2179
- s++;
2180
- if (! (s % 3)) {
2181
- t.push(separator);
2182
- }
2183
- }
2184
- t = t.reverse();
2185
- current[0] = t.join('');
2186
- if (current[0].substr(0,1) == separator) {
2187
- current[0] = current[0].substr(1);
2188
- }
2189
- } else {
2190
- current[0] = '';
2191
- }
2192
-
2193
- // Value
2194
- this.values[this.index] = current.join(decimal);
2195
-
2196
- // Negative
2197
- if (negative) {
2198
- this.values[this.index] = '-' + this.values[this.index];
2199
- }
2200
- }
2201
- },
2202
- '0': function(v) {
2203
- if (v.match(/[0-9]/g)) {
2204
- this.values[this.index] = v;
2205
- this.index++;
2206
- }
2207
- },
2208
- '[0-9a-zA-Z$]+': function(v) {
2209
- if (isBlank(this.values[this.index])) {
2210
- this.values[this.index] = '';
2211
- }
2212
- var t = this.tokens[this.index];
2213
- var s = this.values[this.index];
2214
- var i = s.length;
2215
-
2216
- if (t[i] == v) {
2217
- this.values[this.index] += v;
2218
-
2219
- if (this.values[this.index] == t) {
2220
- this.index++;
2221
- }
2222
- } else {
2223
- this.values[this.index] = t;
2224
- this.index++;
2225
-
2226
- if (v.match(/[\-0-9]/g)) {
2227
- // Repeat the character
2228
- this.position--;
2229
- }
2230
- }
2231
- },
2232
- 'A': function(v) {
2233
- if (v.match(/[a-zA-Z]/gi)) {
2234
- this.values[this.index] = v;
2235
- this.index++;
2236
- }
2237
- },
2238
- '.': function(v) {
2239
- parser['[0-9a-zA-Z$]+'].call(this, v);
2240
- },
2241
- '@': function(v) {
2242
- if (isBlank(this.values[this.index])) {
2243
- this.values[this.index] = '';
2244
- }
2245
- this.values[this.index] += v;
2246
- }
2247
- }
2248
-
2249
- /**
2250
- * Get the tokens in the mask string
2251
- */
2252
- var getTokens = function(str) {
2253
- if (this.type == 'general') {
2254
- var t = [].concat(tokens.general);
2255
- } else {
2256
- var t = [].concat(tokens.currency, tokens.datetime, tokens.percentage, tokens.numeric, tokens.text, tokens.general);
2257
- }
2258
- // Expression to extract all tokens from the string
2259
- var e = new RegExp(t.join('|'), 'gi');
2260
- // Extract
2261
- return str.match(e);
2262
- }
2263
-
2264
- /**
2265
- * Get the method of one given token
2266
- */
2267
- var getMethod = function(str) {
2268
- if (! this.type) {
2269
- var types = Object.keys(tokens);
2270
- } else if (this.type == 'text') {
2271
- var types = [ 'text' ];
2272
- } else if (this.type == 'general') {
2273
- var types = [ 'general' ];
2274
- } else if (this.type == 'datetime') {
2275
- var types = [ 'numeric', 'datetime', 'general' ];
2276
- } else {
2277
- var types = [ 'currency', 'percentage', 'numeric', 'general' ];
2278
- }
2279
-
2280
- // Found
2281
- for (var i = 0; i < types.length; i++) {
2282
- var type = types[i];
2283
- for (var j = 0; j < tokens[type].length; j++) {
2284
- var e = new RegExp(tokens[type][j], 'gi');
2285
- var r = str.match(e);
2286
- if (r) {
2287
- return { type: type, method: tokens[type][j] }
2288
- }
2289
- }
2290
- }
2291
- }
2292
-
2293
- /**
2294
- * Identify each method for each token
2295
- */
2296
- var getMethods = function(t) {
2297
- var result = [];
2298
- for (var i = 0; i < t.length; i++) {
2299
- var m = getMethod.call(this, t[i]);
2300
- if (m) {
2301
- result.push(m.method);
2302
- } else {
2303
- result.push(null);
2304
- }
2305
- }
2306
-
2307
- // Compatibility with excel
2308
- for (var i = 0; i < result.length; i++) {
2309
- if (result[i] == 'MM') {
2310
- // Not a month, correct to minutes
2311
- if (result[i-1] && result[i-1].indexOf('H') >= 0) {
2312
- result[i] = 'MI';
2313
- } else if (result[i-2] && result[i-2].indexOf('H') >= 0) {
2314
- result[i] = 'MI';
2315
- } else if (result[i+1] && result[i+1].indexOf('S') >= 0) {
2316
- result[i] = 'MI';
2317
- } else if (result[i+2] && result[i+2].indexOf('S') >= 0) {
2318
- result[i] = 'MI';
2319
- }
2320
- }
2321
- }
2322
-
2323
- return result;
2324
- }
2325
-
2326
- /**
2327
- * Get the type for one given token
2328
- */
2329
- var getType = function(str) {
2330
- var m = getMethod.call(this, str);
2331
- if (m) {
2332
- var type = m.type;
2333
- }
2334
-
2335
- if (type) {
2336
- var numeric = 0;
2337
- // Make sure the correct type
2338
- var t = getTokens.call(this, str);
2339
- for (var i = 0; i < t.length; i++) {
2340
- m = getMethod.call(this, t[i]);
2341
- if (m && isNumeric(m.type)) {
2342
- numeric++;
2343
- }
2344
- }
2345
- if (numeric > 1) {
2346
- type = 'general';
2347
- }
2348
- }
2349
-
2350
- return type;
2351
- }
2352
-
2353
- /**
2354
- * Parse character per character using the detected tokens in the mask
2355
- */
2356
- var parse = function() {
2357
- // Parser method for this position
2358
- if (typeof(parser[this.methods[this.index]]) == 'function') {
2359
- parser[this.methods[this.index]].call(this, this.value[this.position]);
2360
- this.position++;
2361
- } else {
2362
- this.values[this.index] = this.tokens[this.index];
2363
- this.index++;
2364
- }
2365
- }
2366
-
2367
- var toPlainString = function(num) {
2368
- return (''+ +num).replace(/(-?)(\d*)\.?(\d*)e([+-]\d+)/,
2369
- function(a,b,c,d,e) {
2370
- return e < 0
2371
- ? b + '0.' + Array(1-e-c.length).join(0) + c + d
2372
- : b + c + d + Array(e-d.length+1).join(0);
2373
- });
2374
- }
2375
-
2376
- /**
2377
- * Mask function
2378
- * @param {mixed|string} JS input or a string to be parsed
2379
- * @param {object|string} When the first param is a string, the second is the mask or object with the mask options
2380
- */
2381
- var obj = function(e, config, returnObject) {
2382
- // Options
2383
- var r = null;
2384
- var t = null;
2385
- var o = {
2386
- // Element
2387
- input: null,
2388
- // Current value
2389
- value: null,
2390
- // Mask options
2391
- options: {},
2392
- // New values for each token found
2393
- values: [],
2394
- // Token position
2395
- index: 0,
2396
- // Character position
2397
- position: 0,
2398
- // Date raw values
2399
- date: [0,0,0,0,0,0],
2400
- // Raw number for the numeric values
2401
- number: 0,
2402
- }
2403
-
2404
- // This is a JavaScript Event
2405
- if (typeof(e) == 'object') {
2406
- // Element
2407
- o.input = e.target;
2408
- // Current value
2409
- o.value = Value.call(e.target);
2410
- // Current caret position
2411
- o.caret = Caret.call(e.target);
2412
- // Mask
2413
- if (t = e.target.getAttribute('data-mask')) {
2414
- o.mask = t;
2415
- }
2416
- // Type
2417
- if (t = e.target.getAttribute('data-type')) {
2418
- o.type = t;
2419
- }
2420
- // Options
2421
- if (e.target.mask) {
2422
- if (e.target.mask.options) {
2423
- o.options = e.target.mask.options;
2424
- }
2425
- if (e.target.mask.locale) {
2426
- o.locale = e.target.mask.locale;
2427
- }
2428
- } else {
2429
- // Locale
2430
- if (t = e.target.getAttribute('data-locale')) {
2431
- o.locale = t;
2432
- if (o.mask) {
2433
- o.options.style = o.mask;
2434
- }
2435
- }
2436
- }
2437
- // Extra configuration
2438
- if (e.target.attributes && e.target.attributes.length) {
2439
- for (var i = 0; i < e.target.attributes.length; i++) {
2440
- var k = e.target.attributes[i].name;
2441
- var v = e.target.attributes[i].value;
2442
- if (k.substr(0,4) == 'data') {
2443
- o.options[k.substr(5)] = v;
2444
- }
2445
- }
2446
- }
2447
- } else {
2448
- // Options
2449
- if (typeof(config) == 'string') {
2450
- // Mask
2451
- o.mask = config;
2452
- } else {
2453
- // Mask
2454
- var k = Object.keys(config);
2455
- for (var i = 0; i < k.length; i++) {
2456
- o[k[i]] = config[k[i]];
2457
- }
2458
- }
2459
-
2460
- if (typeof(e) === 'number') {
2461
- // Get decimal
2462
- getDecimal.call(o, o.mask);
2463
- // Replace to the correct decimal
2464
- e = (''+e).replace('.', o.options.decimal);
2465
- }
2466
-
2467
- // Current
2468
- o.value = e;
2469
-
2470
- if (o.input) {
2471
- // Value
2472
- Value.call(o.input, e);
2473
- // Focus
2474
- helpers.focus(o.input);
2475
- // Caret
2476
- o.caret = Caret.call(o.input);
2477
- }
2478
- }
2479
-
2480
- // Mask detected start the process
2481
- if (! isFormula(o.value) && (o.mask || o.locale)) {
2482
- // Compatibility fixes
2483
- if (o.mask) {
2484
- // Remove []
2485
- o.mask = o.mask.replace(new RegExp(/\[h]/),'|h|');
2486
- o.mask = o.mask.replace(new RegExp(/\[.*?\]/),'');
2487
- o.mask = o.mask.replace(new RegExp(/\|h\|/),'[h]');
2488
- if (o.mask.indexOf(';') !== -1) {
2489
- var t = o.mask.split(';');
2490
- o.mask = t[0];
2491
- }
2492
- // Excel mask TODO: Improve
2493
- if (o.mask.indexOf('##') !== -1) {
2494
- var d = o.mask.split(';');
2495
- if (d[0]) {
2496
- if (typeof(e) == 'object') {
2497
- d[0] = d[0].replace(new RegExp(/_\)/g), '');
2498
- d[0] = d[0].replace(new RegExp(/_\(/g), '');
2499
- }
2500
- d[0] = d[0].replace('*', '\t');
2501
- d[0] = d[0].replace(new RegExp(/_-/g), '');
2502
- d[0] = d[0].replace(new RegExp(/_/g), '');
2503
- d[0] = d[0].replace('##0.###','##0.000');
2504
- d[0] = d[0].replace('##0.##','##0.00');
2505
- d[0] = d[0].replace('##0.#','##0.0');
2506
- d[0] = d[0].replace('##0,###','##0,000');
2507
- d[0] = d[0].replace('##0,##','##0,00');
2508
- d[0] = d[0].replace('##0,#','##0,0');
2509
- }
2510
- o.mask = d[0];
2511
- }
2512
- // Remove back slashes
2513
- if (o.mask.indexOf('\\') !== -1) {
2514
- var d = o.mask.split(';');
2515
- d[0] = d[0].replace(new RegExp(/\\/g), '');
2516
- o.mask = d[0];
2517
- }
2518
- // Get type
2519
- if (! o.type) {
2520
- o.type = getType.call(o, o.mask);
2521
- }
2522
- // Get tokens
2523
- o.tokens = getTokens.call(o, o.mask);
2524
- }
2525
-
2526
- // On new input
2527
- if (typeof(e) !== 'object' || ! e.inputType || ! e.inputType.indexOf('insert') || ! e.inputType.indexOf('delete')) {
2528
- // Start transformation
2529
- if (o.locale) {
2530
- if (o.input) {
2531
- Format.call(o, o.input, e);
2532
- } else {
2533
- var newValue = FormatValue.call(o, o.value);
2534
- }
2535
- } else {
2536
- // Get tokens
2537
- o.methods = getMethods.call(o, o.tokens);
2538
- o.event = e;
2539
-
2540
- // Go through all tokes
2541
- while (o.position < o.value.length && typeof(o.tokens[o.index]) !== 'undefined') {
2542
- // Get the appropriate parser
2543
- parse.call(o);
2544
- }
2545
-
2546
- // New value
2547
- var newValue = o.values.join('');
2548
-
2549
- // Add tokens to the end of string only if string is not empty
2550
- if (isNumeric(o.type) && newValue !== '') {
2551
- // Complement things in the end of the mask
2552
- while (typeof(o.tokens[o.index]) !== 'undefined') {
2553
- var t = getMethod.call(o, o.tokens[o.index]);
2554
- if (t && t.type == 'general') {
2555
- o.values[o.index] = o.tokens[o.index];
2556
- }
2557
- o.index++;
2558
- }
2559
-
2560
- var adjustNumeric = true;
2561
- } else {
2562
- var adjustNumeric = false;
2563
- }
2564
-
2565
- // New value
2566
- newValue = o.values.join('');
2567
-
2568
- // Reset value
2569
- if (o.input) {
2570
- t = newValue.length - o.value.length;
2571
- if (t > 0) {
2572
- var caret = o.caret + t;
2573
- } else {
2574
- var caret = o.caret;
2575
- }
2576
- Value.call(o.input, newValue, caret, adjustNumeric);
2577
- }
2578
- }
2579
- }
2580
-
2581
- // Update raw data
2582
- if (o.input) {
2583
- var label = null;
2584
- if (isNumeric(o.type)) {
2585
- let v = Value.call(o.input);
2586
- // Extract the number
2587
- o.number = Extract.call(o, v);
2588
- // Keep the raw data as a property of the tag
2589
- if (o.type == 'percentage' && v.indexOf('%') !== -1) {
2590
- label = obj.adjustPrecision(o.number / 100);
2591
- } else {
2592
- label = o.number;
2593
- }
2594
- } else if (o.type == 'datetime') {
2595
- label = getDate.call(o);
2596
-
2597
- if (o.date[0] && o.date[1] && o.date[2]) {
2598
- o.input.setAttribute('data-completed', true);
2599
- }
2600
- }
2601
-
2602
- if (label) {
2603
- o.input.setAttribute('data-value', label);
2604
- }
2605
- }
2606
-
2607
- if (newValue !== undefined) {
2608
- if (returnObject) {
2609
- return o;
2610
- } else {
2611
- return newValue;
2612
- }
2613
- }
2614
- }
2615
- }
2616
-
2617
- obj.adjustPrecision = function(num) {
2618
- if (typeof num === 'number' && !Number.isInteger(num)) {
2619
- const v = num.toString().split('.');
2620
-
2621
- if (v[1] && v[1].length > 10) {
2622
- let t0 = 0;
2623
- const t1 = v[1][v[1].length - 2];
2624
-
2625
- if (t1 == 0 || t1 == 9) {
2626
- for (let i = v[1].length - 2; i > 0; i--) {
2627
- if (t0 >= 0 && v[1][i] == t1) {
2628
- t0++;
2629
- if (t0 > 6) {
2630
- break;
2631
- }
2632
- } else {
2633
- t0 = 0;
2634
- break;
2635
- }
2636
- }
2637
-
2638
- if (t0) {
2639
- return parseFloat(parseFloat(num).toFixed(v[1].length - 1));
2640
- }
2641
- }
2642
- }
2643
- }
2644
-
2645
- return num;
2646
- }
2647
-
2648
- // Get the type of the mask
2649
- obj.getType = getType;
2650
-
2651
- // Extract the tokens from a mask
2652
- obj.prepare = function(str, o) {
2653
- if (! o) {
2654
- o = {};
2655
- }
2656
- return getTokens.call(o, str);
2657
- }
2658
-
2659
- /**
2660
- * Apply the mask to a element (legacy)
2661
- */
2662
- obj.apply = function(e) {
2663
- var v = Value.call(e.target);
2664
- if (e.key.length == 1) {
2665
- v += e.key;
2666
- }
2667
- Value.call(e.target, obj(v, e.target.getAttribute('data-mask')));
2668
- }
2669
-
2670
- /**
2671
- * Legacy support
2672
- */
2673
- obj.run = function(value, mask, decimal) {
2674
- return obj(value, { mask: mask, decimal: decimal });
2675
- }
2676
-
2677
- /**
2678
- * Extract number from masked string
2679
- */
2680
- obj.extract = function(v, options, returnObject) {
2681
- if (isBlank(v)) {
2682
- return v;
2683
- }
2684
- if (typeof(options) != 'object') {
2685
- return v;
2686
- } else {
2687
- options = Object.assign({}, options);
2688
-
2689
- if (! options.options) {
2690
- options.options = {};
2691
- }
2692
- }
2693
-
2694
- // Compatibility
2695
- if (! options.mask && options.format) {
2696
- options.mask = options.format;
2697
- }
2698
-
2699
- // Remove []
2700
- if (options.mask) {
2701
- if (options.mask.indexOf(';') !== -1) {
2702
- var t = options.mask.split(';');
2703
- options.mask = t[0];
2704
- }
2705
- options.mask = options.mask.replace(new RegExp(/\[h]/),'|h|');
2706
- options.mask = options.mask.replace(new RegExp(/\[.*?\]/),'');
2707
- options.mask = options.mask.replace(new RegExp(/\|h\|/),'[h]');
2708
- }
2709
-
2710
- // Get decimal
2711
- getDecimal.call(options, options.mask);
2712
-
2713
- var type = null;
2714
- var value = null;
2715
-
2716
- if (options.type == 'percent' || options.options.style == 'percent') {
2717
- type = 'percentage';
2718
- } else if (options.mask) {
2719
- type = getType.call(options, options.mask);
2720
- }
2721
-
2722
- if (type === 'general') {
2723
- var o = obj(v, options, true);
2724
-
2725
- value = v;
2726
- } else if (type === 'datetime') {
2727
- if (v instanceof Date) {
2728
- v = obj.getDateString(v, options.mask);
2729
- }
2730
-
2731
- var o = obj(v, options, true);
2732
-
2733
- if (helpers.isNumeric(v)) {
2734
- value = v;
2735
- } else {
2736
- value = extractDate.call(o);
2737
- }
2738
- } else {
2739
- value = Extract.call(options, v);
2740
- // Percentage
2741
- if (type === 'percentage' && v.indexOf('%') !== -1) {
2742
- value /= 100;
2743
- }
2744
- var o = options;
2745
- }
2746
-
2747
- o.value = value;
2748
-
2749
- if (! o.type && type) {
2750
- o.type = type;
2751
- }
2752
-
2753
- if (returnObject) {
2754
- return o;
2755
- } else {
2756
- return value;
2757
- }
2758
- }
2759
-
2760
- /**
2761
- * Render
2762
- */
2763
- obj.render = function(value, options, fullMask) {
2764
- if (isBlank(value)) {
2765
- return value;
2766
- }
2767
-
2768
- if (typeof(options) != 'object') {
2769
- return value;
2770
- } else {
2771
- options = Object.assign({}, options);
2772
-
2773
- if (! options.options) {
2774
- options.options = {};
2775
- }
2776
- }
2777
-
2778
- // Compatibility
2779
- if (! options.mask && options.format) {
2780
- options.mask = options.format;
2781
- }
2782
-
2783
- // Remove []
2784
- if (options.mask) {
2785
- if (options.mask.indexOf(';') !== -1) {
2786
- var t = options.mask.split(';');
2787
- if (! fullMask) {
2788
- t[0] = t[0].replace(new RegExp(/_\)/g), '');
2789
- t[0] = t[0].replace(new RegExp(/_\(/g), '');
2790
- }
2791
- options.mask = t[0];
2792
- }
2793
- options.mask = options.mask.replace(new RegExp(/\[h]/),'|h|');
2794
- options.mask = options.mask.replace(new RegExp(/\[.*?\]/),'');
2795
- options.mask = options.mask.replace(new RegExp(/\|h\|/),'[h]');
2796
- }
2797
-
2798
- var type = null;
2799
- if (options.type == 'percent' || options.options.style == 'percent') {
2800
- type = 'percentage';
2801
- } else if (options.mask) {
2802
- type = getType.call(options, options.mask);
2803
- } else if (value instanceof Date) {
2804
- type = 'datetime';
2805
- }
2806
-
2807
- // Fill with blanks
2808
- var fillWithBlanks = false;
2809
-
2810
- if (type =='datetime' || options.type == 'calendar') {
2811
- var t = obj.getDateString(value, options.mask);
2812
- if (t) {
2813
- value = t;
2814
- }
2815
- if (options.mask && fullMask) {
2816
- fillWithBlanks = true;
2817
- }
2818
- } else {
2819
- // Percentage
2820
- if (type === 'percentage') {
2821
- value = obj.adjustPrecision(value*100);
2822
- }
2823
- // Number of decimal places
2824
- if (typeof(value) === 'number') {
2825
- var t = null;
2826
- if (options.mask && fullMask && ((''+value).indexOf('e') === -1)) {
2827
- var d = getDecimal.call(options, options.mask);
2828
- if (options.mask.indexOf(d) !== -1) {
2829
- d = options.mask.split(d);
2830
- d = (''+d[1].match(/[0-9]+/g))
2831
- d = d.length;
2832
- t = value.toFixed(d);
2833
- // TODO: when the number
2834
- /*let n = value.toString().split('.');
2835
- if (n[1] && n[1].length < 10 && d < 10) {
2836
- if (value > 0) {
2837
- t = (value + Number.EPSILON).toFixed(d);
2838
- } else {
2839
- t = (value - Number.EPSILON).toFixed(d);
2840
- }
2841
- } else {
2842
- t = value.toFixed(d);
2843
- }*/
2844
- } else {
2845
- t = value.toFixed(0);
2846
- }
2847
- } else if (options.locale && fullMask) {
2848
- // Append zeros
2849
- var d = (''+value).split('.');
2850
- if (options.options) {
2851
- if (typeof(d[1]) === 'undefined') {
2852
- d[1] = '';
2853
- }
2854
- var len = d[1].length;
2855
- if (options.options.minimumFractionDigits > len) {
2856
- for (var i = 0; i < options.options.minimumFractionDigits - len; i++) {
2857
- d[1] += '0';
2858
- }
2859
- }
2860
- }
2861
- if (! d[1].length) {
2862
- t = d[0]
2863
- } else {
2864
- t = d.join('.');
2865
- }
2866
- var len = d[1].length;
2867
- if (options.options && options.options.maximumFractionDigits < len) {
2868
- t = parseFloat(t).toFixed(options.options.maximumFractionDigits);
2869
- }
2870
- } else {
2871
- t = toPlainString(value);
2872
- }
2873
-
2874
- if (t !== null) {
2875
- value = t;
2876
- // Get decimal
2877
- getDecimal.call(options, options.mask);
2878
- // Replace to the correct decimal
2879
- if (options.options.decimal) {
2880
- value = value.replace('.', options.options.decimal);
2881
- }
2882
- }
2883
- } else {
2884
- if (options.mask && fullMask) {
2885
- fillWithBlanks = true;
2886
- }
2887
- }
2888
- }
2889
-
2890
- if (fillWithBlanks) {
2891
- var s = options.mask.length - value.length;
2892
- if (s > 0) {
2893
- for (var i = 0; i < s; i++) {
2894
- value += ' ';
2895
- }
2896
- }
2897
- }
2898
-
2899
- value = obj(value, options);
2900
-
2901
- // Numeric mask, number of zeros
2902
- if (fullMask && type === 'numeric') {
2903
- var maskZeros = options.mask.match(new RegExp(/^[0]+$/gm));
2904
- if (maskZeros && maskZeros.length === 1) {
2905
- var maskLength = maskZeros[0].length;
2906
- if (maskLength > 3) {
2907
- value = '' + value;
2908
- while (value.length < maskLength) {
2909
- value = '0' + value;
2910
- }
2911
- }
2912
- }
2913
- }
2914
-
2915
- return value;
2916
- }
2917
-
2918
- obj.set = function(e, m) {
2919
- if (m) {
2920
- e.setAttribute('data-mask', m);
2921
- // Reset the value
2922
- var event = new Event('input', {
2923
- bubbles: true,
2924
- cancelable: true,
2925
- });
2926
- e.dispatchEvent(event);
2927
- }
2928
- }
2929
-
2930
- // Helper to extract date from a string
2931
- obj.extractDateFromString = function (date, format) {
2932
- var o = obj(date, { mask: format }, true);
2933
-
2934
- // Check if in format Excel (Need difference with format date or type detected is numeric)
2935
- if (date > 0 && Number(date) == date && (o.values.join("") !== o.value || o.type == "numeric")) {
2936
- var d = new Date(Math.round((date - 25569) * 86400 * 1000));
2937
- return d.getFullYear() + "-" + helpers.two(d.getMonth()) + "-" + helpers.two(d.getDate()) + ' 00:00:00';
2938
- }
2939
-
2940
- var complete = false;
2941
-
2942
- if (o.values.length === o.tokens.length && o.values[o.values.length - 1].length >= o.tokens[o.tokens.length - 1].length) {
2943
- complete = true;
2944
- }
2945
-
2946
- if (o.date[0] && o.date[1] && (o.date[2] || complete)) {
2947
- if (!o.date[2]) {
2948
- o.date[2] = 1;
2949
- }
2950
-
2951
- 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]);
2952
- }
2953
-
2954
- return '';
2955
- }
2956
-
2957
- // Helper to convert date into string
2958
- obj.getDateString = function (value, options) {
2959
- if (!options) {
2960
- var options = {};
2961
- }
2962
-
2963
- // Labels
2964
- if (options && typeof (options) == 'object') {
2965
- var format = options.format;
2966
- } else {
2967
- var format = options;
2968
- }
2969
-
2970
- if (!format) {
2971
- format = 'YYYY-MM-DD';
2972
- }
2973
-
2974
- // Convert to number of hours
2975
- if (format.indexOf('[h]') >= 0) {
2976
- var result = 0;
2977
- if (value && helpers.isNumeric(value)) {
2978
- result = parseFloat(24 * Number(value));
2979
- if (format.indexOf('mm') >= 0) {
2980
- var h = ('' + result).split('.');
2981
- if (h[1]) {
2982
- var d = 60 * parseFloat('0.' + h[1])
2983
- d = parseFloat(d.toFixed(2));
2984
- } else {
2985
- var d = 0;
2986
- }
2987
- result = parseInt(h[0]) + ':' + helpers.two(d);
2988
- }
2989
- }
2990
- return result;
2991
- }
2992
-
2993
- // Date instance
2994
- if (value instanceof Date) {
2995
- value = helpers_date.now(value);
2996
- } else if (value && helpers.isNumeric(value)) {
2997
- value = helpers_date.numToDate(value);
2998
- }
2999
-
3000
- // Tokens
3001
- 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', '.'];
3002
-
3003
- // Expression to extract all tokens from the string
3004
- var e = new RegExp(tokens.join('|'), 'gi');
3005
- // Extract
3006
- var t = format.match(e);
3007
-
3008
- // Compatibility with excel
3009
- for (var i = 0; i < t.length; i++) {
3010
- if (t[i].toUpperCase() == 'MM') {
3011
- // Not a month, correct to minutes
3012
- if (t[i - 1] && t[i - 1].toUpperCase().indexOf('H') >= 0) {
3013
- t[i] = 'mi';
3014
- } else if (t[i - 2] && t[i - 2].toUpperCase().indexOf('H') >= 0) {
3015
- t[i] = 'mi';
3016
- } else if (t[i + 1] && t[i + 1].toUpperCase().indexOf('S') >= 0) {
3017
- t[i] = 'mi';
3018
- } else if (t[i + 2] && t[i + 2].toUpperCase().indexOf('S') >= 0) {
3019
- t[i] = 'mi';
3020
- }
3021
- }
3022
- }
3023
-
3024
- // Object
3025
- var o = {
3026
- tokens: t
3027
- }
3028
-
3029
- // Value
3030
- if (value) {
3031
- var d = '' + value;
3032
- var splitStr = (d.indexOf('T') !== -1) ? 'T' : ' ';
3033
- d = d.split(splitStr);
3034
-
3035
- var h = 0;
3036
- var m = 0;
3037
- var s = 0;
3038
-
3039
- if (d[1]) {
3040
- h = d[1].split(':');
3041
- m = h[1] ? h[1] : 0;
3042
- s = h[2] ? h[2] : 0;
3043
- h = h[0] ? h[0] : 0;
3044
- }
3045
-
3046
- d = d[0].split('-');
3047
-
3048
- if (d[0] && d[1] && d[2] && d[0] > 0 && d[1] > 0 && d[1] < 13 && d[2] > 0 && d[2] < 32) {
3049
-
3050
- // Data
3051
- o.data = [d[0], d[1], d[2], h, m, s];
3052
-
3053
- // Value
3054
- o.value = [];
3055
-
3056
- // Calendar instance
3057
- var calendar = new Date(o.data[0], o.data[1] - 1, o.data[2], o.data[3], o.data[4], o.data[5]);
3058
-
3059
- // Get method
3060
- var get = function (i) {
3061
- // Token
3062
- var t = this.tokens[i];
3063
- // Case token
3064
- var s = t.toUpperCase();
3065
- var v = null;
3066
-
3067
- if (s === 'YYYY') {
3068
- v = this.data[0];
3069
- } else if (s === 'YYY') {
3070
- v = this.data[0].substring(1, 4);
3071
- } else if (s === 'YY') {
3072
- v = this.data[0].substring(2, 4);
3073
- } else if (s === 'Y') {
3074
- v = this.data[0].substring(3, 4);
3075
- } else if (t === 'MON') {
3076
- v = helpers_date.months[calendar.getMonth()].substr(0, 3).toUpperCase();
3077
- } else if (t === 'mon') {
3078
- v = helpers_date.months[calendar.getMonth()].substr(0, 3).toLowerCase();
3079
- } else if (t === 'MONTH') {
3080
- v = helpers_date.months[calendar.getMonth()].toUpperCase();
3081
- } else if (t === 'month') {
3082
- v = helpers_date.months[calendar.getMonth()].toLowerCase();
3083
- } else if (s === 'MMMMM') {
3084
- v = helpers_date.months[calendar.getMonth()].substr(0, 1);
3085
- } else if (s === 'MMMM' || t === 'Month') {
3086
- v = helpers_date.months[calendar.getMonth()];
3087
- } else if (s === 'MMM' || t == 'Mon') {
3088
- v = helpers_date.months[calendar.getMonth()].substr(0, 3);
3089
- } else if (s === 'MM') {
3090
- v = helpers.two(this.data[1]);
3091
- } else if (s === 'M') {
3092
- v = calendar.getMonth() + 1;
3093
- } else if (t === 'DAY') {
3094
- v = helpers_date.weekdays[calendar.getDay()].toUpperCase();
3095
- } else if (t === 'day') {
3096
- v = helpers_date.weekdays[calendar.getDay()].toLowerCase();
3097
- } else if (s === 'DDDD' || t == 'Day') {
3098
- v = helpers_date.weekdays[calendar.getDay()];
3099
- } else if (s === 'DDD') {
3100
- v = helpers_date.weekdays[calendar.getDay()].substr(0, 3);
3101
- } else if (s === 'DD') {
3102
- v = helpers.two(this.data[2]);
3103
- } else if (s === 'D') {
3104
- v = parseInt(this.data[2]);
3105
- } else if (s === 'Q') {
3106
- v = Math.floor((calendar.getMonth() + 3) / 3);
3107
- } else if (s === 'HH24' || s === 'HH') {
3108
- v = this.data[3];
3109
- if (v > 12 && this.tokens.indexOf('am/pm') !== -1) {
3110
- v -= 12;
3111
- }
3112
- v = helpers.two(v);
3113
- } else if (s === 'HH12') {
3114
- if (this.data[3] > 12) {
3115
- v = helpers.two(this.data[3] - 12);
3116
- } else {
3117
- v = helpers.two(this.data[3]);
3118
- }
3119
- } else if (s === 'H') {
3120
- v = this.data[3];
3121
- if (v > 12 && this.tokens.indexOf('am/pm') !== -1) {
3122
- v -= 12;
3123
- v = helpers.two(v);
3124
- }
3125
- } else if (s === 'MI') {
3126
- v = helpers.two(this.data[4]);
3127
- } else if (s === 'SS') {
3128
- v = helpers.two(this.data[5]);
3129
- } else if (s === 'MS') {
3130
- v = calendar.getMilliseconds();
3131
- } else if (s === 'AM/PM') {
3132
- if (this.data[3] >= 12) {
3133
- v = 'PM';
3134
- } else {
3135
- v = 'AM';
3136
- }
3137
- } else if (s === 'WD') {
3138
- v = helpers_date.weekdays[calendar.getDay()];
3139
- }
3140
-
3141
- if (v === null) {
3142
- this.value[i] = this.tokens[i];
3143
- } else {
3144
- this.value[i] = v;
3145
- }
3146
- }
3147
-
3148
- for (var i = 0; i < o.tokens.length; i++) {
3149
- get.call(o, i);
3150
- }
3151
- // Put pieces together
3152
- value = o.value.join('');
3153
- } else {
3154
- value = '';
3155
- }
3156
- }
3157
-
3158
- return value;
3159
- }
3160
-
3161
- return obj;
3162
- }
3163
-
1380
+
1381
+
1382
+
1383
+ function Mask() {
1384
+ // Currency
1385
+ var tokens = {
1386
+ // Text
1387
+ text: [ '@' ],
1388
+ // Currency tokens
1389
+ currency: [ '#(.{1})##0?(.{1}0+)?( ?;(.*)?)?', '#' ],
1390
+ // Percentage
1391
+ percentage: [ '0{1}(.{1}0+)?%' ],
1392
+ // Number
1393
+ numeric: [ '0{1}(.{1}0+)?' ],
1394
+ // Data tokens
1395
+ 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' ],
1396
+ // Other
1397
+ general: [ 'A', '0', '[0-9a-zA-Z\$]+', '.']
1398
+ }
1399
+
1400
+ var getDate = function() {
1401
+ if (this.mask.toLowerCase().indexOf('[h]') !== -1) {
1402
+ var m = 0;
1403
+ if (this.date[4]) {
1404
+ m = parseFloat(this.date[4] / 60);
1405
+ }
1406
+ var v = parseInt(this.date[3]) + m;
1407
+ v /= 24;
1408
+ } else if (! (this.date[0] && this.date[1] && this.date[2]) && (this.date[3] || this.date[4])) {
1409
+ v = helpers.two(this.date[3]) + ':' + helpers.two(this.date[4]) + ':' + helpers.two(this.date[5])
1410
+ } else {
1411
+ if (this.date[0] && this.date[1] && ! this.date[2]) {
1412
+ this.date[2] = 1;
1413
+ }
1414
+ v = helpers.two(this.date[0]) + '-' + helpers.two(this.date[1]) + '-' + helpers.two(this.date[2]);
1415
+
1416
+ if (this.date[3] || this.date[4] || this.date[5]) {
1417
+ v += ' ' + helpers.two(this.date[3]) + ':' + helpers.two(this.date[4]) + ':' + helpers.two(this.date[5]);
1418
+ }
1419
+ }
1420
+
1421
+ return v;
1422
+ }
1423
+
1424
+ var extractDate = function() {
1425
+ var v = '';
1426
+ if (! (this.date[0] && this.date[1] && this.date[2]) && (this.date[3] || this.date[4])) {
1427
+ if (this.mask.toLowerCase().indexOf('[h]') !== -1) {
1428
+ v = parseInt(this.date[3]);
1429
+ } else {
1430
+ let h = parseInt(this.date[3]);
1431
+ if (h < 13 && this.values.indexOf('PM') !== -1) {
1432
+ v = (h+12) % 24;
1433
+ } else {
1434
+ v = h % 24;
1435
+ }
1436
+ }
1437
+ if (this.date[4]) {
1438
+ v += parseFloat(this.date[4] / 60);
1439
+ }
1440
+ if (this.date[5]) {
1441
+ v += parseFloat(this.date[5] / 3600);
1442
+ }
1443
+ v /= 24;
1444
+ } else if (this.date[0] || this.date[1] || this.date[2] || this.date[3] || this.date[4] || this.date[5]) {
1445
+ if (this.date[0] && this.date[1] && ! this.date[2]) {
1446
+ this.date[2] = 1;
1447
+ }
1448
+ var t = helpers_date.now(this.date);
1449
+ v = helpers_date.dateToNum(t);
1450
+ if (this.date[4]) {
1451
+ v += parseFloat(this.date[4] / 60);
1452
+ }
1453
+ }
1454
+
1455
+ if (isNaN(v)) {
1456
+ v = '';
1457
+ }
1458
+
1459
+ return v;
1460
+ }
1461
+
1462
+ var isBlank = function(v) {
1463
+ return v === null || v === '' || v === undefined ? true : false;
1464
+ }
1465
+
1466
+ var isFormula = function(value) {
1467
+ var v = (''+value)[0];
1468
+ return v == '=' ? true : false;
1469
+ }
1470
+
1471
+ var isNumeric = function(t) {
1472
+ return t === 'currency' || t === 'percentage' || t === 'numeric' ? true : false;
1473
+ }
1474
+
1475
+ /**
1476
+ * Get the decimal defined in the mask configuration
1477
+ */
1478
+ var getDecimal = function(v) {
1479
+ if (v && Number(v) == v) {
1480
+ return '.';
1481
+ } else {
1482
+ if (this.options.decimal) {
1483
+ return this.options.decimal;
1484
+ } else {
1485
+ if (this.locale) {
1486
+ var t = Intl.NumberFormat(this.locale).format(1.1);
1487
+ return this.options.decimal = t[1];
1488
+ } else {
1489
+ if (! v) {
1490
+ v = this.mask;
1491
+ }
1492
+ var e = new RegExp('0{1}(.{1})0+', 'ig');
1493
+ var t = e.exec(v);
1494
+ if (t && t[1] && t[1].length == 1) {
1495
+ // Save decimal
1496
+ this.options.decimal = t[1];
1497
+ // Return decimal
1498
+ return t[1];
1499
+ } else {
1500
+ // Did not find any decimal last resort the default
1501
+ var e = new RegExp('#{1}(.{1})#+', 'ig');
1502
+ var t = e.exec(v);
1503
+ if (t && t[1] && t[1].length == 1) {
1504
+ if (t[1] === ',') {
1505
+ this.options.decimal = '.';
1506
+ } else {
1507
+ this.options.decimal = ',';
1508
+ }
1509
+ } else {
1510
+ this.options.decimal = '1.1'.toLocaleString().substring(1,2);
1511
+ }
1512
+ }
1513
+ }
1514
+ }
1515
+ }
1516
+
1517
+ if (this.options.decimal) {
1518
+ return this.options.decimal;
1519
+ } else {
1520
+ return null;
1521
+ }
1522
+ }
1523
+
1524
+ var ParseValue = function(v, decimal) {
1525
+ if (v == '') {
1526
+ return '';
1527
+ }
1528
+
1529
+ // Get decimal
1530
+ if (! decimal) {
1531
+ decimal = getDecimal.call(this);
1532
+ }
1533
+
1534
+ // New value
1535
+ v = (''+v).split(decimal);
1536
+
1537
+ // Signal
1538
+ var signal = v[0].match(/[-]+/g);
1539
+ if (signal && signal.length) {
1540
+ signal = true;
1541
+ } else {
1542
+ signal = false;
1543
+ }
1544
+
1545
+ v[0] = v[0].match(/[0-9]+/g);
1546
+
1547
+ if (v[0]) {
1548
+ if (signal) {
1549
+ v[0].unshift('-');
1550
+ }
1551
+ v[0] = v[0].join('');
1552
+ } else {
1553
+ if (signal) {
1554
+ v[0] = '-';
1555
+ }
1556
+ }
1557
+
1558
+ if (v[0] || v[1]) {
1559
+ if (v[1] !== undefined) {
1560
+ v[1] = v[1].match(/[0-9]+/g);
1561
+ if (v[1]) {
1562
+ v[1] = v[1].join('');
1563
+ } else {
1564
+ v[1] = '';
1565
+ }
1566
+ }
1567
+ } else {
1568
+ return '';
1569
+ }
1570
+ return v;
1571
+ }
1572
+
1573
+ var FormatValue = function(v, event) {
1574
+ if (v === '') {
1575
+ return '';
1576
+ }
1577
+ // Get decimal
1578
+ var d = getDecimal.call(this);
1579
+ // Convert value
1580
+ var o = this.options;
1581
+ // Parse value
1582
+ v = ParseValue.call(this, v);
1583
+ if (v === '') {
1584
+ return '';
1585
+ }
1586
+ var t = null;
1587
+ // Temporary value
1588
+ if (v[0]) {
1589
+ if (o.style === 'percent') {
1590
+ t = parseFloat(v[0]) / 100;
1591
+ } else {
1592
+ t = parseFloat(v[0] + '.1');
1593
+ }
1594
+ }
1595
+
1596
+ if ((v[0] === '-' || v[0] === '-00') && ! v[1] && (event && event.inputType == "deleteContentBackward")) {
1597
+ return '';
1598
+ }
1599
+
1600
+ var n = new Intl.NumberFormat(this.locale, o).format(t);
1601
+ n = n.split(d);
1602
+
1603
+ if (o.style === 'percent') {
1604
+ if (n[0].indexOf('%') !== -1) {
1605
+ n[0] = n[0].replace('%', '');
1606
+ n[2] = '%';
1607
+ }
1608
+ }
1609
+
1610
+ if (typeof(n[1]) !== 'undefined') {
1611
+ var s = n[1].replace(/[0-9]*/g, '');
1612
+ if (s) {
1613
+ n[2] = s;
1614
+ }
1615
+ }
1616
+
1617
+ if (v[1] !== undefined) {
1618
+ n[1] = d + v[1];
1619
+ } else {
1620
+ n[1] = '';
1621
+ }
1622
+
1623
+ return n.join('');
1624
+ }
1625
+
1626
+ var Format = function(e, event) {
1627
+ var v = Value.call(e);
1628
+ if (! v) {
1629
+ return;
1630
+ }
1631
+
1632
+ // Get decimal
1633
+ var n = FormatValue.call(this, v, event);
1634
+ var t = (n.length) - v.length;
1635
+ var index = Caret.call(e) + t;
1636
+ // Set value and update caret
1637
+ Value.call(e, n, index, true);
1638
+ }
1639
+
1640
+ var Extract = function(v) {
1641
+ // Keep the raw value
1642
+ var current = ParseValue.call(this, v);
1643
+ if (current) {
1644
+ // Negative values
1645
+ if (current[0] === '-') {
1646
+ current[0] = '-0';
1647
+ }
1648
+ return parseFloat(current.join('.'));
1649
+ }
1650
+ return null;
1651
+ }
1652
+
1653
+ /**
1654
+ * Caret getter and setter methods
1655
+ */
1656
+ var Caret = function(index, adjustNumeric) {
1657
+ if (index === undefined) {
1658
+ if (this.tagName == 'DIV') {
1659
+ var pos = 0;
1660
+ var s = window.getSelection();
1661
+ if (s) {
1662
+ if (s.rangeCount !== 0) {
1663
+ var r = s.getRangeAt(0);
1664
+ var p = r.cloneRange();
1665
+ p.selectNodeContents(this);
1666
+ p.setEnd(r.endContainer, r.endOffset);
1667
+ pos = p.toString().length;
1668
+ }
1669
+ }
1670
+ return pos;
1671
+ } else {
1672
+ return this.selectionStart;
1673
+ }
1674
+ } else {
1675
+ // Get the current value
1676
+ var n = Value.call(this);
1677
+
1678
+ // Review the position
1679
+ if (adjustNumeric) {
1680
+ var p = null;
1681
+ for (var i = 0; i < n.length; i++) {
1682
+ if (n[i].match(/[\-0-9]/g) || n[i] === '.' || n[i] === ',') {
1683
+ p = i;
1684
+ }
1685
+ }
1686
+
1687
+ // If the string has no numbers
1688
+ if (p === null) {
1689
+ p = n.indexOf(' ');
1690
+ }
1691
+
1692
+ if (index >= p) {
1693
+ index = p + 1;
1694
+ }
1695
+ }
1696
+
1697
+ // Do not update caret
1698
+ if (index > n.length) {
1699
+ index = n.length;
1700
+ }
1701
+
1702
+ if (index) {
1703
+ // Set caret
1704
+ if (this.tagName == 'DIV') {
1705
+ var s = window.getSelection();
1706
+ var r = document.createRange();
1707
+
1708
+ if (this.childNodes[0]) {
1709
+ r.setStart(this.childNodes[0], index);
1710
+ s.removeAllRanges();
1711
+ s.addRange(r);
1712
+ }
1713
+ } else {
1714
+ this.selectionStart = index;
1715
+ this.selectionEnd = index;
1716
+ }
1717
+ }
1718
+ }
1719
+ }
1720
+
1721
+ /**
1722
+ * Value getter and setter method
1723
+ */
1724
+ var Value = function(v, updateCaret, adjustNumeric) {
1725
+ if (this.tagName == 'DIV') {
1726
+ if (v === undefined) {
1727
+ var v = this.innerText;
1728
+ if (this.value && this.value.length > v.length) {
1729
+ v = this.value;
1730
+ }
1731
+ return v;
1732
+ } else {
1733
+ if (this.innerText !== v) {
1734
+ this.innerText = v;
1735
+
1736
+ if (updateCaret) {
1737
+ Caret.call(this, updateCaret, adjustNumeric);
1738
+ }
1739
+ }
1740
+ }
1741
+ } else {
1742
+ if (v === undefined) {
1743
+ return this.value;
1744
+ } else {
1745
+ if (this.value !== v) {
1746
+ this.value = v;
1747
+ if (updateCaret) {
1748
+ Caret.call(this, updateCaret, adjustNumeric);
1749
+ }
1750
+ }
1751
+ }
1752
+ }
1753
+ }
1754
+
1755
+ // Labels
1756
+ var weekDaysFull = helpers_date.weekdays;
1757
+ var weekDays = helpers_date.weekdaysShort;
1758
+ var monthsFull = helpers_date.months;
1759
+ var months = helpers_date.monthsShort;
1760
+
1761
+ var parser = {
1762
+ 'YEAR': function(v, s) {
1763
+ var y = ''+new Date().getFullYear();
1764
+
1765
+ if (typeof(this.values[this.index]) === 'undefined') {
1766
+ this.values[this.index] = '';
1767
+ }
1768
+ if (parseInt(v) >= 0 && parseInt(v) <= 10) {
1769
+ if (this.values[this.index].length < s) {
1770
+ this.values[this.index] += v;
1771
+ }
1772
+ }
1773
+ if (this.values[this.index].length == s) {
1774
+ if (s == 2) {
1775
+ var y = y.substr(0,2) + this.values[this.index];
1776
+ } else if (s == 3) {
1777
+ var y = y.substr(0,1) + this.values[this.index];
1778
+ } else if (s == 4) {
1779
+ var y = this.values[this.index];
1780
+ }
1781
+ this.date[0] = y;
1782
+ this.index++;
1783
+ }
1784
+ },
1785
+ 'YYYY': function(v) {
1786
+ parser.YEAR.call(this, v, 4);
1787
+ },
1788
+ 'YYY': function(v) {
1789
+ parser.YEAR.call(this, v, 3);
1790
+ },
1791
+ 'YY': function(v) {
1792
+ parser.YEAR.call(this, v, 2);
1793
+ },
1794
+ 'FIND': function(v, a) {
1795
+ if (isBlank(this.values[this.index])) {
1796
+ this.values[this.index] = '';
1797
+ }
1798
+ if (this.event && this.event.inputType && this.event.inputType.indexOf('delete') > -1) {
1799
+ this.values[this.index] += v;
1800
+ return;
1801
+ }
1802
+ var pos = 0;
1803
+ var count = 0;
1804
+ var value = (this.values[this.index] + v).toLowerCase();
1805
+ for (var i = 0; i < a.length; i++) {
1806
+ if (a[i].toLowerCase().indexOf(value) == 0) {
1807
+ pos = i;
1808
+ count++;
1809
+ }
1810
+ }
1811
+ if (count > 1) {
1812
+ this.values[this.index] += v;
1813
+ } else if (count == 1) {
1814
+ // Jump number of chars
1815
+ var t = (a[pos].length - this.values[this.index].length) - 1;
1816
+ this.position += t;
1817
+
1818
+ this.values[this.index] = a[pos];
1819
+ this.index++;
1820
+ return pos;
1821
+ }
1822
+ },
1823
+ 'MMM': function(v) {
1824
+ var ret = parser.FIND.call(this, v, months);
1825
+ if (ret !== undefined) {
1826
+ this.date[1] = ret + 1;
1827
+ }
1828
+ },
1829
+ 'MON': function(v) {
1830
+ parser['MMM'].call(this, v);
1831
+ },
1832
+ 'MMMM': function(v) {
1833
+ var ret = parser.FIND.call(this, v, monthsFull);
1834
+ if (ret !== undefined) {
1835
+ this.date[1] = ret + 1;
1836
+ }
1837
+ },
1838
+ 'MONTH': function(v) {
1839
+ parser['MMMM'].call(this, v);
1840
+ },
1841
+ 'MMMMM': function(v) {
1842
+ if (isBlank(this.values[this.index])) {
1843
+ this.values[this.index] = '';
1844
+ }
1845
+ var pos = 0;
1846
+ var count = 0;
1847
+ var value = (this.values[this.index] + v).toLowerCase();
1848
+ for (var i = 0; i < monthsFull.length; i++) {
1849
+ if (monthsFull[i][0].toLowerCase().indexOf(value) == 0) {
1850
+ this.values[this.index] = monthsFull[i][0];
1851
+ this.date[1] = i + 1;
1852
+ this.index++;
1853
+ break;
1854
+ }
1855
+ }
1856
+ },
1857
+ 'MM': function(v) {
1858
+ if (isBlank(this.values[this.index])) {
1859
+ if (parseInt(v) > 1 && parseInt(v) < 10) {
1860
+ this.date[1] = this.values[this.index] = '0' + v;
1861
+ this.index++;
1862
+ } else if (parseInt(v) < 2) {
1863
+ this.values[this.index] = v;
1864
+ }
1865
+ } else {
1866
+ if (this.values[this.index] == 1 && parseInt(v) < 3) {
1867
+ this.date[1] = this.values[this.index] += v;
1868
+ this.index++;
1869
+ } else if (this.values[this.index] == 0 && parseInt(v) > 0 && parseInt(v) < 10) {
1870
+ this.date[1] = this.values[this.index] += v;
1871
+ this.index++;
1872
+ }
1873
+ }
1874
+ },
1875
+ 'M': function(v) {
1876
+ var test = false;
1877
+ if (parseInt(v) >= 0 && parseInt(v) < 10) {
1878
+ if (isBlank(this.values[this.index])) {
1879
+ this.values[this.index] = v;
1880
+ if (v > 1) {
1881
+ this.date[1] = this.values[this.index];
1882
+ this.index++;
1883
+ }
1884
+ } else {
1885
+ if (this.values[this.index] == 1 && parseInt(v) < 3) {
1886
+ this.date[1] = this.values[this.index] += v;
1887
+ this.index++;
1888
+ } else if (this.values[this.index] == 0 && parseInt(v) > 0) {
1889
+ this.date[1] = this.values[this.index] += v;
1890
+ this.index++;
1891
+ } else {
1892
+ var test = true;
1893
+ }
1894
+ }
1895
+ } else {
1896
+ var test = true;
1897
+ }
1898
+
1899
+ // Re-test
1900
+ if (test == true) {
1901
+ var t = parseInt(this.values[this.index]);
1902
+ if (t > 0 && t < 12) {
1903
+ this.date[1] = this.values[this.index];
1904
+ this.index++;
1905
+ // Repeat the character
1906
+ this.position--;
1907
+ }
1908
+ }
1909
+ },
1910
+ 'D': function(v) {
1911
+ var test = false;
1912
+ if (parseInt(v) >= 0 && parseInt(v) < 10) {
1913
+ if (isBlank(this.values[this.index])) {
1914
+ this.values[this.index] = v;
1915
+ if (parseInt(v) > 3) {
1916
+ this.date[2] = this.values[this.index];
1917
+ this.index++;
1918
+ }
1919
+ } else {
1920
+ if (this.values[this.index] == 3 && parseInt(v) < 2) {
1921
+ this.date[2] = this.values[this.index] += v;
1922
+ this.index++;
1923
+ } else if (this.values[this.index] == 1 || this.values[this.index] == 2) {
1924
+ this.date[2] = this.values[this.index] += v;
1925
+ this.index++;
1926
+ } else if (this.values[this.index] == 0 && parseInt(v) > 0) {
1927
+ this.date[2] = this.values[this.index] += v;
1928
+ this.index++;
1929
+ } else {
1930
+ var test = true;
1931
+ }
1932
+ }
1933
+ } else {
1934
+ var test = true;
1935
+ }
1936
+
1937
+ // Re-test
1938
+ if (test == true) {
1939
+ var t = parseInt(this.values[this.index]);
1940
+ if (t > 0 && t < 32) {
1941
+ this.date[2] = this.values[this.index];
1942
+ this.index++;
1943
+ // Repeat the character
1944
+ this.position--;
1945
+ }
1946
+ }
1947
+ },
1948
+ 'DD': function(v) {
1949
+ if (isBlank(this.values[this.index])) {
1950
+ if (parseInt(v) > 3 && parseInt(v) < 10) {
1951
+ this.date[2] = this.values[this.index] = '0' + v;
1952
+ this.index++;
1953
+ } else if (parseInt(v) < 10) {
1954
+ this.values[this.index] = v;
1955
+ }
1956
+ } else {
1957
+ if (this.values[this.index] == 3 && parseInt(v) < 2) {
1958
+ this.date[2] = this.values[this.index] += v;
1959
+ this.index++;
1960
+ } else if ((this.values[this.index] == 1 || this.values[this.index] == 2) && parseInt(v) < 10) {
1961
+ this.date[2] = this.values[this.index] += v;
1962
+ this.index++;
1963
+ } else if (this.values[this.index] == 0 && parseInt(v) > 0 && parseInt(v) < 10) {
1964
+ this.date[2] = this.values[this.index] += v;
1965
+ this.index++;
1966
+ }
1967
+ }
1968
+ },
1969
+ 'DDD': function(v) {
1970
+ parser.FIND.call(this, v, weekDays);
1971
+ },
1972
+ 'DY': function(v) {
1973
+ parser['DDD'].call(this, v);
1974
+ },
1975
+ 'DDDD': function(v) {
1976
+ parser.FIND.call(this, v, weekDaysFull);
1977
+ },
1978
+ 'DAY': function(v) {
1979
+ parser['DDDD'].call(this, v);
1980
+ },
1981
+ 'HH12': function(v, two) {
1982
+ if (isBlank(this.values[this.index])) {
1983
+ if (parseInt(v) > 1 && parseInt(v) < 10) {
1984
+ if (two) {
1985
+ v = 0 + v;
1986
+ }
1987
+ this.date[3] = this.values[this.index] = v;
1988
+ this.index++;
1989
+ } else if (parseInt(v) < 10) {
1990
+ this.values[this.index] = v;
1991
+ }
1992
+ } else {
1993
+ if (this.values[this.index] == 1 && parseInt(v) < 3) {
1994
+ this.date[3] = this.values[this.index] += v;
1995
+ this.index++;
1996
+ } else if (this.values[this.index] < 1 && parseInt(v) < 10) {
1997
+ this.date[3] = this.values[this.index] += v;
1998
+ this.index++;
1999
+ }
2000
+ }
2001
+ },
2002
+ 'HH24': function(v, two) {
2003
+ if (parseInt(v) >= 0 && parseInt(v) < 10) {
2004
+ if (this.values[this.index] == null || this.values[this.index] == '') {
2005
+ if (parseInt(v) > 2 && parseInt(v) < 10) {
2006
+ if (two) {
2007
+ v = 0 + v;
2008
+ }
2009
+ this.date[3] = this.values[this.index] = v;
2010
+ this.index++;
2011
+ } else if (parseInt(v) < 10) {
2012
+ this.values[this.index] = v;
2013
+ }
2014
+ } else {
2015
+ if (this.values[this.index] == 2 && parseInt(v) < 4) {
2016
+ if (! two && this.values[this.index] === '0') {
2017
+ this.values[this.index] = '';
2018
+ }
2019
+ this.date[3] = this.values[this.index] += v;
2020
+ this.index++;
2021
+ } else if (this.values[this.index] < 2 && parseInt(v) < 10) {
2022
+ if (! two && this.values[this.index] === '0') {
2023
+ this.values[this.index] = '';
2024
+ }
2025
+ this.date[3] = this.values[this.index] += v;
2026
+ this.index++;
2027
+ }
2028
+ }
2029
+ }
2030
+ },
2031
+ 'HH': function(v) {
2032
+ parser['HH24'].call(this, v, 1);
2033
+ },
2034
+ 'H': function(v) {
2035
+ parser['HH24'].call(this, v, 0);
2036
+ },
2037
+ '\\[H\\]': function(v) {
2038
+ if (this.values[this.index] == undefined) {
2039
+ this.values[this.index] = '';
2040
+ }
2041
+ if (v.match(/[0-9]/g)) {
2042
+ this.date[3] = this.values[this.index] += v;
2043
+ } else {
2044
+ if (this.values[this.index].match(/[0-9]/g)) {
2045
+ this.date[3] = this.values[this.index];
2046
+ this.index++;
2047
+ // Repeat the character
2048
+ this.position--;
2049
+ }
2050
+ }
2051
+ },
2052
+ 'N60': function(v, i) {
2053
+ if (this.values[this.index] == null || this.values[this.index] == '') {
2054
+ if (parseInt(v) > 5 && parseInt(v) < 10) {
2055
+ this.date[i] = this.values[this.index] = '0' + v;
2056
+ this.index++;
2057
+ } else if (parseInt(v) < 10) {
2058
+ this.values[this.index] = v;
2059
+ }
2060
+ } else {
2061
+ if (parseInt(v) < 10) {
2062
+ this.date[i] = this.values[this.index] += v;
2063
+ this.index++;
2064
+ }
2065
+ }
2066
+ },
2067
+ 'MI': function(v) {
2068
+ parser.N60.call(this, v, 4);
2069
+ },
2070
+ 'SS': function(v) {
2071
+ parser.N60.call(this, v, 5);
2072
+ },
2073
+ 'AM/PM': function(v) {
2074
+ if (typeof(this.values[this.index]) === 'undefined') {
2075
+ this.values[this.index] = '';
2076
+ }
2077
+
2078
+ if (this.values[this.index] === '') {
2079
+ if (v.match(/a/i) && this.date[3] < 13) {
2080
+ this.values[this.index] += 'A';
2081
+ } else if (v.match(/p/i)) {
2082
+ this.values[this.index] += 'P';
2083
+ }
2084
+ } else if (this.values[this.index] === 'A' || this.values[this.index] === 'P') {
2085
+ this.values[this.index] += 'M';
2086
+ this.index++;
2087
+ }
2088
+ },
2089
+ 'WD': function(v) {
2090
+ if (typeof(this.values[this.index]) === 'undefined') {
2091
+ this.values[this.index] = '';
2092
+ }
2093
+ if (parseInt(v) >= 0 && parseInt(v) < 7) {
2094
+ this.values[this.index] = v;
2095
+ }
2096
+ if (this.values[this.index].length == 1) {
2097
+ this.index++;
2098
+ }
2099
+ },
2100
+ '0{1}(.{1}0+)?': function(v) {
2101
+ // Get decimal
2102
+ var decimal = getDecimal.call(this);
2103
+ // Negative number
2104
+ var neg = false;
2105
+ // Create if is blank
2106
+ if (isBlank(this.values[this.index])) {
2107
+ this.values[this.index] = '';
2108
+ } else {
2109
+ if (this.values[this.index] == '-') {
2110
+ neg = true;
2111
+ }
2112
+ }
2113
+ var current = ParseValue.call(this, this.values[this.index], decimal);
2114
+ if (current) {
2115
+ this.values[this.index] = current.join(decimal);
2116
+ }
2117
+ // New entry
2118
+ if (parseInt(v) >= 0 && parseInt(v) < 10) {
2119
+ // Replace the zero for a number
2120
+ if (this.values[this.index] == '0' && v > 0) {
2121
+ this.values[this.index] = '';
2122
+ } else if (this.values[this.index] == '-0' && v > 0) {
2123
+ this.values[this.index] = '-';
2124
+ }
2125
+ // Don't add up zeros because does not mean anything here
2126
+ if ((this.values[this.index] != '0' && this.values[this.index] != '-0') || v == decimal) {
2127
+ this.values[this.index] += v;
2128
+ }
2129
+ } else if (decimal && v == decimal) {
2130
+ if (this.values[this.index].indexOf(decimal) == -1) {
2131
+ if (! this.values[this.index]) {
2132
+ this.values[this.index] = '0';
2133
+ }
2134
+ this.values[this.index] += v;
2135
+ }
2136
+ } else if (v == '-') {
2137
+ // Negative signed
2138
+ neg = true;
2139
+ }
2140
+
2141
+ if (neg === true && this.values[this.index][0] !== '-') {
2142
+ this.values[this.index] = '-' + this.values[this.index];
2143
+ }
2144
+ },
2145
+ '0{1}(.{1}0+)?%': function(v) {
2146
+ parser['0{1}(.{1}0+)?'].call(this, v);
2147
+
2148
+ if (this.values[this.index].match(/[\-0-9]/g)) {
2149
+ if (this.values[this.index] && this.values[this.index].indexOf('%') == -1) {
2150
+ this.values[this.index] += '%';
2151
+ }
2152
+ } else {
2153
+ this.values[this.index] = '';
2154
+ }
2155
+ },
2156
+ '#(.{1})##0?(.{1}0+)?( ?;(.*)?)?': function(v) {
2157
+ // Parse number
2158
+ parser['0{1}(.{1}0+)?'].call(this, v);
2159
+ // Get decimal
2160
+ var decimal = getDecimal.call(this);
2161
+ // Get separator
2162
+ var separator = this.tokens[this.index].substr(1,1);
2163
+ // Negative
2164
+ var negative = this.values[this.index][0] === '-' ? true : false;
2165
+ // Current value
2166
+ var current = ParseValue.call(this, this.values[this.index], decimal);
2167
+
2168
+ // Get main and decimal parts
2169
+ if (current !== '') {
2170
+ // Format number
2171
+ var n = current[0].match(/[0-9]/g);
2172
+ if (n) {
2173
+ // Format
2174
+ n = n.join('');
2175
+ var t = [];
2176
+ var s = 0;
2177
+ for (var j = n.length - 1; j >= 0 ; j--) {
2178
+ t.push(n[j]);
2179
+ s++;
2180
+ if (! (s % 3)) {
2181
+ t.push(separator);
2182
+ }
2183
+ }
2184
+ t = t.reverse();
2185
+ current[0] = t.join('');
2186
+ if (current[0].substr(0,1) == separator) {
2187
+ current[0] = current[0].substr(1);
2188
+ }
2189
+ } else {
2190
+ current[0] = '';
2191
+ }
2192
+
2193
+ // Value
2194
+ this.values[this.index] = current.join(decimal);
2195
+
2196
+ // Negative
2197
+ if (negative) {
2198
+ this.values[this.index] = '-' + this.values[this.index];
2199
+ }
2200
+ }
2201
+ },
2202
+ '0': function(v) {
2203
+ if (v.match(/[0-9]/g)) {
2204
+ this.values[this.index] = v;
2205
+ this.index++;
2206
+ }
2207
+ },
2208
+ '[0-9a-zA-Z$]+': function(v) {
2209
+ if (isBlank(this.values[this.index])) {
2210
+ this.values[this.index] = '';
2211
+ }
2212
+ var t = this.tokens[this.index];
2213
+ var s = this.values[this.index];
2214
+ var i = s.length;
2215
+
2216
+ if (t[i] == v) {
2217
+ this.values[this.index] += v;
2218
+
2219
+ if (this.values[this.index] == t) {
2220
+ this.index++;
2221
+ }
2222
+ } else {
2223
+ this.values[this.index] = t;
2224
+ this.index++;
2225
+
2226
+ if (v.match(/[\-0-9]/g)) {
2227
+ // Repeat the character
2228
+ this.position--;
2229
+ }
2230
+ }
2231
+ },
2232
+ 'A': function(v) {
2233
+ if (v.match(/[a-zA-Z]/gi)) {
2234
+ this.values[this.index] = v;
2235
+ this.index++;
2236
+ }
2237
+ },
2238
+ '.': function(v) {
2239
+ parser['[0-9a-zA-Z$]+'].call(this, v);
2240
+ },
2241
+ '@': function(v) {
2242
+ if (isBlank(this.values[this.index])) {
2243
+ this.values[this.index] = '';
2244
+ }
2245
+ this.values[this.index] += v;
2246
+ }
2247
+ }
2248
+
2249
+ /**
2250
+ * Get the tokens in the mask string
2251
+ */
2252
+ var getTokens = function(str) {
2253
+ if (this.type == 'general') {
2254
+ var t = [].concat(tokens.general);
2255
+ } else {
2256
+ var t = [].concat(tokens.currency, tokens.datetime, tokens.percentage, tokens.numeric, tokens.text, tokens.general);
2257
+ }
2258
+ // Expression to extract all tokens from the string
2259
+ var e = new RegExp(t.join('|'), 'gi');
2260
+ // Extract
2261
+ return str.match(e);
2262
+ }
2263
+
2264
+ /**
2265
+ * Get the method of one given token
2266
+ */
2267
+ var getMethod = function(str) {
2268
+ if (! this.type) {
2269
+ var types = Object.keys(tokens);
2270
+ } else if (this.type == 'text') {
2271
+ var types = [ 'text' ];
2272
+ } else if (this.type == 'general') {
2273
+ var types = [ 'general' ];
2274
+ } else if (this.type == 'datetime') {
2275
+ var types = [ 'numeric', 'datetime', 'general' ];
2276
+ } else {
2277
+ var types = [ 'currency', 'percentage', 'numeric', 'general' ];
2278
+ }
2279
+
2280
+ // Found
2281
+ for (var i = 0; i < types.length; i++) {
2282
+ var type = types[i];
2283
+ for (var j = 0; j < tokens[type].length; j++) {
2284
+ var e = new RegExp(tokens[type][j], 'gi');
2285
+ var r = str.match(e);
2286
+ if (r) {
2287
+ return { type: type, method: tokens[type][j] }
2288
+ }
2289
+ }
2290
+ }
2291
+ }
2292
+
2293
+ /**
2294
+ * Identify each method for each token
2295
+ */
2296
+ var getMethods = function(t) {
2297
+ var result = [];
2298
+ for (var i = 0; i < t.length; i++) {
2299
+ var m = getMethod.call(this, t[i]);
2300
+ if (m) {
2301
+ result.push(m.method);
2302
+ } else {
2303
+ result.push(null);
2304
+ }
2305
+ }
2306
+
2307
+ // Compatibility with excel
2308
+ for (var i = 0; i < result.length; i++) {
2309
+ if (result[i] == 'MM') {
2310
+ // Not a month, correct to minutes
2311
+ if (result[i-1] && result[i-1].indexOf('H') >= 0) {
2312
+ result[i] = 'MI';
2313
+ } else if (result[i-2] && result[i-2].indexOf('H') >= 0) {
2314
+ result[i] = 'MI';
2315
+ } else if (result[i+1] && result[i+1].indexOf('S') >= 0) {
2316
+ result[i] = 'MI';
2317
+ } else if (result[i+2] && result[i+2].indexOf('S') >= 0) {
2318
+ result[i] = 'MI';
2319
+ }
2320
+ }
2321
+ }
2322
+
2323
+ return result;
2324
+ }
2325
+
2326
+ /**
2327
+ * Get the type for one given token
2328
+ */
2329
+ var getType = function(str) {
2330
+ var m = getMethod.call(this, str);
2331
+ if (m) {
2332
+ var type = m.type;
2333
+ }
2334
+
2335
+ if (type) {
2336
+ var numeric = 0;
2337
+ // Make sure the correct type
2338
+ var t = getTokens.call(this, str);
2339
+ for (var i = 0; i < t.length; i++) {
2340
+ m = getMethod.call(this, t[i]);
2341
+ if (m && isNumeric(m.type)) {
2342
+ numeric++;
2343
+ }
2344
+ }
2345
+ if (numeric > 1) {
2346
+ type = 'general';
2347
+ }
2348
+ }
2349
+
2350
+ return type;
2351
+ }
2352
+
2353
+ /**
2354
+ * Parse character per character using the detected tokens in the mask
2355
+ */
2356
+ var parse = function() {
2357
+ // Parser method for this position
2358
+ if (typeof(parser[this.methods[this.index]]) == 'function') {
2359
+ parser[this.methods[this.index]].call(this, this.value[this.position]);
2360
+ this.position++;
2361
+ } else {
2362
+ this.values[this.index] = this.tokens[this.index];
2363
+ this.index++;
2364
+ }
2365
+ }
2366
+
2367
+ var toPlainString = function(num) {
2368
+ return (''+ +num).replace(/(-?)(\d*)\.?(\d*)e([+-]\d+)/,
2369
+ function(a,b,c,d,e) {
2370
+ return e < 0
2371
+ ? b + '0.' + Array(1-e-c.length).join(0) + c + d
2372
+ : b + c + d + Array(e-d.length+1).join(0);
2373
+ });
2374
+ }
2375
+
2376
+ /**
2377
+ * Mask function
2378
+ * @param {mixed|string} JS input or a string to be parsed
2379
+ * @param {object|string} When the first param is a string, the second is the mask or object with the mask options
2380
+ */
2381
+ var obj = function(e, config, returnObject) {
2382
+ // Options
2383
+ var r = null;
2384
+ var t = null;
2385
+ var o = {
2386
+ // Element
2387
+ input: null,
2388
+ // Current value
2389
+ value: null,
2390
+ // Mask options
2391
+ options: {},
2392
+ // New values for each token found
2393
+ values: [],
2394
+ // Token position
2395
+ index: 0,
2396
+ // Character position
2397
+ position: 0,
2398
+ // Date raw values
2399
+ date: [0,0,0,0,0,0],
2400
+ // Raw number for the numeric values
2401
+ number: 0,
2402
+ }
2403
+
2404
+ // This is a JavaScript Event
2405
+ if (typeof(e) == 'object') {
2406
+ // Element
2407
+ o.input = e.target;
2408
+ // Current value
2409
+ o.value = Value.call(e.target);
2410
+ // Current caret position
2411
+ o.caret = Caret.call(e.target);
2412
+ // Mask
2413
+ if (t = e.target.getAttribute('data-mask')) {
2414
+ o.mask = t;
2415
+ }
2416
+ // Type
2417
+ if (t = e.target.getAttribute('data-type')) {
2418
+ o.type = t;
2419
+ }
2420
+ // Options
2421
+ if (e.target.mask) {
2422
+ if (e.target.mask.options) {
2423
+ o.options = e.target.mask.options;
2424
+ }
2425
+ if (e.target.mask.locale) {
2426
+ o.locale = e.target.mask.locale;
2427
+ }
2428
+ } else {
2429
+ // Locale
2430
+ if (t = e.target.getAttribute('data-locale')) {
2431
+ o.locale = t;
2432
+ if (o.mask) {
2433
+ o.options.style = o.mask;
2434
+ }
2435
+ }
2436
+ }
2437
+ // Extra configuration
2438
+ if (e.target.attributes && e.target.attributes.length) {
2439
+ for (var i = 0; i < e.target.attributes.length; i++) {
2440
+ var k = e.target.attributes[i].name;
2441
+ var v = e.target.attributes[i].value;
2442
+ if (k.substr(0,4) == 'data') {
2443
+ o.options[k.substr(5)] = v;
2444
+ }
2445
+ }
2446
+ }
2447
+ } else {
2448
+ // Options
2449
+ if (typeof(config) == 'string') {
2450
+ // Mask
2451
+ o.mask = config;
2452
+ } else {
2453
+ // Mask
2454
+ var k = Object.keys(config);
2455
+ for (var i = 0; i < k.length; i++) {
2456
+ o[k[i]] = config[k[i]];
2457
+ }
2458
+ }
2459
+
2460
+ if (typeof(e) === 'number') {
2461
+ // Get decimal
2462
+ getDecimal.call(o, o.mask);
2463
+ // Replace to the correct decimal
2464
+ e = (''+e).replace('.', o.options.decimal);
2465
+ }
2466
+
2467
+ // Current
2468
+ o.value = e;
2469
+
2470
+ if (o.input) {
2471
+ // Value
2472
+ Value.call(o.input, e);
2473
+ // Focus
2474
+ helpers.focus(o.input);
2475
+ // Caret
2476
+ o.caret = Caret.call(o.input);
2477
+ }
2478
+ }
2479
+
2480
+ // Mask detected start the process
2481
+ if (! isFormula(o.value) && (o.mask || o.locale)) {
2482
+ // Compatibility fixes
2483
+ if (o.mask) {
2484
+ // Remove []
2485
+ o.mask = o.mask.replace(new RegExp(/\[h]/),'|h|');
2486
+ o.mask = o.mask.replace(new RegExp(/\[.*?\]/),'');
2487
+ o.mask = o.mask.replace(new RegExp(/\|h\|/),'[h]');
2488
+ if (o.mask.indexOf(';') !== -1) {
2489
+ var t = o.mask.split(';');
2490
+ o.mask = t[0];
2491
+ }
2492
+ // Excel mask TODO: Improve
2493
+ if (o.mask.indexOf('##') !== -1) {
2494
+ var d = o.mask.split(';');
2495
+ if (d[0]) {
2496
+ if (typeof(e) == 'object') {
2497
+ d[0] = d[0].replace(new RegExp(/_\)/g), '');
2498
+ d[0] = d[0].replace(new RegExp(/_\(/g), '');
2499
+ }
2500
+ d[0] = d[0].replace('*', '\t');
2501
+ d[0] = d[0].replace(new RegExp(/_-/g), '');
2502
+ d[0] = d[0].replace(new RegExp(/_/g), '');
2503
+ d[0] = d[0].replace('##0.###','##0.000');
2504
+ d[0] = d[0].replace('##0.##','##0.00');
2505
+ d[0] = d[0].replace('##0.#','##0.0');
2506
+ d[0] = d[0].replace('##0,###','##0,000');
2507
+ d[0] = d[0].replace('##0,##','##0,00');
2508
+ d[0] = d[0].replace('##0,#','##0,0');
2509
+ }
2510
+ o.mask = d[0];
2511
+ }
2512
+ // Remove back slashes
2513
+ if (o.mask.indexOf('\\') !== -1) {
2514
+ var d = o.mask.split(';');
2515
+ d[0] = d[0].replace(new RegExp(/\\/g), '');
2516
+ o.mask = d[0];
2517
+ }
2518
+ // Get type
2519
+ if (! o.type) {
2520
+ o.type = getType.call(o, o.mask);
2521
+ }
2522
+ // Get tokens
2523
+ o.tokens = getTokens.call(o, o.mask);
2524
+ }
2525
+
2526
+ // On new input
2527
+ if (typeof(e) !== 'object' || ! e.inputType || ! e.inputType.indexOf('insert') || ! e.inputType.indexOf('delete')) {
2528
+ // Start transformation
2529
+ if (o.locale) {
2530
+ if (o.input) {
2531
+ Format.call(o, o.input, e);
2532
+ } else {
2533
+ var newValue = FormatValue.call(o, o.value);
2534
+ }
2535
+ } else {
2536
+ // Get tokens
2537
+ o.methods = getMethods.call(o, o.tokens);
2538
+ o.event = e;
2539
+
2540
+ // Go through all tokes
2541
+ while (o.position < o.value.length && typeof(o.tokens[o.index]) !== 'undefined') {
2542
+ // Get the appropriate parser
2543
+ parse.call(o);
2544
+ }
2545
+
2546
+ // New value
2547
+ var newValue = o.values.join('');
2548
+
2549
+ // Add tokens to the end of string only if string is not empty
2550
+ if (isNumeric(o.type) && newValue !== '') {
2551
+ // Complement things in the end of the mask
2552
+ while (typeof(o.tokens[o.index]) !== 'undefined') {
2553
+ var t = getMethod.call(o, o.tokens[o.index]);
2554
+ if (t && t.type == 'general') {
2555
+ o.values[o.index] = o.tokens[o.index];
2556
+ }
2557
+ o.index++;
2558
+ }
2559
+
2560
+ var adjustNumeric = true;
2561
+ } else {
2562
+ var adjustNumeric = false;
2563
+ }
2564
+
2565
+ // New value
2566
+ newValue = o.values.join('');
2567
+
2568
+ // Reset value
2569
+ if (o.input) {
2570
+ t = newValue.length - o.value.length;
2571
+ if (t > 0) {
2572
+ var caret = o.caret + t;
2573
+ } else {
2574
+ var caret = o.caret;
2575
+ }
2576
+ Value.call(o.input, newValue, caret, adjustNumeric);
2577
+ }
2578
+ }
2579
+ }
2580
+
2581
+ // Update raw data
2582
+ if (o.input) {
2583
+ var label = null;
2584
+ if (isNumeric(o.type)) {
2585
+ let v = Value.call(o.input);
2586
+ // Extract the number
2587
+ o.number = Extract.call(o, v);
2588
+ // Keep the raw data as a property of the tag
2589
+ if (o.type == 'percentage' && v.indexOf('%') !== -1) {
2590
+ label = obj.adjustPrecision(o.number / 100);
2591
+ } else {
2592
+ label = o.number;
2593
+ }
2594
+ } else if (o.type == 'datetime') {
2595
+ label = getDate.call(o);
2596
+
2597
+ if (o.date[0] && o.date[1] && o.date[2]) {
2598
+ o.input.setAttribute('data-completed', true);
2599
+ }
2600
+ }
2601
+
2602
+ if (label) {
2603
+ o.input.setAttribute('data-value', label);
2604
+ }
2605
+ }
2606
+
2607
+ if (newValue !== undefined) {
2608
+ if (returnObject) {
2609
+ return o;
2610
+ } else {
2611
+ return newValue;
2612
+ }
2613
+ }
2614
+ }
2615
+ }
2616
+
2617
+ obj.adjustPrecision = function(num) {
2618
+ if (typeof num === 'number' && !Number.isInteger(num)) {
2619
+ const v = num.toString().split('.');
2620
+
2621
+ if (v[1] && v[1].length > 10) {
2622
+ let t0 = 0;
2623
+ const t1 = v[1][v[1].length - 2];
2624
+
2625
+ if (t1 == 0 || t1 == 9) {
2626
+ for (let i = v[1].length - 2; i > 0; i--) {
2627
+ if (t0 >= 0 && v[1][i] == t1) {
2628
+ t0++;
2629
+ if (t0 > 6) {
2630
+ break;
2631
+ }
2632
+ } else {
2633
+ t0 = 0;
2634
+ break;
2635
+ }
2636
+ }
2637
+
2638
+ if (t0) {
2639
+ return parseFloat(parseFloat(num).toFixed(v[1].length - 1));
2640
+ }
2641
+ }
2642
+ }
2643
+ }
2644
+
2645
+ return num;
2646
+ }
2647
+
2648
+ // Get the type of the mask
2649
+ obj.getType = getType;
2650
+
2651
+ // Extract the tokens from a mask
2652
+ obj.prepare = function(str, o) {
2653
+ if (! o) {
2654
+ o = {};
2655
+ }
2656
+ return getTokens.call(o, str);
2657
+ }
2658
+
2659
+ /**
2660
+ * Apply the mask to a element (legacy)
2661
+ */
2662
+ obj.apply = function(e) {
2663
+ var v = Value.call(e.target);
2664
+ if (e.key.length == 1) {
2665
+ v += e.key;
2666
+ }
2667
+ Value.call(e.target, obj(v, e.target.getAttribute('data-mask')));
2668
+ }
2669
+
2670
+ /**
2671
+ * Legacy support
2672
+ */
2673
+ obj.run = function(value, mask, decimal) {
2674
+ return obj(value, { mask: mask, decimal: decimal });
2675
+ }
2676
+
2677
+ /**
2678
+ * Extract number from masked string
2679
+ */
2680
+ obj.extract = function(v, options, returnObject) {
2681
+ if (isBlank(v)) {
2682
+ return v;
2683
+ }
2684
+ if (typeof(options) != 'object') {
2685
+ return v;
2686
+ } else {
2687
+ options = Object.assign({}, options);
2688
+
2689
+ if (! options.options) {
2690
+ options.options = {};
2691
+ }
2692
+ }
2693
+
2694
+ // Compatibility
2695
+ if (! options.mask && options.format) {
2696
+ options.mask = options.format;
2697
+ }
2698
+
2699
+ // Remove []
2700
+ if (options.mask) {
2701
+ if (options.mask.indexOf(';') !== -1) {
2702
+ var t = options.mask.split(';');
2703
+ options.mask = t[0];
2704
+ }
2705
+ options.mask = options.mask.replace(new RegExp(/\[h]/),'|h|');
2706
+ options.mask = options.mask.replace(new RegExp(/\[.*?\]/),'');
2707
+ options.mask = options.mask.replace(new RegExp(/\|h\|/),'[h]');
2708
+ }
2709
+
2710
+ // Get decimal
2711
+ getDecimal.call(options, options.mask);
2712
+
2713
+ var type = null;
2714
+ var value = null;
2715
+
2716
+ if (options.type == 'percent' || options.options.style == 'percent') {
2717
+ type = 'percentage';
2718
+ } else if (options.mask) {
2719
+ type = getType.call(options, options.mask);
2720
+ }
2721
+
2722
+ if (type === 'general') {
2723
+ var o = obj(v, options, true);
2724
+
2725
+ value = v;
2726
+ } else if (type === 'datetime') {
2727
+ if (v instanceof Date) {
2728
+ v = obj.getDateString(v, options.mask);
2729
+ }
2730
+
2731
+ var o = obj(v, options, true);
2732
+
2733
+ if (helpers.isNumeric(v)) {
2734
+ value = v;
2735
+ } else {
2736
+ value = extractDate.call(o);
2737
+ }
2738
+ } else {
2739
+ value = Extract.call(options, v);
2740
+ // Percentage
2741
+ if (type === 'percentage' && v.indexOf('%') !== -1) {
2742
+ value /= 100;
2743
+ }
2744
+ var o = options;
2745
+ }
2746
+
2747
+ o.value = value;
2748
+
2749
+ if (! o.type && type) {
2750
+ o.type = type;
2751
+ }
2752
+
2753
+ if (returnObject) {
2754
+ return o;
2755
+ } else {
2756
+ return value;
2757
+ }
2758
+ }
2759
+
2760
+ /**
2761
+ * Render
2762
+ */
2763
+ obj.render = function(value, options, fullMask) {
2764
+ if (isBlank(value)) {
2765
+ return value;
2766
+ }
2767
+
2768
+ if (typeof(options) != 'object') {
2769
+ return value;
2770
+ } else {
2771
+ options = Object.assign({}, options);
2772
+
2773
+ if (! options.options) {
2774
+ options.options = {};
2775
+ }
2776
+ }
2777
+
2778
+ // Compatibility
2779
+ if (! options.mask && options.format) {
2780
+ options.mask = options.format;
2781
+ }
2782
+
2783
+ // Remove []
2784
+ if (options.mask) {
2785
+ if (options.mask.indexOf(';') !== -1) {
2786
+ var t = options.mask.split(';');
2787
+ if (! fullMask) {
2788
+ t[0] = t[0].replace(new RegExp(/_\)/g), '');
2789
+ t[0] = t[0].replace(new RegExp(/_\(/g), '');
2790
+ }
2791
+ options.mask = t[0];
2792
+ }
2793
+ options.mask = options.mask.replace(new RegExp(/\[h]/),'|h|');
2794
+ options.mask = options.mask.replace(new RegExp(/\[.*?\]/),'');
2795
+ options.mask = options.mask.replace(new RegExp(/\|h\|/),'[h]');
2796
+ }
2797
+
2798
+ var type = null;
2799
+ if (options.type == 'percent' || options.options.style == 'percent') {
2800
+ type = 'percentage';
2801
+ } else if (options.mask) {
2802
+ type = getType.call(options, options.mask);
2803
+ } else if (value instanceof Date) {
2804
+ type = 'datetime';
2805
+ }
2806
+
2807
+ // Fill with blanks
2808
+ var fillWithBlanks = false;
2809
+
2810
+ if (type =='datetime' || options.type == 'calendar') {
2811
+ var t = obj.getDateString(value, options.mask);
2812
+ if (t) {
2813
+ value = t;
2814
+ }
2815
+ if (options.mask && fullMask) {
2816
+ fillWithBlanks = true;
2817
+ }
2818
+ } else {
2819
+ // Percentage
2820
+ if (type === 'percentage') {
2821
+ value = obj.adjustPrecision(value*100);
2822
+ }
2823
+ // Number of decimal places
2824
+ if (typeof(value) === 'number') {
2825
+ var t = null;
2826
+ if (options.mask && fullMask && ((''+value).indexOf('e') === -1)) {
2827
+ var d = getDecimal.call(options, options.mask);
2828
+ if (options.mask.indexOf(d) !== -1) {
2829
+ d = options.mask.split(d);
2830
+ d = (''+d[1].match(/[0-9]+/g))
2831
+ d = d.length;
2832
+ t = value.toFixed(d);
2833
+ let n = value.toString().split('.');
2834
+ let fraction = n[1];
2835
+ if (fraction && fraction.length > d && fraction[fraction.length-1] === '5') {
2836
+ if (value > 0) {
2837
+ t = (value + Number.EPSILON).toFixed(d);
2838
+ } else {
2839
+ t = (value - Number.EPSILON).toFixed(d);
2840
+ }
2841
+ } else {
2842
+ t = value.toFixed(d);
2843
+ }
2844
+ } else {
2845
+ t = value.toFixed(0);
2846
+ }
2847
+ } else if (options.locale && fullMask) {
2848
+ // Append zeros
2849
+ var d = (''+value).split('.');
2850
+ if (options.options) {
2851
+ if (typeof(d[1]) === 'undefined') {
2852
+ d[1] = '';
2853
+ }
2854
+ var len = d[1].length;
2855
+ if (options.options.minimumFractionDigits > len) {
2856
+ for (var i = 0; i < options.options.minimumFractionDigits - len; i++) {
2857
+ d[1] += '0';
2858
+ }
2859
+ }
2860
+ }
2861
+ if (! d[1].length) {
2862
+ t = d[0]
2863
+ } else {
2864
+ t = d.join('.');
2865
+ }
2866
+ var len = d[1].length;
2867
+ if (options.options && options.options.maximumFractionDigits < len) {
2868
+ t = parseFloat(t).toFixed(options.options.maximumFractionDigits);
2869
+ }
2870
+ } else {
2871
+ t = toPlainString(value);
2872
+ }
2873
+
2874
+ if (t !== null) {
2875
+ value = t;
2876
+ // Get decimal
2877
+ getDecimal.call(options, options.mask);
2878
+ // Replace to the correct decimal
2879
+ if (options.options.decimal) {
2880
+ value = value.replace('.', options.options.decimal);
2881
+ }
2882
+ }
2883
+ } else {
2884
+ if (options.mask && fullMask) {
2885
+ fillWithBlanks = true;
2886
+ }
2887
+ }
2888
+ }
2889
+
2890
+ if (fillWithBlanks) {
2891
+ var s = options.mask.length - value.length;
2892
+ if (s > 0) {
2893
+ for (var i = 0; i < s; i++) {
2894
+ value += ' ';
2895
+ }
2896
+ }
2897
+ }
2898
+
2899
+ value = obj(value, options);
2900
+
2901
+ // Numeric mask, number of zeros
2902
+ if (fullMask && type === 'numeric') {
2903
+ var maskZeros = options.mask.match(new RegExp(/^[0]+$/gm));
2904
+ if (maskZeros && maskZeros.length === 1) {
2905
+ var maskLength = maskZeros[0].length;
2906
+ if (maskLength > 3) {
2907
+ value = '' + value;
2908
+ while (value.length < maskLength) {
2909
+ value = '0' + value;
2910
+ }
2911
+ }
2912
+ }
2913
+ }
2914
+
2915
+ return value;
2916
+ }
2917
+
2918
+ obj.set = function(e, m) {
2919
+ if (m) {
2920
+ e.setAttribute('data-mask', m);
2921
+ // Reset the value
2922
+ var event = new Event('input', {
2923
+ bubbles: true,
2924
+ cancelable: true,
2925
+ });
2926
+ e.dispatchEvent(event);
2927
+ }
2928
+ }
2929
+
2930
+ // Helper to extract date from a string
2931
+ obj.extractDateFromString = function (date, format) {
2932
+ var o = obj(date, { mask: format }, true);
2933
+
2934
+ // Check if in format Excel (Need difference with format date or type detected is numeric)
2935
+ if (date > 0 && Number(date) == date && (o.values.join("") !== o.value || o.type == "numeric")) {
2936
+ var d = new Date(Math.round((date - 25569) * 86400 * 1000));
2937
+ return d.getFullYear() + "-" + helpers.two(d.getMonth()) + "-" + helpers.two(d.getDate()) + ' 00:00:00';
2938
+ }
2939
+
2940
+ var complete = false;
2941
+
2942
+ if (o.values.length === o.tokens.length && o.values[o.values.length - 1].length >= o.tokens[o.tokens.length - 1].length) {
2943
+ complete = true;
2944
+ }
2945
+
2946
+ if (o.date[0] && o.date[1] && (o.date[2] || complete)) {
2947
+ if (!o.date[2]) {
2948
+ o.date[2] = 1;
2949
+ }
2950
+
2951
+ 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]);
2952
+ }
2953
+
2954
+ return '';
2955
+ }
2956
+
2957
+ // Helper to convert date into string
2958
+ obj.getDateString = function (value, options) {
2959
+ if (!options) {
2960
+ var options = {};
2961
+ }
2962
+
2963
+ // Labels
2964
+ if (options && typeof (options) == 'object') {
2965
+ var format = options.format;
2966
+ } else {
2967
+ var format = options;
2968
+ }
2969
+
2970
+ if (!format) {
2971
+ format = 'YYYY-MM-DD';
2972
+ }
2973
+
2974
+ // Convert to number of hours
2975
+ if (format.indexOf('[h]') >= 0) {
2976
+ var result = 0;
2977
+ if (value && helpers.isNumeric(value)) {
2978
+ result = parseFloat(24 * Number(value));
2979
+ if (format.indexOf('mm') >= 0) {
2980
+ var h = ('' + result).split('.');
2981
+ if (h[1]) {
2982
+ var d = 60 * parseFloat('0.' + h[1])
2983
+ d = parseFloat(d.toFixed(2));
2984
+ } else {
2985
+ var d = 0;
2986
+ }
2987
+ result = parseInt(h[0]) + ':' + helpers.two(d);
2988
+ }
2989
+ }
2990
+ return result;
2991
+ }
2992
+
2993
+ // Date instance
2994
+ if (value instanceof Date) {
2995
+ value = helpers_date.now(value);
2996
+ } else if (value && helpers.isNumeric(value)) {
2997
+ value = helpers_date.numToDate(value);
2998
+ }
2999
+
3000
+ // Tokens
3001
+ 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', '.'];
3002
+
3003
+ // Expression to extract all tokens from the string
3004
+ var e = new RegExp(tokens.join('|'), 'gi');
3005
+ // Extract
3006
+ var t = format.match(e);
3007
+
3008
+ // Compatibility with excel
3009
+ for (var i = 0; i < t.length; i++) {
3010
+ if (t[i].toUpperCase() == 'MM') {
3011
+ // Not a month, correct to minutes
3012
+ if (t[i - 1] && t[i - 1].toUpperCase().indexOf('H') >= 0) {
3013
+ t[i] = 'mi';
3014
+ } else if (t[i - 2] && t[i - 2].toUpperCase().indexOf('H') >= 0) {
3015
+ t[i] = 'mi';
3016
+ } else if (t[i + 1] && t[i + 1].toUpperCase().indexOf('S') >= 0) {
3017
+ t[i] = 'mi';
3018
+ } else if (t[i + 2] && t[i + 2].toUpperCase().indexOf('S') >= 0) {
3019
+ t[i] = 'mi';
3020
+ }
3021
+ }
3022
+ }
3023
+
3024
+ // Object
3025
+ var o = {
3026
+ tokens: t
3027
+ }
3028
+
3029
+ // Value
3030
+ if (value) {
3031
+ var d = '' + value;
3032
+ var splitStr = (d.indexOf('T') !== -1) ? 'T' : ' ';
3033
+ d = d.split(splitStr);
3034
+
3035
+ var h = 0;
3036
+ var m = 0;
3037
+ var s = 0;
3038
+
3039
+ if (d[1]) {
3040
+ h = d[1].split(':');
3041
+ m = h[1] ? h[1] : 0;
3042
+ s = h[2] ? h[2] : 0;
3043
+ h = h[0] ? h[0] : 0;
3044
+ }
3045
+
3046
+ d = d[0].split('-');
3047
+
3048
+ if (d[0] && d[1] && d[2] && d[0] > 0 && d[1] > 0 && d[1] < 13 && d[2] > 0 && d[2] < 32) {
3049
+
3050
+ // Data
3051
+ o.data = [d[0], d[1], d[2], h, m, s];
3052
+
3053
+ // Value
3054
+ o.value = [];
3055
+
3056
+ // Calendar instance
3057
+ var calendar = new Date(o.data[0], o.data[1] - 1, o.data[2], o.data[3], o.data[4], o.data[5]);
3058
+
3059
+ // Get method
3060
+ var get = function (i) {
3061
+ // Token
3062
+ var t = this.tokens[i];
3063
+ // Case token
3064
+ var s = t.toUpperCase();
3065
+ var v = null;
3066
+
3067
+ if (s === 'YYYY') {
3068
+ v = this.data[0];
3069
+ } else if (s === 'YYY') {
3070
+ v = this.data[0].substring(1, 4);
3071
+ } else if (s === 'YY') {
3072
+ v = this.data[0].substring(2, 4);
3073
+ } else if (s === 'Y') {
3074
+ v = this.data[0].substring(3, 4);
3075
+ } else if (t === 'MON') {
3076
+ v = helpers_date.months[calendar.getMonth()].substr(0, 3).toUpperCase();
3077
+ } else if (t === 'mon') {
3078
+ v = helpers_date.months[calendar.getMonth()].substr(0, 3).toLowerCase();
3079
+ } else if (t === 'MONTH') {
3080
+ v = helpers_date.months[calendar.getMonth()].toUpperCase();
3081
+ } else if (t === 'month') {
3082
+ v = helpers_date.months[calendar.getMonth()].toLowerCase();
3083
+ } else if (s === 'MMMMM') {
3084
+ v = helpers_date.months[calendar.getMonth()].substr(0, 1);
3085
+ } else if (s === 'MMMM' || t === 'Month') {
3086
+ v = helpers_date.months[calendar.getMonth()];
3087
+ } else if (s === 'MMM' || t == 'Mon') {
3088
+ v = helpers_date.months[calendar.getMonth()].substr(0, 3);
3089
+ } else if (s === 'MM') {
3090
+ v = helpers.two(this.data[1]);
3091
+ } else if (s === 'M') {
3092
+ v = calendar.getMonth() + 1;
3093
+ } else if (t === 'DAY') {
3094
+ v = helpers_date.weekdays[calendar.getDay()].toUpperCase();
3095
+ } else if (t === 'day') {
3096
+ v = helpers_date.weekdays[calendar.getDay()].toLowerCase();
3097
+ } else if (s === 'DDDD' || t == 'Day') {
3098
+ v = helpers_date.weekdays[calendar.getDay()];
3099
+ } else if (s === 'DDD') {
3100
+ v = helpers_date.weekdays[calendar.getDay()].substr(0, 3);
3101
+ } else if (s === 'DD') {
3102
+ v = helpers.two(this.data[2]);
3103
+ } else if (s === 'D') {
3104
+ v = parseInt(this.data[2]);
3105
+ } else if (s === 'Q') {
3106
+ v = Math.floor((calendar.getMonth() + 3) / 3);
3107
+ } else if (s === 'HH24' || s === 'HH') {
3108
+ v = this.data[3];
3109
+ if (v > 12 && this.tokens.indexOf('am/pm') !== -1) {
3110
+ v -= 12;
3111
+ }
3112
+ v = helpers.two(v);
3113
+ } else if (s === 'HH12') {
3114
+ if (this.data[3] > 12) {
3115
+ v = helpers.two(this.data[3] - 12);
3116
+ } else {
3117
+ v = helpers.two(this.data[3]);
3118
+ }
3119
+ } else if (s === 'H') {
3120
+ v = this.data[3];
3121
+ if (v > 12 && this.tokens.indexOf('am/pm') !== -1) {
3122
+ v -= 12;
3123
+ v = helpers.two(v);
3124
+ }
3125
+ } else if (s === 'MI') {
3126
+ v = helpers.two(this.data[4]);
3127
+ } else if (s === 'SS') {
3128
+ v = helpers.two(this.data[5]);
3129
+ } else if (s === 'MS') {
3130
+ v = calendar.getMilliseconds();
3131
+ } else if (s === 'AM/PM') {
3132
+ if (this.data[3] >= 12) {
3133
+ v = 'PM';
3134
+ } else {
3135
+ v = 'AM';
3136
+ }
3137
+ } else if (s === 'WD') {
3138
+ v = helpers_date.weekdays[calendar.getDay()];
3139
+ }
3140
+
3141
+ if (v === null) {
3142
+ this.value[i] = this.tokens[i];
3143
+ } else {
3144
+ this.value[i] = v;
3145
+ }
3146
+ }
3147
+
3148
+ for (var i = 0; i < o.tokens.length; i++) {
3149
+ get.call(o, i);
3150
+ }
3151
+ // Put pieces together
3152
+ value = o.value.join('');
3153
+ } else {
3154
+ value = '';
3155
+ }
3156
+ }
3157
+
3158
+ return value;
3159
+ }
3160
+
3161
+ return obj;
3162
+ }
3163
+
3164
3164
  /* harmony default export */ var mask = (Mask());
3165
3165
  ;// CONCATENATED MODULE: ./src/plugins/calendar.js
3166
3166
 
@@ -12706,7 +12706,7 @@ var jSuites = {
12706
12706
  ...dictionary,
12707
12707
  ...helpers,
12708
12708
  /** Current version */
12709
- version: '5.0.27',
12709
+ version: '5.1.0',
12710
12710
  /** Bind new extensions to Jsuites */
12711
12711
  setExtensions: function(o) {
12712
12712
  if (typeof(o) == 'object') {