dothtml 4.8.5 → 5.0.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.
- package/{jest.config.js → jest.config.ts} +19 -16
- package/lib/arg-callback-obj.d.ts +29 -0
- package/lib/built-in-components/nav-link.d.ts +8 -0
- package/lib/built-in-components/router.d.ts +57 -0
- package/lib/component.d.ts +73 -0
- package/lib/dot-component-legacy.d.ts +0 -0
- package/lib/dot-document.d.ts +0 -0
- package/lib/dot-util.d.ts +13 -0
- package/lib/dot.d.ts +5 -0
- package/lib/dothtml.d.ts +21 -0
- package/lib/dothtml.js +2 -0
- package/lib/dothtml.js.LICENSE.txt +1 -0
- package/lib/err.d.ts +2 -0
- package/lib/event-bus.d.ts +10 -0
- package/lib/i-dot.d.ts +674 -0
- package/lib/i-dotcss.d.ts +827 -0
- package/lib/node-polyfill.d.ts +2 -0
- package/lib/observable-array.d.ts +49 -0
- package/lib/style-builder.d.ts +3 -0
- package/package.json +11 -5
- package/readme.md +3 -2
- package/src/{arg-callback-obj.js → arg-callback-obj.ts} +18 -6
- package/src/built-in-components/nav-link.ts +21 -0
- package/src/built-in-components/router.ts +315 -0
- package/src/component.ts +369 -0
- package/src/dot-component-legacy.ts +79 -0
- package/src/dot-document.ts +0 -0
- package/src/dot-util.ts +33 -0
- package/src/dot.ts +1147 -0
- package/src/dothtml.ts +33 -0
- package/src/err.ts +22 -0
- package/src/event-bus.ts +39 -0
- package/src/i-dot.ts +787 -0
- package/src/i-dotcss.ts +918 -0
- package/src/node-polyfill.ts +11 -0
- package/src/{observable-array.js → observable-array.ts} +10 -5
- package/src/{style-builder.js → style-builder.ts} +219 -183
- package/tsconfig.json +99 -0
- package/unittests/advanced-bindings.test.ts +421 -0
- package/unittests/{array-evaluation.test.js → array-evaluation.test.ts} +1 -1
- package/unittests/{basic-functionality.test.js → basic-functionality.test.ts} +14 -10
- package/unittests/class-binding.test.ts +227 -0
- package/unittests/component-decorator.-.ts +14 -0
- package/unittests/components-data.test.ts +153 -0
- package/unittests/components.test.ts +257 -0
- package/unittests/computed.test.ts +35 -0
- package/unittests/{core.js → core.ts} +5 -2
- package/unittests/element-and-attribute-coverage.test.ts +472 -0
- package/unittests/hooks.test.ts +67 -0
- package/unittests/immutable-if.test.ts +19 -0
- package/unittests/input-bindings.test.ts +166 -0
- package/unittests/integration.test.ts +5 -0
- package/unittests/{iterations.test.js → iterations.test.ts} +5 -5
- package/unittests/logic.test.ts +18 -0
- package/unittests/refs.test.ts +36 -0
- package/unittests/routing.-.ts +56 -0
- package/unittests/{scopes.test.js → scopes.test.ts} +5 -5
- package/unittests/special-tags.test.ts +39 -0
- package/unittests/styles.test.ts +9 -0
- package/unittests/{testpage.js → testpage.ts} +2 -0
- package/unittests/{wait.test.js → wait.test.ts} +8 -5
- package/webpack.config.js +13 -1
- package/lib/dothtml.min.js +0 -1
- package/src/component.js +0 -305
- package/src/err.js +0 -20
- package/src/event-bus.js +0 -40
- package/src/index.js +0 -1453
- package/src/util.js +0 -13
- package/unittests/advanced-bindings.test.js +0 -386
- package/unittests/class-binding.test.js +0 -53
- package/unittests/components-data.test.js +0 -97
- package/unittests/components.test.js +0 -151
- package/unittests/computed.test.js +0 -36
- package/unittests/hooks.test.js +0 -57
- package/unittests/immutable-if.test.js +0 -15
- package/unittests/input-bindings.test.js +0 -155
- package/unittests/integration.test.js +0 -6
- package/unittests/logic.test.js +0 -18
- package/unittests/routing.-.js +0 -56
- package/unittests/special-tags.test.js +0 -32
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default function ObservableArray(items: any): void;
|
|
2
|
+
/**
|
|
3
|
+
|
|
4
|
+
(function testing() {
|
|
5
|
+
|
|
6
|
+
var x = new ObservableArray(["a", "b", "c", "d"]);
|
|
7
|
+
|
|
8
|
+
console.log("original array: %o", x.slice());
|
|
9
|
+
|
|
10
|
+
x.addEventListener("itemadded", function(e) {
|
|
11
|
+
console.log("Added %o at index %d.", e.item, e.index);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
x.addEventListener("itemset", function(e) {
|
|
15
|
+
console.log("Set index %d to %o.", e.index, e.item);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
x.addEventListener("itemremoved", function(e) {
|
|
19
|
+
console.log("Removed %o at index %d.", e.item, e.index);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
console.log("popping and unshifting...");
|
|
23
|
+
x.unshift(x.pop());
|
|
24
|
+
|
|
25
|
+
console.log("updated array: %o", x.slice());
|
|
26
|
+
|
|
27
|
+
console.log("reversing array...");
|
|
28
|
+
console.log("updated array: %o", x.reverse().slice());
|
|
29
|
+
|
|
30
|
+
console.log("splicing...");
|
|
31
|
+
x.splice(1, 2, "x");
|
|
32
|
+
console.log("setting index 2...");
|
|
33
|
+
x[2] = "foo";
|
|
34
|
+
|
|
35
|
+
console.log("setting length to 10...");
|
|
36
|
+
x.length = 10;
|
|
37
|
+
console.log("updated array: %o", x.slice());
|
|
38
|
+
|
|
39
|
+
console.log("setting length to 2...");
|
|
40
|
+
x.length = 2;
|
|
41
|
+
|
|
42
|
+
console.log("extracting first element via shift()");
|
|
43
|
+
x.shift();
|
|
44
|
+
|
|
45
|
+
console.log("updated array: %o", x.slice());
|
|
46
|
+
|
|
47
|
+
})();
|
|
48
|
+
|
|
49
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dothtml",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "DOThtml is a client-side framework for building single-page applications.",
|
|
5
|
-
"main": "lib/dothtml.
|
|
6
|
-
"dependencies": {},
|
|
5
|
+
"main": "lib/dothtml.js",
|
|
7
6
|
"devDependencies": {
|
|
8
7
|
"@babel/preset-env": "^7.14.5",
|
|
9
8
|
"@testing-library/jest-dom": "^5.13.0",
|
|
9
|
+
"copyfiles": "^2.4.1",
|
|
10
10
|
"esm": "^3.2.25",
|
|
11
11
|
"jest": "^27.0.6",
|
|
12
|
+
"ts-jest": "^27.1.4",
|
|
13
|
+
"ts-loader": "^9.2.8",
|
|
14
|
+
"typescript": "^4.6.3",
|
|
12
15
|
"webpack": "^5.49.0",
|
|
13
|
-
"webpack-cli": "^4.
|
|
16
|
+
"webpack-cli": "^4.9.2"
|
|
14
17
|
},
|
|
15
18
|
"scripts": {
|
|
16
|
-
"test": "
|
|
19
|
+
"test": "npm run build & jest",
|
|
17
20
|
"build": "webpack"
|
|
18
21
|
},
|
|
19
22
|
"repository": {
|
|
@@ -23,6 +26,9 @@
|
|
|
23
26
|
"keywords": [
|
|
24
27
|
"html",
|
|
25
28
|
"page",
|
|
29
|
+
"dynamic",
|
|
30
|
+
"javascript",
|
|
31
|
+
"typescript",
|
|
26
32
|
"web",
|
|
27
33
|
"builder",
|
|
28
34
|
"generation",
|
package/readme.md
CHANGED
|
@@ -5,7 +5,8 @@ This project is a work in progress with several phases:
|
|
|
5
5
|
1. Basic web building framework in JavaScript. ✅
|
|
6
6
|
2. Provide some JQuery-like syntax and functionality. ✅
|
|
7
7
|
3. Add routing and components. ✅
|
|
8
|
-
4. Bridge the gap between DOThtml and modern frameworks, like Vue.
|
|
9
|
-
5.
|
|
8
|
+
4. Bridge the gap between DOThtml and modern frameworks, like Vue. ✅
|
|
9
|
+
5. Lots of testing, tweaking, documentation. 🔲
|
|
10
|
+
6. Take over the world. 🔲
|
|
10
11
|
|
|
11
12
|
Special thanks to [dosy](https://www.npmjs.com/~dosy) for giving me the module on NPM. Please check out ViewFinderJs - [a remote isolated browser with co-browsing](https://github.com/i5ik/ViewFinderJS).
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
import { IDotDocument } from "./i-dot";
|
|
1
2
|
|
|
2
|
-
export class ArgCallback{
|
|
3
|
-
|
|
3
|
+
export abstract class ArgCallback{
|
|
4
|
+
el: Element;
|
|
5
|
+
f: (content?: any, index?: number)=>string;
|
|
6
|
+
|
|
7
|
+
constructor(element: Element, value: (content?: any, index?: number)=>string){
|
|
4
8
|
this.el = element;
|
|
5
9
|
this.f = value;
|
|
6
10
|
}
|
|
11
|
+
|
|
12
|
+
abstract updateContent(dot: IDotDocument, propVal?: any);
|
|
7
13
|
}
|
|
8
14
|
|
|
9
15
|
export class AttrArgCallback extends ArgCallback{
|
|
10
|
-
|
|
16
|
+
attr: string;
|
|
17
|
+
constructor(element: Element, attributeName: string, value: (content?: any)=>string){
|
|
11
18
|
super(element, value);
|
|
12
19
|
this.attr = attributeName;
|
|
13
20
|
}
|
|
@@ -18,16 +25,17 @@ export class AttrArgCallback extends ArgCallback{
|
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
export class ContentArgCallback extends ArgCallback{
|
|
21
|
-
constructor(element, content){
|
|
28
|
+
constructor(element: Element, content: ()=>string){
|
|
22
29
|
super(element, content);
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
updateContent(dot, propVal){
|
|
32
|
+
updateContent(dot, propVal: string){
|
|
26
33
|
dot(this.el).empty().h(this.f(propVal));
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
export class ArrayArgCallback extends ArgCallback{
|
|
38
|
+
dotTarget: IDotDocument;
|
|
31
39
|
constructor(dotTarget, content){
|
|
32
40
|
super(null, content);
|
|
33
41
|
this.dotTarget = dotTarget;
|
|
@@ -37,6 +45,10 @@ export class ArrayArgCallback extends ArgCallback{
|
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
export class ConditionalArgCallback extends ArgCallback{
|
|
48
|
+
startNode: Node;
|
|
49
|
+
endNode: Node;
|
|
50
|
+
condition: ()=>boolean | boolean;
|
|
51
|
+
lastValue: boolean;
|
|
40
52
|
constructor(startNode, endNode, content, condition){
|
|
41
53
|
super(null, content);
|
|
42
54
|
this.startNode = startNode;
|
|
@@ -61,4 +73,4 @@ export class ConditionalArgCallback extends ArgCallback{
|
|
|
61
73
|
}
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
|
-
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Component from "../component";
|
|
2
|
+
import dot from "../dot";
|
|
3
|
+
import { DotContent } from "../i-dot";
|
|
4
|
+
|
|
5
|
+
// TODO: make text and links mutable by making them properties.
|
|
6
|
+
export class NavLink extends Component{
|
|
7
|
+
content: DotContent;
|
|
8
|
+
hRef: string;
|
|
9
|
+
constructor(content: DotContent, href: string){
|
|
10
|
+
super();
|
|
11
|
+
this.content = content;
|
|
12
|
+
this.hRef = href;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
builder() {
|
|
16
|
+
return dot.a(this.content).hRef(this.hRef).onClick(e => {
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
dot.navigate(this.hRef);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
// ROUTING:
|
|
2
|
+
// TODO: Put this in the register hook for router.
|
|
3
|
+
|
|
4
|
+
import Component from "../component";
|
|
5
|
+
import dot from "../dot";
|
|
6
|
+
import ERR from "../err";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
interface RouterParams{
|
|
12
|
+
autoNavigate: boolean;
|
|
13
|
+
onNavigateInit: Function;
|
|
14
|
+
onError: Function;
|
|
15
|
+
onResponse: Function;
|
|
16
|
+
onComplete: Function;
|
|
17
|
+
routes: Array<{
|
|
18
|
+
path: string
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default class DotRouter extends Component{
|
|
23
|
+
|
|
24
|
+
// TODO: Test to make sure allRouters get cleared when a nested router gets deleted.
|
|
25
|
+
static allRouters: {[key: string]: DotRouter} = {};
|
|
26
|
+
static routerId = 1;
|
|
27
|
+
static mayRedirect = false;
|
|
28
|
+
|
|
29
|
+
static _get(url, success, fail){
|
|
30
|
+
var xhttp = new XMLHttpRequest();
|
|
31
|
+
xhttp.onreadystatechange = function() {
|
|
32
|
+
if(this.readyState == 4){
|
|
33
|
+
if (this.status == 200) {
|
|
34
|
+
success && success(this);
|
|
35
|
+
}
|
|
36
|
+
else{
|
|
37
|
+
fail && fail(this);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
xhttp.open("GET", url, true);
|
|
42
|
+
xhttp.send();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static routerEventSet = false;
|
|
46
|
+
static setupPopupFunction(){
|
|
47
|
+
!DotRouter.routerEventSet && (DotRouter.routerEventSet = true) ? window.onpopstate = function(e){
|
|
48
|
+
if(e.state){
|
|
49
|
+
dot.navigate(e.state.path, true);
|
|
50
|
+
document.title = e.state.pageTitle;
|
|
51
|
+
}
|
|
52
|
+
} : 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
id: number = 0;
|
|
56
|
+
outlet: Element = null;
|
|
57
|
+
navId: number = 0;
|
|
58
|
+
currentRoute: string = null;
|
|
59
|
+
currentParams: RouterParams = null;
|
|
60
|
+
params: RouterParams;
|
|
61
|
+
routesAndSegments: Array<{
|
|
62
|
+
path: string,
|
|
63
|
+
segments: string[]
|
|
64
|
+
}> = [];
|
|
65
|
+
|
|
66
|
+
constructor(params: RouterParams){
|
|
67
|
+
super();
|
|
68
|
+
this.params = params;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* TODO: convert to interface.
|
|
73
|
+
* @param {Object} params - Parameters.
|
|
74
|
+
* @param {Array.<{path: string, title: string, component: Object}>} params.routes - Array of routes.
|
|
75
|
+
* @param {boolean} params.autoNavigate - Router will automatically navigate when outlet is created.
|
|
76
|
+
* @param {Function} params.onNavigateInit - Occurs before any request is sent, and before the router outlet is emptied.
|
|
77
|
+
* @param {Function} params.onError - Occurs in the event of an HTTP error.
|
|
78
|
+
* @param {Function} params.onResponse - Occurs after a successful HTTP response, but before rendering.
|
|
79
|
+
* @param {Function} params.onComplete - Occurs after an uncancelled route completes without an error.
|
|
80
|
+
*/
|
|
81
|
+
builder() {
|
|
82
|
+
let t = this;
|
|
83
|
+
|
|
84
|
+
if(!t.params || !t.params.routes) ERR("R");;
|
|
85
|
+
t.routesAndSegments = t.params.routes.map(r => {
|
|
86
|
+
if(r.path === null || r.path === undefined) ERR("R");
|
|
87
|
+
return { path: r.path, segments: r.path.split("/") };
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
//t.navigate = function(p, nh, f){return routerNavigate.call(t, p, nh, f)};
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if(t.params.autoNavigate === undefined) t.params.autoNavigate = true;
|
|
94
|
+
var o = dot.el("dothtml-router");
|
|
95
|
+
t.outlet = o.getLast();
|
|
96
|
+
t.id = DotRouter.routerId++;
|
|
97
|
+
DotRouter.allRouters[t.id] = t;
|
|
98
|
+
// This use to be here, but not sure what the point of it is anymore. It's not used anywhere.
|
|
99
|
+
// t.outlet.dothtmlRouterId = t.id;
|
|
100
|
+
return o;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
registered(): void {
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
ready(): void {
|
|
108
|
+
// If there is a route left inside the route queue
|
|
109
|
+
DotRouter.setupPopupFunction();
|
|
110
|
+
|
|
111
|
+
// TODO: this method is messed up. Params might not be set when replaceState is called.
|
|
112
|
+
if(this.params.autoNavigate){
|
|
113
|
+
DotRouter.mayRedirect = true;
|
|
114
|
+
var params = this.navigate(window.location.pathname + (window.location.hash || ""), true);
|
|
115
|
+
DotRouter.mayRedirect = false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if(history.pushState) history.replaceState({"pageTitle":params.title || document.title, "path": params.path}, "", params.path);
|
|
119
|
+
else window.location.hash = params.path;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
deleting(): void {
|
|
123
|
+
delete DotRouter.allRouters[this.id];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
navigate(path: string, noHistory: boolean = false, force: boolean = false){
|
|
127
|
+
let t = this;
|
|
128
|
+
//console.log("NAVIGATING", path);
|
|
129
|
+
// Step 1: parse the path into a route queue:
|
|
130
|
+
path = path || "";
|
|
131
|
+
if(typeof path != "string") path = path + "";
|
|
132
|
+
var hashPath = path;
|
|
133
|
+
if(path.indexOf("#") != -1) hashPath = path.split("#")[1];
|
|
134
|
+
|
|
135
|
+
var hashParts = path.split("#");
|
|
136
|
+
var allQueues = [];
|
|
137
|
+
|
|
138
|
+
// Route navigating.
|
|
139
|
+
var routeQueue = hashParts[0].split("?")[0].split("/");
|
|
140
|
+
routeQueue[0] === "" ? routeQueue.shift() : 0;
|
|
141
|
+
allQueues.push(routeQueue);
|
|
142
|
+
|
|
143
|
+
// Hash navigating.
|
|
144
|
+
var tryHashQueue = hashParts.length > 1 ? hashParts[1].split("/") : null;
|
|
145
|
+
tryHashQueue ? ((tryHashQueue[0] === "" ? tryHashQueue.shift() : 0)) : 0;
|
|
146
|
+
tryHashQueue ? ((routeQueue.length > 1 ? allQueues.push(tryHashQueue) : allQueues.unshift(tryHashQueue))) : 0;
|
|
147
|
+
|
|
148
|
+
var cancel = false;
|
|
149
|
+
var navParams = {
|
|
150
|
+
cancel: function(){
|
|
151
|
+
cancel = true;
|
|
152
|
+
navParams.wasCancelled = true;
|
|
153
|
+
},
|
|
154
|
+
element: t.outlet,
|
|
155
|
+
httpResponse: null,
|
|
156
|
+
isNew: true,
|
|
157
|
+
params: null,
|
|
158
|
+
path: path,
|
|
159
|
+
title: null,
|
|
160
|
+
wasCancelled: false
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Step 2: determine the last router that is correctly loaded.
|
|
164
|
+
|
|
165
|
+
// var deepestRouter = null;
|
|
166
|
+
var bestRoute = null;
|
|
167
|
+
// Loop through the router stack from start to finish to find the deepest router and the best route to take.
|
|
168
|
+
// for(var i = 0; i < routerOutletStack.length; i++){
|
|
169
|
+
|
|
170
|
+
// var candidate = routerOutletStack[i];
|
|
171
|
+
// Find the an available route that matches.
|
|
172
|
+
// bestRoute = null;
|
|
173
|
+
for(var q in allQueues){
|
|
174
|
+
var Q = allQueues[q];
|
|
175
|
+
var rFound = false;
|
|
176
|
+
for(var r in t.routesAndSegments){
|
|
177
|
+
rFound = true;
|
|
178
|
+
var nextRoute = t.routesAndSegments[r];
|
|
179
|
+
var prms = {};
|
|
180
|
+
var rs = 0;
|
|
181
|
+
var ps = 0;
|
|
182
|
+
var lastRn = null;
|
|
183
|
+
while(1){
|
|
184
|
+
var rSn = nextRoute.segments[rs] || null;
|
|
185
|
+
var pSn = Q[ps] || null;
|
|
186
|
+
if(rSn === null && pSn === null) break;
|
|
187
|
+
if(rSn === null && pSn !== null || rSn !== null && pSn === null) {
|
|
188
|
+
rFound = false;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
if(rSn === null && lastRn == "*") rSn = "*";
|
|
192
|
+
|
|
193
|
+
if(rSn == pSn || rSn == "+" || rSn == "*"){ // It's the route, or it's a wildcard.
|
|
194
|
+
rs++;
|
|
195
|
+
}
|
|
196
|
+
else if(rSn.length > 2 && rSn.charAt(0) == "{" && rSn.charAt(rSn.length - 1) == "}"){ // It's a parameterized route.
|
|
197
|
+
rs++;
|
|
198
|
+
prms[rSn.substring(1, rSn.length - 1)] = pSn;
|
|
199
|
+
}
|
|
200
|
+
else if(lastRn != "*"){ // If the route doesn't match but the previous term was a super-wildcard, do nothing. Else, break.
|
|
201
|
+
rFound = false;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
ps++;
|
|
205
|
+
lastRn = rSn;
|
|
206
|
+
}
|
|
207
|
+
if(rFound){
|
|
208
|
+
bestRoute = nextRoute;
|
|
209
|
+
navParams.params = prms;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if(rFound){
|
|
214
|
+
if(Q == routeQueue) {
|
|
215
|
+
if(!history.pushState && DotRouter.mayRedirect) {
|
|
216
|
+
window.location.hash = path;
|
|
217
|
+
window.location.pathname = "/";
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
};
|
|
222
|
+
if(Q == tryHashQueue) {
|
|
223
|
+
path = hashPath;
|
|
224
|
+
navParams.path = path;
|
|
225
|
+
if(history.pushState) {
|
|
226
|
+
window.location.hash = "";
|
|
227
|
+
history.replaceState({"pageTitle":document.title, "path": path}, document.title, path);
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
navParams.isNew = !(!force && t.currentRoute == bestRoute && (!t.currentParams || t.currentParams == navParams.params || JSON.stringify(t.currentParams) === JSON.stringify(navParams.params)));
|
|
235
|
+
|
|
236
|
+
t.params.onNavigateInit && t.params.onNavigateInit(navParams);
|
|
237
|
+
|
|
238
|
+
if(!navParams.isNew || cancel) return navParams;
|
|
239
|
+
t.currentRoute = bestRoute;
|
|
240
|
+
t.currentParams = navParams.params;
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
var ro = t.outlet;
|
|
244
|
+
dot(ro).empty();
|
|
245
|
+
var navId = ++t.navId;
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
//if(deepestRouter == null) return this;
|
|
249
|
+
if(routeQueue.length == 0) return navParams;
|
|
250
|
+
if(bestRoute == null) return navParams;
|
|
251
|
+
|
|
252
|
+
navParams.title = bestRoute.title;
|
|
253
|
+
|
|
254
|
+
if(typeof bestRoute.component == "string"){
|
|
255
|
+
DotRouter._get(bestRoute.component, function(result){
|
|
256
|
+
var text = result.responseText;
|
|
257
|
+
navParams.httpResponse = result;
|
|
258
|
+
if(navId != t.navId) return navParams;
|
|
259
|
+
t.params.onResponse && t.params.onResponse(navParams);
|
|
260
|
+
if(cancel) return navParams;
|
|
261
|
+
if(bestRoute.component.split("?")[0].split("#")[0].toLowerCase().indexOf(".js") == bestRoute.component.length - 3){
|
|
262
|
+
try{
|
|
263
|
+
text = Function("var exports=null,module={},route=arguments[0];" + text + "\r\nreturn module.exports || exports;")(navParams);
|
|
264
|
+
}
|
|
265
|
+
catch(e){
|
|
266
|
+
//e.fileName = bestRoute.component;
|
|
267
|
+
console.error(e);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
dot(ro).h(text);
|
|
271
|
+
t.params.onComplete && t.params.onComplete(navParams);
|
|
272
|
+
}, function(result){
|
|
273
|
+
navParams.httpResponse = result;
|
|
274
|
+
t.params.onError && t.params.onError(navParams);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
else{
|
|
278
|
+
dot(ro).h(bestRoute.component.call(dot, navParams));
|
|
279
|
+
t.params.onComplete && t.params.onComplete(navParams);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return navParams;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Extend dot.
|
|
287
|
+
dot.navigate = function(path: string, noHistory: boolean = false, force: boolean = false){
|
|
288
|
+
|
|
289
|
+
DotRouter.setupPopupFunction();
|
|
290
|
+
|
|
291
|
+
var K = Object.keys(DotRouter.allRouters);
|
|
292
|
+
var lastNavParams: {[key: string]: unknown} = {};
|
|
293
|
+
var bestTitle = document.title;
|
|
294
|
+
for(var k = 0; k < K.length; k++){
|
|
295
|
+
var kk = K[k];
|
|
296
|
+
var r = DotRouter.allRouters[kk];
|
|
297
|
+
if(r) {
|
|
298
|
+
var currentNavParams = r.navigate(path, noHistory, force);
|
|
299
|
+
if(currentNavParams.isNew && !currentNavParams.wasCancelled){
|
|
300
|
+
lastNavParams = currentNavParams;
|
|
301
|
+
bestTitle = (lastNavParams.title as string) || bestTitle;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
try{
|
|
307
|
+
if(lastNavParams && !noHistory){
|
|
308
|
+
//if(history.replaceState) history.replaceState({"pageTitle":title, "path": path}, title, path);
|
|
309
|
+
if(history.pushState) history.pushState({"pageTitle":bestTitle, "path": lastNavParams.path}, bestTitle, (lastNavParams.path as string));
|
|
310
|
+
else window.location.hash = (lastNavParams.path as string);
|
|
311
|
+
}
|
|
312
|
+
}catch(e){}
|
|
313
|
+
|
|
314
|
+
return this;
|
|
315
|
+
}
|