@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,701 +0,0 @@
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
- })();