@base-framework/base 2.6.0 → 2.6.1

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 (190) hide show
  1. package/base.min.js +1 -0
  2. package/es5/base.js +2968 -0
  3. package/es5/modules/ajax.js +663 -0
  4. package/es5/modules/animation.js +188 -0
  5. package/es5/modules/animations.js +1080 -0
  6. package/es5/modules/atom.js +65 -0
  7. package/es5/modules/component.js +1310 -0
  8. package/es5/modules/data-binder.js +1131 -0
  9. package/es5/modules/data.js +1808 -0
  10. package/es5/modules/date.js +525 -0
  11. package/es5/modules/form-validator.js +324 -0
  12. package/es5/modules/history.js +126 -0
  13. package/es5/modules/html-builder.js +461 -0
  14. package/es5/modules/layout.js +1679 -0
  15. package/es5/modules/mouse.js +124 -0
  16. package/es5/modules/nav-link.js +123 -0
  17. package/es5/modules/olderversions/animations-ease.js +1095 -0
  18. package/es5/modules/olderversions/animations-update.js +1048 -0
  19. package/es5/modules/olderversions/base-animations.js +636 -0
  20. package/es5/modules/olderversions/base-component-class.js +100 -0
  21. package/es5/modules/olderversions/base-data-binder-1.js +407 -0
  22. package/es5/modules/olderversions/base-data-binder-class.js +358 -0
  23. package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  24. package/es5/modules/olderversions/base-mode-1.js +777 -0
  25. package/es5/modules/olderversions/base-model-class.js +585 -0
  26. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  27. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  28. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  29. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  30. package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  31. package/es5/modules/olderversions/data-tracker.js +187 -0
  32. package/es5/modules/olderversions/event-update.js +666 -0
  33. package/es5/modules/olderversions/nav-link.js +119 -0
  34. package/es5/modules/olderversions/router-with-templates-1.js +785 -0
  35. package/es5/modules/olderversions/router-with-templates.js +701 -0
  36. package/es5/modules/prototypes/ajax.js +657 -0
  37. package/es5/modules/prototypes/atom.js +65 -0
  38. package/es5/modules/prototypes/component.js +972 -0
  39. package/es5/modules/prototypes/data-binder.js +1089 -0
  40. package/es5/modules/prototypes/data.js +1290 -0
  41. package/es5/modules/prototypes/html-builder.js +414 -0
  42. package/es5/modules/prototypes/layout.js +879 -0
  43. package/es5/modules/router.js +1680 -0
  44. package/es5/modules/state.js +274 -0
  45. package/es6/.jshintrc +3 -0
  46. package/es6/base.js +41 -0
  47. package/es6/core.js +1 -0
  48. package/es6/data-tracker.js +351 -0
  49. package/es6/events.js +602 -0
  50. package/es6/legacy/es5/base.js +2968 -0
  51. package/es6/legacy/es5/modules/ajax.js +663 -0
  52. package/es6/legacy/es5/modules/animation.js +188 -0
  53. package/es6/legacy/es5/modules/animations.js +1080 -0
  54. package/es6/legacy/es5/modules/atom.js +65 -0
  55. package/es6/legacy/es5/modules/component.js +1310 -0
  56. package/es6/legacy/es5/modules/data-binder.js +1131 -0
  57. package/es6/legacy/es5/modules/data.js +1808 -0
  58. package/es6/legacy/es5/modules/date.js +525 -0
  59. package/es6/legacy/es5/modules/form-validator.js +324 -0
  60. package/es6/legacy/es5/modules/history.js +126 -0
  61. package/es6/legacy/es5/modules/html-builder.js +461 -0
  62. package/es6/legacy/es5/modules/layout.js +1679 -0
  63. package/es6/legacy/es5/modules/mouse.js +124 -0
  64. package/es6/legacy/es5/modules/nav-link.js +123 -0
  65. package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  66. package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  67. package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
  68. package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  69. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  70. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  71. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  72. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  73. package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  74. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  75. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  76. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  77. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  78. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  79. package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  80. package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
  81. package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
  82. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  83. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  84. package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
  85. package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
  86. package/es6/legacy/es5/modules/prototypes/component.js +972 -0
  87. package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  88. package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
  89. package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
  90. package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
  91. package/es6/legacy/es5/modules/router.js +1680 -0
  92. package/es6/legacy/es5/modules/state.js +274 -0
  93. package/es6/main.js +1331 -0
  94. package/es6/modules/ajax/ajax.js +514 -0
  95. package/es6/modules/animation/animation.js +236 -0
  96. package/es6/modules/animations/animation-controller.js +231 -0
  97. package/es6/modules/animations/animation.js +64 -0
  98. package/es6/modules/animations/attr-movement.js +66 -0
  99. package/es6/modules/animations/css-movement.js +170 -0
  100. package/es6/modules/animations/movement.js +131 -0
  101. package/es6/modules/animations/value.js +187 -0
  102. package/es6/modules/atom/atom.js +54 -0
  103. package/es6/modules/component/component.js +230 -0
  104. package/es6/modules/component/event-helper.js +119 -0
  105. package/es6/modules/component/jot.js +144 -0
  106. package/es6/modules/component/state-helper.js +262 -0
  107. package/es6/modules/component/unit.js +551 -0
  108. package/es6/modules/data/attrs.js +40 -0
  109. package/es6/modules/data/basic-data.js +500 -0
  110. package/es6/modules/data/data-utils.js +29 -0
  111. package/es6/modules/data/data.js +3 -0
  112. package/es6/modules/data/deep-data.js +541 -0
  113. package/es6/modules/data/model-service.js +528 -0
  114. package/es6/modules/data/model.js +133 -0
  115. package/es6/modules/data/simple-data.js +33 -0
  116. package/es6/modules/data-binder/connection-tracker.js +113 -0
  117. package/es6/modules/data-binder/connection.js +16 -0
  118. package/es6/modules/data-binder/data-binder.js +352 -0
  119. package/es6/modules/data-binder/data-pub-sub.js +141 -0
  120. package/es6/modules/data-binder/data-source.js +56 -0
  121. package/es6/modules/data-binder/element-source.js +219 -0
  122. package/es6/modules/data-binder/one-way-connection.js +46 -0
  123. package/es6/modules/data-binder/one-way-source.js +43 -0
  124. package/es6/modules/data-binder/source.js +36 -0
  125. package/es6/modules/data-binder/two-way-connection.js +75 -0
  126. package/es6/modules/data-binder/two-way-source.js +41 -0
  127. package/es6/modules/date/date.js +544 -0
  128. package/es6/modules/history/history.js +89 -0
  129. package/es6/modules/html-builder/html-builder.js +434 -0
  130. package/es6/modules/import/import.js +390 -0
  131. package/es6/modules/layout/layout-builder.js +1269 -0
  132. package/es6/modules/layout/layout-parser.js +134 -0
  133. package/es6/modules/layout/watcher-helper.js +282 -0
  134. package/es6/modules/mouse/mouse.js +114 -0
  135. package/es6/modules/router/component-helper.js +163 -0
  136. package/es6/modules/router/history-controller.js +216 -0
  137. package/es6/modules/router/nav-link.js +124 -0
  138. package/es6/modules/router/route.js +401 -0
  139. package/es6/modules/router/router.js +789 -0
  140. package/es6/modules/router/utils.js +31 -0
  141. package/es6/modules/state/state-target.js +91 -0
  142. package/es6/modules/state/state.js +171 -0
  143. package/es6/package-lock.json +13 -0
  144. package/es6/package.json +28 -0
  145. package/es6/shared/objects.js +99 -0
  146. package/legacy/es5/base.js +2968 -0
  147. package/legacy/es5/modules/ajax.js +663 -0
  148. package/legacy/es5/modules/animation.js +188 -0
  149. package/legacy/es5/modules/animations.js +1080 -0
  150. package/legacy/es5/modules/atom.js +65 -0
  151. package/legacy/es5/modules/component.js +1310 -0
  152. package/legacy/es5/modules/data-binder.js +1131 -0
  153. package/legacy/es5/modules/data.js +1808 -0
  154. package/legacy/es5/modules/date.js +525 -0
  155. package/legacy/es5/modules/form-validator.js +324 -0
  156. package/legacy/es5/modules/history.js +126 -0
  157. package/legacy/es5/modules/html-builder.js +461 -0
  158. package/legacy/es5/modules/layout.js +1679 -0
  159. package/legacy/es5/modules/mouse.js +124 -0
  160. package/legacy/es5/modules/nav-link.js +123 -0
  161. package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  162. package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  163. package/legacy/es5/modules/olderversions/base-animations.js +636 -0
  164. package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  165. package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  166. package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  167. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  168. package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  169. package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  170. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  171. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  172. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  173. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  174. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  175. package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  176. package/legacy/es5/modules/olderversions/event-update.js +666 -0
  177. package/legacy/es5/modules/olderversions/nav-link.js +119 -0
  178. package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  179. package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  180. package/legacy/es5/modules/prototypes/ajax.js +657 -0
  181. package/legacy/es5/modules/prototypes/atom.js +65 -0
  182. package/legacy/es5/modules/prototypes/component.js +972 -0
  183. package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  184. package/legacy/es5/modules/prototypes/data.js +1290 -0
  185. package/legacy/es5/modules/prototypes/html-builder.js +414 -0
  186. package/legacy/es5/modules/prototypes/layout.js +879 -0
  187. package/legacy/es5/modules/router.js +1680 -0
  188. package/legacy/es5/modules/state.js +274 -0
  189. package/package.json +8 -3
  190. package/update +16 -0
