@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,1680 +0,0 @@
1
- /* base framework module */
2
- (function()
3
- {
4
- "use strict";
5
-
6
- /* this will register the route system to the
7
- data tracker to remove routes that have been
8
- nested in layouts. */
9
- base.DataTracker.addType('routes', function(data)
10
- {
11
- if(!data)
12
- {
13
- return false;
14
- }
15
-
16
- var route = data.route;
17
- if(route)
18
- {
19
- base.router.removeRoute(route);
20
- }
21
- });
22
-
23
- base.DataTracker.addType('switch', function(data)
24
- {
25
- if(!data)
26
- {
27
- return false;
28
- }
29
-
30
- var id = data.id;
31
- base.router.removeSwitch(id);
32
- });
33
-
34
- /**
35
- * Utils
36
- *
37
- * These are some helper functions for the router.
38
- */
39
- var Utils =
40
- {
41
- /**
42
- * This will remove the begining and ending slashes from a url.
43
- *
44
- * @param {string} uri
45
- * @return {string}
46
- */
47
- removeSlashes: function(uri)
48
- {
49
- if(typeof uri === 'string')
50
- {
51
- if(uri.substring(0, 1) === '/')
52
- {
53
- uri = uri.substring(1);
54
- }
55
-
56
- if(uri.substring(-1) === '/')
57
- {
58
- uri = uri.substring(0, uri.length - 1);
59
- }
60
- }
61
-
62
- return uri;
63
- }
64
- };
65
-
66
- /**
67
- * Router
68
- *
69
- * This will create a browser router.
70
- * @class
71
- */
72
- var Router = base.Class.extend(
73
- {
74
- constructor: function()
75
- {
76
- /**
77
- * @member {string} version
78
- */
79
- this.version = '1.0.2';
80
-
81
- /* this is the root of the uri for the routing object
82
- and the base title */
83
- this.baseURI = '/';
84
- this.title = '';
85
-
86
- this.lastPath = null;
87
- this.path = null;
88
-
89
- /* this will be used to access our history object */
90
- this.history = null;
91
- this.callBackLink = null;
92
- this.location = window.location;
93
-
94
- /* this will store each route added to the
95
- router. */
96
- this.routes = [];
97
- this.switches = {};
98
- this.switchCount = 0;
99
-
100
- /**
101
- * @member {object} data
102
- */
103
- this.data = new base.Data(
104
- {
105
- path: ''
106
- });
107
- },
108
-
109
- /**
110
- * This will setup our history object.
111
- */
112
- setupHistory: function()
113
- {
114
- this.history = RouterEvents.create(this);
115
- this.history.setup();
116
- },
117
-
118
- /**
119
- * This will create a new route.
120
- *
121
- * @protected
122
- * @param {object} settings
123
- * @return {object}
124
- */
125
- createRoute: function(settings)
126
- {
127
- var uri = settings.uri || '*';
128
- settings.baseUri = this.createURI(uri);
129
-
130
- var route = new Route(settings);
131
- return route;
132
- },
133
-
134
- /**
135
- * This will add a new route to the router.
136
- *
137
- * @param {object} settings
138
- * @return {object}
139
- */
140
- add: function(settings)
141
- {
142
- if(typeof settings !== 'object')
143
- {
144
- var args = arguments;
145
- settings =
146
- {
147
- uri: args[0],
148
- component: args[1],
149
- callBack: args[2],
150
- title: args[3],
151
- id: args[4],
152
- container: args[5]
153
- };
154
- }
155
-
156
- var route = this.createRoute(settings);
157
- this.addRoute(route);
158
- return route;
159
- },
160
-
161
- addRoute: function(route)
162
- {
163
- this.routes.push(route);
164
- this.checkRoute(route, this.getPath());
165
- },
166
-
167
- /**
168
- * This will resume a route.
169
- *
170
- * @param {object} route
171
- * @param {object} container
172
- */
173
- resume: function(route, container)
174
- {
175
- route.resume(container);
176
- this.addRoute(route);
177
- },
178
-
179
- /**
180
- * This will get the base path.
181
- *
182
- * @protected
183
- * @return {string}
184
- */
185
- getBasePath: function()
186
- {
187
- if(!this.basePath)
188
- {
189
- var pathURI = this.baseURI || '';
190
- if((pathURI[pathURI.length - 1] !== '/'))
191
- {
192
- pathURI += '/';
193
- }
194
- this.basePath = pathURI;
195
- }
196
- return this.basePath;
197
- },
198
-
199
- /**
200
- * This will create a uri.
201
- *
202
- * @protected
203
- * @param {string} uri
204
- * @return {string}
205
- */
206
- createURI: function(uri)
207
- {
208
- var baseUri = this.getBasePath();
209
- return (baseUri + Utils.removeSlashes(uri));
210
- },
211
-
212
- /**
213
- * This will get a route by uri.
214
- *
215
- * @param {string} uri
216
- * @return {(object|boolean)}
217
- */
218
- getRoute: function(uri)
219
- {
220
- var routes = this.routes,
221
- length = routes.length;
222
- if(length > 0)
223
- {
224
- for(var i = 0; i < length; i++)
225
- {
226
- var route = routes[i];
227
- if(route.uri === uri)
228
- {
229
- return route;
230
- }
231
- }
232
- }
233
- return false;
234
- },
235
-
236
- /**
237
- * This will get a route by id.
238
- *
239
- * @param {string} id
240
- * @return {(object|boolean)}
241
- */
242
- getRouteById: function(id)
243
- {
244
- var routes = this.routes,
245
- length = routes.length;
246
- if(length > 0)
247
- {
248
- for(var i = 0; i < length; i++)
249
- {
250
- var route = routes[i];
251
- if(route.id === id)
252
- {
253
- return route;
254
- }
255
- }
256
- }
257
- return false;
258
- },
259
-
260
- /**
261
- * This will remove a route.
262
- *
263
- * @param {object} route
264
- */
265
- removeRoute: function(route)
266
- {
267
- var routes = this.routes;
268
- var index = base.inArray(routes, route);
269
- if(index > -1)
270
- {
271
- routes.splice(index, 1);
272
- }
273
- },
274
-
275
- /**
276
- * This will add a switch.
277
- *
278
- * @param {array} group
279
- * @return {string} the switch id.
280
- */
281
- addSwitch: function(group)
282
- {
283
- var id = this.switchCount++;
284
- var switchArray = this.getSwitchGroup(id);
285
-
286
- for(var i = 0, length = group.length; i < length; i++)
287
- {
288
- var route = this.createRoute(group[i]);
289
- switchArray.push(route);
290
- }
291
-
292
- this.checkGroup(switchArray, this.getPath());
293
- return id;
294
- },
295
-
296
- /**
297
- * This will resume a switch.
298
- *
299
- * @param {object} group
300
- * @param {object} container
301
- * @return {int} the switch id.
302
- */
303
- resumeSwitch: function(group, container)
304
- {
305
- var id = this.switchCount++;
306
- var switchArray = this.getSwitchGroup(id);
307
-
308
- for(var i = 0, length = group.length; i < length; i++)
309
- {
310
- var route = group[i].component.route;
311
- route.resume(container);
312
- switchArray.push(route);
313
- }
314
-
315
- this.checkGroup(switchArray, this.getPath());
316
- return id;
317
- },
318
-
319
- getSwitchGroup: function(id)
320
- {
321
- return (this.switches[id] = []);
322
- },
323
-
324
- /**
325
- * This will remove a switch by id.
326
- *
327
- * @param {string} id
328
- */
329
- removeSwitch: function(id)
330
- {
331
- var switches = this.switches;
332
- if(switches[id])
333
- {
334
- delete switches[id];
335
- }
336
- },
337
-
338
- /**
339
- * This will remove a route by uri.
340
- *
341
- * @param {string} uri
342
- * @return {object} a reference to the router object.
343
- */
344
- remove: function(uri)
345
- {
346
- uri = this.createURI(uri);
347
-
348
- var route = this.getRoute(uri);
349
- if(route !== false)
350
- {
351
- this.removeRoute(route);
352
- }
353
- return this;
354
- },
355
-
356
- /**
357
- * This will setup the router.
358
- *
359
- * @param {string} [baseURI]
360
- * @param {string} [title]
361
- * @return {object} a reference to the router object.
362
- */
363
- setup: function(baseURI, title)
364
- {
365
- this.baseURI = baseURI || '/';
366
- this.updateBaseTag(this.baseURI);
367
- this.title = (typeof title !== 'undefined')? title : '';
368
-
369
- this.setupHistory();
370
-
371
- this.data.set('path', this.getPath());
372
-
373
- this.callBackLink = base.bind(this, this.checkLink);
374
- base.on('click', document, this.callBackLink);
375
-
376
- /* this will route to the first url entered
377
- when the router loads. this will fix the issue
378
- that stopped the first endpoint from being
379
- added to the history */
380
- var endPoint = this.getEndPoint();
381
- this.navigate(endPoint, null, true);
382
- return this;
383
- },
384
-
385
- updateBaseTag: function(url)
386
- {
387
- /* this will modify the base tag to ref from
388
- the base url for all xhr */
389
- var ele = document.getElementsByTagName('base');
390
- if(ele.length)
391
- {
392
- ele[0].href = url;
393
- }
394
- },
395
-
396
- /**
397
- * This will get the parent element link.
398
- *
399
- * @param {object} ele
400
- * @return {(object|boolean)}
401
- */
402
- getParentLink: function(ele)
403
- {
404
- var target = ele.parentNode;
405
- while(target !== null)
406
- {
407
- if(target.nodeName.toLowerCase() === 'a')
408
- {
409
- return target;
410
- }
411
-
412
- target = target.parentNode;
413
- }
414
- return false;
415
- },
416
-
417
- /**
418
- * This will check if a link was routed.
419
- *
420
- * @protected
421
- * @param {object} evt
422
- */
423
- checkLink: function(evt)
424
- {
425
- if(evt.ctrlKey === true)
426
- {
427
- return true;
428
- }
429
-
430
- var target = evt.target || evt.srcElement;
431
- if(target.nodeName.toLowerCase() !== 'a')
432
- {
433
- /* this will check to get the parent to check
434
- if the child is contained in a link */
435
- target = this.getParentLink(target);
436
- if(target === false)
437
- {
438
- return true;
439
- }
440
- }
441
-
442
- if(target.target === '_blank' || base.data(target, 'cancel-route'))
443
- {
444
- return true;
445
- }
446
-
447
- var href = target.getAttribute('href');
448
- if(typeof href !== 'undefined')
449
- {
450
- var baseUri = this.baseURI,
451
- path = (baseUri !== '/')? href.replace(baseUri, '') : href;
452
- this.navigate(path);
453
-
454
- evt.preventDefault();
455
- evt.stopPropagation();
456
- return false;
457
- }
458
- },
459
-
460
- /**
461
- * This will reset the router.
462
- *
463
- * @return {object} a reference to the router object.
464
- */
465
- reset: function()
466
- {
467
- this.routes = [];
468
- this.switches = [];
469
- this.switchCount = 0;
470
-
471
- return this;
472
- },
473
-
474
- /**
475
- * This will check the active routes.
476
- *
477
- * @return {object} a reference to the router object.
478
- */
479
- activate: function()
480
- {
481
- this.checkActiveRoutes();
482
- return this;
483
- },
484
-
485
- /**
486
- * This will navigate the router.
487
- *
488
- * @param {string} uri
489
- * @param {object} [data]
490
- * @param {boolean} [replace]
491
- * @return {object} a reference to the router object.
492
- */
493
- navigate: function(uri, data, replace)
494
- {
495
- uri = this.createURI(uri);
496
- this.history.addState(uri, data, replace);
497
- this.activate();
498
-
499
- return this;
500
- },
501
-
502
- /**
503
- * This will update the data path.
504
- * @protected
505
- */
506
- updatePath: function()
507
- {
508
- var path = this.getPath();
509
- this.data.set('path', path);
510
- },
511
-
512
- /**
513
- * This will update the title.
514
- *
515
- * @protected
516
- * @param {object} route
517
- */
518
- updateTitle: function(route)
519
- {
520
- if(!route || !route.title)
521
- {
522
- return this;
523
- }
524
-
525
- var title = route.title,
526
- parent = this;
527
-
528
- var getTitle = function(title)
529
- {
530
- /* this will uppercase each word in a string
531
- @param (string) str = the string to uppercase
532
- @return (string) the uppercase string */
533
- var toTitleCase = function(str)
534
- {
535
- var pattern = /\w\S*/;
536
- return str.replace(pattern, function(txt)
537
- {
538
- return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
539
- });
540
- };
541
-
542
-
543
- /* this will replace the params in the title
544
- @param (string) str = the route title
545
- @return (string) the title string */
546
- var replaceParams = function(str)
547
- {
548
- if(str.indexOf(':') > -1)
549
- {
550
- var params = route.stage;
551
- for(var prop in params)
552
- {
553
- if(params.hasOwnProperty(prop))
554
- {
555
- var param = params[prop];
556
- var pattern = new RegExp(':' + prop, 'gi');
557
- str = str.replace(pattern, param);
558
- }
559
- }
560
- }
561
- return str;
562
- };
563
-
564
- if(title)
565
- {
566
- if(typeof title === 'function')
567
- {
568
- title = title(route.stage);
569
- }
570
-
571
- /* we want to replace any params in the title
572
- and uppercase the title */
573
- title = replaceParams(title);
574
- title = toTitleCase(title);
575
-
576
- /* we want to check to add the base title to the
577
- to the end of the title */
578
- if(parent.title !== '')
579
- {
580
- title += " - " + parent.title;
581
- }
582
- }
583
- return title;
584
- };
585
-
586
- document.title = getTitle(title);
587
- },
588
-
589
- /**
590
- * This will check the routes to match the path.
591
- *
592
- * @protected
593
- * @param {string} [path]
594
- */
595
- checkActiveRoutes: function(path)
596
- {
597
- this.lastPath = this.path;
598
-
599
- path = path || this.getPath();
600
- this.path = path;
601
-
602
- var routes = this.routes,
603
- length = routes.length;
604
-
605
- var route;
606
- for(var i = 0; i < length; i++)
607
- {
608
- route = routes[i];
609
- if(typeof route === 'undefined')
610
- {
611
- continue;
612
- }
613
-
614
- this.checkRoute(route, path);
615
- }
616
-
617
- this.checkSwitches(path);
618
- this.updatePath();
619
- },
620
-
621
- /**
622
- * This will check the switches to match the path.
623
- *
624
- * @protected
625
- * @param {string} [path]
626
- */
627
- checkSwitches: function(path)
628
- {
629
- var switches = this.switches;
630
- for(var id in switches)
631
- {
632
- if(switches.hasOwnProperty(id) === false)
633
- {
634
- continue;
635
- }
636
-
637
- var group = switches[id];
638
- this.checkGroup(group, path);
639
- }
640
- },
641
-
642
- /**
643
- * This will check a group to match a path.
644
- *
645
- * @protected
646
- * @param {object} group
647
- * @param {string} path
648
- */
649
- checkGroup: function(group, path)
650
- {
651
- var check = false,
652
- route, firstRoute, lastSelected, selected, hasController = false;
653
-
654
- for(var i = 0, length = group.length; i < length; i++)
655
- {
656
- route = group[i];
657
- if(typeof route === 'undefined')
658
- {
659
- continue;
660
- }
661
-
662
- /* we want to save the first route in the switch
663
- so it can be selected if no route is active */
664
- if(i === 0)
665
- {
666
- firstRoute = route;
667
- }
668
-
669
- if(!lastSelected && route.get('active'))
670
- {
671
- lastSelected = route;
672
- }
673
-
674
- if(check !== false)
675
- {
676
- if(hasController)
677
- {
678
- route.deactivate();
679
- }
680
- continue;
681
- }
682
-
683
- /* we will break the loop on the first match */
684
- check = route.match(path);
685
- if(check !== false)
686
- {
687
- selected = route;
688
-
689
- if(route.controller)
690
- {
691
- this.select(route);
692
- hasController = true;
693
- }
694
- }
695
- }
696
-
697
- if(selected === undefined)
698
- {
699
- this.select(firstRoute);
700
-
701
- if(lastSelected && firstRoute !== lastSelected)
702
- {
703
- lastSelected.deactivate();
704
- }
705
- }
706
- else
707
- {
708
- if(lastSelected)
709
- {
710
- if(hasController && selected !== lastSelected)
711
- {
712
- lastSelected.deactivate();
713
- }
714
- }
715
- else if(firstRoute && hasController === false)
716
- {
717
- this.select(firstRoute);
718
- }
719
- }
720
- },
721
-
722
- /**
723
- * This will check if a route matches the path.
724
- *
725
- * @param {object} route
726
- * @param {string} path
727
- * @return {boolean}
728
- */
729
- checkRoute: function(route, path)
730
- {
731
- var check = this.check(route, path);
732
- if(check !== false)
733
- {
734
- this.select(route);
735
- }
736
- else
737
- {
738
- route.deactivate();
739
- }
740
- return check;
741
- },
742
-
743
- /**
744
- * This will select a route if the route matches the path.
745
- *
746
- * @param {object} route
747
- * @param {string} [path]
748
- */
749
- check: function(route, path)
750
- {
751
- /* we want to check if the route has been
752
- deleted from the routes */
753
- if(!route)
754
- {
755
- return false;
756
- }
757
-
758
- /* we want to check to use the supplied uri or get the
759
- current uri if not setup */
760
- path = path || this.getPath();
761
-
762
- /* we want to check if the route uri matches the path uri */
763
- return (route.match(path) !== false);
764
- },
765
-
766
- /**
767
- * This will select the route.
768
- *
769
- * @param {object} route
770
- */
771
- select: function(route)
772
- {
773
- if(!route)
774
- {
775
- return false;
776
- }
777
-
778
- route.setPath(this.path, this.lastPath);
779
- route.select();
780
- this.updateTitle(route);
781
- },
782
-
783
- /**
784
- * This will get the endpoint.
785
- *
786
- * @return {string}
787
- */
788
- getEndPoint: function()
789
- {
790
- var path = this.getPath();
791
- return (path.replace(this.baseURI, '') || '/');
792
- },
793
-
794
- /**
795
- * This will remove the router events.
796
- */
797
- destroy: function()
798
- {
799
- base.off('click', document, this.callBackLink);
800
- },
801
-
802
- /**
803
- * This will get the location pathname.
804
- *
805
- * @return {string}
806
- */
807
- getPath: function()
808
- {
809
- /* we want to get the window location path */
810
- var location = this.location,
811
- path = this.path = location.pathname;
812
-
813
- if(this.history.type === 'hash')
814
- {
815
- return location.hash.replace('#', '');
816
- }
817
-
818
- return path + location.search + location.hash;
819
- }
820
- });
821
-
822
- var routerNumber = 0;
823
-
824
- var RouterEvents = base.Class.extend(
825
- {
826
- /**
827
- * @constructor
828
- * @param {object} router
829
- */
830
- constructor: function(router)
831
- {
832
- this.router = router;
833
-
834
- /* this will check if the history api is supported
835
- and enabled */
836
- this.locationId = 'base-app-router-' + routerNumber++;
837
- this.callBack = null;
838
- },
839
-
840
- /**
841
- * This will check if the history api is supported
842
- * and add events.
843
- *
844
- * @return {object} a reference to the object.
845
- */
846
- setup: function()
847
- {
848
- this.callBack = base.bind(this, this.check);
849
- this.addEvent();
850
- return this;
851
- }
852
- });
853
-
854
- /**
855
- * This will check if the history API is supported.
856
- *
857
- * @returns {boolean}
858
- */
859
- var isHistorySupported = function()
860
- {
861
- if('history' in window && 'pushState' in window.history)
862
- {
863
- return true;
864
- }
865
-
866
- return false;
867
- };
868
-
869
- RouterEvents.create = function(router)
870
- {
871
- if(isHistorySupported() === true)
872
- {
873
- return new HistoryRouter(router);
874
- }
875
-
876
- return new HashRouter(router);
877
- };
878
-
879
- var HistoryRouter = RouterEvents.extend(
880
- {
881
- type: 'history',
882
-
883
- /**
884
- * This will add the events.
885
- *
886
- * @return {object} a reference to the object.
887
- */
888
- addEvent: function()
889
- {
890
- base.on('popstate', window, this.callBack);
891
- return this;
892
- },
893
-
894
- /**
895
- * This will remove the events.
896
- *
897
- * @return {object} a reference to the object.
898
- */
899
- removeEvent: function()
900
- {
901
- base.off('popstate', window, this.callBack);
902
- return this;
903
- },
904
-
905
- /**
906
- * This will check to activate the router.
907
- *
908
- * @param {object} evt
909
- */
910
- check: function(evt)
911
- {
912
- /* we want to check if the event has a state and if the
913
- state location is from the background */
914
- var state = evt.state;
915
- if(!state || state.location !== this.locationId)
916
- {
917
- return false;
918
- }
919
-
920
- evt.preventDefault();
921
- evt.stopPropagation();
922
-
923
- this.router.checkActiveRoutes(state.uri);
924
- },
925
-
926
- /**
927
- * This will create a state object.
928
- *
929
- * @param {string} uri
930
- * @param {*} data
931
- * @return {object}
932
- */
933
- createState: function(uri, data)
934
- {
935
- var stateObj = {
936
- location: this.locationId,
937
- uri: uri
938
- };
939
-
940
- if(data && typeof data === 'object')
941
- {
942
- stateObj = base.extendObject(stateObj, data);
943
- }
944
-
945
- return stateObj;
946
- },
947
-
948
- /**
949
- * This will add a state to the history.
950
- *
951
- * @param {string} uri
952
- * @param {object} data
953
- * @param {boolean} replace
954
- * @return {object} a reference to the object.
955
- */
956
- addState: function(uri, data, replace)
957
- {
958
- var history = window.history,
959
- lastState = history.state;
960
-
961
- if(lastState && lastState.uri === uri)
962
- {
963
- return this;
964
- }
965
-
966
- var stateObj = this.createState(uri, data);
967
-
968
- /* this will check to push state or
969
- replace state */
970
- replace = (replace === true);
971
- var method = (replace === false)? 'pushState' : 'replaceState';
972
- history[method](stateObj, null, uri);
973
-
974
- return this;
975
- }
976
- });
977
-
978
- var HashRouter = RouterEvents.extend(
979
- {
980
- type: 'hash',
981
-
982
- /**
983
- * This will add the events.
984
- *
985
- * @return {object} a reference to the object.
986
- */
987
- addEvent: function()
988
- {
989
- base.on('hashchange', window, this.callBack);
990
- return this;
991
- },
992
-
993
- /**
994
- * This will remove the events.
995
- *
996
- * @return {object} a reference to the object.
997
- */
998
- removeEvent: function()
999
- {
1000
- base.off('hashchange', window, this.callBack);
1001
- return this;
1002
- },
1003
-
1004
- /**
1005
- * This will check to activate the router.
1006
- *
1007
- * @param {object} evt
1008
- */
1009
- check: function(evt)
1010
- {
1011
- this.router.checkActiveRoutes();
1012
- },
1013
-
1014
- /**
1015
- * This will add a state to the history.
1016
- *
1017
- * @param {string} uri
1018
- * @param {object} data
1019
- * @param {boolean} replace
1020
- * @return {object} a reference to the object.
1021
- */
1022
- addState: function(uri, data, replace)
1023
- {
1024
- window.location.hash = uri;
1025
-
1026
- return this;
1027
- }
1028
- });
1029
-
1030
- /**
1031
- * This will setup a route uri pattern.
1032
- *
1033
- * @param {string} uri
1034
- * @return {string}
1035
- */
1036
- var routePattern = function(uri)
1037
- {
1038
- var uriQuery = "";
1039
- if(uri)
1040
- {
1041
- var filter = /\//g;
1042
- uriQuery = uri.replace(filter, "\/");
1043
-
1044
- /* this will setup for optional slashes before the optional params */
1045
- var optionalSlash = /(\/):[^\/(]*?\?/g;
1046
- uriQuery = uriQuery.replace(optionalSlash, function(str)
1047
- {
1048
- var pattern = /\//g;
1049
- return str.replace(pattern, '(?:$|\/)');
1050
- });
1051
-
1052
- /* this will setup for optional params and params
1053
- and stop at the last slash or query start */
1054
- var param = /(:[^\/?&($]+)/g;
1055
- var optionalParams = /(\?\/+\*?)/g;
1056
- uriQuery = uriQuery.replace(optionalParams, '?\/*');
1057
- uriQuery = uriQuery.replace(param, function(str)
1058
- {
1059
- return (str.indexOf('.') < 0)? '([^\/|?]+)' : '([^\/|?]+.*)';
1060
- });
1061
-
1062
- /* we want to setup the wild card and param
1063
- checks to be modified to the route uri string */
1064
- var allowAll = /(\*)/g;
1065
- uriQuery = uriQuery.replace(allowAll, '.*');
1066
- }
1067
-
1068
- /* we want to set and string end if the wild card is not set */
1069
- uriQuery += (uri[uri.length - 1] === '*')? '' : '$';
1070
- return uriQuery;
1071
- };
1072
-
1073
- /**
1074
- * This will get the param keys from the uri.
1075
- *
1076
- * @param {string} uri
1077
- * @return {array}
1078
- */
1079
- var paramPattern = function(uri)
1080
- {
1081
- var params = [];
1082
- if(!uri)
1083
- {
1084
- return params;
1085
- }
1086
-
1087
- var filter = /[\*?]/g;
1088
- uri = uri.replace(filter, '');
1089
-
1090
- var pattern = /:(.[^.\/?&($]+)\?*/g,
1091
- matches = uri.match(pattern);
1092
- if(matches === null)
1093
- {
1094
- return params;
1095
- }
1096
-
1097
- for(var i = 0, maxLength = matches.length; i < maxLength; i++)
1098
- {
1099
- var param = matches[i];
1100
- if(param)
1101
- {
1102
- param = param.replace(':', '');
1103
- params.push(param);
1104
- }
1105
- }
1106
- return params;
1107
- };
1108
-
1109
- var routeCount = 0;
1110
-
1111
- /**
1112
- * Route
1113
- *
1114
- * This will create a route.
1115
- * @class
1116
- * @augments base.SimpleData
1117
- */
1118
- var Route = base.SimpleData.extend(
1119
- {
1120
- /**
1121
- * @constructor
1122
- * @param {object} settings
1123
- */
1124
- constructor: function(settings)
1125
- {
1126
- this.setupRoute(settings);
1127
-
1128
- var params = this.getParamDefaults();
1129
- base.SimpleData.call(this, params);
1130
-
1131
- this.set('active', false);
1132
- },
1133
-
1134
- /**
1135
- * This will setup the route settings.
1136
- *
1137
- * @protected
1138
- * @param {object} settings
1139
- */
1140
- setupRoute: function(settings)
1141
- {
1142
- this.id = settings.id || 'bs-rte-' + routeCount++;
1143
-
1144
- var uri = settings.baseUri;
1145
- this.uri = uri;
1146
- this.path = null;
1147
- this.referralPath = null;
1148
-
1149
- /* route reg ex */
1150
- var uriMatch = routePattern(uri);
1151
- this.uriQuery = new RegExp('^' + uriMatch);
1152
-
1153
- /* params */
1154
- this.paramKeys = paramPattern(uri);
1155
- this.params = null;
1156
-
1157
- /* this will setup the template and route component
1158
- if one has been set */
1159
- this.setupComponentHelper(settings);
1160
-
1161
- this.callBack = settings.callBack;
1162
- this.title = settings.title;
1163
- },
1164
-
1165
- /**
1166
- * This will get the default route params.
1167
- *
1168
- * @return {(object|null)}
1169
- */
1170
- getParamDefaults: function()
1171
- {
1172
- var params = this.paramKeys;
1173
- if(params.length)
1174
- {
1175
- var defaults = {};
1176
- for(var i = 0, length = params.length; i < length; i++)
1177
- {
1178
- defaults[params[i]] = null;
1179
- }
1180
- return defaults;
1181
- }
1182
- return null;
1183
- },
1184
-
1185
- /**
1186
- * This will update the route title.
1187
- *
1188
- * @param {string|function} title
1189
- */
1190
- setTitle: function(title)
1191
- {
1192
- base.router.updateTitle({
1193
- title: title,
1194
- stage: this.stage
1195
- });
1196
- },
1197
-
1198
- /**
1199
- * This will deactivate the route.
1200
- */
1201
- deactivate: function()
1202
- {
1203
- this.set('active', false);
1204
-
1205
- var controller = this.controller;
1206
- if(controller)
1207
- {
1208
- controller.remove();
1209
- }
1210
- },
1211
-
1212
- /**
1213
- * This will setup the route component.
1214
- *
1215
- * @protected
1216
- * @param {object} settings
1217
- */
1218
- setupComponentHelper: function(settings)
1219
- {
1220
- var component = settings.component;
1221
- if(component)
1222
- {
1223
- var helperSettings =
1224
- {
1225
- component: component,
1226
- container: settings.container,
1227
- persist: settings.persist || false,
1228
- parent: settings.parent
1229
- };
1230
- this.controller = new ComponentHelper(this, helperSettings);
1231
- }
1232
- },
1233
-
1234
- /**
1235
- * This will resume the route.
1236
- *
1237
- * @param {object} container
1238
- */
1239
- resume: function(container)
1240
- {
1241
- var controller = this.controller;
1242
- if(controller)
1243
- {
1244
- controller.container = container;
1245
- }
1246
- },
1247
-
1248
- /**
1249
- * This will set the route path.
1250
- *
1251
- * @param {string} path
1252
- * @param {string} referralPath
1253
- */
1254
- setPath: function(path, referralPath)
1255
- {
1256
- this.path = path;
1257
- this.referralPath = referralPath;
1258
- },
1259
-
1260
- /**
1261
- * This will select the route.
1262
- */
1263
- select: function()
1264
- {
1265
- this.set('active', true);
1266
-
1267
- var params = this.stage;
1268
- var callBack = this.callBack;
1269
- if(typeof callBack === 'function')
1270
- {
1271
- callBack(params);
1272
- }
1273
-
1274
- var controller = this.controller;
1275
- if(controller)
1276
- {
1277
- controller.focus(params);
1278
- }
1279
-
1280
- var path = this.path;
1281
- if(!path)
1282
- {
1283
- return;
1284
- }
1285
-
1286
- var hash = path.split('#')[1];
1287
- if(!hash)
1288
- {
1289
- return;
1290
- }
1291
-
1292
- this.scrollToId(hash);
1293
- },
1294
-
1295
- scrollToId: function(hash)
1296
- {
1297
- if(!hash)
1298
- {
1299
- return;
1300
- }
1301
-
1302
- var ele = document.getElementById(hash);
1303
- if(!ele)
1304
- {
1305
- return;
1306
- }
1307
-
1308
- ele.scrollIntoView(true);
1309
- },
1310
-
1311
- /**
1312
- * This will check if a route matches the path.
1313
- *
1314
- * @param {string} path
1315
- * @return {(object|boolean)}
1316
- */
1317
- match: function(path)
1318
- {
1319
- var matched = false;
1320
-
1321
- /* we want to check to use the supplied uri or get the
1322
- current uri if not setup */
1323
- var result = path.match(this.uriQuery);
1324
- if(result === null)
1325
- {
1326
- this.resetParams();
1327
- return matched;
1328
- }
1329
-
1330
- if(result && typeof result === 'object')
1331
- {
1332
- /* this will remove the first match from the
1333
- the params */
1334
- result.shift();
1335
- matched = result;
1336
- /* this will get the uri params of the route
1337
- and if set will save them to the route */
1338
- this.setParams(result);
1339
- }
1340
-
1341
- return matched;
1342
- },
1343
-
1344
- /**
1345
- * This will reset the params.
1346
- */
1347
- resetParams: function()
1348
- {
1349
- this.stage = {};
1350
- },
1351
-
1352
- /**
1353
- * This will set the params.
1354
- *
1355
- * @param {object} values
1356
- */
1357
- setParams: function(values)
1358
- {
1359
- if(values && typeof values === 'object')
1360
- {
1361
- var keys = this.paramKeys;
1362
- if(keys)
1363
- {
1364
- var params = {};
1365
- for(var i = 0, maxL = keys.length; i < maxL; i++)
1366
- {
1367
- var key = keys[i];
1368
- if(typeof key !== 'undefined')
1369
- {
1370
- params[key] = values[i];
1371
- }
1372
- }
1373
- this.set(params);
1374
- }
1375
- }
1376
- },
1377
-
1378
- /**
1379
- * This will get the params.
1380
- *
1381
- * @return {object}
1382
- */
1383
- getParams: function()
1384
- {
1385
- return this.stage;
1386
- }
1387
- });
1388
-
1389
- /**
1390
- * ComponentHelper
1391
- *
1392
- * This will create a helper to create and destroy components
1393
- * that are added to a route.
1394
- * @class
1395
- */
1396
- var ComponentHelper = base.Class.extend(
1397
- {
1398
- /**
1399
- * @constructor
1400
- * @param {object} route
1401
- * @param {object} settings
1402
- */
1403
- constructor: function(route, settings)
1404
- {
1405
- this.route = route;
1406
-
1407
- this.template = settings.component;
1408
- this.component = null;
1409
- this.hasTemplate = false;
1410
-
1411
- this.setup = false;
1412
- this.container = settings.container;
1413
- this.persist = settings.persist;
1414
- this.parent = settings.parent;
1415
-
1416
- this.setupTemplate();
1417
- },
1418
-
1419
- /**
1420
- * This will create the component.
1421
- *
1422
- * @param {object} params
1423
- */
1424
- focus: function(params)
1425
- {
1426
- if(this.setup === false)
1427
- {
1428
- this.create();
1429
- }
1430
-
1431
- this.update(params);
1432
- },
1433
-
1434
- /**
1435
- * This will setup the template.
1436
- * @protected
1437
- */
1438
- setupTemplate: function()
1439
- {
1440
- var template = this.template;
1441
- if(typeof template === 'string')
1442
- {
1443
- template = this.template = window[template];
1444
- if(!template)
1445
- {
1446
- return;
1447
- }
1448
- }
1449
-
1450
- var type = typeof template;
1451
- if(type === 'function')
1452
- {
1453
- this.component = new this.template({
1454
- route: this.route,
1455
- persist: this.persist,
1456
- parent: this.parent
1457
- });
1458
- }
1459
- else if(type === 'object')
1460
- {
1461
- if(!this.template.isUnit)
1462
- {
1463
- this.template = Jot(this.template);
1464
- }
1465
-
1466
- var comp = this.component = this.template;
1467
- var persist = (comp.persist !== false);
1468
-
1469
- comp.route = this.route;
1470
- comp.persist = persist;
1471
- comp.parent = this.parent;
1472
- this.persist = persist;
1473
- }
1474
-
1475
- this.hasTemplate = true;
1476
- },
1477
-
1478
- /**
1479
- * This will create the route component.
1480
- * @protected
1481
- */
1482
- create: function()
1483
- {
1484
- if(!this.hasTemplate)
1485
- {
1486
- return false;
1487
- }
1488
-
1489
- this.setup = true;
1490
-
1491
- var comp = this.component;
1492
- if(!this.persist || !comp)
1493
- {
1494
- comp = this.component = this.template;
1495
- }
1496
-
1497
- base.builder.render(comp, this.container, this.parent);
1498
- },
1499
-
1500
- /**
1501
- * This will remove the component.
1502
- */
1503
- remove: function()
1504
- {
1505
- if(this.setup !== true)
1506
- {
1507
- return false;
1508
- }
1509
-
1510
- this.setup = false;
1511
-
1512
- var component = this.component;
1513
- if(!component)
1514
- {
1515
- return false;
1516
- }
1517
-
1518
- if(typeof component.destroy === 'function')
1519
- {
1520
- component.destroy();
1521
- }
1522
-
1523
- // this will remove the reference to the component if persit is false
1524
- if(this.persist === false)
1525
- {
1526
- this.component = null;
1527
- }
1528
- },
1529
-
1530
- /**
1531
- * This will call the component update method and pass the params.
1532
- *
1533
- * @protected
1534
- * @param {object} params
1535
- */
1536
- update: function(params)
1537
- {
1538
- var component = this.component;
1539
- if(!component)
1540
- {
1541
- return false;
1542
- }
1543
-
1544
- if(typeof component.update === 'function')
1545
- {
1546
- component.update(params);
1547
- }
1548
- }
1549
- });
1550
-
1551
- /**
1552
- * NavLink
1553
- *
1554
- * This will create a nav link that will add an active
1555
- * class when the browser route path matches the link
1556
- * href.
1557
- *
1558
- * @class
1559
- */
1560
- var NavLink = base.Component.extend(
1561
- {
1562
- /**
1563
- * This will configure the link active class.
1564
- *
1565
- * @protected
1566
- */
1567
- beforeSetup: function()
1568
- {
1569
- this.selectedClass = this.activeClass || 'active';
1570
- },
1571
-
1572
- /**
1573
- * This will render the component.
1574
- *
1575
- * @return {object}
1576
- */
1577
- render: function()
1578
- {
1579
- var href = this.href,
1580
- text = this.text;
1581
-
1582
- var watchers = this.setupWatchers(href, text);
1583
-
1584
- var onState = {};
1585
- onState[this.selectedClass] = true;
1586
-
1587
- return {
1588
- tag: 'a',
1589
- className: this.className || null,
1590
- onState: ['selected', onState],
1591
- href: this.getString(href),
1592
- text: this.getString(text),
1593
- children: this.children,
1594
- watch: watchers
1595
- };
1596
- },
1597
-
1598
- /**
1599
- * This will get string.
1600
- *
1601
- * @param {string} string
1602
- * @return {(string|null)}
1603
- */
1604
- getString: function(string)
1605
- {
1606
- var type = typeof string;
1607
- return (type !== 'object' && type !== 'undefined')? string : null;
1608
- },
1609
-
1610
- /**
1611
- * This will setup the watchers.
1612
- *
1613
- * @protected
1614
- * @param {string} href
1615
- * @param {string} text
1616
- * @return {array}
1617
- */
1618
- setupWatchers: function(href, text)
1619
- {
1620
- var self = this,
1621
- exact = (this.exact !== false),
1622
- data = base.router.data;
1623
-
1624
- var watchers = [];
1625
-
1626
- if(href && typeof href === 'object')
1627
- {
1628
- watchers.push(
1629
- {
1630
- attr: 'href',
1631
- value: href
1632
- });
1633
- }
1634
-
1635
- if(text && typeof text === 'object')
1636
- {
1637
- watchers.push(
1638
- {
1639
- attr: 'text',
1640
- value: text
1641
- });
1642
- }
1643
-
1644
- watchers.push({
1645
- value: ['[[path]]', data],
1646
- callBack: function(ele, value)
1647
- {
1648
- var path = ele.pathname + ele.hash;
1649
- var selected = exact? (value === path) : (new RegExp('^' + ele.pathname + '($|#|\/|\\.).*').test(value));
1650
- self.update(ele, selected);
1651
- }
1652
- });
1653
-
1654
- return watchers;
1655
- },
1656
-
1657
- setupStates: function()
1658
- {
1659
- return {
1660
- selected: false
1661
- };
1662
- },
1663
-
1664
- /**
1665
- * This will update the class on the element.
1666
- *
1667
- * @param {object} ele
1668
- * @param {bool} selected
1669
- */
1670
- update: function(ele, selected)
1671
- {
1672
- this.state.set('selected', selected);
1673
- }
1674
- });
1675
-
1676
- window.NavLink = NavLink;
1677
-
1678
- base.router = new Router();
1679
- base.extend.Router = Router;
1680
- })();