@base-framework/base 2.6.1 → 2.6.3
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/README.md +1 -0
- package/dist/base.js +1 -0
- package/package.json +30 -26
- package/.jshintrc +0 -3
- package/base.js +0 -41
- package/base.min.js +0 -1
- package/core.js +0 -1
- package/data-tracker.js +0 -351
- package/es5/base.js +0 -2968
- package/es5/modules/ajax.js +0 -663
- package/es5/modules/animation.js +0 -188
- package/es5/modules/animations.js +0 -1080
- package/es5/modules/atom.js +0 -65
- package/es5/modules/component.js +0 -1310
- package/es5/modules/data-binder.js +0 -1131
- package/es5/modules/data.js +0 -1808
- package/es5/modules/date.js +0 -525
- package/es5/modules/form-validator.js +0 -324
- package/es5/modules/history.js +0 -126
- package/es5/modules/html-builder.js +0 -461
- package/es5/modules/layout.js +0 -1679
- package/es5/modules/mouse.js +0 -124
- package/es5/modules/nav-link.js +0 -123
- package/es5/modules/olderversions/animations-ease.js +0 -1095
- package/es5/modules/olderversions/animations-update.js +0 -1048
- package/es5/modules/olderversions/base-animations.js +0 -636
- package/es5/modules/olderversions/base-component-class.js +0 -100
- package/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/es5/modules/olderversions/base-mode-1.js +0 -777
- package/es5/modules/olderversions/base-model-class.js +0 -585
- package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/es5/modules/olderversions/data-tracker.js +0 -187
- package/es5/modules/olderversions/event-update.js +0 -666
- package/es5/modules/olderversions/nav-link.js +0 -119
- package/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/es5/modules/olderversions/router-with-templates.js +0 -701
- package/es5/modules/prototypes/ajax.js +0 -657
- package/es5/modules/prototypes/atom.js +0 -65
- package/es5/modules/prototypes/component.js +0 -972
- package/es5/modules/prototypes/data-binder.js +0 -1089
- package/es5/modules/prototypes/data.js +0 -1290
- package/es5/modules/prototypes/html-builder.js +0 -414
- package/es5/modules/prototypes/layout.js +0 -879
- package/es5/modules/router.js +0 -1680
- package/es5/modules/state.js +0 -274
- package/es6/.jshintrc +0 -3
- package/es6/base.js +0 -41
- package/es6/core.js +0 -1
- package/es6/data-tracker.js +0 -351
- package/es6/events.js +0 -602
- package/es6/legacy/es5/base.js +0 -2968
- package/es6/legacy/es5/modules/ajax.js +0 -663
- package/es6/legacy/es5/modules/animation.js +0 -188
- package/es6/legacy/es5/modules/animations.js +0 -1080
- package/es6/legacy/es5/modules/atom.js +0 -65
- package/es6/legacy/es5/modules/component.js +0 -1310
- package/es6/legacy/es5/modules/data-binder.js +0 -1131
- package/es6/legacy/es5/modules/data.js +0 -1808
- package/es6/legacy/es5/modules/date.js +0 -525
- package/es6/legacy/es5/modules/form-validator.js +0 -324
- package/es6/legacy/es5/modules/history.js +0 -126
- package/es6/legacy/es5/modules/html-builder.js +0 -461
- package/es6/legacy/es5/modules/layout.js +0 -1679
- package/es6/legacy/es5/modules/mouse.js +0 -124
- package/es6/legacy/es5/modules/nav-link.js +0 -123
- package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
- package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
- package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
- package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
- package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
- package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
- package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
- package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
- package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
- package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
- package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
- package/es6/legacy/es5/modules/prototypes/component.js +0 -972
- package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
- package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
- package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
- package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
- package/es6/legacy/es5/modules/router.js +0 -1680
- package/es6/legacy/es5/modules/state.js +0 -274
- package/es6/main.js +0 -1331
- package/es6/modules/ajax/ajax.js +0 -514
- package/es6/modules/animation/animation.js +0 -236
- package/es6/modules/animations/animation-controller.js +0 -231
- package/es6/modules/animations/animation.js +0 -64
- package/es6/modules/animations/attr-movement.js +0 -66
- package/es6/modules/animations/css-movement.js +0 -170
- package/es6/modules/animations/movement.js +0 -131
- package/es6/modules/animations/value.js +0 -187
- package/es6/modules/atom/atom.js +0 -54
- package/es6/modules/component/component.js +0 -230
- package/es6/modules/component/event-helper.js +0 -119
- package/es6/modules/component/jot.js +0 -144
- package/es6/modules/component/state-helper.js +0 -262
- package/es6/modules/component/unit.js +0 -551
- package/es6/modules/data/attrs.js +0 -40
- package/es6/modules/data/basic-data.js +0 -500
- package/es6/modules/data/data-utils.js +0 -29
- package/es6/modules/data/data.js +0 -3
- package/es6/modules/data/deep-data.js +0 -541
- package/es6/modules/data/model-service.js +0 -528
- package/es6/modules/data/model.js +0 -133
- package/es6/modules/data/simple-data.js +0 -33
- package/es6/modules/data-binder/connection-tracker.js +0 -113
- package/es6/modules/data-binder/connection.js +0 -16
- package/es6/modules/data-binder/data-binder.js +0 -352
- package/es6/modules/data-binder/data-pub-sub.js +0 -141
- package/es6/modules/data-binder/data-source.js +0 -56
- package/es6/modules/data-binder/element-source.js +0 -219
- package/es6/modules/data-binder/one-way-connection.js +0 -46
- package/es6/modules/data-binder/one-way-source.js +0 -43
- package/es6/modules/data-binder/source.js +0 -36
- package/es6/modules/data-binder/two-way-connection.js +0 -75
- package/es6/modules/data-binder/two-way-source.js +0 -41
- package/es6/modules/date/date.js +0 -544
- package/es6/modules/history/history.js +0 -89
- package/es6/modules/html-builder/html-builder.js +0 -434
- package/es6/modules/import/import.js +0 -390
- package/es6/modules/layout/layout-builder.js +0 -1269
- package/es6/modules/layout/layout-parser.js +0 -134
- package/es6/modules/layout/watcher-helper.js +0 -282
- package/es6/modules/mouse/mouse.js +0 -114
- package/es6/modules/router/component-helper.js +0 -163
- package/es6/modules/router/history-controller.js +0 -216
- package/es6/modules/router/nav-link.js +0 -124
- package/es6/modules/router/route.js +0 -401
- package/es6/modules/router/router.js +0 -789
- package/es6/modules/router/utils.js +0 -31
- package/es6/modules/state/state-target.js +0 -91
- package/es6/modules/state/state.js +0 -171
- package/es6/package-lock.json +0 -13
- package/es6/package.json +0 -28
- package/es6/shared/objects.js +0 -99
- package/events.js +0 -602
- package/legacy/es5/base.js +0 -2968
- package/legacy/es5/modules/ajax.js +0 -663
- package/legacy/es5/modules/animation.js +0 -188
- package/legacy/es5/modules/animations.js +0 -1080
- package/legacy/es5/modules/atom.js +0 -65
- package/legacy/es5/modules/component.js +0 -1310
- package/legacy/es5/modules/data-binder.js +0 -1131
- package/legacy/es5/modules/data.js +0 -1808
- package/legacy/es5/modules/date.js +0 -525
- package/legacy/es5/modules/form-validator.js +0 -324
- package/legacy/es5/modules/history.js +0 -126
- package/legacy/es5/modules/html-builder.js +0 -461
- package/legacy/es5/modules/layout.js +0 -1679
- package/legacy/es5/modules/mouse.js +0 -124
- package/legacy/es5/modules/nav-link.js +0 -123
- package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
- package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
- package/legacy/es5/modules/olderversions/base-animations.js +0 -636
- package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
- package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
- package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
- package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
- package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
- package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
- package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
- package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
- package/legacy/es5/modules/olderversions/event-update.js +0 -666
- package/legacy/es5/modules/olderversions/nav-link.js +0 -119
- package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
- package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
- package/legacy/es5/modules/prototypes/ajax.js +0 -657
- package/legacy/es5/modules/prototypes/atom.js +0 -65
- package/legacy/es5/modules/prototypes/component.js +0 -972
- package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
- package/legacy/es5/modules/prototypes/data.js +0 -1290
- package/legacy/es5/modules/prototypes/html-builder.js +0 -414
- package/legacy/es5/modules/prototypes/layout.js +0 -879
- package/legacy/es5/modules/router.js +0 -1680
- package/legacy/es5/modules/state.js +0 -274
- package/main.js +0 -1331
- package/modules/ajax/ajax.js +0 -514
- package/modules/animation/animation.js +0 -236
- package/modules/animations/animation-controller.js +0 -231
- package/modules/animations/animation.js +0 -64
- package/modules/animations/attr-movement.js +0 -66
- package/modules/animations/css-movement.js +0 -170
- package/modules/animations/movement.js +0 -131
- package/modules/animations/value.js +0 -187
- package/modules/atom/atom.js +0 -54
- package/modules/component/component.js +0 -230
- package/modules/component/event-helper.js +0 -119
- package/modules/component/jot.js +0 -144
- package/modules/component/state-helper.js +0 -262
- package/modules/component/unit.js +0 -551
- package/modules/data/attrs.js +0 -40
- package/modules/data/basic-data.js +0 -500
- package/modules/data/data-utils.js +0 -29
- package/modules/data/data.js +0 -3
- package/modules/data/deep-data.js +0 -541
- package/modules/data/model-service.js +0 -528
- package/modules/data/model.js +0 -133
- package/modules/data/simple-data.js +0 -33
- package/modules/data-binder/connection-tracker.js +0 -113
- package/modules/data-binder/connection.js +0 -16
- package/modules/data-binder/data-binder.js +0 -352
- package/modules/data-binder/data-pub-sub.js +0 -141
- package/modules/data-binder/data-source.js +0 -56
- package/modules/data-binder/element-source.js +0 -219
- package/modules/data-binder/one-way-connection.js +0 -46
- package/modules/data-binder/one-way-source.js +0 -43
- package/modules/data-binder/source.js +0 -36
- package/modules/data-binder/two-way-connection.js +0 -75
- package/modules/data-binder/two-way-source.js +0 -41
- package/modules/date/date.js +0 -544
- package/modules/history/history.js +0 -89
- package/modules/html-builder/html-builder.js +0 -434
- package/modules/import/import.js +0 -390
- package/modules/layout/layout-builder.js +0 -1269
- package/modules/layout/layout-parser.js +0 -134
- package/modules/layout/watcher-helper.js +0 -282
- package/modules/mouse/mouse.js +0 -114
- package/modules/router/component-helper.js +0 -163
- package/modules/router/history-controller.js +0 -216
- package/modules/router/nav-link.js +0 -124
- package/modules/router/route.js +0 -401
- package/modules/router/router.js +0 -789
- package/modules/router/utils.js +0 -31
- package/modules/state/state-target.js +0 -91
- package/modules/state/state.js +0 -171
- package/shared/objects.js +0 -99
- package/update +0 -16
package/es6/modules/date/date.js
DELETED
|
@@ -1,544 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This will add date functions to the base framework.
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
export const date = {
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @member {array} monthName
|
|
9
|
-
*/
|
|
10
|
-
monthNames: ["January","February","March","April","May","June","July","August","September","October","November","December"],
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @member {array} dayNames
|
|
14
|
-
*/
|
|
15
|
-
dayNames: ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* This will get the day name.
|
|
19
|
-
*
|
|
20
|
-
* @param {int} [day]
|
|
21
|
-
* @param {boolean} [shortenName=false]
|
|
22
|
-
* @return {string}
|
|
23
|
-
*/
|
|
24
|
-
getDayName(day = new Date().getDay(), shortenName = false)
|
|
25
|
-
{
|
|
26
|
-
let days = this.dayNames;
|
|
27
|
-
if(day > days.length)
|
|
28
|
-
{
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/* we want to check to shorten name */
|
|
33
|
-
let dayName = days[day];
|
|
34
|
-
return (shortenName)? dayName.substring(0, 3) : dayName;
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* This will convert month to js.
|
|
39
|
-
*
|
|
40
|
-
* @param {int} month
|
|
41
|
-
* @return {int}
|
|
42
|
-
*/
|
|
43
|
-
convertJsMonth(month)
|
|
44
|
-
{
|
|
45
|
-
return this.padNumber(month + 1);
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* This will convert a date.
|
|
50
|
-
*
|
|
51
|
-
* @param {string} dateString
|
|
52
|
-
* @param {bool} addYear
|
|
53
|
-
* @returns {string}
|
|
54
|
-
*/
|
|
55
|
-
convertDate(dateString, addYear)
|
|
56
|
-
{
|
|
57
|
-
var baseDate = base.date;
|
|
58
|
-
dateString = (dateString)? dateString.replace(/\s/, 'T'): ''; //For safari
|
|
59
|
-
|
|
60
|
-
var date = new Date(dateString),
|
|
61
|
-
year = (addYear === true)? ' ' + date.getFullYear() : '';
|
|
62
|
-
return baseDate.getDayName(date.getDay()) + ', ' + baseDate.getMonthName(date.getMonth(), true) + ' ' + baseDate.padNumber(date.getDate()) + year;
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* This will add leading zero to number less than 10.
|
|
67
|
-
*
|
|
68
|
-
* @param {int} number
|
|
69
|
-
* @return {string}
|
|
70
|
-
*/
|
|
71
|
-
padNumber(number)
|
|
72
|
-
{
|
|
73
|
-
return (number <= 9)? '0' + number : String(number);
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* This will create a new date object.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} dateString
|
|
80
|
-
* @returns {Date}
|
|
81
|
-
*/
|
|
82
|
-
createDate(dateString)
|
|
83
|
-
{
|
|
84
|
-
if(!dateString)
|
|
85
|
-
{
|
|
86
|
-
return new Date();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if(typeof dateString === 'string' && dateString.indexOf('-') > -1)
|
|
90
|
-
{
|
|
91
|
-
dateString = dateString.replace(/\s/, 'T'); //For safari
|
|
92
|
-
dateString = (dateString.indexOf(':') > -1)? dateString : dateString + "T00:00:00";
|
|
93
|
-
}
|
|
94
|
-
return new Date(dateString);
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* This will format a date.
|
|
99
|
-
*
|
|
100
|
-
* @param {string} type
|
|
101
|
-
* @param {string} dateString
|
|
102
|
-
* @return {string}
|
|
103
|
-
*/
|
|
104
|
-
format(type, dateString)
|
|
105
|
-
{
|
|
106
|
-
let date = this.createDate(dateString);
|
|
107
|
-
switch(type)
|
|
108
|
-
{
|
|
109
|
-
case 'sql':
|
|
110
|
-
dateString = date.getFullYear() + '-' + this.convertJsMonth(date.getMonth()) + '-' + this.padNumber(date.getDate());
|
|
111
|
-
break;
|
|
112
|
-
default:
|
|
113
|
-
dateString = this.convertJsMonth(date.getMonth()) + '/' + this.padNumber(date.getDate()) + '/' + date.getFullYear();
|
|
114
|
-
break;
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
return dateString;
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* This will format time.
|
|
122
|
-
*
|
|
123
|
-
* @param {string} dateString
|
|
124
|
-
* @param {int} format
|
|
125
|
-
* @returns {stirng}
|
|
126
|
-
*/
|
|
127
|
-
formatTime(dateString, format)
|
|
128
|
-
{
|
|
129
|
-
let date = this.createDate(dateString);
|
|
130
|
-
if(format === 24)
|
|
131
|
-
{
|
|
132
|
-
return this.padNumber(date.getHours()) + ':' + this.padNumber(date.getMinutes()) + ':' + this.padNumber(date.getSeconds());
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
let hours = date.getHours(),
|
|
136
|
-
meridian = 'AM';
|
|
137
|
-
|
|
138
|
-
if(hours >= 12)
|
|
139
|
-
{
|
|
140
|
-
meridian = 'PM';
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if(hours > 12)
|
|
144
|
-
{
|
|
145
|
-
hours = hours - 12;
|
|
146
|
-
}
|
|
147
|
-
return (hours + ':' + this.padNumber(date.getMinutes()) + ' ' + meridian);
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* This will check for leap year.
|
|
152
|
-
*
|
|
153
|
-
* @param {int} year
|
|
154
|
-
* @return {boolean}
|
|
155
|
-
*/
|
|
156
|
-
leapYear(year)
|
|
157
|
-
{
|
|
158
|
-
return ((year % 400 === 0) || (year % 100 !== 0 && year % 4 === 0));
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* This will get a month name.
|
|
163
|
-
*
|
|
164
|
-
* @param {int} [month]
|
|
165
|
-
* @param {boolean} [shortenName]
|
|
166
|
-
* @return {string}
|
|
167
|
-
*/
|
|
168
|
-
getMonthName(month = new Date().getMonth(), shortenName = false)
|
|
169
|
-
{
|
|
170
|
-
let months = this.monthNames;
|
|
171
|
-
if(month > months.length)
|
|
172
|
-
{
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let monthName = months[month];
|
|
177
|
-
return (shortenName)? monthName.substring(0, 3) : monthName;
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* This will return the month length.
|
|
182
|
-
*
|
|
183
|
-
* @param {int} [month]
|
|
184
|
-
* @param {int} [year]
|
|
185
|
-
* @return {int}
|
|
186
|
-
*/
|
|
187
|
-
getMonthLength(month, year)
|
|
188
|
-
{
|
|
189
|
-
/* we want to check to use params or use
|
|
190
|
-
default */
|
|
191
|
-
let date = new Date();
|
|
192
|
-
month = (typeof month !== 'undefined')? month : date.getMonth();
|
|
193
|
-
year = (typeof year !== 'undefined')? year : date.getFullYear();
|
|
194
|
-
|
|
195
|
-
/* we need to get the month lengths for
|
|
196
|
-
the year */
|
|
197
|
-
let yearMonthLengths = this.getMonthsLength(year);
|
|
198
|
-
|
|
199
|
-
/* we can select the month length from
|
|
200
|
-
the yearMonthLengths array */
|
|
201
|
-
let monthLength = yearMonthLengths[month];
|
|
202
|
-
return monthLength;
|
|
203
|
-
},
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* This will get the length of all the months.
|
|
207
|
-
*
|
|
208
|
-
* @param {int} year
|
|
209
|
-
* @return {array}
|
|
210
|
-
*/
|
|
211
|
-
getMonthsLength(year = new Date().getFullYear())
|
|
212
|
-
{
|
|
213
|
-
let isLeapYear = this.leapYear(year);
|
|
214
|
-
let days = (isLeapYear === true)?
|
|
215
|
-
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
216
|
-
:
|
|
217
|
-
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
218
|
-
|
|
219
|
-
return days;
|
|
220
|
-
},
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* This will get the difference from now.
|
|
224
|
-
*
|
|
225
|
-
* @param {string} date
|
|
226
|
-
* @param {bool} setHours
|
|
227
|
-
* @returns {int}
|
|
228
|
-
*/
|
|
229
|
-
getDiffFromNow(date, setHours)
|
|
230
|
-
{
|
|
231
|
-
date = date.replace(/\s/, 'T'); //For safari
|
|
232
|
-
date = new Date(date);
|
|
233
|
-
|
|
234
|
-
let now = new Date();
|
|
235
|
-
if(setHours === true)
|
|
236
|
-
{
|
|
237
|
-
now.setHours(0,0,0,0);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
let timeDiff = now.getTime() - date.getTime();
|
|
241
|
-
return timeDiff;
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* This will get the age.
|
|
246
|
-
*
|
|
247
|
-
* @param {string} date
|
|
248
|
-
* @returns {string}
|
|
249
|
-
*/
|
|
250
|
-
getAge(date)
|
|
251
|
-
{
|
|
252
|
-
const milliseconds = this.getDiffFromNow(date);
|
|
253
|
-
|
|
254
|
-
let age = '';
|
|
255
|
-
switch(true)
|
|
256
|
-
{
|
|
257
|
-
case milliseconds < 86400000:
|
|
258
|
-
age = '1 day';
|
|
259
|
-
break;
|
|
260
|
-
case milliseconds < 604800000:
|
|
261
|
-
var days = this.toDays(milliseconds);
|
|
262
|
-
age = (days) + ' days';
|
|
263
|
-
break;
|
|
264
|
-
case milliseconds < 1209600000:
|
|
265
|
-
age = '1 week';
|
|
266
|
-
break;
|
|
267
|
-
case milliseconds < 2592000000:
|
|
268
|
-
var days = this.toDays(milliseconds),
|
|
269
|
-
weeks = Math.floor(days / 7);
|
|
270
|
-
age = weeks + ' weeks';
|
|
271
|
-
break;
|
|
272
|
-
case milliseconds < 5184000000:
|
|
273
|
-
age = '1 month';
|
|
274
|
-
break;
|
|
275
|
-
case milliseconds < 31104000000:
|
|
276
|
-
var months = this.toMonths(milliseconds);
|
|
277
|
-
age = months + ' months';
|
|
278
|
-
break;
|
|
279
|
-
default:
|
|
280
|
-
var years = this.toYears(milliseconds);
|
|
281
|
-
age = years;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return age;
|
|
285
|
-
},
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* This will get the time frame.
|
|
289
|
-
*
|
|
290
|
-
* @param {string} date
|
|
291
|
-
* @returns {string}
|
|
292
|
-
*/
|
|
293
|
-
getTimeFrame(date)
|
|
294
|
-
{
|
|
295
|
-
let timeDiff = this.getDiffFromNow(date);
|
|
296
|
-
return this.convertToEstimate(timeDiff);
|
|
297
|
-
},
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
*
|
|
301
|
-
* @param {int} milliseconds
|
|
302
|
-
* @returns {string}
|
|
303
|
-
*/
|
|
304
|
-
convertToEstimate(milliseconds)
|
|
305
|
-
{
|
|
306
|
-
let timeFrame = '';
|
|
307
|
-
|
|
308
|
-
if(milliseconds <= 0)
|
|
309
|
-
{
|
|
310
|
-
switch(true)
|
|
311
|
-
{
|
|
312
|
-
case milliseconds < -63072000000:
|
|
313
|
-
var years = this.toYears(Math.abs(milliseconds));
|
|
314
|
-
timeFrame = 'in ' + years + ' years';
|
|
315
|
-
break;
|
|
316
|
-
case milliseconds < -31536000000:
|
|
317
|
-
timeFrame = 'in a year';
|
|
318
|
-
break;
|
|
319
|
-
case milliseconds < -5184000000:
|
|
320
|
-
var months = this.toMonths(Math.abs(milliseconds));
|
|
321
|
-
timeFrame = 'in ' + months + ' months';
|
|
322
|
-
break;
|
|
323
|
-
case milliseconds < -2592000000:
|
|
324
|
-
timeFrame = 'in a month';
|
|
325
|
-
break;
|
|
326
|
-
case milliseconds < -1209600000:
|
|
327
|
-
var days = this.toDays(Math.abs(milliseconds)),
|
|
328
|
-
weeks = Math.floor(days / 7);
|
|
329
|
-
timeFrame = 'in ' + weeks + ' weeks';
|
|
330
|
-
break;
|
|
331
|
-
case milliseconds < -604800000:
|
|
332
|
-
timeFrame = 'in a week';
|
|
333
|
-
break;
|
|
334
|
-
case milliseconds < -172800000:
|
|
335
|
-
var days = this.toDays(Math.abs(milliseconds));
|
|
336
|
-
timeFrame = 'in ' + (days) + ' days';
|
|
337
|
-
break;
|
|
338
|
-
case milliseconds < -86400000:
|
|
339
|
-
timeFrame = 'tomorrow';
|
|
340
|
-
break;
|
|
341
|
-
case milliseconds < -7200000:
|
|
342
|
-
var hours = this.toHours(Math.abs(milliseconds));
|
|
343
|
-
timeFrame = 'in ' + hours + ' hours';
|
|
344
|
-
break;
|
|
345
|
-
case milliseconds <= -3600000:
|
|
346
|
-
timeFrame = 'in an hour';
|
|
347
|
-
break;
|
|
348
|
-
case milliseconds < -120000:
|
|
349
|
-
var minutes = this.toMinutes(Math.abs(milliseconds));
|
|
350
|
-
timeFrame = 'in ' + minutes + ' minutes';
|
|
351
|
-
break;
|
|
352
|
-
case milliseconds < -60000:
|
|
353
|
-
timeFrame = 'in a minute';
|
|
354
|
-
break;
|
|
355
|
-
case milliseconds < -2000:
|
|
356
|
-
var seconds = this.toSeconds(Math.abs(milliseconds));
|
|
357
|
-
timeFrame = 'in ' + seconds + ' seconds';
|
|
358
|
-
break;
|
|
359
|
-
case milliseconds < -1:
|
|
360
|
-
timeFrame = 'in 1 second';
|
|
361
|
-
break;
|
|
362
|
-
default:
|
|
363
|
-
timeFrame = 'now';
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
else
|
|
367
|
-
{
|
|
368
|
-
switch(true)
|
|
369
|
-
{
|
|
370
|
-
case milliseconds < 1000:
|
|
371
|
-
timeFrame = '1 second ago';
|
|
372
|
-
break;
|
|
373
|
-
case milliseconds < 60000:
|
|
374
|
-
var seconds = this.toSeconds(milliseconds);
|
|
375
|
-
timeFrame = seconds + ' seconds ago';
|
|
376
|
-
break;
|
|
377
|
-
case milliseconds < 120000:
|
|
378
|
-
timeFrame = '1 minute ago';
|
|
379
|
-
break;
|
|
380
|
-
case milliseconds < 3600000:
|
|
381
|
-
var minutes = this.toMinutes(milliseconds);
|
|
382
|
-
timeFrame = minutes + ' minutes ago';
|
|
383
|
-
break;
|
|
384
|
-
case milliseconds < 7200000:
|
|
385
|
-
timeFrame = '1 hour ago';
|
|
386
|
-
break;
|
|
387
|
-
case milliseconds < 86400000:
|
|
388
|
-
var hours = this.toHours(milliseconds);
|
|
389
|
-
timeFrame = hours + ' hours ago';
|
|
390
|
-
break;
|
|
391
|
-
case milliseconds < 172800000:
|
|
392
|
-
timeFrame = 'yesterday';
|
|
393
|
-
break;
|
|
394
|
-
case milliseconds < 604800000:
|
|
395
|
-
var days = this.toDays(milliseconds);
|
|
396
|
-
timeFrame = (days) + ' days ago';
|
|
397
|
-
break;
|
|
398
|
-
case milliseconds < 1209600000:
|
|
399
|
-
timeFrame = 'a week ago';
|
|
400
|
-
break;
|
|
401
|
-
case milliseconds < 2592000000:
|
|
402
|
-
var days = this.toDays(milliseconds),
|
|
403
|
-
weeks = Math.floor(days / 7);
|
|
404
|
-
timeFrame = weeks + ' weeks ago';
|
|
405
|
-
break;
|
|
406
|
-
case milliseconds < 5184000000:
|
|
407
|
-
timeFrame = 'a month ago';
|
|
408
|
-
break;
|
|
409
|
-
case milliseconds < 31536000000:
|
|
410
|
-
var months = this.toMonths(milliseconds);
|
|
411
|
-
timeFrame = months + ' months ago';
|
|
412
|
-
break;
|
|
413
|
-
case milliseconds < 63072000000:
|
|
414
|
-
timeFrame = 'a year ago';
|
|
415
|
-
break;
|
|
416
|
-
default:
|
|
417
|
-
var years = this.toYears(milliseconds);
|
|
418
|
-
timeFrame = years + ' years ago';
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
return timeFrame;
|
|
423
|
-
},
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* This will convert to years.
|
|
427
|
-
*
|
|
428
|
-
* @param {int} milliseconds
|
|
429
|
-
* @return {int}
|
|
430
|
-
*/
|
|
431
|
-
toYears(milliseconds)
|
|
432
|
-
{
|
|
433
|
-
if(typeof milliseconds !== 'number')
|
|
434
|
-
{
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return Math.floor(milliseconds / (1000 * 60 * 60 * 24 * 365.26));
|
|
439
|
-
},
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* This will convert to months.
|
|
443
|
-
*
|
|
444
|
-
* @param {int} milliseconds
|
|
445
|
-
* @returns {int}
|
|
446
|
-
*/
|
|
447
|
-
toMonths(milliseconds)
|
|
448
|
-
{
|
|
449
|
-
if(typeof milliseconds === 'number')
|
|
450
|
-
{
|
|
451
|
-
return Math.floor(milliseconds / (1000 * 60 * 60 * 24 * 30));
|
|
452
|
-
}
|
|
453
|
-
return false;
|
|
454
|
-
},
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* This will convert to days.
|
|
458
|
-
*
|
|
459
|
-
* @param {int} milliseconds
|
|
460
|
-
* @return {int}
|
|
461
|
-
*/
|
|
462
|
-
toDays(milliseconds)
|
|
463
|
-
{
|
|
464
|
-
if(typeof milliseconds !== 'number')
|
|
465
|
-
{
|
|
466
|
-
return false;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return Math.floor(milliseconds / (60 * 60 * 1000 * 24) * 1);
|
|
470
|
-
},
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* This will convert to hours.
|
|
474
|
-
*
|
|
475
|
-
* @param {int} milliseconds
|
|
476
|
-
* @return {int}
|
|
477
|
-
*/
|
|
478
|
-
toHours(milliseconds)
|
|
479
|
-
{
|
|
480
|
-
if(typeof milliseconds !== 'number')
|
|
481
|
-
{
|
|
482
|
-
return false;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
return Math.floor((milliseconds % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
|
|
486
|
-
},
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* This will convert to minutes.
|
|
490
|
-
*
|
|
491
|
-
* @param {int} milliseconds
|
|
492
|
-
* @return {int}
|
|
493
|
-
*/
|
|
494
|
-
toMinutes(milliseconds)
|
|
495
|
-
{
|
|
496
|
-
if(typeof milliseconds !== 'number')
|
|
497
|
-
{
|
|
498
|
-
return false;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
return Math.floor(((milliseconds % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
|
|
502
|
-
},
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* This will convert to seconds.
|
|
506
|
-
*
|
|
507
|
-
* @param {int} milliseconds
|
|
508
|
-
* @return {int}
|
|
509
|
-
*/
|
|
510
|
-
toSeconds(milliseconds)
|
|
511
|
-
{
|
|
512
|
-
if(typeof milliseconds !== 'number')
|
|
513
|
-
{
|
|
514
|
-
return false;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
return Math.floor((((milliseconds % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);
|
|
518
|
-
},
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* This will get the difference between two dates.
|
|
522
|
-
*
|
|
523
|
-
* @param {string} startDate
|
|
524
|
-
* @param {string} endDate
|
|
525
|
-
* @return {object}
|
|
526
|
-
*/
|
|
527
|
-
getDifference(startDate, endDate)
|
|
528
|
-
{
|
|
529
|
-
/* we want to convert the dates to objects */
|
|
530
|
-
let start = new Date(startDate),
|
|
531
|
-
end = new Date(endDate),
|
|
532
|
-
|
|
533
|
-
/* we want to subtract the start time from the end */
|
|
534
|
-
difference = (end.getTime() - start.getTime());
|
|
535
|
-
|
|
536
|
-
return {
|
|
537
|
-
years: this.toYears(difference),
|
|
538
|
-
days: this.toDays(difference),
|
|
539
|
-
hours: this.toHours(difference),
|
|
540
|
-
minutes: this.toMinutes(difference),
|
|
541
|
-
seconds: this.toSeconds(difference)
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import {base} from '../../core.js';
|
|
2
|
-
|
|
3
|
-
const updateTitle = (title) =>
|
|
4
|
-
{
|
|
5
|
-
if(typeof title === 'string')
|
|
6
|
-
{
|
|
7
|
-
document.title = title;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const getStateTitle = (title, stateObj) =>
|
|
12
|
-
{
|
|
13
|
-
return (title === null && (stateObj && stateObj.title))? stateObj.title : title;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const history =
|
|
17
|
-
{
|
|
18
|
-
isSupported()
|
|
19
|
-
{
|
|
20
|
-
return ('history' in window && 'pushState' in window.history);
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
addEvent(fn, capture)
|
|
24
|
-
{
|
|
25
|
-
const popEvent = (e) =>
|
|
26
|
-
{
|
|
27
|
-
let state = e.state;
|
|
28
|
-
if(state && state.title)
|
|
29
|
-
{
|
|
30
|
-
updateTitle(state.title);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
fn(e);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
base.events.add('popstate', window, popEvent, capture, true, fn);
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
removeEvent(fn, capture)
|
|
40
|
-
{
|
|
41
|
-
base.off('popstate', window, fn, capture);
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
pushState(object, title, url)
|
|
45
|
-
{
|
|
46
|
-
const history = window.history,
|
|
47
|
-
lastState = history.state;
|
|
48
|
-
|
|
49
|
-
/* we want to check if the object is not already
|
|
50
|
-
the last saved state */
|
|
51
|
-
if(!lastState || base.equals(lastState, object) === false)
|
|
52
|
-
{
|
|
53
|
-
title = getStateTitle(title, object);
|
|
54
|
-
updateTitle(title);
|
|
55
|
-
|
|
56
|
-
/* we want to add the new state to the window history*/
|
|
57
|
-
history.pushState(object, title, url);
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
replaceState(object, title, url)
|
|
62
|
-
{
|
|
63
|
-
title = getStateTitle(title, object);
|
|
64
|
-
updateTitle(title);
|
|
65
|
-
|
|
66
|
-
/* we want to add the new state to the window history*/
|
|
67
|
-
window.history.replaceState(object, title, url);
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
/* this will go to the next state in the window history */
|
|
71
|
-
nextState()
|
|
72
|
-
{
|
|
73
|
-
window.history.forward();
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
/* this will go to the previous state in the window history */
|
|
77
|
-
prevState()
|
|
78
|
-
{
|
|
79
|
-
window.history.back();
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
/* this will take you to a specified number in the history
|
|
83
|
-
index.
|
|
84
|
-
@param (int) indexNumber= the number to go to */
|
|
85
|
-
goTo(indexNumber)
|
|
86
|
-
{
|
|
87
|
-
window.history.go(indexNumber);
|
|
88
|
-
}
|
|
89
|
-
};
|