@@ -0,0 +1,701 @@
1
+ (function()
2
+ {
3
+ "use strict";
4
+
5
+ /*
6
+ router
7
+
8
+ this will add client side routing to allow routes to be
9
+ setup and the router to navigate and activate the routes
10
+ that match the uri.
11
+
12
+ @param (string) baseURI = the root of the router uri
13
+ @param (string) title = the root title
14
+ */
15
+ var router = function(baseURI, title)
16
+ {
17
+ /* this is the root of the uri for the routing object
18
+ and the base title */
19
+ this.baseURI = baseURI || '/';
20
+ this.title = (typeof title !== 'undefined')? title : '';
21
+
22
+ /* this will setup the router and check
23
+ to add the history support */
24
+ this.setup();
25
+ };
26
+
27
+ router.prototype =
28
+ {
29
+ constructor: router,
30
+
31
+ /* this will store each route added to the
32
+ router. */
33
+ routes: [],
34
+
35
+ /* this will be used to accessour history object */
36
+ history: null,
37
+
38
+ /* this will setup our child history object and
39
+ create a closure to allow our child to retain
40
+ the parents scope */
41
+ setupHistory: function()
42
+ {
43
+ var parent = this;
44
+
45
+ this.history =
46
+ {
47
+ /* this will check if the history api is supported
48
+ and enabled */
49
+ enabled: false,
50
+
51
+ locationId: 'base-app-router',
52
+
53
+ callBack: null,
54
+
55
+ /* this will check to add history support is
56
+ the browser supports it */
57
+ setup: function()
58
+ {
59
+ /* we want to check if history is enabled */
60
+ this.enabled = base.history.isSupported();
61
+
62
+ /* we want to check to add the history event listener
63
+ that will check the popsate events and select the
64
+ nav option by the history state object */
65
+ if(this.enabled === true)
66
+ {
67
+ this.callBackLink = base.bind(this, this.checkLink);
68
+ this.callBack = base.bind(this, this.checkHistoryState);
69
+ this.addEvent();
70
+ }
71
+ return this;
72
+ },
73
+
74
+ callBackLink: null,
75
+
76
+ checkLink: function(evt)
77
+ {
78
+ var target = evt.target || evt.srcElement;
79
+ var nodeName = target.nodeName.toLowerCase();
80
+ if(nodeName !== 'a')
81
+ {
82
+ /* this will check to get the parent to check
83
+ if the child is contained in a link */
84
+ target = target.parentNode;
85
+ nodeName = target.nodeName.toLowerCase();
86
+ if(nodeName !== 'a')
87
+ {
88
+ return true;
89
+ }
90
+ }
91
+
92
+ if(!base.data(target, 'cancel-route'))
93
+ {
94
+ if(!base.data(target, 'cancel-route'))
95
+ {
96
+ var href = target.getAttribute('href');
97
+ var path = href.replace(parent.baseURI, '');
98
+ parent.navigate(path);
99
+
100
+ evt.preventDefault();
101
+ evt.stopPropagation();
102
+ return false;
103
+ }
104
+ }
105
+ },
106
+
107
+ /* this will add an event history listener that will
108
+ trigger when the window history is changed */
109
+ addEvent: function()
110
+ {
111
+ base.on('click', document, this.callBackLink);
112
+
113
+ base.history.addEvent(this.callBack);
114
+ return this;
115
+ },
116
+
117
+ removeEvent: function()
118
+ {
119
+ base.off('click', document, this.callBackLink);
120
+
121
+ base.history.removeEvent(this.callBack);
122
+ return this;
123
+ },
124
+
125
+ checkHistoryState: function(evt)
126
+ {
127
+ /* we want to check if the event has a state and if the
128
+ state location is from the background */
129
+ var state = evt.state;
130
+ if(state && state.location === this.locationId)
131
+ {
132
+ base.preventDefault(evt);
133
+
134
+ parent.checkActiveRoutes(state.uri);
135
+ }
136
+ },
137
+
138
+ createStateObject: function(uri, data)
139
+ {
140
+ var stateObj = {
141
+ location: this.locationId,
142
+ uri: uri
143
+ };
144
+
145
+ if(data && typeof data === 'object')
146
+ {
147
+ stateObj = base.extendObject(stateObj, data);
148
+ }
149
+
150
+ return stateObj;
151
+ },
152
+
153
+ addState: function(uri, data, replace)
154
+ {
155
+ if(this.enabled === true)
156
+ {
157
+ uri = parent.createURI(uri);
158
+
159
+ var lastState = window.history.state;
160
+ var stateObj = this.createStateObject(uri, data);
161
+
162
+ /* we want to check if the object is not already
163
+ the last saved state */
164
+ if(!lastState || lastState.uri !== uri)
165
+ {
166
+ /* this will check to push state or
167
+ replace state */
168
+ replace = replace === true? true : false;
169
+ var method = (replace === false)? 'pushState' : 'replaceState';
170
+ history[method](stateObj, null, uri);
171
+ }
172
+ }
173
+
174
+ parent.activate();
175
+ return this;
176
+ }
177
+ };
178
+
179
+ this.history.setup();
180
+ },
181
+
182
+ /* this will add a route to the router.
183
+ @param (string) uri = the route uri
184
+ @param (string) template = the template name
185
+ @param [(function)] callBack = the call back function
186
+ @param [(string)] title = the route title
187
+ @param [(string)] id = the route id
188
+ @return (object) reference to the object */
189
+ add: function(uri, template, callBack, title, id)
190
+ {
191
+ if(typeof uri === 'string')
192
+ {
193
+ /* this will setup the route uri string to be used in
194
+ a regexp match.
195
+ @param (string) uri = the route uri
196
+ @return (string) the uri to be used in a regexp match */
197
+ var setupMatch = function(uri)
198
+ {
199
+ var uriQuery = "";
200
+ if(uri)
201
+ {
202
+ /* we want to setup the wild card and param
203
+ checks to be modified to the route uri string */
204
+ var allowAll = /(\*)/g,
205
+ param = /(:[^\/]*)/g,
206
+ optionalParams = /(\?\/+\*?)/g,
207
+ optionalSlash = /(\/):[^\/]*?\?/g,
208
+ filter = /\//g;
209
+ uriQuery = uri.replace(filter, "\/").replace(allowAll, '.*');
210
+
211
+ /* this will setup for optional slashes before the optional params */
212
+ uriQuery = uriQuery.replace(optionalSlash, function(str)
213
+ {
214
+ var pattern = /\//g;
215
+ return str.replace(pattern, '\/*');
216
+ });
217
+
218
+ /* this will setup for optional params and params
219
+ and stop at the last slash or query start */
220
+ uriQuery = uriQuery.replace(optionalParams, '?\/*').replace(param, '([^\/|?]*)');
221
+ }
222
+
223
+ /* we want to set and string end if the wild card is not set */
224
+ uriQuery += (uri[uri.length - 1] === '*')? '' : '$';
225
+ return uriQuery;
226
+ };
227
+
228
+ /* this will get the param names from the route uri.
229
+ @param (string) uri = the route uri
230
+ @return (array) an array with the param keys */
231
+ var setupParamKeys = function(uri)
232
+ {
233
+ var params = [];
234
+ if(uri)
235
+ {
236
+ var pattern = /:(.[^\/]*)/g,
237
+ matches = uri.match(pattern);
238
+ if(matches)
239
+ {
240
+ for(var i = 0, maxLength = matches.length; i < maxLength; i++)
241
+ {
242
+ var param = matches[i];
243
+ if(param)
244
+ {
245
+ pattern = /(:|\?)/g;
246
+ var filter = /\*/g;
247
+ /* we need to remove the colon, question mark, or asterisk
248
+ from the key name */
249
+ param = param.replace(pattern, '').replace(filter, '');
250
+ params.push(param);
251
+ }
252
+ }
253
+ }
254
+ }
255
+ return params;
256
+ };
257
+
258
+ /* we need to format the uri and setup the uri query
259
+ reg exp that is used to check the route */
260
+ uri = this.removeSlashes(uri);
261
+ var uriQuery = '^' + this.createURI(setupMatch(uri));
262
+ var routes = this.routes;
263
+
264
+ var route =
265
+ {
266
+ uri: uri,
267
+ template: template,
268
+ component: '',
269
+ callBack: callBack,
270
+ title: title,
271
+ uriQuery: uriQuery,
272
+ paramKeys: setupParamKeys(uri),
273
+ params: null,
274
+ id: id || 'bs-rte-' + routes.length,
275
+ setup: false
276
+ };
277
+ routes.push(route);
278
+ }
279
+ return this;
280
+ },
281
+
282
+ /* this will get a route by the route settings.
283
+ @param (string) uri = the route uri
284
+ @param (string) template = the template name
285
+ @param [(function)] callBack = the call back function
286
+ @return (mixed) the routeobject or false on error */
287
+ getRoute: function(uri, template, callBack)
288
+ {
289
+ var routes = this.routes,
290
+ length = routes.length;
291
+ if(length)
292
+ {
293
+ for(var i = 0; i < length; i++)
294
+ {
295
+ var route = routes[i];
296
+ if(route.uri === uri && route.template === template && route.callBack === callBack)
297
+ {
298
+ return route;
299
+ }
300
+ }
301
+ }
302
+ return false;
303
+ },
304
+
305
+ /* this will remove a route from the router by the route settings.
306
+ @param (string) uri = the route uri
307
+ @param (string) template = the template name
308
+ @param [(function)] callBack = the call back function
309
+ @return (object) reference to the object */
310
+ remove: function(uri, template, callBack)
311
+ {
312
+ uri = this.removeSlashes(uri);
313
+ var route = this.getRoute(uri, template, callBack);
314
+ if(route)
315
+ {
316
+ var index = base.inArray(this.routes, route);
317
+ if(index > -1)
318
+ {
319
+ this.routes.splice(index, 1);
320
+ }
321
+ }
322
+ return this;
323
+ },
324
+
325
+ /* this will setup the history object
326
+ @return (object) reference to the object */
327
+ setup: function()
328
+ {
329
+ this.setupHistory();
330
+
331
+ /* this will route to the first url entered
332
+ when the router loads. this will fix the issue
333
+ that stopped the first endpoint from being
334
+ added to the history */
335
+ var endPoint = this.getEndPoint() || '/';
336
+ this.navigate(endPoint, null, true);
337
+ return this;
338
+ },
339
+
340
+ /* this will reset the router
341
+ @return (object) reference to the object */
342
+ reset: function()
343
+ {
344
+ this.routes = [];
345
+ return this;
346
+ },
347
+
348
+ /* this will activate any active routes
349
+ @return (object) reference to the object */
350
+ activate: function()
351
+ {
352
+ this.checkActiveRoutes();
353
+ return this;
354
+ },
355
+
356
+ /* this will navigate the router to the uri.
357
+ @param (string) uri = the relative uri
358
+ @param [(object)] data = a data object that will
359
+ be added to the history state object
360
+ @param [(bool)] replace = settrue to replace state
361
+ @return (object) a reference to the router object */
362
+ navigate: function(uri, data, replace)
363
+ {
364
+ this.history.addState(uri, data, replace);
365
+ return this;
366
+ },
367
+
368
+ /* this will update the window title with the route title.
369
+ @param (object) route = a route that has a title
370
+ @return (object) a reference to the router object */
371
+ updateTitle: function(route)
372
+ {
373
+ if(route && route.title)
374
+ {
375
+ var title = route.title,
376
+ parent = this;
377
+
378
+ var getTitle = function(title)
379
+ {
380
+
381
+ /* this will uppercase each word in a string
382
+ @param (string) str = the string to uppercase
383
+ @return (string) the uppercase string */
384
+ var toTitleCase = function(str)
385
+ {
386
+ var pattern = /\w\S*/;
387
+ return str.replace(pattern, function(txt)
388
+ {
389
+ return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
390
+ });
391
+ };
392
+
393
+ /* this will replace the params in the title
394
+ @param (string) str = the route title
395
+ @return (string) the title string */
396
+ var replaceParams = function(str)
397
+ {
398
+ if(str.indexOf(':') > -1)
399
+ {
400
+ var params = route.params;
401
+ for(var prop in params)
402
+ {
403
+ if(params.hasOwnProperty(prop) === true)
404
+ {
405
+ var param = params[prop];
406
+ var pattern = new RegExp(':' + prop, 'gi');
407
+ str = str.replace(pattern, param);
408
+ }
409
+ }
410
+ }
411
+ return str;
412
+ };
413
+
414
+ if(title)
415
+ {
416
+ /* we want to replace any params in the title
417
+ and uppercase the title */
418
+ title = replaceParams(title);
419
+ var pattern = /-/g;
420
+ title = toTitleCase(title.replace(pattern, ' '));
421
+
422
+ /* we want to check to add the base title to the
423
+ to the end of the title */
424
+ if(parent.title != '')
425
+ {
426
+ title += " - " + parent.title;
427
+ }
428
+ }
429
+ return title;
430
+ };
431
+
432
+ document.title = getTitle(title);
433
+ }
434
+ return this;
435
+ },
436
+
437
+ /* this will get all active routes from a path.
438
+ @param [(string)] path = the path or the current
439
+ url path will be used
440
+ @return (array) an array of active routes */
441
+ checkActiveRoutes: function(path)
442
+ {
443
+ var active = [],
444
+ routes = this.routes,
445
+ length = routes.length;
446
+ if(length)
447
+ {
448
+ path = path || this.getPath();
449
+
450
+ for(var i = 0; i < length; i++)
451
+ {
452
+ var route = routes[i];
453
+ if(typeof route !== 'undefined')
454
+ {
455
+ var check = this.check(route, path);
456
+ if(check !== false)
457
+ {
458
+ active.push(route);
459
+
460
+ }
461
+ else
462
+ {
463
+ if(route.template && route.setup === true && route.component)
464
+ {
465
+ routeComponents.remove(route);
466
+ }
467
+ }
468
+ }
469
+ }
470
+ }
471
+ return active;
472
+ },
473
+
474
+ /* this will remove the begining and ending slashes on a url.
475
+ @param (string) uri = the uri to remove
476
+ @return (string) the uri */
477
+ removeSlashes: function(uri)
478
+ {
479
+ if(typeof uri === 'string')
480
+ {
481
+ var pattern = /(^\/|\/$)/g;
482
+ uri = uri.toString().replace(pattern, '');
483
+ }
484
+
485
+ return uri;
486
+ },
487
+
488
+ /* this will create a uri with the base path and
489
+ the route uri.
490
+ @param (string) uri = the uri
491
+ @return (string) the uri */
492
+ createURI: function(uri)
493
+ {
494
+ var pathURI = '';
495
+ if(this.baseURI !== '/')
496
+ {
497
+ pathURI += this.baseURI;
498
+ }
499
+ pathURI += ((pathURI[pathURI.length - 1] !== '/')? '/' : '') + this.removeSlashes(uri);
500
+
501
+ return pathURI;
502
+ },
503
+
504
+ /* this will check to select a route if it the route uri
505
+ matches the path.
506
+ @param (object) route = the route
507
+ @param [(string)] path = the path. if left null the
508
+ active path will beused
509
+ @return (bool) true or false if active */
510
+ check: function(route, path)
511
+ {
512
+ var matched = false;
513
+
514
+ /* we want to check to use the supplied uri or get the
515
+ current uri if not setup */
516
+ path = path || this.getPath();
517
+
518
+ /* we want to check if the route uri matches the path uri */
519
+ var validURI = this.match(route, path);
520
+ if(validURI)
521
+ {
522
+ matched = true;
523
+ this.select(route);
524
+ }
525
+ return matched;
526
+ },
527
+
528
+ /* this will match a route if it the route uri
529
+ matches the path.
530
+ @param (object) route = the route
531
+ @param [(string)] path = the path. if left null the
532
+ active path will beused
533
+ @return (bool) true or false if active */
534
+ match: function(route, path)
535
+ {
536
+ /* we want to check if the route has been
537
+ deleted from the routes */
538
+ if(!route)
539
+ {
540
+ return false;
541
+ }
542
+
543
+ /* this will get the param names from the route uri.
544
+ @param (string) paramKeys = the route param keys
545
+ @param (array) values = the path param values
546
+ @return (mixed) an empty object or an object with key
547
+ and values of the params */
548
+ var getParams = function(paramKeys, values)
549
+ {
550
+ var keys = paramKeys,
551
+ params = {};
552
+
553
+ if(values && typeof values === 'object')
554
+ {
555
+ /* we want to add the value to each key */
556
+ if(keys)
557
+ {
558
+ for(var i = 0, maxL = keys.length; i < maxL; i++)
559
+ {
560
+ var key = keys[i];
561
+ if(typeof key !== 'undefined')
562
+ {
563
+ params[key] = values[i];
564
+ }
565
+ }
566
+ }
567
+ }
568
+ return params;
569
+ };
570
+
571
+ var matched = false;
572
+
573
+ /* we want to check to use the supplied uri or get the
574
+ current uri if not setup */
575
+ path = path || this.getPath();
576
+
577
+ /* we need to setup the uri reg expression to match the
578
+ route uri to the path uri */
579
+ var routeURI = route.uriQuery;
580
+
581
+ /* we want to check if the route uri matches the path uri */
582
+ var validURI = path.match(routeURI);
583
+ if(validURI)
584
+ {
585
+ matched = true;
586
+
587
+ /* this will remove the first match from the
588
+ the params */
589
+ if(validURI && typeof validURI === 'object')
590
+ {
591
+ validURI.shift();
592
+ matched = validURI;
593
+ }
594
+
595
+ /* this will get the uri params of the route
596
+ and if set will save them to the route */
597
+ var params = getParams(route.paramKeys, validURI);
598
+ if(params)
599
+ {
600
+ route.params = params;
601
+ }
602
+ }
603
+ return matched;
604
+ },
605
+
606
+ /* this will get the param names from the route uri.
607
+ @param (object) route = the route object */
608
+ select: function(route)
609
+ {
610
+ if(route)
611
+ {
612
+ var params = (route.params)? route.params : null;
613
+ if(typeof route.callBack === 'function')
614
+ {
615
+ route.callBack.call({}, params);
616
+ }
617
+
618
+ if(route.template)
619
+ {
620
+ /* this will check to setup the component if
621
+ the component has notbeen setup */
622
+ if(!route.component && route.setup === false)
623
+ {
624
+ routeComponents.create(route);
625
+ }
626
+
627
+ routeComponents.update(route);
628
+ }
629
+
630
+ this.updateTitle(route);
631
+ }
632
+ },
633
+
634
+ /* this will return the set endpoint not including the
635
+ base uri.
636
+ @return (string) the last endpoint */
637
+ getEndPoint: function()
638
+ {
639
+ var path = this.getPath();
640
+ return path.replace(this.baseURI, '');
641
+ },
642
+
643
+ /* this will get the location pathname.
644
+ @return (string) the location pathname */
645
+ getPath: function()
646
+ {
647
+ /* we want to get the window location path */
648
+ return window.location.pathname;
649
+ }
650
+ };
651
+
652
+ var routeComponents =
653
+ {
654
+ /* this will create and setup a component
655
+ from a route template.
656
+ @param (object) route */
657
+ create: function(route)
658
+ {
659
+ route.setup = true;
660
+
661
+ if(route.template)
662
+ {
663
+ var template = window[route.template];
664
+ if(template)
665
+ {
666
+ var comp = route.component = new template();
667
+ comp.setup();
668
+ }
669
+ }
670
+ },
671
+
672
+ /* this will remove a route component
673
+ @param (object) route */
674
+ remove: function(route)
675
+ {
676
+ route.setup = false;
677
+
678
+ var component = route.component;
679
+ if(component)
680
+ {
681
+ if(typeof component.destroy === 'function')
682
+ {
683
+ component.destroy();
684
+ }
685
+ route.component = null;
686
+ }
687
+ },
688
+
689
+ update: function(route)
690
+ {
691
+ var component = route.component;
692
+ if(component && typeof component.update === 'function')
693
+ {
694
+ component.update(route.params);
695
+ }
696
+ }
697
+ };
698
+
699
+ base.extend.router = router;
700
+
701
+ })();