mpa-enhancer
Advanced tools
Comparing version 2.2.6 to 2.3.0
@@ -61,2 +61,6 @@ // @ts-check | ||
let target = active === doc.body ? lastClick : active | ||
let mpaTarget = getAttr(target, 'mpa-target') | ||
if (mpaTarget) { | ||
target = query(mpaTarget) | ||
} | ||
let miss = getAttr(target?.closest('[mpa-miss]'), 'mpa-miss') | ||
@@ -133,1 +137,2 @@ let name = target?.getAttribute('name') | ||
@@ -167,6 +167,6 @@ // node_modules/idb-keyval/dist/index.js | ||
<li> | ||
<a id=link-all class="selected" href="?filter=all">All</a> | ||
<a class="selected" href="?filter=all">All</a> | ||
</li> | ||
<li><a id=link-active href="?filter=active">Active</a></li> | ||
<li><a id=link-completed href="?filter=completed">Completed</a></li> | ||
<li><a href="?filter=active">Active</a></li> | ||
<li><a href="?filter=completed">Completed</a></li> | ||
</ul> | ||
@@ -173,0 +173,0 @@ <!--Hidden if no completed items are left ↓ --> |
{ | ||
"name": "mpa-enhancer", | ||
"version": "2.2.6", | ||
"version": "2.3.0", | ||
"description": "Minimalist JavaScript to make your MPA work that much better", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -31,2 +31,12 @@ # MPA Enhancer | ||
`mpa-target`: This will target a different element instead of the active | ||
element. This is useful when the active element is hidden and so the top value | ||
is 0. | ||
```html | ||
<div id="my-id"> | ||
<input mpa-target="#my-id" type=hidden name=whatever> | ||
</div> | ||
``` | ||
`mpa-page-name`: This overrides the default page name (the pathname in your | ||
@@ -33,0 +43,0 @@ URL). Use it like so: |
@@ -75,6 +75,6 @@ import html from "html-template-tag-stream" | ||
<li> | ||
<a id=link-all class="selected" href="?filter=all">All</a> | ||
<a class="selected" href="?filter=all">All</a> | ||
</li> | ||
<li><a id=link-active href="?filter=active">Active</a></li> | ||
<li><a id=link-completed href="?filter=completed">Completed</a></li> | ||
<li><a href="?filter=active">Active</a></li> | ||
<li><a href="?filter=completed">Completed</a></li> | ||
</ul> | ||
@@ -81,0 +81,0 @@ <!--Hidden if no completed items are left ↓ --> |
@@ -61,2 +61,6 @@ // @ts-check | ||
let target = active === doc.body ? lastClick : active | ||
let mpaTarget = getAttr(target, 'mpa-target') | ||
if (mpaTarget) { | ||
target = query(mpaTarget) | ||
} | ||
let miss = getAttr(target?.closest('[mpa-miss]'), 'mpa-miss') | ||
@@ -133,1 +137,2 @@ let name = target?.getAttribute('name') | ||
@@ -1,1 +0,1 @@ | ||
(()=>{let l=document,n=window,o=l.querySelector.bind(l);function s(t,e){return t?.hasAttribute(e)}function f(t,e){return t?.getAttribute(e)}function m(){let t=f(l.body,"mpa-page-name");return t||new URL(l.location.href).pathname.replace(/\/$/,"")}let p=null;n.addEventListener("click",t=>{p=t.target});function u(t){return t?.getBoundingClientRect().top}n.addEventListener("unload",()=>{let t=y()||{},e=new Set(t.__||[]),r=m();s(l.body,"mpa-persist")&&(e.add(r),t.__=Array.from(e));for(let d in Object.keys(t))e.has(d)||d==="__"||delete t[d];let i=l.activeElement,a=i===l.body?p:i,c=f(a?.closest("[mpa-miss]"),"mpa-miss"),b=a?.getAttribute("name");t[r]={y:n.scrollY,a:{t:{y:u(a),q:a?.id&&`#${a.id}`||b&&`[name="${b}"]`},m:{y:u(o(c)),q:c}}},localStorage._mpa=JSON.stringify(t)});function q(){if(o("[autofocus]"))return;let t=y(m());if(!t)return;let{y:e,a:{t:r,m:i}}=t,a,c=r.q&&(a=o(r.q))?r.y:i.q&&(a=o(i.q))?i.y:0;s(a,"mpa-skip-focus")||(g("focus",a),g("select",a)),!s(l.body,"mpa-skip-scroll")&&e&&(a?n.scrollTo({top:n.scrollY+u(a)-c}):n.scrollTo({top:e}))}function g(t,e){e&&e[t]&&e[t]()}function y(t){let e=localStorage._mpa;return e=e&&JSON.parse(e),t==null?e:e&&e[t]}q()})(); | ||
(()=>{let l=document,r=window,o=l.querySelector.bind(l);function s(t,e){return t?.hasAttribute(e)}function u(t,e){return t?.getAttribute(e)}function p(){let t=u(l.body,"mpa-page-name");return t||new URL(l.location.href).pathname.replace(/\/$/,"")}let d=null;r.addEventListener("click",t=>{d=t.target});function m(t){return t?.getBoundingClientRect().top}r.addEventListener("unload",()=>{let t=y()||{},e=new Set(t.__||[]),n=p();s(l.body,"mpa-persist")&&(e.add(n),t.__=Array.from(e));for(let f in Object.keys(t))e.has(f)||f==="__"||delete t[f];let i=l.activeElement,a=i===l.body?d:i,c=u(a,"mpa-target");c&&(a=o(c));let b=u(a?.closest("[mpa-miss]"),"mpa-miss"),q=a?.getAttribute("name");t[n]={y:r.scrollY,a:{t:{y:m(a),q:a?.id&&`#${a.id}`||q&&`[name="${q}"]`},m:{y:m(o(b)),q:b}}},localStorage._mpa=JSON.stringify(t)});function _(){if(o("[autofocus]"))return;let t=y(p());if(!t)return;let{y:e,a:{t:n,m:i}}=t,a,c=n.q&&(a=o(n.q))?n.y:i.q&&(a=o(i.q))?i.y:0;s(a,"mpa-skip-focus")||(g("focus",a),g("select",a)),!s(l.body,"mpa-skip-scroll")&&e&&(a?r.scrollTo({top:r.scrollY+m(a)-c}):r.scrollTo({top:e}))}function g(t,e){e&&e[t]&&e[t]()}function y(t){let e=localStorage._mpa;return e=e&&JSON.parse(e),t==null?e:e&&e[t]}_()})(); |
76021
2559
109