@lexriver/dome 1.5.0 → 1.5.3
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/out/DomeRouter.js +16 -5
- package/package.json +1 -1
- package/src/DomeRouter.ts +18 -5
package/out/DomeRouter.js
CHANGED
|
@@ -8,8 +8,9 @@ export var DomeRouter;
|
|
|
8
8
|
let onNotFoundAction = undefined;
|
|
9
9
|
window.addEventListener('popstate', async (e) => {
|
|
10
10
|
// on go back
|
|
11
|
-
|
|
11
|
+
console.log(filename, 'window.popstate event', e, 'historyUrls=', historyUrls);
|
|
12
12
|
const url = window.location.pathname;
|
|
13
|
+
addUrlToHistory(url);
|
|
13
14
|
await executeAsync(url, getScrollPositionForUrl(url));
|
|
14
15
|
// await DomeManipulator.scrollToAsync({
|
|
15
16
|
// pxFromTop: getScrollPositionForUrl(window.location.pathname)
|
|
@@ -17,13 +18,21 @@ export var DomeRouter;
|
|
|
17
18
|
});
|
|
18
19
|
function getScrollPositionForUrl(url) {
|
|
19
20
|
// well, let's find the last url? or which index?
|
|
20
|
-
let result = 0
|
|
21
|
-
for (let
|
|
21
|
+
//let result = 0
|
|
22
|
+
for (let i = historyUrls.length - 1; i >= 0; i--) {
|
|
23
|
+
const item = historyUrls[i];
|
|
22
24
|
if (item.url === url) {
|
|
23
|
-
result = item.scroll
|
|
25
|
+
//result = item.scroll
|
|
26
|
+
return item.scroll;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
return
|
|
29
|
+
return 0;
|
|
30
|
+
// for(let item of historyUrls){
|
|
31
|
+
// if(item.url === url){
|
|
32
|
+
// result = item.scroll
|
|
33
|
+
// }
|
|
34
|
+
// }
|
|
35
|
+
// return result
|
|
27
36
|
}
|
|
28
37
|
function navigate(url) {
|
|
29
38
|
window.history.pushState(null, '', url);
|
|
@@ -56,6 +65,8 @@ export var DomeRouter;
|
|
|
56
65
|
if (historyUrls.length > 1) {
|
|
57
66
|
historyUrls[historyUrls.length - 2].scroll = DomeManipulator.getCurrentScrollPosition();
|
|
58
67
|
}
|
|
68
|
+
console.log('adding url to history', url);
|
|
69
|
+
console.log('historyUrls=', historyUrls);
|
|
59
70
|
}
|
|
60
71
|
function getCurrentUrl() {
|
|
61
72
|
return historyUrls.length > 0 ? historyUrls[historyUrls.length - 1] : window.location.pathname;
|
package/package.json
CHANGED
package/src/DomeRouter.ts
CHANGED
|
@@ -27,8 +27,9 @@ export module DomeRouter {
|
|
|
27
27
|
|
|
28
28
|
window.addEventListener('popstate', async (e) => {
|
|
29
29
|
// on go back
|
|
30
|
-
|
|
30
|
+
console.log(filename, 'window.popstate event', e, 'historyUrls=', historyUrls)
|
|
31
31
|
const url = window.location.pathname
|
|
32
|
+
addUrlToHistory(url)
|
|
32
33
|
await executeAsync(url, getScrollPositionForUrl(url) )
|
|
33
34
|
// await DomeManipulator.scrollToAsync({
|
|
34
35
|
// pxFromTop: getScrollPositionForUrl(window.location.pathname)
|
|
@@ -37,13 +38,22 @@ export module DomeRouter {
|
|
|
37
38
|
|
|
38
39
|
function getScrollPositionForUrl(url:string){
|
|
39
40
|
// well, let's find the last url? or which index?
|
|
40
|
-
let result = 0
|
|
41
|
-
for(let
|
|
41
|
+
//let result = 0
|
|
42
|
+
for(let i=historyUrls.length-1;i>=0;i--){
|
|
43
|
+
const item = historyUrls[i]
|
|
42
44
|
if(item.url === url){
|
|
43
|
-
result = item.scroll
|
|
45
|
+
//result = item.scroll
|
|
46
|
+
return item.scroll
|
|
47
|
+
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
return
|
|
50
|
+
return 0
|
|
51
|
+
// for(let item of historyUrls){
|
|
52
|
+
// if(item.url === url){
|
|
53
|
+
// result = item.scroll
|
|
54
|
+
// }
|
|
55
|
+
// }
|
|
56
|
+
// return result
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
export function navigate(url:string){
|
|
@@ -78,6 +88,9 @@ export module DomeRouter {
|
|
|
78
88
|
if(historyUrls.length>1){
|
|
79
89
|
historyUrls[historyUrls.length-2].scroll = DomeManipulator.getCurrentScrollPosition()
|
|
80
90
|
}
|
|
91
|
+
|
|
92
|
+
console.log('adding url to history', url)
|
|
93
|
+
console.log('historyUrls=', historyUrls)
|
|
81
94
|
}
|
|
82
95
|
|
|
83
96
|
|