@base-framework/base 2.6.1 → 2.6.2

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.
Files changed (248) hide show
  1. package/README.md +1 -0
  2. package/dist/base.js +1 -0
  3. package/package.json +9 -4
  4. package/.jshintrc +0 -3
  5. package/base.js +0 -41
  6. package/base.min.js +0 -1
  7. package/core.js +0 -1
  8. package/data-tracker.js +0 -351
  9. package/es5/base.js +0 -2968
  10. package/es5/modules/ajax.js +0 -663
  11. package/es5/modules/animation.js +0 -188
  12. package/es5/modules/animations.js +0 -1080
  13. package/es5/modules/atom.js +0 -65
  14. package/es5/modules/component.js +0 -1310
  15. package/es5/modules/data-binder.js +0 -1131
  16. package/es5/modules/data.js +0 -1808
  17. package/es5/modules/date.js +0 -525
  18. package/es5/modules/form-validator.js +0 -324
  19. package/es5/modules/history.js +0 -126
  20. package/es5/modules/html-builder.js +0 -461
  21. package/es5/modules/layout.js +0 -1679
  22. package/es5/modules/mouse.js +0 -124
  23. package/es5/modules/nav-link.js +0 -123
  24. package/es5/modules/olderversions/animations-ease.js +0 -1095
  25. package/es5/modules/olderversions/animations-update.js +0 -1048
  26. package/es5/modules/olderversions/base-animations.js +0 -636
  27. package/es5/modules/olderversions/base-component-class.js +0 -100
  28. package/es5/modules/olderversions/base-data-binder-1.js +0 -407
  29. package/es5/modules/olderversions/base-data-binder-class.js +0 -358
  30. package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  31. package/es5/modules/olderversions/base-mode-1.js +0 -777
  32. package/es5/modules/olderversions/base-model-class.js +0 -585
  33. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  34. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  35. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  36. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  37. package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  38. package/es5/modules/olderversions/data-tracker.js +0 -187
  39. package/es5/modules/olderversions/event-update.js +0 -666
  40. package/es5/modules/olderversions/nav-link.js +0 -119
  41. package/es5/modules/olderversions/router-with-templates-1.js +0 -785
  42. package/es5/modules/olderversions/router-with-templates.js +0 -701
  43. package/es5/modules/prototypes/ajax.js +0 -657
  44. package/es5/modules/prototypes/atom.js +0 -65
  45. package/es5/modules/prototypes/component.js +0 -972
  46. package/es5/modules/prototypes/data-binder.js +0 -1089
  47. package/es5/modules/prototypes/data.js +0 -1290
  48. package/es5/modules/prototypes/html-builder.js +0 -414
  49. package/es5/modules/prototypes/layout.js +0 -879
  50. package/es5/modules/router.js +0 -1680
  51. package/es5/modules/state.js +0 -274
  52. package/es6/.jshintrc +0 -3
  53. package/es6/base.js +0 -41
  54. package/es6/core.js +0 -1
  55. package/es6/data-tracker.js +0 -351
  56. package/es6/events.js +0 -602
  57. package/es6/legacy/es5/base.js +0 -2968
  58. package/es6/legacy/es5/modules/ajax.js +0 -663
  59. package/es6/legacy/es5/modules/animation.js +0 -188
  60. package/es6/legacy/es5/modules/animations.js +0 -1080
  61. package/es6/legacy/es5/modules/atom.js +0 -65
  62. package/es6/legacy/es5/modules/component.js +0 -1310
  63. package/es6/legacy/es5/modules/data-binder.js +0 -1131
  64. package/es6/legacy/es5/modules/data.js +0 -1808
  65. package/es6/legacy/es5/modules/date.js +0 -525
  66. package/es6/legacy/es5/modules/form-validator.js +0 -324
  67. package/es6/legacy/es5/modules/history.js +0 -126
  68. package/es6/legacy/es5/modules/html-builder.js +0 -461
  69. package/es6/legacy/es5/modules/layout.js +0 -1679
  70. package/es6/legacy/es5/modules/mouse.js +0 -124
  71. package/es6/legacy/es5/modules/nav-link.js +0 -123
  72. package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  73. package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  74. package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
  75. package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  76. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  77. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  78. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  79. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  80. package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  81. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  82. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  83. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  84. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  85. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  86. package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  87. package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
  88. package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
  89. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  90. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  91. package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
  92. package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
  93. package/es6/legacy/es5/modules/prototypes/component.js +0 -972
  94. package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  95. package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
  96. package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
  97. package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
  98. package/es6/legacy/es5/modules/router.js +0 -1680
  99. package/es6/legacy/es5/modules/state.js +0 -274
  100. package/es6/main.js +0 -1331
  101. package/es6/modules/ajax/ajax.js +0 -514
  102. package/es6/modules/animation/animation.js +0 -236
  103. package/es6/modules/animations/animation-controller.js +0 -231
  104. package/es6/modules/animations/animation.js +0 -64
  105. package/es6/modules/animations/attr-movement.js +0 -66
  106. package/es6/modules/animations/css-movement.js +0 -170
  107. package/es6/modules/animations/movement.js +0 -131
  108. package/es6/modules/animations/value.js +0 -187
  109. package/es6/modules/atom/atom.js +0 -54
  110. package/es6/modules/component/component.js +0 -230
  111. package/es6/modules/component/event-helper.js +0 -119
  112. package/es6/modules/component/jot.js +0 -144
  113. package/es6/modules/component/state-helper.js +0 -262
  114. package/es6/modules/component/unit.js +0 -551
  115. package/es6/modules/data/attrs.js +0 -40
  116. package/es6/modules/data/basic-data.js +0 -500
  117. package/es6/modules/data/data-utils.js +0 -29
  118. package/es6/modules/data/data.js +0 -3
  119. package/es6/modules/data/deep-data.js +0 -541
  120. package/es6/modules/data/model-service.js +0 -528
  121. package/es6/modules/data/model.js +0 -133
  122. package/es6/modules/data/simple-data.js +0 -33
  123. package/es6/modules/data-binder/connection-tracker.js +0 -113
  124. package/es6/modules/data-binder/connection.js +0 -16
  125. package/es6/modules/data-binder/data-binder.js +0 -352
  126. package/es6/modules/data-binder/data-pub-sub.js +0 -141
  127. package/es6/modules/data-binder/data-source.js +0 -56
  128. package/es6/modules/data-binder/element-source.js +0 -219
  129. package/es6/modules/data-binder/one-way-connection.js +0 -46
  130. package/es6/modules/data-binder/one-way-source.js +0 -43
  131. package/es6/modules/data-binder/source.js +0 -36
  132. package/es6/modules/data-binder/two-way-connection.js +0 -75
  133. package/es6/modules/data-binder/two-way-source.js +0 -41
  134. package/es6/modules/date/date.js +0 -544
  135. package/es6/modules/history/history.js +0 -89
  136. package/es6/modules/html-builder/html-builder.js +0 -434
  137. package/es6/modules/import/import.js +0 -390
  138. package/es6/modules/layout/layout-builder.js +0 -1269
  139. package/es6/modules/layout/layout-parser.js +0 -134
  140. package/es6/modules/layout/watcher-helper.js +0 -282
  141. package/es6/modules/mouse/mouse.js +0 -114
  142. package/es6/modules/router/component-helper.js +0 -163
  143. package/es6/modules/router/history-controller.js +0 -216
  144. package/es6/modules/router/nav-link.js +0 -124
  145. package/es6/modules/router/route.js +0 -401
  146. package/es6/modules/router/router.js +0 -789
  147. package/es6/modules/router/utils.js +0 -31
  148. package/es6/modules/state/state-target.js +0 -91
  149. package/es6/modules/state/state.js +0 -171
  150. package/es6/package-lock.json +0 -13
  151. package/es6/package.json +0 -28
  152. package/es6/shared/objects.js +0 -99
  153. package/events.js +0 -602
  154. package/legacy/es5/base.js +0 -2968
  155. package/legacy/es5/modules/ajax.js +0 -663
  156. package/legacy/es5/modules/animation.js +0 -188
  157. package/legacy/es5/modules/animations.js +0 -1080
  158. package/legacy/es5/modules/atom.js +0 -65
  159. package/legacy/es5/modules/component.js +0 -1310
  160. package/legacy/es5/modules/data-binder.js +0 -1131
  161. package/legacy/es5/modules/data.js +0 -1808
  162. package/legacy/es5/modules/date.js +0 -525
  163. package/legacy/es5/modules/form-validator.js +0 -324
  164. package/legacy/es5/modules/history.js +0 -126
  165. package/legacy/es5/modules/html-builder.js +0 -461
  166. package/legacy/es5/modules/layout.js +0 -1679
  167. package/legacy/es5/modules/mouse.js +0 -124
  168. package/legacy/es5/modules/nav-link.js +0 -123
  169. package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  170. package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  171. package/legacy/es5/modules/olderversions/base-animations.js +0 -636
  172. package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  173. package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  174. package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  175. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  176. package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  177. package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  178. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  179. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  180. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  181. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  182. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  183. package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  184. package/legacy/es5/modules/olderversions/event-update.js +0 -666
  185. package/legacy/es5/modules/olderversions/nav-link.js +0 -119
  186. package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  187. package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  188. package/legacy/es5/modules/prototypes/ajax.js +0 -657
  189. package/legacy/es5/modules/prototypes/atom.js +0 -65
  190. package/legacy/es5/modules/prototypes/component.js +0 -972
  191. package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  192. package/legacy/es5/modules/prototypes/data.js +0 -1290
  193. package/legacy/es5/modules/prototypes/html-builder.js +0 -414
  194. package/legacy/es5/modules/prototypes/layout.js +0 -879
  195. package/legacy/es5/modules/router.js +0 -1680
  196. package/legacy/es5/modules/state.js +0 -274
  197. package/main.js +0 -1331
  198. package/modules/ajax/ajax.js +0 -514
  199. package/modules/animation/animation.js +0 -236
  200. package/modules/animations/animation-controller.js +0 -231
  201. package/modules/animations/animation.js +0 -64
  202. package/modules/animations/attr-movement.js +0 -66
  203. package/modules/animations/css-movement.js +0 -170
  204. package/modules/animations/movement.js +0 -131
  205. package/modules/animations/value.js +0 -187
  206. package/modules/atom/atom.js +0 -54
  207. package/modules/component/component.js +0 -230
  208. package/modules/component/event-helper.js +0 -119
  209. package/modules/component/jot.js +0 -144
  210. package/modules/component/state-helper.js +0 -262
  211. package/modules/component/unit.js +0 -551
  212. package/modules/data/attrs.js +0 -40
  213. package/modules/data/basic-data.js +0 -500
  214. package/modules/data/data-utils.js +0 -29
  215. package/modules/data/data.js +0 -3
  216. package/modules/data/deep-data.js +0 -541
  217. package/modules/data/model-service.js +0 -528
  218. package/modules/data/model.js +0 -133
  219. package/modules/data/simple-data.js +0 -33
  220. package/modules/data-binder/connection-tracker.js +0 -113
  221. package/modules/data-binder/connection.js +0 -16
  222. package/modules/data-binder/data-binder.js +0 -352
  223. package/modules/data-binder/data-pub-sub.js +0 -141
  224. package/modules/data-binder/data-source.js +0 -56
  225. package/modules/data-binder/element-source.js +0 -219
  226. package/modules/data-binder/one-way-connection.js +0 -46
  227. package/modules/data-binder/one-way-source.js +0 -43
  228. package/modules/data-binder/source.js +0 -36
  229. package/modules/data-binder/two-way-connection.js +0 -75
  230. package/modules/data-binder/two-way-source.js +0 -41
  231. package/modules/date/date.js +0 -544
  232. package/modules/history/history.js +0 -89
  233. package/modules/html-builder/html-builder.js +0 -434
  234. package/modules/import/import.js +0 -390
  235. package/modules/layout/layout-builder.js +0 -1269
  236. package/modules/layout/layout-parser.js +0 -134
  237. package/modules/layout/watcher-helper.js +0 -282
  238. package/modules/mouse/mouse.js +0 -114
  239. package/modules/router/component-helper.js +0 -163
  240. package/modules/router/history-controller.js +0 -216
  241. package/modules/router/nav-link.js +0 -124
  242. package/modules/router/route.js +0 -401
  243. package/modules/router/router.js +0 -789
  244. package/modules/router/utils.js +0 -31
  245. package/modules/state/state-target.js +0 -91
  246. package/modules/state/state.js +0 -171
  247. package/shared/objects.js +0 -99
  248. package/update +0 -16
@@ -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
- };