@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,789 +0,0 @@
1
- import {base} from '../../core.js';
2
- import {Data} from '../data/data.js';
3
- export {NavLink} from './nav-link.js';
4
- import {Utils} from './utils.js';
5
- import {Route} from './route.js';
6
- import {HistoryController} from './history-controller.js';
7
-
8
- /* this will register the route system to the
9
- data tracker to remove routes that have been
10
- nested in layouts. */
11
- base.dataTracker.addType('routes', (data) =>
12
- {
13
- if(!data)
14
- {
15
- return false;
16
- }
17
-
18
- const route = data.route;
19
- if(route)
20
- {
21
- router.removeRoute(route);
22
- }
23
- });
24
-
25
- base.dataTracker.addType('switch', (data) =>
26
- {
27
- if(!data)
28
- {
29
- return false;
30
- }
31
-
32
- let id = data.id;
33
- router.removeSwitch(id);
34
- });
35
-
36
- /**
37
- * Router
38
- *
39
- * This will create a browser router.
40
- * @class
41
- */
42
- export class Router
43
- {
44
- constructor()
45
- {
46
- /**
47
- * @member {string} version
48
- */
49
- this.version = '1.0.2';
50
-
51
- /* this is the root of the uri for the routing object
52
- and the base title */
53
- this.baseURI = '/';
54
- this.title = '';
55
-
56
- this.lastPath = null;
57
- this.path = null;
58
-
59
- /* this will be used to access our history object */
60
- this.history = null;
61
- this.callBackLink = null;
62
- this.location = window.location;
63
-
64
- /* this will store each route added to the
65
- router. */
66
- this.routes = [];
67
- this.switches = {};
68
- this.switchCount = 0;
69
-
70
- /**
71
- * @member {object} data
72
- */
73
- this.data = new Data(
74
- {
75
- path: ''
76
- });
77
- }
78
-
79
- /**
80
- * This will setup our history object.
81
- */
82
- setupHistory()
83
- {
84
- this.history = HistoryController.setup(this);
85
- }
86
-
87
- /**
88
- * This will create a new route.
89
- *
90
- * @protected
91
- * @param {object} settings
92
- * @return {object}
93
- */
94
- createRoute(settings)
95
- {
96
- let uri = settings.uri || '*';
97
- settings.baseUri = this.createURI(uri);
98
-
99
- let route = new Route(settings);
100
- return route;
101
- }
102
-
103
- /**
104
- * This will add a new route to the router.
105
- *
106
- * @param {object} settings
107
- * @return {object}
108
- */
109
- add(settings)
110
- {
111
- if(typeof settings !== 'object')
112
- {
113
- let args = arguments;
114
- settings =
115
- {
116
- uri: args[0],
117
- component: args[1],
118
- callBack: args[2],
119
- title: args[3],
120
- id: args[4],
121
- container: args[5]
122
- };
123
- }
124
-
125
- const route = this.createRoute(settings);
126
- this.addRoute(route);
127
- return route;
128
- }
129
-
130
- addRoute(route)
131
- {
132
- this.routes.push(route);
133
- this.checkRoute(route, this.getPath());
134
- }
135
-
136
- /**
137
- * This will resume a route.
138
- *
139
- * @param {object} route
140
- * @param {object} container
141
- */
142
- resume(route, container)
143
- {
144
- route.resume(container);
145
- this.addRoute(route);
146
- }
147
-
148
- /**
149
- * This will get the base path.
150
- *
151
- * @protected
152
- * @return {string}
153
- */
154
- getBasePath()
155
- {
156
- if(!this.basePath)
157
- {
158
- let pathURI = this.baseURI || '';
159
- if((pathURI[pathURI.length - 1] !== '/'))
160
- {
161
- pathURI += '/';
162
- }
163
- this.basePath = pathURI;
164
- }
165
- return this.basePath;
166
- }
167
-
168
- /**
169
- * This will create a uri.
170
- *
171
- * @protected
172
- * @param {string} uri
173
- * @return {string}
174
- */
175
- createURI(uri)
176
- {
177
- let baseUri = this.getBasePath();
178
- return (baseUri + Utils.removeSlashes(uri));
179
- }
180
-
181
- /**
182
- * This will get a route by uri.
183
- *
184
- * @param {string} uri
185
- * @return {(object|boolean)}
186
- */
187
- getRoute(uri)
188
- {
189
- let routes = this.routes,
190
- length = routes.length;
191
- if(length > 0)
192
- {
193
- for(var i = 0; i < length; i++)
194
- {
195
- var route = routes[i];
196
- if(route.uri === uri)
197
- {
198
- return route;
199
- }
200
- }
201
- }
202
- return false;
203
- }
204
-
205
- /**
206
- * This will get a route by id.
207
- *
208
- * @param {string} id
209
- * @return {(object|boolean)}
210
- */
211
- getRouteById(id)
212
- {
213
- let routes = this.routes,
214
- length = routes.length;
215
- if(length > 0)
216
- {
217
- for(var i = 0; i < length; i++)
218
- {
219
- var route = routes[i];
220
- if(route.id === id)
221
- {
222
- return route;
223
- }
224
- }
225
- }
226
- return false;
227
- }
228
-
229
- /**
230
- * This will remove a route.
231
- *
232
- * @param {object} route
233
- */
234
- removeRoute(route)
235
- {
236
- let routes = this.routes,
237
- index = routes.indexOf(route);
238
- if(index > -1)
239
- {
240
- routes.splice(index, 1);
241
- }
242
- }
243
-
244
- /**
245
- * This will add a switch.
246
- *
247
- * @param {array} group
248
- * @return {string} the switch id.
249
- */
250
- addSwitch(group)
251
- {
252
- let id = this.switchCount++;
253
- let switchArray = this.getSwitchGroup(id);
254
-
255
- for(var i = 0, length = group.length; i < length; i++)
256
- {
257
- var route = this.createRoute(group[i]);
258
- switchArray.push(route);
259
- }
260
-
261
- this.checkGroup(switchArray, this.getPath());
262
- return id;
263
- }
264
-
265
- /**
266
- * This will resume a switch.
267
- *
268
- * @param {object} group
269
- * @param {object} container
270
- * @return {int} the switch id.
271
- */
272
- resumeSwitch(group, container)
273
- {
274
- let id = this.switchCount++;
275
- let switchArray = this.getSwitchGroup(id);
276
-
277
- for(var i = 0, length = group.length; i < length; i++)
278
- {
279
- var route = group[i].component.route;
280
- route.resume(container);
281
- switchArray.push(route);
282
- }
283
-
284
- this.checkGroup(switchArray, this.getPath());
285
- return id;
286
- }
287
-
288
- getSwitchGroup(id)
289
- {
290
- return (this.switches[id] = []);
291
- }
292
-
293
- /**
294
- * This will remove a switch by id.
295
- *
296
- * @param {string} id
297
- */
298
- removeSwitch(id)
299
- {
300
- let switches = this.switches;
301
- if(switches[id])
302
- {
303
- delete switches[id];
304
- }
305
- }
306
-
307
- /**
308
- * This will remove a route by uri.
309
- *
310
- * @param {string} uri
311
- * @return {object} a reference to the router object.
312
- */
313
- remove(uri)
314
- {
315
- uri = this.createURI(uri);
316
-
317
- let route = this.getRoute(uri);
318
- if(route !== false)
319
- {
320
- this.removeRoute(route);
321
- }
322
- return this;
323
- }
324
-
325
- /**
326
- * This will setup the router.
327
- *
328
- * @param {string} [baseURI]
329
- * @param {string} [title]
330
- * @return {object} a reference to the router object.
331
- */
332
- setup(baseURI, title)
333
- {
334
- this.baseURI = baseURI || '/';
335
- this.updateBaseTag(this.baseURI);
336
- this.title = (typeof title !== 'undefined')? title : '';
337
-
338
- this.setupHistory();
339
-
340
- this.data.set('path', this.getPath());
341
-
342
- this.callBackLink = this.checkLink.bind(this);
343
- base.on('click', document, this.callBackLink);
344
-
345
- /* this will route to the first url entered
346
- when the router loads. this will fix the issue
347
- that stopped the first endpoint from being
348
- added to the history */
349
- let endPoint = this.getEndPoint();
350
- this.navigate(endPoint, null, true);
351
- return this;
352
- }
353
-
354
- updateBaseTag(url)
355
- {
356
- /* this will modify the base tag to ref from
357
- the base url for all xhr */
358
- let ele = document.getElementsByTagName('base');
359
- if(ele.length)
360
- {
361
- ele[0].href = url;
362
- }
363
- }
364
-
365
- /**
366
- * This will get the parent element link.
367
- *
368
- * @param {object} ele
369
- * @return {(object|boolean)}
370
- */
371
- getParentLink(ele)
372
- {
373
- let target = ele.parentNode;
374
- while(target !== null)
375
- {
376
- if(target.nodeName.toLowerCase() === 'a')
377
- {
378
- return target;
379
- }
380
-
381
- target = target.parentNode;
382
- }
383
- return false;
384
- }
385
-
386
- /**
387
- * This will check if a link was routed.
388
- *
389
- * @protected
390
- * @param {object} evt
391
- */
392
- checkLink(evt)
393
- {
394
- if(evt.ctrlKey === true)
395
- {
396
- return true;
397
- }
398
-
399
- let target = evt.target || evt.srcElement;
400
- if(target.nodeName.toLowerCase() !== 'a')
401
- {
402
- /* this will check to get the parent to check
403
- if the child is contained in a link */
404
- target = this.getParentLink(target);
405
- if(target === false)
406
- {
407
- return true;
408
- }
409
- }
410
-
411
- if(target.target === '_blank' || base.data(target, 'cancel-route'))
412
- {
413
- return true;
414
- }
415
-
416
- let href = target.getAttribute('href');
417
- if(typeof href !== 'undefined')
418
- {
419
- let baseUri = this.baseURI,
420
- path = (baseUri !== '/')? href.replace(baseUri, '') : href;
421
- this.navigate(path);
422
-
423
- evt.preventDefault();
424
- evt.stopPropagation();
425
- return false;
426
- }
427
- }
428
-
429
- /**
430
- * This will reset the router.
431
- *
432
- * @return {object} a reference to the router object.
433
- */
434
- reset()
435
- {
436
- this.routes = [];
437
- this.switches = [];
438
- this.switchCount = 0;
439
-
440
- return this;
441
- }
442
-
443
- /**
444
- * This will check the active routes.
445
- *
446
- * @return {object} a reference to the router object.
447
- */
448
- activate()
449
- {
450
- this.checkActiveRoutes();
451
- return this;
452
- }
453
-
454
- /**
455
- * This will navigate the router.
456
- *
457
- * @param {string} uri
458
- * @param {object} [data]
459
- * @param {boolean} [replace]
460
- * @return {object} a reference to the router object.
461
- */
462
- navigate(uri, data, replace)
463
- {
464
- uri = this.createURI(uri);
465
- this.history.addState(uri, data, replace);
466
- this.activate();
467
-
468
- return this;
469
- }
470
-
471
- /**
472
- * This will update the data path.
473
- * @protected
474
- */
475
- updatePath()
476
- {
477
- let path = this.getPath();
478
- this.data.set('path', path);
479
- }
480
-
481
- /**
482
- * This will update the title.
483
- *
484
- * @protected
485
- * @param {object} route
486
- */
487
- updateTitle(route)
488
- {
489
- if(!route || !route.title)
490
- {
491
- return this;
492
- }
493
-
494
- let getTitle = (title) =>
495
- {
496
- /* this will uppercase each word in a string
497
- @param (string) str = the string to uppercase
498
- @return (string) the uppercase string */
499
- let toTitleCase = (str) =>
500
- {
501
- let pattern = /\w\S*/;
502
- return str.replace(pattern, (txt) =>
503
- {
504
- return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
505
- });
506
- };
507
-
508
-
509
- /* this will replace the params in the title
510
- @param (string) str = the route title
511
- @return (string) the title string */
512
- let replaceParams = (str) =>
513
- {
514
- if(str.indexOf(':') > -1)
515
- {
516
- let params = route.stage;
517
- for(var prop in params)
518
- {
519
- if(params.hasOwnProperty(prop))
520
- {
521
- var param = params[prop],
522
- pattern = new RegExp(':' + prop, 'gi');
523
- str = str.replace(pattern, param);
524
- }
525
- }
526
- }
527
- return str;
528
- };
529
-
530
- if(title)
531
- {
532
- if(typeof title === 'function')
533
- {
534
- title = title(route.stage);
535
- }
536
-
537
- /* we want to replace any params in the title
538
- and uppercase the title */
539
- title = replaceParams(title);
540
- title = toTitleCase(title);
541
-
542
- /* we want to check to add the base title to the
543
- to the end of the title */
544
- if(this.title !== '')
545
- {
546
- title += " - " + this.title;
547
- }
548
- }
549
- return title;
550
- };
551
-
552
- let title = route.title;
553
- document.title = getTitle(title);
554
- }
555
-
556
- /**
557
- * This will check the routes to match the path.
558
- *
559
- * @protected
560
- * @param {string} [path]
561
- */
562
- checkActiveRoutes(path)
563
- {
564
- this.lastPath = path;
565
-
566
- path = path || this.getPath();
567
- this.path = path;
568
-
569
- let routes = this.routes,
570
- length = routes.length;
571
-
572
- let route;
573
- for(var i = 0; i < length; i++)
574
- {
575
- route = routes[i];
576
- if(typeof route === 'undefined')
577
- {
578
- continue;
579
- }
580
-
581
- this.checkRoute(route, path);
582
- }
583
-
584
- this.checkSwitches(path);
585
- this.updatePath();
586
- }
587
-
588
- /**
589
- * This will check the switches to match the path.
590
- *
591
- * @protected
592
- * @param {string} [path]
593
- */
594
- checkSwitches(path)
595
- {
596
- let switches = this.switches;
597
- for(var id in switches)
598
- {
599
- if(switches.hasOwnProperty(id) === false)
600
- {
601
- continue;
602
- }
603
-
604
- var group = switches[id];
605
- this.checkGroup(group, path);
606
- }
607
- }
608
-
609
- /**
610
- * This will check a group to match a path.
611
- *
612
- * @protected
613
- * @param {object} group
614
- * @param {string} path
615
- */
616
- checkGroup(group, path)
617
- {
618
- let check = false,
619
- route, firstRoute, lastSelected, selected, hasController = false;
620
-
621
- for(var i = 0, length = group.length; i < length; i++)
622
- {
623
- route = group[i];
624
- if(typeof route === 'undefined')
625
- {
626
- continue;
627
- }
628
-
629
- /* we want to save the first route in the switch
630
- so it can be selected if no route is active */
631
- if(i === 0)
632
- {
633
- firstRoute = route;
634
- }
635
-
636
- if(!lastSelected && route.get('active'))
637
- {
638
- lastSelected = route;
639
- }
640
-
641
- if(check !== false)
642
- {
643
- if(hasController)
644
- {
645
- route.deactivate();
646
- }
647
- continue;
648
- }
649
-
650
- /* we will break the loop on the first match */
651
- check = route.match(path);
652
- if(check !== false)
653
- {
654
- selected = route;
655
-
656
- if(route.controller)
657
- {
658
- this.select(route);
659
- hasController = true;
660
- }
661
- }
662
- }
663
-
664
- if(selected === undefined)
665
- {
666
- this.select(firstRoute);
667
-
668
- if(lastSelected && firstRoute !== lastSelected)
669
- {
670
- lastSelected.deactivate();
671
- }
672
- }
673
- else
674
- {
675
- if(lastSelected)
676
- {
677
- if(hasController && selected !== lastSelected)
678
- {
679
- lastSelected.deactivate();
680
- }
681
- }
682
- else if(firstRoute && hasController === false)
683
- {
684
- this.select(firstRoute);
685
- }
686
- }
687
- }
688
-
689
- /**
690
- * This will check if a route matches the path.
691
- *
692
- * @param {object} route
693
- * @param {string} path
694
- * @return {boolean}
695
- */
696
- checkRoute(route, path)
697
- {
698
- let check = this.check(route, path);
699
- if(check !== false)
700
- {
701
- this.select(route);
702
- }
703
- else
704
- {
705
- route.deactivate();
706
- }
707
- return check;
708
- }
709
-
710
- /**
711
- * This will select a route if the route matches the path.
712
- *
713
- * @param {object} route
714
- * @param {string} [path]
715
- */
716
- check(route, path)
717
- {
718
- /* we want to check if the route has been
719
- deleted from the routes */
720
- if(!route)
721
- {
722
- return false;
723
- }
724
-
725
- /* we want to check to use the supplied uri or get the
726
- current uri if not setup */
727
- path = path || this.getPath();
728
-
729
- /* we want to check if the route uri matches the path uri */
730
- return (route.match(path) !== false);
731
- }
732
-
733
- /**
734
- * This will select the route.
735
- *
736
- * @param {object} route
737
- */
738
- select(route)
739
- {
740
- if(!route)
741
- {
742
- return false;
743
- }
744
-
745
- route.setPath(this.path, this.lastPath);
746
- route.select();
747
- this.updateTitle(route);
748
- }
749
-
750
- /**
751
- * This will get the endpoint.
752
- *
753
- * @return {string}
754
- */
755
- getEndPoint()
756
- {
757
- let path = this.getPath();
758
- return (path.replace(this.baseURI, '') || '/');
759
- }
760
-
761
- /**
762
- * This will remove the router events.
763
- */
764
- destroy()
765
- {
766
- base.off('click', document, this.callBackLink);
767
- }
768
-
769
- /**
770
- * This will get the location pathname.
771
- *
772
- * @return {string}
773
- */
774
- getPath()
775
- {
776
- /* we want to get the window location path */
777
- let location = this.location,
778
- path = this.path = location.pathname;
779
-
780
- if(this.history.type === 'hash')
781
- {
782
- return location.hash.replace('#', '');
783
- }
784
-
785
- return path + location.search + location.hash;
786
- }
787
- }
788
-
789
- export const router = new Router();