mpa-enhancer
Advanced tools
Comparing version 2.2.1 to 2.2.2
@@ -46,4 +46,4 @@ // @ts-check | ||
data[pageName] = { | ||
elY: target?.getBoundingClientRect().top, | ||
y: w.scrollY, | ||
height: doc.body.scrollHeight, | ||
active: { | ||
@@ -61,3 +61,3 @@ id: target?.id, | ||
if (!location) return | ||
let { y, height, active: { id, name } } = location | ||
let { y, elY, active: { id, name } } = location | ||
@@ -73,3 +73,7 @@ let active = | ||
if (!hasAttr(doc.body, 'mpa-skip-scroll') && y) { | ||
w.scrollTo({ top: y + doc.body.scrollHeight - height }) | ||
if (active) { | ||
w.scrollTo({ top: w.scrollY + active.getBoundingClientRect().top - elY }) | ||
} else { | ||
w.scrollTo({ top: y }) | ||
} | ||
} | ||
@@ -99,1 +103,2 @@ } | ||
{ | ||
"name": "mpa-enhancer", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Minimalist JavaScript to make your MPA work that much better", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -53,2 +53,6 @@ # MPA Enhancer | ||
**2.2.2** | ||
Improved scrolling location. | ||
**2.2.1** | ||
@@ -55,0 +59,0 @@ |
@@ -46,4 +46,4 @@ // @ts-check | ||
data[pageName] = { | ||
elY: target?.getBoundingClientRect().top, | ||
y: w.scrollY, | ||
height: doc.body.scrollHeight, | ||
active: { | ||
@@ -61,3 +61,3 @@ id: target?.id, | ||
if (!location) return | ||
let { y, height, active: { id, name } } = location | ||
let { y, elY, active: { id, name } } = location | ||
@@ -73,3 +73,7 @@ let active = | ||
if (!hasAttr(doc.body, 'mpa-skip-scroll') && y) { | ||
w.scrollTo({ top: y + doc.body.scrollHeight - height }) | ||
if (active) { | ||
w.scrollTo({ top: w.scrollY + active.getBoundingClientRect().top - elY }) | ||
} else { | ||
w.scrollTo({ top: y }) | ||
} | ||
} | ||
@@ -99,1 +103,2 @@ } | ||
@@ -1,1 +0,1 @@ | ||
(()=>{let a=document,l=window,u=a.querySelector.bind(a);function o(e,t){return e?.hasAttribute(t)}function s(){let e=a.body.getAttribute("mpa-page-name");return e||new URL(a.location.href).pathname.replace(/\/$/,"")}let d=null;l.addEventListener("click",e=>{d=e.target}),l.addEventListener("unload",()=>{let e=f()||{},t=new Set(e.__||[]),n=s();o(a.body,"mpa-persist")&&(t.add(n),e.__=Array.from(t));for(let i in Object.keys(e))t.has(i)||i==="__"||delete e[i];let c=a.activeElement,r=a.activeElement===a.body?d:c;e[n]={y:l.scrollY,height:a.body.scrollHeight,active:{id:r?.id,name:r?.getAttribute("name")}},localStorage.pageLocations=JSON.stringify(e)});function p(){if(u("[autofocus]"))return;let e=f(s());if(!e)return;let{y:t,height:n,active:{id:c,name:r}}=e,i=a.getElementById(c)||u(`[name="${r}"]`);o(i,"mpa-skip-focus")||(g("focus",i),g("select",i)),!o(a.body,"mpa-skip-scroll")&&t&&l.scrollTo({top:t+a.body.scrollHeight-n})}function g(e,t){t&&t[e]&&t[e]()}function f(e){let t=localStorage.pageLocations;return t=t&&JSON.parse(t),e==null?t:t&&t[e]}p()})(); | ||
(()=>{let a=document,n=window,u=a.querySelector.bind(a);function r(e,t){return e?.hasAttribute(t)}function s(){let e=a.body.getAttribute("mpa-page-name");return e||new URL(a.location.href).pathname.replace(/\/$/,"")}let d=null;n.addEventListener("click",e=>{d=e.target}),n.addEventListener("unload",()=>{let e=f()||{},t=new Set(e.__||[]),o=s();r(a.body,"mpa-persist")&&(t.add(o),e.__=Array.from(t));for(let l in Object.keys(e))t.has(l)||l==="__"||delete e[l];let c=a.activeElement,i=a.activeElement===a.body?d:c;e[o]={elY:i?.getBoundingClientRect().top,y:n.scrollY,active:{id:i?.id,name:i?.getAttribute("name")}},localStorage.pageLocations=JSON.stringify(e)});function p(){if(u("[autofocus]"))return;let e=f(s());if(!e)return;let{y:t,elY:o,active:{id:c,name:i}}=e,l=a.getElementById(c)||u(`[name="${i}"]`);r(l,"mpa-skip-focus")||(g("focus",l),g("select",l)),!r(a.body,"mpa-skip-scroll")&&t&&(l?n.scrollTo({top:n.scrollY+l.getBoundingClientRect().top-o}):n.scrollTo({top:t}))}function g(e,t){t&&t[e]&&t[e]()}function f(e){let t=localStorage.pageLocations;return t=t&&JSON.parse(t),e==null?t:t&&t[e]}p()})(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46078
1456
80