jsuites 4.11.2 → 4.11.5

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.
@@ -17,7 +17,7 @@
17
17
 
18
18
  var jSuites = function(options) {
19
19
  var obj = {}
20
- var version = '4.10.1';
20
+ var version = '4.11.5';
21
21
 
22
22
  var find = function(DOMElement, component) {
23
23
  if (DOMElement[component.type] && DOMElement[component.type] == component) {
@@ -1953,25 +1953,53 @@ jSuites.calendar.extractDateFromString = function(date, format) {
1953
1953
  return '';
1954
1954
  }
1955
1955
 
1956
+
1957
+ var excelInitialTime = Date.UTC(1900, 0, 0);
1958
+ var excelLeapYearBug = Date.UTC(1900, 1, 29);
1959
+ var millisecondsPerDay = 86400000;
1960
+
1956
1961
  /**
1957
1962
  * Date to number
1958
1963
  */
1959
- jSuites.calendar.dateToNum = function(a, b) {
1960
- a = new Date(a);
1961
- if (! b) {
1962
- b = '1899-12-30 ' + a.getHours() + ':' + a.getMinutes() + ':' + a.getSeconds();
1963
- }
1964
- b = new Date(b);
1965
- var v = a.getTime() - b.getTime();
1966
- return Math.round(v / 86400000);
1964
+ jSuites.calendar.dateToNum = function(jsDate) {
1965
+ if (typeof(jsDate) === 'string') {
1966
+ jsDate = new Date(jsDate + ' GMT+0');
1967
+ }
1968
+ var jsDateInMilliseconds = jsDate.getTime();
1969
+
1970
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
1971
+ jsDateInMilliseconds += millisecondsPerDay;
1972
+ }
1973
+
1974
+ jsDateInMilliseconds -= excelInitialTime;
1975
+
1976
+ return jsDateInMilliseconds / millisecondsPerDay;
1967
1977
  }
1968
1978
 
1969
1979
  /**
1970
1980
  * Number to date
1971
1981
  */
1972
- jSuites.calendar.numToDate = function(value) {
1973
- var d = new Date(Math.round((value - 25569)*86400*1000));
1974
- return d.getFullYear() + "-" + jSuites.two(d.getMonth()+1) + "-" + jSuites.two(d.getDate()) + ' 00:00:00';
1982
+ // !IMPORTANT!
1983
+ // Excel incorrectly considers 1900 to be a leap year
1984
+ jSuites.calendar.numToDate = function(excelSerialNumber) {
1985
+ var jsDateInMilliseconds = excelInitialTime + excelSerialNumber * millisecondsPerDay;
1986
+
1987
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
1988
+ jsDateInMilliseconds -= millisecondsPerDay;
1989
+ }
1990
+
1991
+ const d = new Date(jsDateInMilliseconds);
1992
+
1993
+ var date = [
1994
+ d.getUTCFullYear(),
1995
+ d.getUTCMonth()+1,
1996
+ d.getUTCDate(),
1997
+ d.getUTCHours(),
1998
+ d.getUTCMinutes(),
1999
+ d.getUTCSeconds(),
2000
+ ];
2001
+
2002
+ return jSuites.calendar.now(date);
1975
2003
  }
1976
2004
 
1977
2005
  // Helper to convert date into string
@@ -7136,7 +7164,7 @@ jSuites.mask = (function() {
7136
7164
  }
7137
7165
  // Temporary value
7138
7166
  if (v[0]) {
7139
- var t = parseFloat(v[0]);
7167
+ var t = parseFloat(v[0] + '.1');
7140
7168
  if (o.style == 'percent') {
7141
7169
  t /= 100;
7142
7170
  }
@@ -7243,9 +7271,12 @@ jSuites.mask = (function() {
7243
7271
  if (this.tagName == 'DIV') {
7244
7272
  var s = window.getSelection();
7245
7273
  var r = document.createRange();
7246
- r.setStart(this.childNodes[0], index);
7247
- s.removeAllRanges();
7248
- s.addRange(r);
7274
+
7275
+ if (this.childNodes[0]) {
7276
+ r.setStart(this.childNodes[0], index);
7277
+ s.removeAllRanges();
7278
+ s.addRange(r);
7279
+ }
7249
7280
  } else {
7250
7281
  this.selectionStart = index;
7251
7282
  this.selectionEnd = index;
@@ -8159,10 +8190,8 @@ jSuites.mask = (function() {
8159
8190
 
8160
8191
  var o = obj(v, options, true);
8161
8192
  var value = getDate.call(o);
8162
- if ((o.date[0] && o.date[1] && o.date[2]) && ! (o.date[3] || o.date[4] || o.date[5])) {
8163
- var t = jSuites.calendar.now(o.date);
8164
- value = jSuites.calendar.dateToNum(t);
8165
- }
8193
+ var t = jSuites.calendar.now(o.date);
8194
+ value = jSuites.calendar.dateToNum(t);
8166
8195
  } else {
8167
8196
  var value = Extract.call(options, v);
8168
8197
  // Percentage
@@ -8174,6 +8203,10 @@ jSuites.mask = (function() {
8174
8203
 
8175
8204
  o.value = value;
8176
8205
 
8206
+ if (! o.type && type) {
8207
+ o.type = type;
8208
+ }
8209
+
8177
8210
  if (returnObject) {
8178
8211
  return o;
8179
8212
  } else {
@@ -9829,7 +9862,9 @@ jSuites.toolbar = (function(el, options) {
9829
9862
  // Available parent space
9830
9863
  var available = parseInt(obj.options.maxWidth);
9831
9864
  // Remove arrow
9832
- toolbarArrow.remove();
9865
+ if (toolbarArrow.parentNode) {
9866
+ toolbarArrow.parentNode.removeChild(toolbarArrow);
9867
+ }
9833
9868
  // Move all items to the toolbar
9834
9869
  while (toolbarFloating.firstChild) {
9835
9870
  toolbarContent.appendChild(toolbarFloating.firstChild);
package/dist/jsuites.js CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  var jSuites = function(options) {
19
19
  var obj = {}
20
- var version = '4.11.2';
20
+ var version = '4.11.5';
21
21
 
22
22
  var find = function(DOMElement, component) {
23
23
  if (DOMElement[component.type] && DOMElement[component.type] == component) {
@@ -1964,25 +1964,53 @@ jSuites.calendar.extractDateFromString = function(date, format) {
1964
1964
  return '';
1965
1965
  }
1966
1966
 
1967
+
1968
+ var excelInitialTime = Date.UTC(1900, 0, 0);
1969
+ var excelLeapYearBug = Date.UTC(1900, 1, 29);
1970
+ var millisecondsPerDay = 86400000;
1971
+
1967
1972
  /**
1968
1973
  * Date to number
1969
1974
  */
1970
- jSuites.calendar.dateToNum = function(a, b) {
1971
- a = new Date(a);
1972
- if (! b) {
1973
- b = '1899-12-30 ' + a.getHours() + ':' + a.getMinutes() + ':' + a.getSeconds();
1974
- }
1975
- b = new Date(b);
1976
- var v = a.getTime() - b.getTime();
1977
- return Math.round(v / 86400000);
1975
+ jSuites.calendar.dateToNum = function(jsDate) {
1976
+ if (typeof(jsDate) === 'string') {
1977
+ jsDate = new Date(jsDate + ' GMT+0');
1978
+ }
1979
+ var jsDateInMilliseconds = jsDate.getTime();
1980
+
1981
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
1982
+ jsDateInMilliseconds += millisecondsPerDay;
1983
+ }
1984
+
1985
+ jsDateInMilliseconds -= excelInitialTime;
1986
+
1987
+ return jsDateInMilliseconds / millisecondsPerDay;
1978
1988
  }
1979
1989
 
1980
1990
  /**
1981
1991
  * Number to date
1982
1992
  */
1983
- jSuites.calendar.numToDate = function(value) {
1984
- var d = new Date(Math.round((value - 25569)*86400*1000));
1985
- return d.getFullYear() + "-" + jSuites.two(d.getMonth()+1) + "-" + jSuites.two(d.getDate()) + ' 00:00:00';
1993
+ // !IMPORTANT!
1994
+ // Excel incorrectly considers 1900 to be a leap year
1995
+ jSuites.calendar.numToDate = function(excelSerialNumber) {
1996
+ var jsDateInMilliseconds = excelInitialTime + excelSerialNumber * millisecondsPerDay;
1997
+
1998
+ if (jsDateInMilliseconds >= excelLeapYearBug) {
1999
+ jsDateInMilliseconds -= millisecondsPerDay;
2000
+ }
2001
+
2002
+ const d = new Date(jsDateInMilliseconds);
2003
+
2004
+ var date = [
2005
+ d.getUTCFullYear(),
2006
+ d.getUTCMonth()+1,
2007
+ d.getUTCDate(),
2008
+ d.getUTCHours(),
2009
+ d.getUTCMinutes(),
2010
+ d.getUTCSeconds(),
2011
+ ];
2012
+
2013
+ return jSuites.calendar.now(date);
1986
2014
  }
1987
2015
 
1988
2016
  // Helper to convert date into string
@@ -7561,7 +7589,7 @@ jSuites.mask = (function() {
7561
7589
  }
7562
7590
  // Temporary value
7563
7591
  if (v[0]) {
7564
- var t = parseFloat(v[0]);
7592
+ var t = parseFloat(v[0] + '.1');
7565
7593
  if (o.style == 'percent') {
7566
7594
  t /= 100;
7567
7595
  }
@@ -7668,9 +7696,12 @@ jSuites.mask = (function() {
7668
7696
  if (this.tagName == 'DIV') {
7669
7697
  var s = window.getSelection();
7670
7698
  var r = document.createRange();
7671
- r.setStart(this.childNodes[0], index);
7672
- s.removeAllRanges();
7673
- s.addRange(r);
7699
+
7700
+ if (this.childNodes[0]) {
7701
+ r.setStart(this.childNodes[0], index);
7702
+ s.removeAllRanges();
7703
+ s.addRange(r);
7704
+ }
7674
7705
  } else {
7675
7706
  this.selectionStart = index;
7676
7707
  this.selectionEnd = index;
@@ -8583,8 +8614,11 @@ jSuites.mask = (function() {
8583
8614
  }
8584
8615
 
8585
8616
  var o = obj(v, options, true);
8586
- var value = getDate.call(o);
8587
- if ((o.date[0] && o.date[1] && o.date[2]) && ! (o.date[3] || o.date[4] || o.date[5])) {
8617
+
8618
+ if (jSuites.isNumeric(v)) {
8619
+ value = v;
8620
+ } else {
8621
+ var value = getDate.call(o);
8588
8622
  var t = jSuites.calendar.now(o.date);
8589
8623
  value = jSuites.calendar.dateToNum(t);
8590
8624
  }
@@ -8599,6 +8633,10 @@ jSuites.mask = (function() {
8599
8633
 
8600
8634
  o.value = value;
8601
8635
 
8636
+ if (! o.type && type) {
8637
+ o.type = type;
8638
+ }
8639
+
8602
8640
  if (returnObject) {
8603
8641
  return o;
8604
8642
  } else {
@@ -11791,7 +11829,9 @@ jSuites.toolbar = (function(el, options) {
11791
11829
  // Available parent space
11792
11830
  var available = parseInt(obj.options.maxWidth);
11793
11831
  // Remove arrow
11794
- toolbarArrow.remove();
11832
+ if (toolbarArrow.parentNode) {
11833
+ toolbarArrow.parentNode.removeChild(toolbarArrow);
11834
+ }
11795
11835
  // Move all items to the toolbar
11796
11836
  while (toolbarFloating.firstChild) {
11797
11837
  toolbarContent.appendChild(toolbarFloating.firstChild);
@@ -11978,12 +12018,11 @@ jSuites.validations = (function() {
11978
12018
  return false;
11979
12019
  }
11980
12020
 
11981
- return numberCriterias[options.criteria](
11982
- data,
11983
- options.value.map(function(num) {
11984
- return parseFloat(num);
11985
- }),
11986
- );
12021
+ var values = options.value.map(function(num) {
12022
+ return parseFloat(num);
12023
+ })
12024
+
12025
+ return numberCriterias[options.criteria](data, values);
11987
12026
  };
11988
12027
 
11989
12028
  component.login = function(data) {
@@ -12017,12 +12056,11 @@ jSuites.validations = (function() {
12017
12056
  return false;
12018
12057
  }
12019
12058
 
12020
- return dateCriterias[options.criteria](
12021
- new Date(data).getTime(),
12022
- options.value.map(function(date) {
12023
- return new Date(date).getTime();
12024
- }),
12025
- );
12059
+ var values = options.value.map(function(date) {
12060
+ return new Date(date).getTime();
12061
+ });
12062
+
12063
+ return dateCriterias[options.criteria](new Date(data).getTime(), values);
12026
12064
  }
12027
12065
 
12028
12066
  component.text = function(data, options) {
@@ -12038,10 +12076,7 @@ jSuites.validations = (function() {
12038
12076
  return false;
12039
12077
  }
12040
12078
 
12041
- return textCriterias[options.criteria](
12042
- data,
12043
- options.value,
12044
- );
12079
+ return textCriterias[options.criteria](data, options.value);
12045
12080
  }
12046
12081
 
12047
12082
  return component;
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "javascript plugins"
20
20
  ],
21
21
  "main": "dist/jsuites.js",
22
- "version": "4.11.2",
22
+ "version": "4.11.5",
23
23
  "bugs": "https://github.com/jsuites/jsuites/issues",
24
24
  "homepage": "https://github.com/jsuites/jsuites",
25
25
  "docs": "https://jsuites.net",