mpa-enhancer
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -22,4 +22,10 @@ // @ts-check | ||
let lastClick = null | ||
w.addEventListener('click', e => { | ||
lastClick = e.target | ||
}) | ||
w.addEventListener('beforeunload', () => { | ||
let active = doc.activeElement | ||
let target = doc.activeElement === doc.body ? lastClick : active | ||
localStorage.pageLocation = JSON.stringify({ | ||
@@ -30,4 +36,4 @@ href: getCleanUrlPath(), | ||
active: { | ||
id: active?.id, | ||
name: active?.getAttribute('name') | ||
id: target?.id, | ||
name: target?.getAttribute('name') | ||
} | ||
@@ -68,1 +74,2 @@ }) | ||
})() | ||
{ | ||
"name": "mpa-enhancer", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Minimalist JavaScript to make your MPA work that much better", | ||
@@ -13,3 +13,3 @@ "main": "src/mpa.js", | ||
"clean": "rm -rf docs/todo", | ||
"build": "npm run clean && npm run make-dirs && npm run static && esbuild --format=esm --outdir=docs/todo --bundle ./src-todo/sw.ts", | ||
"build": "npm run clean && npm run make-dirs && npm run static && esbuild --format=esm --outdir=docs/todo --bundle ./src-todo/sw.ts && npm run build-mpa", | ||
"build-mpa": "npx esbuild src/mpa.js --minify --outfile=src/mpa.min.js" | ||
@@ -16,0 +16,0 @@ }, |
@@ -14,2 +14,7 @@ # MPA Enhancer | ||
**2.1.0**: | ||
When an element is hidden before reload still collect its information before | ||
reload and use that instead of the `body` element. | ||
**2.0.0**: | ||
@@ -16,0 +21,0 @@ |
@@ -22,4 +22,10 @@ // @ts-check | ||
let lastClick = null | ||
w.addEventListener('click', e => { | ||
lastClick = e.target | ||
}) | ||
w.addEventListener('beforeunload', () => { | ||
let active = doc.activeElement | ||
let target = doc.activeElement === doc.body ? lastClick : active | ||
localStorage.pageLocation = JSON.stringify({ | ||
@@ -30,4 +36,4 @@ href: getCleanUrlPath(), | ||
active: { | ||
id: active?.id, | ||
name: active?.getAttribute('name') | ||
id: target?.id, | ||
name: target?.getAttribute('name') | ||
} | ||
@@ -68,1 +74,2 @@ }) | ||
})() | ||
@@ -1,1 +0,1 @@ | ||
(()=>{let t=document,n=window,a=t.querySelector.bind(t);function i(e,o){return e.hasAttribute(o)}function l(){return new URL(t.location.href).pathname.replace(/\/$/,"")}n.addEventListener("beforeunload",()=>{let e=t.activeElement;localStorage.pageLocation=JSON.stringify({href:l(),y:n.scrollY,height:t.body.scrollHeight,active:{id:e?.id,name:e?.getAttribute("name")}})});function u(){if(a("[autofocus]"))return;let e=localStorage.pageLocation;if(!e)return;let{y:o,height:f,href:s,active:{id:d,name:g}}=JSON.parse(e),r=t.getElementById(d)||a(`[name="${g}"]`);!r||i(r,"mpa-skip-focus")||(c("focus",r),c("select",r),!i(t.body,"mpa-skip-scroll")&&s===l()&&o&&n.scrollTo({top:o+t.body.scrollHeight-f}))}function c(e,o){o[e]&&o[e]()}u()})(); | ||
(()=>{let t=document,a=window,r=t.querySelector.bind(t);function i(e,l){return e.hasAttribute(l)}function o(){return new URL(t.location.href).pathname.replace(/\/$/,"")}let c=null;a.addEventListener("click",e=>{c=e.target}),a.addEventListener("beforeunload",()=>{let e=t.activeElement,l=t.activeElement===t.body?c:e;localStorage.pageLocation=JSON.stringify({href:o(),y:a.scrollY,height:t.body.scrollHeight,active:{id:l?.id,name:l?.getAttribute("name")}})});function s(){if(r("[autofocus]"))return;let e=localStorage.pageLocation;if(!e)return;let{y:l,height:d,href:f,active:{id:g,name:h}}=JSON.parse(e),n=t.getElementById(g)||r(`[name="${h}"]`);!n||i(n,"mpa-skip-focus")||(u("focus",n),u("select",n),!i(t.body,"mpa-skip-scroll")&&f===o()&&l&&a.scrollTo({top:l+t.body.scrollHeight-d}))}function u(e,l){l[e]&&l[e]()}s()})(); |
43078
1407
25