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