hexo-theme-gnix 4.2.8 → 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/layout/comment/twikoo.jsx +5 -2
- package/layout/common/scripts.jsx +1 -1
- package/layout/layout.jsx +1 -5
- package/layout/plugin/swup.jsx +20 -0
- package/layout/search/insight.jsx +2 -2
- package/package.json +1 -1
- package/source/css/default.css +8 -5
- package/source/js/host/swup/Swup.umd.min.js +2 -0
- package/source/js/main.js +18 -2
- package/layout/plugin/pjax.jsx +0 -20
- package/source/js/host/pjax/0.2.8/pjax.min.js +0 -1
- package/source/js/pjax.js +0 -23
|
@@ -19,7 +19,10 @@ const {
|
|
|
19
19
|
class Twikoo extends Component {
|
|
20
20
|
render() {
|
|
21
21
|
const { envId, region, lang, jsUrl } = this.props;
|
|
22
|
-
const js = `
|
|
22
|
+
const js = `
|
|
23
|
+
window.twikooConfig = { envId: '${envId}', ${region ? `region: ${JSON.stringify(region)},` : ""} ${lang ? `lang: ${JSON.stringify(lang)},` : ""} };
|
|
24
|
+
twikoo.init(window.twikooConfig);
|
|
25
|
+
`;
|
|
23
26
|
const lazy_load_css_script = lazy_load_css("/css/twikoo.css");
|
|
24
27
|
return (
|
|
25
28
|
<Fragment>
|
|
@@ -27,7 +30,7 @@ class Twikoo extends Component {
|
|
|
27
30
|
<script
|
|
28
31
|
dangerouslySetInnerHTML={{ __html: lazy_load_css_script }}
|
|
29
32
|
></script>
|
|
30
|
-
<script async
|
|
33
|
+
<script async src={jsUrl} onload={`${js}`}></script>
|
|
31
34
|
</Fragment>
|
|
32
35
|
);
|
|
33
36
|
}
|
|
@@ -17,7 +17,7 @@ module.exports = class extends Component {
|
|
|
17
17
|
helper={helper}
|
|
18
18
|
head={false}
|
|
19
19
|
/>
|
|
20
|
-
<script defer
|
|
20
|
+
<script defer src="/js/main.js"></script>
|
|
21
21
|
<script
|
|
22
22
|
async
|
|
23
23
|
src="/js/host/iconify-icon/3.0.2/iconify-icon.min.js"
|
package/layout/layout.jsx
CHANGED
|
@@ -19,11 +19,7 @@ module.exports = class extends Component {
|
|
|
19
19
|
<Navbar config={config} helper={helper} page={page} />
|
|
20
20
|
<ThemeSelector />
|
|
21
21
|
<section class="section">
|
|
22
|
-
<div
|
|
23
|
-
class="main-content"
|
|
24
|
-
data-pjax
|
|
25
|
-
dangerouslySetInnerHTML={{ __html: body }}
|
|
26
|
-
></div>
|
|
22
|
+
<div class="main-content" dangerouslySetInnerHTML={{ __html: body }} ></div>
|
|
27
23
|
</section>
|
|
28
24
|
<Footer site={site} config={config} helper={helper} />
|
|
29
25
|
<Scripts site={site} config={config} helper={helper} page={page} />
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const { Component, Fragment } = require("../../include/util/common");
|
|
2
|
+
|
|
3
|
+
class Swup extends Component {
|
|
4
|
+
render() {
|
|
5
|
+
if (this.props.head) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const swupScript =
|
|
10
|
+
'const swup = new Swup({ containers: [".main-content"], });';
|
|
11
|
+
return (
|
|
12
|
+
<Fragment>
|
|
13
|
+
<script src="/js/host/swup/Swup.umd.min.js"></script>
|
|
14
|
+
<script dangerouslySetInnerHTML={{ __html: swupScript }}> </script>
|
|
15
|
+
</Fragment>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = Swup;
|
|
@@ -26,8 +26,8 @@ class Insight extends Component {
|
|
|
26
26
|
<div class="searchbox-body"></div>
|
|
27
27
|
</div>
|
|
28
28
|
</div>
|
|
29
|
-
<script
|
|
30
|
-
<script
|
|
29
|
+
<script src={jsUrl} defer={true}></script>
|
|
30
|
+
<script dangerouslySetInnerHTML={{ __html: js }}></script>
|
|
31
31
|
</>
|
|
32
32
|
);
|
|
33
33
|
}
|
package/package.json
CHANGED
package/source/css/default.css
CHANGED
|
@@ -478,6 +478,7 @@ body {
|
|
|
478
478
|
justify-content: flex-start;
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
+
.toc-text,
|
|
481
482
|
.footer,
|
|
482
483
|
.widget {
|
|
483
484
|
font-family: var(--font-sans-serif);
|
|
@@ -504,7 +505,7 @@ body {
|
|
|
504
505
|
.navbar {
|
|
505
506
|
min-height: 4rem;
|
|
506
507
|
position: sticky;
|
|
507
|
-
top:
|
|
508
|
+
top: env(safe-area-inset-top);
|
|
508
509
|
left: 0;
|
|
509
510
|
right: 0;
|
|
510
511
|
transition: transform 0.3s ease-in-out;
|
|
@@ -956,7 +957,8 @@ body {
|
|
|
956
957
|
|
|
957
958
|
img,
|
|
958
959
|
video {
|
|
959
|
-
|
|
960
|
+
display: block;
|
|
961
|
+
max-width: 100%;
|
|
960
962
|
margin: 0 auto 0 auto;
|
|
961
963
|
|
|
962
964
|
&:hover {
|
|
@@ -1233,8 +1235,8 @@ small {
|
|
|
1233
1235
|
|
|
1234
1236
|
/* #endregion Content */
|
|
1235
1237
|
|
|
1236
|
-
:target {
|
|
1237
|
-
scroll-margin-top:
|
|
1238
|
+
article :target {
|
|
1239
|
+
scroll-margin-top: 5rem;
|
|
1238
1240
|
}
|
|
1239
1241
|
|
|
1240
1242
|
article,
|
|
@@ -1493,4 +1495,5 @@ input.searchbox-input {
|
|
|
1493
1495
|
object-fit: cover;
|
|
1494
1496
|
}
|
|
1495
1497
|
|
|
1496
|
-
/* #endregion Article Cover */
|
|
1498
|
+
/* #endregion Article Cover */
|
|
1499
|
+
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Swup=e()}(this,function(){const t=new WeakMap;function e(e,n,o,i){if(!e&&!t.has(n))return!1;const r=t.get(n)??new WeakMap;t.set(n,r);const s=r.get(o)??new Set;r.set(o,s);const a=s.has(i);return e?s.add(i):s.delete(i),a&&e}const n=(t,e)=>String(t).toLowerCase().replace(/[\s/_.]+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"")||e||"",o=function(t){let{hash:e}=void 0===t?{}:t;return window.location.pathname+window.location.search+(e?window.location.hash:"")},i=function(t,e){void 0===t&&(t=null),void 0===e&&(e={}),t=t||o({hash:!0});const n={...window.history.state||{},url:t,random:Math.random(),source:"swup",...e};window.history.replaceState(n,"",t)},r=(t,n,o,i)=>{const r=new AbortController;return function(t,n,o,i={}){const{signal:r,base:s=document}=i;if(r?.aborted)return;const{once:a,...c}=i,l=s instanceof Document?s.documentElement:s,h=Boolean("object"==typeof i?i.capture:i),u=i=>{const r=function(t,e){let n=t.target;if(n instanceof Text&&(n=n.parentElement),n instanceof Element&&t.currentTarget instanceof Element){const o=n.closest(e);if(o&&t.currentTarget.contains(o))return o}}(i,String(t));if(r){const t=Object.assign(i,{delegateTarget:r});o.call(l,t),a&&(l.removeEventListener(n,u,c),e(!1,l,o,d))}},d=JSON.stringify({selector:t,type:n,capture:h});e(!0,l,o,d)||l.addEventListener(n,u,c),r?.addEventListener("abort",()=>{e(!1,l,o,d)})}(t,n,o,i={...i,signal:r.signal}),{destroy:()=>r.abort()}};class s extends URL{constructor(t,e){void 0===e&&(e=document.baseURI),super(t.toString(),e),Object.setPrototypeOf(this,s.prototype)}get url(){return this.pathname+this.search}static fromElement(t){const e=t.getAttribute("href")||t.getAttribute("xlink:href")||"";return new s(e)}static fromUrl(t){return new s(t)}}const a=function(t,e){void 0===e&&(e={});try{const o=this;function n(n){const{status:r,url:a}=u;return Promise.resolve(u.text()).then(function(n){if(500===r)throw o.hooks.call("fetch:error",i,{status:r,response:u,url:a}),new c(`Server error: ${a}`,{status:r,url:a});if(!n)throw new c(`Empty response: ${a}`,{status:r,url:a});const{url:l}=s.fromUrl(a),h={url:l,html:n};return!i.cache.write||e.method&&"GET"!==e.method||t!==l||o.cache.set(h.url,h),h})}t=s.fromUrl(t).url;const{visit:i=o.visit}=e,r={...o.options.requestHeaders,...e.headers},a=e.timeout??o.options.timeout,l=new AbortController,{signal:h}=l;e={...e,headers:r,signal:h};let u,d=!1,f=null;a&&a>0&&(f=setTimeout(()=>{d=!0,l.abort("timeout")},a));const m=function(n,r){try{var s=Promise.resolve(o.hooks.call("fetch:request",i,{url:t,options:e},(t,e)=>{let{url:n,options:o}=e;return fetch(n,o)})).then(function(t){u=t,f&&clearTimeout(f)})}catch(t){return r(t)}return s&&s.then?s.then(void 0,r):s}(0,function(e){if(d)throw o.hooks.call("fetch:timeout",i,{url:t}),new c(`Request timed out: ${t}`,{url:t,timedOut:d});if("AbortError"===e?.name||h.aborted)throw new c(`Request aborted: ${t}`,{url:t,aborted:!0});throw e});return Promise.resolve(m&&m.then?m.then(n):n())}catch(p){return Promise.reject(p)}};class c extends Error{constructor(t,e){super(t),this.url=void 0,this.status=void 0,this.aborted=void 0,this.timedOut=void 0,this.name="FetchError",this.url=e.url,this.status=e.status,this.aborted=e.aborted||!1,this.timedOut=e.timedOut||!1}}class l{constructor(t){this.swup=void 0,this.pages=new Map,this.swup=t}get size(){return this.pages.size}get all(){const t=new Map;return this.pages.forEach((e,n)=>{t.set(n,{...e})}),t}has(t){return this.pages.has(this.resolve(t))}get(t){const e=this.pages.get(this.resolve(t));return e?{...e}:e}set(t,e){t=this.resolve(t),e={...e,url:t},this.pages.set(t,e),this.swup.hooks.callSync("cache:set",void 0,{page:e})}update(t,e){t=this.resolve(t);const n={...this.get(t),...e,url:t};this.pages.set(t,n)}delete(t){this.pages.delete(this.resolve(t))}clear(){this.pages.clear(),this.swup.hooks.callSync("cache:clear",void 0,void 0)}prune(t){this.pages.forEach((e,n)=>{t(n,e)&&this.delete(n)})}resolve(t){const{url:e}=s.fromUrl(t);return this.swup.resolveUrl(e)}}const h=function(t,e){return void 0===e&&(e=document),e.querySelector(t)},u=function(t,e){return void 0===e&&(e=document),Array.from(e.querySelectorAll(t))},d=()=>new Promise(t=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})});function f(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}function m(t,e){const n=t?.closest(`[${e}]`);return n?.hasAttribute(e)?n?.getAttribute(e)||!0:void 0}class p{constructor(t){this.swup=void 0,this.swupClasses=["to-","is-changing","is-rendering","is-popstate","is-animating","is-leaving"],this.swup=t}get selectors(){const{scope:t}=this.swup.visit.animation;return"containers"===t?this.swup.visit.containers:"html"===t?["html"]:Array.isArray(t)?t:[]}get selector(){return this.selectors.join(",")}get targets(){return this.selector.trim()?u(this.selector):[]}add(){this.targets.forEach(t=>t.classList.add(...[].slice.call(arguments)))}remove(){this.targets.forEach(t=>t.classList.remove(...[].slice.call(arguments)))}clear(){this.targets.forEach(t=>{const e=t.className.split(" ").filter(t=>this.isSwupClass(t));t.classList.remove(...e)})}isSwupClass(t){return this.swupClasses.some(e=>t.startsWith(e))}}class v{constructor(t,e){this.id=void 0,this.state=void 0,this.from=void 0,this.to=void 0,this.containers=void 0,this.animation=void 0,this.trigger=void 0,this.cache=void 0,this.history=void 0,this.scroll=void 0,this.meta=void 0;const{to:n,from:o,hash:i,el:r,event:s}=e;this.id=Math.random(),this.state=1,this.from={url:o??t.location.url,hash:t.location.hash},this.to={url:n,hash:i},this.containers=t.options.containers,this.animation={animate:!0,wait:!1,name:void 0,native:t.options.native,scope:t.options.animationScope,selector:t.options.animationSelector},this.trigger={el:r,event:s},this.cache={read:t.options.cache,write:t.options.cache},this.history={action:"push",popstate:!1,direction:void 0},this.scroll={reset:!0,target:void 0},this.meta={}}advance(t){this.state<t&&(this.state=t)}abort(){this.state=8}get done(){return this.state>=7}}function g(t){return new v(this,t)}const w="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function y(t,e,n){if(!t.s){if(n instanceof k){if(!n.s)return void(n.o=y.bind(null,t,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(y.bind(null,t,e),y.bind(null,t,2));t.s=e,t.v=n;const o=t.o;o&&o(t)}}const k=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,n){const o=new t,i=this.s;if(i){const t=1&i?e:n;if(t){try{y(o,1,t(this.v))}catch(t){y(o,2,t)}return o}return this}return this.o=function(t){try{const i=t.v;1&t.s?y(o,1,e?e(i):i):n?y(o,1,n(i)):y(o,2,i)}catch(t){y(o,2,t)}},o},t}();function P(t){return t instanceof k&&1&t.s}class b{constructor(t){this.swup=void 0,this.registry=new Map,this.hooks=["animation:out:start","animation:out:await","animation:out:end","animation:in:start","animation:in:await","animation:in:end","animation:skip","cache:clear","cache:set","content:replace","content:scroll","enable","disable","fetch:request","fetch:error","fetch:timeout","history:popstate","link:click","link:self","link:anchor","link:newtab","page:load","page:view","scroll:top","scroll:anchor","visit:start","visit:transition","visit:abort","visit:end"],this.swup=t,this.init()}init(){this.hooks.forEach(t=>this.create(t))}create(t){this.registry.has(t)||this.registry.set(t,new Map)}exists(t){return this.registry.has(t)}get(t){const e=this.registry.get(t);if(e)return e;console.error(`Unknown hook '${t}'`)}clear(){this.registry.forEach(t=>t.clear())}on(t,e,n){void 0===n&&(n={});const o=this.get(t);if(!o)return console.warn(`Hook '${t}' not found.`),()=>{};const i=o.size+1,r={...n,id:i,hook:t,handler:e};return o.set(e,r),()=>this.off(t,e)}before(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,before:!0})}replace(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,replace:!0})}once(t,e,n){return void 0===n&&(n={}),this.on(t,e,{...n,once:!0})}off(t,e){const n=this.get(t);n&&e?n.delete(e)||console.warn(`Handler for hook '${t}' not found.`):n&&n.clear()}call(t,e,n,o){try{const i=this,[r,s,a]=i.parseCallArgs(t,e,n,o),{before:c,handler:l,after:h}=i.getHandlers(t,a);return Promise.resolve(i.run(c,r,s)).then(function(){return Promise.resolve(i.run(l,r,s,!0)).then(function(e){let[n]=e;return Promise.resolve(i.run(h,r,s)).then(function(){return i.dispatchDomEvent(t,r,s),n})})})}catch(t){return Promise.reject(t)}}callSync(t,e,n,o){const[i,r,s]=this.parseCallArgs(t,e,n,o),{before:a,handler:c,after:l}=this.getHandlers(t,s);this.runSync(a,i,r);const[h]=this.runSync(c,i,r,!0);return this.runSync(l,i,r),this.dispatchDomEvent(t,i,r),h}parseCallArgs(t,e,n,o){return e instanceof v||"object"!=typeof e&&"function"!=typeof n?[e,n,o]:[void 0,e,n]}run(t,e,n,o){void 0===o&&(o=!1);try{let i;const r=this;void 0===e&&(e=r.swup.visit);const s=[],a=function(t,e,n){if("function"==typeof t[w]){var o,i,r,s=t[w]();if(function t(a){try{for(;!((o=s.next()).done||n&&n());)if((a=e(o.value))&&a.then){if(!P(a))return void a.then(t,r||(r=y.bind(null,i=new k,2)));a=a.v}i?y(i,1,a):i=a}catch(t){y(i||(i=new k),2,t)}}(),s.return){var a=function(t){try{o.done||s.return()}catch(t){}return t};if(i&&i.then)return i.then(a,function(t){throw a(t)});a()}return i}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return function(t,e,n){var o,i,r=-1;return function s(a){try{for(;++r<t.length&&(!n||!n());)if((a=e(r))&&a.then){if(!P(a))return void a.then(s,i||(i=y.bind(null,o=new k,2)));a=a.v}o?y(o,1,a):o=a}catch(t){y(o||(o=new k),2,t)}}(),o}(c,function(t){return e(c[t])},n)}(t,function(t){let{hook:i,handler:a,defaultHandler:c,once:l}=t;if(!e?.done)return l&&r.off(i,a),function(t,o){try{var i=Promise.resolve(function(t,e){return void 0===e&&(e=[]),new Promise((n,o)=>{const i=t(...e);f(i)?i.then(n,o):n(i)})}(a,[e,n,c])).then(function(t){s.push(t)})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(o)throw t;console.error(`Error in hook '${i}':`,t)})},function(){return i});return Promise.resolve(a&&a.then?a.then(function(t){return i?t:s}):i?a:s)}catch(t){return Promise.reject(t)}}runSync(t,e,n,o){void 0===e&&(e=this.swup.visit),void 0===o&&(o=!1);const i=[];for(const{hook:r,handler:s,defaultHandler:a,once:c}of t)if(!e?.done){c&&this.off(r,s);try{const t=s(e,n,a);i.push(t),f(t)&&console.warn(`Swup will not await Promises in handler for synchronous hook '${r}'.`)}catch(t){if(o)throw t;console.error(`Error in hook '${r}':`,t)}}return i}getHandlers(t,e){const n=this.get(t);if(!n)return{found:!1,before:[],handler:[],after:[],replaced:!1};const o=Array.from(n.values()),i=this.sortRegistrations,r=o.filter(t=>{let{before:e,replace:n}=t;return e&&!n}).sort(i),s=o.filter(t=>{let{replace:e}=t;return e}).filter(t=>!0).sort(i),a=o.filter(t=>{let{before:e,replace:n}=t;return!e&&!n}).sort(i),c=s.length>0;let l=[];if(e&&(l=[{id:0,hook:t,handler:e}],c)){const n=s.length-1,{handler:o,once:i}=s[n],r=t=>{const n=s[t-1];return n?(e,o)=>n.handler(e,o,r(t-1)):e};l=[{id:0,hook:t,once:i,handler:o,defaultHandler:r(n)}]}return{found:!0,before:r,handler:l,after:a,replaced:c}}sortRegistrations(t,e){return(t.priority??0)-(e.priority??0)||t.id-e.id||0}dispatchDomEvent(t,e,n){if(e?.done)return;const o={hook:t,args:n,visit:e||this.swup.visit};document.dispatchEvent(new CustomEvent("swup:any",{detail:o,bubbles:!0})),document.dispatchEvent(new CustomEvent(`swup:${t}`,{detail:o,bubbles:!0}))}parseName(t){const[e,...n]=t.split(".");return[e,n.reduce((t,e)=>({...t,[e]:!0}),{})]}}const S=t=>{if(t&&"#"===t.charAt(0)&&(t=t.substring(1)),!t)return null;const e=decodeURIComponent(t);let n=document.getElementById(t)||document.getElementById(e)||h(`a[name='${CSS.escape(t)}']`)||h(`a[name='${CSS.escape(e)}']`);return n||"top"!==t||(n=document.body),n},E=function(t){let{selector:e,elements:n}=t;try{if(!1===e&&!n)return Promise.resolve();let t=[];if(n)t=Array.from(n);else if(e&&(t=u(e,document.body),!t.length))return console.warn(`[swup] No elements found matching animationSelector \`${e}\``),Promise.resolve();const o=t.map(t=>function(t){const{type:e,timeout:n,propCount:o}=function(t){const e=window.getComputedStyle(t),n=x(e,`${C}Delay`),o=x(e,`${C}Duration`),i=$(n,o),r=x(e,`${U}Delay`),s=x(e,`${U}Duration`),a=$(r,s),c=Math.max(i,a),l=c>0?i>a?C:U:null;return{type:l,timeout:c,propCount:l?l===C?o.length:s.length:0}}(t);return!(!e||!n)&&new Promise(i=>{const r=`${e}end`,s=performance.now();let a=0;const c=()=>{t.removeEventListener(r,l),i()},l=e=>{e.target===t&&((performance.now()-s)/1e3<e.elapsedTime||++a>=o&&c())};setTimeout(()=>{a<o&&c()},n+1),t.addEventListener(r,l)})}(t));return o.filter(Boolean).length>0?Promise.resolve(Promise.all(o)).then(function(){}):(e&&console.warn(`[swup] No CSS animation duration defined on elements matching \`${e}\``),Promise.resolve())}catch(t){return Promise.reject(t)}},C="transition",U="animation";function x(t,e){return(t[e]||"").split(", ")}function $(t,e){for(;t.length<e.length;)t=t.concat(t);return Math.max(...e.map((e,n)=>A(e)+A(t[n])))}function A(t){return 1e3*parseFloat(t)}const H=function(t,e){void 0===e&&(e={});try{let a;const c=this;function r(r){if(a)return r;c.navigating=!0,c.visit=t;const{el:l}=t.trigger;e.referrer=e.referrer||c.location.url,!1===e.animate&&(t.animation.animate=!1),t.animation.animate||c.classes.clear();const h=e.history||m(l,"data-swup-history");"string"==typeof h&&["push","replace"].includes(h)&&(t.history.action=h);const u=e.animation||m(l,"data-swup-animation");return"string"==typeof u&&(t.animation.name=u),t.meta=e.meta||{},"object"==typeof e.cache?(t.cache.read=e.cache.read??t.cache.read,t.cache.write=e.cache.write??t.cache.write):void 0!==e.cache&&(t.cache={read:!!e.cache,write:!!e.cache}),delete e.cache,function(r,a){try{var l=function(r,a){try{var l=Promise.resolve(c.hooks.call("visit:start",t,void 0)).then(function(){function r(){if(!t.done)return Promise.resolve(c.hooks.call("visit:transition",t,void 0,function(){try{let n;function e(e){return n?e:(t.advance(4),Promise.resolve(c.animatePageOut(t)).then(function(){function e(){return Promise.resolve(c.animatePageIn(t)).then(function(){})}const n=function(){if(t.animation.native&&document.startViewTransition)return Promise.resolve(document.startViewTransition(function(){try{const e=c.renderPage;return Promise.resolve(a).then(function(n){return Promise.resolve(e.call(c,t,n))})}catch(t){return Promise.reject(t)}}).finished).then(function(){});{const e=c.renderPage;return Promise.resolve(a).then(function(n){return Promise.resolve(e.call(c,t,n)).then(function(){})})}}();return n&&n.then?n.then(e):e()}))}const o=function(){if(!t.animation.animate)return Promise.resolve(c.hooks.call("animation:skip",void 0)).then(function(){const e=c.renderPage;return Promise.resolve(a).then(function(o){return Promise.resolve(e.call(c,t,o)).then(function(){n=1})})})}();return Promise.resolve(o&&o.then?o.then(e):e(o))}catch(i){return Promise.reject(i)}})).then(function(){if(!t.done)return Promise.resolve(c.hooks.call("visit:end",t,void 0,()=>c.classes.clear())).then(function(){t.state=7,c.navigating=!1,c.onVisitEnd&&(c.onVisitEnd(),c.onVisitEnd=void 0)})})}t.state=3;const a=c.hooks.call("page:load",t,{options:e},function(t,e){try{function n(t){return e.page=t,e.cache=!!o,e.page}let o;return t.cache.read&&(o=c.cache.get(t.to.url)),Promise.resolve(o?n(o):Promise.resolve(c.fetchPage(t.to.url,e.options)).then(n))}catch(i){return Promise.reject(i)}});a.then(e=>{let{html:n}=e;t.advance(5),t.to.html=n,t.to.document=(new DOMParser).parseFromString(n,"text/html")});const l=t.to.url+t.to.hash;t.history.popstate||("replace"===t.history.action||t.to.url===c.location.url?i(l):(c.currentHistoryIndex++,function(t,e){void 0===e&&(e={});const n={url:t=t||o({hash:!0}),random:Math.random(),source:"swup",...e};window.history.pushState(n,"",t)}(l,{index:c.currentHistoryIndex}))),c.location=s.fromUrl(l),t.history.popstate&&c.classes.add("is-popstate"),t.animation.name&&c.classes.add(`to-${n(t.animation.name)}`);const h=function(){if(t.animation.wait)return Promise.resolve(a).then(function(){})}();return h&&h.then?h.then(r):r()})}catch(t){return a(t)}return l&&l.then?l.then(void 0,a):l}(0,function(e){e&&!e?.aborted?(t.state=9,console.error(e),c.options.skipPopStateHandling=()=>(window.location.assign(t.to.url+t.to.hash),!0),window.history.back()):t.state=8})}catch(t){return a(!0,t)}return l&&l.then?l.then(a.bind(null,!1),a.bind(null,!0)):a(!1,l)}(0,function(e,n){if(delete t.to.document,e)throw n;return n})}const l=function(){if(c.navigating)return function(){if(!(c.visit.state>=6))return Promise.resolve(c.hooks.call("visit:abort",c.visit,void 0)).then(function(){delete c.visit.to.document,c.visit.state=8});t.state=2,c.onVisitEnd=()=>c.performNavigation(t,e),a=1}()}();return Promise.resolve(l&&l.then?l.then(r):r(l))}catch(h){return Promise.reject(h)}};function T(t,e,n){if(void 0===e&&(e={}),void 0===n&&(n={}),"string"!=typeof t)throw new Error("swup.navigate() requires a URL parameter");if(this.shouldIgnoreVisit(t,{el:n.el,event:n.event}))return void window.location.assign(t);const{url:o,hash:i}=s.fromUrl(t),r=this.createVisit({...n,to:o,hash:i});this.performNavigation(r,e)}const j=function(t){try{const e=this;return Promise.resolve(e.hooks.call("animation:out:start",t,void 0,()=>{e.classes.add("is-changing","is-animating","is-leaving")})).then(function(){return Promise.resolve(e.hooks.call("animation:out:await",t,{skip:!1},(t,n)=>{let{skip:o}=n;if(!o)return e.awaitAnimations({selector:t.animation.selector})})).then(function(){return Promise.resolve(e.hooks.call("animation:out:end",t,void 0)).then(function(){})})})}catch(t){return Promise.reject(t)}},L=function(t){const e=t.to.document;if(!e)return!1;const n=e.querySelector("title")?.innerText||"";document.title=n;const o=u('[data-swup-persist]:not([data-swup-persist=""])'),i=t.containers.map(t=>{const n=document.querySelector(t),o=e.querySelector(t);return n&&o?(n.replaceWith(o.cloneNode(!0)),!0):(n||console.warn(`[swup] Container missing in current document: ${t}`),o||console.warn(`[swup] Container missing in incoming document: ${t}`),!1)}).filter(Boolean);return o.forEach(t=>{const e=t.getAttribute("data-swup-persist"),n=h(`[data-swup-persist="${e}"]`);n&&n!==t&&n.replaceWith(t)}),i.length===t.containers.length},V=function(t){const e={behavior:"auto"},{target:n,reset:o}=t.scroll,i=n??t.to.hash;let r=!1;return i&&(r=this.hooks.callSync("scroll:anchor",t,{hash:i,options:e},(t,e)=>{let{hash:n,options:o}=e;const i=this.getAnchorElement(n);return i&&i.scrollIntoView(o),!!i})),o&&!r&&(r=this.hooks.callSync("scroll:top",t,{options:e},(t,e)=>{let{options:n}=e;return window.scrollTo({top:0,left:0,...n}),!0})),r},I=function(t){try{const e=this;if(t.done)return Promise.resolve();const n=e.hooks.call("animation:in:await",t,{skip:!1},(t,n)=>{let{skip:o}=n;if(!o)return e.awaitAnimations({selector:t.animation.selector})});return Promise.resolve(d()).then(function(){return Promise.resolve(e.hooks.call("animation:in:start",t,void 0,()=>{e.classes.remove("is-animating")})).then(function(){return Promise.resolve(n).then(function(){return Promise.resolve(e.hooks.call("animation:in:end",t,void 0)).then(function(){})})})})}catch(t){return Promise.reject(t)}},q=function(t,e){try{const r=this;if(t.done)return Promise.resolve();t.advance(6);const{url:a}=e;return r.isSameResolvedUrl(o(),a)||(i(a),r.location=s.fromUrl(a),t.to.url=r.location.url,t.to.hash=r.location.hash),Promise.resolve(r.hooks.call("content:replace",t,{page:e},(t,e)=>{if(r.classes.remove("is-leaving"),t.animation.animate&&r.classes.add("is-rendering"),!r.replaceContent(t))throw new Error("[swup] Container mismatch, aborting");t.animation.animate&&(r.classes.add("is-changing","is-animating","is-rendering"),t.animation.name&&r.classes.add(`to-${n(t.animation.name)}`))})).then(function(){return Promise.resolve(r.hooks.call("content:scroll",t,void 0,()=>r.scrollToContent(t))).then(function(){return Promise.resolve(r.hooks.call("page:view",t,{url:r.location.url,title:document.title})).then(function(){})})})}catch(t){return Promise.reject(t)}},N=function(t){var e;if(e=t,Boolean(e?.isSwupPlugin)){if(t.swup=this,!t._checkRequirements||t._checkRequirements())return t._beforeMount&&t._beforeMount(),t.mount(),this.plugins.push(t),this.plugins}else console.error("Not a swup plugin instance",t)};function R(t){const e=this.findPlugin(t);if(e)return e.unmount(),e._afterUnmount&&e._afterUnmount(),this.plugins=this.plugins.filter(t=>t!==e),this.plugins;console.error("No such plugin",e)}function O(t){return this.plugins.find(e=>e===t||e.name===t||e.name===`Swup${String(t)}`)}function D(t){if("function"!=typeof this.options.resolveUrl)return console.warn("[swup] options.resolveUrl expects a callback function."),t;const e=this.options.resolveUrl(t);return e&&"string"==typeof e?e.startsWith("//")||e.startsWith("http")?(console.warn("[swup] options.resolveUrl needs to return a relative url"),t):e:(console.warn("[swup] options.resolveUrl needs to return a url"),t)}function M(t,e){return this.resolveUrl(t)===this.resolveUrl(e)}const W={animateHistoryBrowsing:!1,animationSelector:'[class*="transition-"]',animationScope:"html",cache:!0,containers:["#swup"],hooks:{},ignoreVisit:function(t,e){let{el:n}=void 0===e?{}:e;return!!n?.closest("[data-no-swup]")},linkSelector:"a[href]",linkToSelf:"scroll",native:!1,plugins:[],resolveUrl:t=>t,requestHeaders:{"X-Requested-With":"swup",Accept:"text/html, application/xhtml+xml"},skipPopStateHandling:t=>"swup"!==t.state?.source,timeout:0};return class{get currentPageUrl(){return this.location.url}constructor(t){void 0===t&&(t={}),this.version="4.8.2",this.options=void 0,this.defaults=W,this.plugins=[],this.visit=void 0,this.cache=void 0,this.hooks=void 0,this.classes=void 0,this.location=s.fromUrl(window.location.href),this.currentHistoryIndex=void 0,this.clickDelegate=void 0,this.navigating=!1,this.onVisitEnd=void 0,this.use=N,this.unuse=R,this.findPlugin=O,this.log=()=>{},this.navigate=T,this.performNavigation=H,this.createVisit=g,this.delegateEvent=r,this.fetchPage=a,this.awaitAnimations=E,this.renderPage=q,this.replaceContent=L,this.animatePageIn=I,this.animatePageOut=j,this.scrollToContent=V,this.getAnchorElement=S,this.getCurrentUrl=o,this.resolveUrl=D,this.isSameResolvedUrl=M,this.options={...this.defaults,...t},this.handleLinkClick=this.handleLinkClick.bind(this),this.handlePopState=this.handlePopState.bind(this),this.cache=new l(this),this.classes=new p(this),this.hooks=new b(this),this.visit=this.createVisit({to:""}),this.currentHistoryIndex=window.history.state?.index??1,this.enable()}enable(){try{const t=this,{linkSelector:e}=t.options;t.clickDelegate=t.delegateEvent(e,"click",t.handleLinkClick),window.addEventListener("popstate",t.handlePopState),t.options.animateHistoryBrowsing&&(window.history.scrollRestoration="manual"),t.options.native=t.options.native&&!!document.startViewTransition,t.options.plugins.forEach(e=>t.use(e));for(const[e,n]of Object.entries(t.options.hooks)){const[o,i]=t.hooks.parseName(e);t.hooks.on(o,n,i)}return"swup"!==window.history.state?.source&&i(null,{index:t.currentHistoryIndex}),Promise.resolve(d()).then(function(){return Promise.resolve(t.hooks.call("enable",void 0,void 0,()=>{const e=document.documentElement;e.classList.add("swup-enabled"),e.classList.toggle("swup-native",t.options.native)})).then(function(){})})}catch(t){return Promise.reject(t)}}destroy(){try{const t=this;return t.clickDelegate.destroy(),window.removeEventListener("popstate",t.handlePopState),t.cache.clear(),t.options.plugins.forEach(e=>t.unuse(e)),Promise.resolve(t.hooks.call("disable",void 0,void 0,()=>{const t=document.documentElement;t.classList.remove("swup-enabled"),t.classList.remove("swup-native")})).then(function(){t.hooks.clear()})}catch(t){return Promise.reject(t)}}shouldIgnoreVisit(t,e){let{el:n,event:o}=void 0===e?{}:e;const{origin:i,url:r,hash:a}=s.fromUrl(t);return i!==window.location.origin||!(!n||!this.triggerWillOpenNewWindow(n))||!!this.options.ignoreVisit(r+a,{el:n,event:o})}handleLinkClick(t){const e=t.delegateTarget,{href:n,url:o,hash:r}=s.fromElement(e);if(this.shouldIgnoreVisit(n,{el:e,event:t}))return;if(this.navigating&&o===this.visit.to.url)return void t.preventDefault();const a=this.createVisit({to:o,hash:r,el:e,event:t});t.metaKey||t.ctrlKey||t.shiftKey||t.altKey?this.hooks.callSync("link:newtab",a,{href:n}):0===t.button&&this.hooks.callSync("link:click",a,{el:e,event:t},()=>{const e=a.from.url??"";t.preventDefault(),o&&o!==e?this.isSameResolvedUrl(o,e)||this.performNavigation(a):r?this.hooks.callSync("link:anchor",a,{hash:r},()=>{i(o+r),this.scrollToContent(a)}):this.hooks.callSync("link:self",a,void 0,()=>{"navigate"===this.options.linkToSelf?this.performNavigation(a):(i(o),this.scrollToContent(a))})})}handlePopState(t){const e=t.state?.url??window.location.href;if(this.options.skipPopStateHandling(t))return;if(this.isSameResolvedUrl(o(),this.location.url))return;const{url:n,hash:i}=s.fromUrl(e),r=this.createVisit({to:n,hash:i,event:t});r.history.popstate=!0;const a=t.state?.index??0;a&&a!==this.currentHistoryIndex&&(r.history.direction=a-this.currentHistoryIndex>0?"forwards":"backwards",this.currentHistoryIndex=a),r.animation.animate=!1,r.scroll.reset=!1,r.scroll.target=!1,this.options.animateHistoryBrowsing&&(r.animation.animate=!0,r.scroll.reset=!0),this.hooks.callSync("history:popstate",r,{event:t},()=>{this.performNavigation(r)})}triggerWillOpenNewWindow(t){return!!t.matches('[download], [target="_blank"]')}}});
|
|
2
|
+
//# sourceMappingURL=Swup.umd.js.map
|
package/source/js/main.js
CHANGED
|
@@ -202,8 +202,24 @@ function initLogic() {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
document.addEventListener("DOMContentLoaded", () =>
|
|
206
|
-
|
|
205
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
206
|
+
initLogic();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Re-initialize on page changes when using swup
|
|
210
|
+
if (typeof swup !== "undefined") {
|
|
211
|
+
swup.hooks.on("page:view", () => {
|
|
212
|
+
initLogic();
|
|
213
|
+
|
|
214
|
+
// Re-initialize Twikoo if available
|
|
215
|
+
if (typeof twikoo !== "undefined" && window.twikooConfig) {
|
|
216
|
+
const twikooContainer = document.getElementById("twikoo");
|
|
217
|
+
if (twikooContainer) {
|
|
218
|
+
twikoo.init(window.twikooConfig);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
207
223
|
|
|
208
224
|
// Global functions
|
|
209
225
|
// biome-ignore lint/correctness/noUnusedVariables: used in <nav click="handleNavbarClick(event)">
|
package/layout/plugin/pjax.jsx
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const { Component, Fragment } = require("../../include/util/common");
|
|
2
|
-
|
|
3
|
-
class Pjax extends Component {
|
|
4
|
-
render() {
|
|
5
|
-
if (this.props.head) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
const { helper } = this.props;
|
|
9
|
-
const { url_for, cdn } = helper;
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<Fragment>
|
|
13
|
-
<script defer src={cdn("pjax", "0.2.8", "pjax.min.js")}></script>
|
|
14
|
-
<script defer src={url_for("/js/pjax.js")}></script>
|
|
15
|
-
</Fragment>
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = Pjax;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Pjax=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r}()({1:[function(require,module,exports){var executeScripts=require("./lib/execute-scripts");var forEachEls=require("./lib/foreach-els");var parseOptions=require("./lib/parse-options");var switches=require("./lib/switches");var newUid=require("./lib/uniqueid");var on=require("./lib/events/on");var trigger=require("./lib/events/trigger");var clone=require("./lib/util/clone");var contains=require("./lib/util/contains");var extend=require("./lib/util/extend");var noop=require("./lib/util/noop");var Pjax=function(options){this.state={numPendingSwitches:0,href:null,options:null};this.options=parseOptions(options);this.log("Pjax options",this.options);if(this.options.scrollRestoration&&"scrollRestoration"in history){history.scrollRestoration="manual"}this.maxUid=this.lastUid=newUid();this.parseDOM(document);on(window,"popstate",function(st){if(st.state){var opt=clone(this.options);opt.url=st.state.url;opt.title=st.state.title;opt.history=false;opt.scrollPos=st.state.scrollPos;if(st.state.uid<this.lastUid){opt.backward=true}else{opt.forward=true}this.lastUid=st.state.uid;this.loadUrl(st.state.url,opt)}}.bind(this))};Pjax.switches=switches;Pjax.prototype={log:require("./lib/proto/log"),getElements:function(el){return el.querySelectorAll(this.options.elements)},parseDOM:function(el){var parseElement=require("./lib/proto/parse-element");forEachEls(this.getElements(el),parseElement,this)},refresh:function(el){this.parseDOM(el||document)},reload:function(){window.location.reload()},attachLink:require("./lib/proto/attach-link"),attachForm:require("./lib/proto/attach-form"),forEachSelectors:function(cb,context,DOMcontext){return require("./lib/foreach-selectors").bind(this)(this.options.selectors,cb,context,DOMcontext)},switchSelectors:function(selectors,fromEl,toEl,options){return require("./lib/switches-selectors").bind(this)(this.options.switches,this.options.switchesOptions,selectors,fromEl,toEl,options)},latestChance:function(href){window.location=href},onSwitch:function(){trigger(window,"resize scroll");this.state.numPendingSwitches--;if(this.state.numPendingSwitches===0){this.afterAllSwitches()}},loadContent:function(html,options){if(typeof html!=="string"){trigger(document,"pjax:complete pjax:error",options);return}var tmpEl=document.implementation.createHTMLDocument("pjax");var htmlRegex=/<html[^>]+>/gi;var htmlAttribsRegex=/\s?[a-z:]+(?:=['"][^'">]+['"])*/gi;var matches=html.match(htmlRegex);if(matches&&matches.length){matches=matches[0].match(htmlAttribsRegex);if(matches.length){matches.shift();matches.forEach(function(htmlAttrib){var attr=htmlAttrib.trim().split("=");if(attr.length===1){tmpEl.documentElement.setAttribute(attr[0],true)}else{tmpEl.documentElement.setAttribute(attr[0],attr[1].slice(1,-1))}})}}tmpEl.documentElement.innerHTML=html;this.log("load content",tmpEl.documentElement.attributes,tmpEl.documentElement.innerHTML.length);if(document.activeElement&&contains(document,this.options.selectors,document.activeElement)){try{document.activeElement.blur()}catch(e){}}this.switchSelectors(this.options.selectors,tmpEl,document,options)},abortRequest:require("./lib/abort-request"),doRequest:require("./lib/send-request"),handleResponse:require("./lib/proto/handle-response"),loadUrl:function(href,options){options=typeof options==="object"?extend({},this.options,options):clone(this.options);this.log("load href",href,options);this.abortRequest(this.request);trigger(document,"pjax:send",options);this.request=this.doRequest(href,options,this.handleResponse.bind(this))},afterAllSwitches:function(){var autofocusEl=Array.prototype.slice.call(document.querySelectorAll("[autofocus]")).pop();if(autofocusEl&&document.activeElement!==autofocusEl){autofocusEl.focus()}this.options.selectors.forEach(function(selector){forEachEls(document.querySelectorAll(selector),function(el){executeScripts(el)})});var state=this.state;if(state.options.history){if(!window.history.state){this.lastUid=this.maxUid=newUid();window.history.replaceState({url:window.location.href,title:document.title,uid:this.maxUid,scrollPos:[0,0]},document.title)}this.lastUid=this.maxUid=newUid();window.history.pushState({url:state.href,title:state.options.title,uid:this.maxUid,scrollPos:[0,0]},state.options.title,state.href)}this.forEachSelectors(function(el){this.parseDOM(el)},this);trigger(document,"pjax:complete pjax:success",state.options);if(typeof state.options.analytics==="function"){state.options.analytics()}if(state.options.history){var a=document.createElement("a");a.href=this.state.href;if(a.hash){var name=a.hash.slice(1);name=decodeURIComponent(name);var curtop=0;var target=document.getElementById(name)||document.getElementsByName(name)[0];if(target){if(target.offsetParent){do{curtop+=target.offsetTop;target=target.offsetParent}while(target)}}window.scrollTo(0,curtop)}else if(state.options.scrollTo!==false){if(state.options.scrollTo.length>1){window.scrollTo(state.options.scrollTo[0],state.options.scrollTo[1])}else{window.scrollTo(0,state.options.scrollTo)}}}else if(state.options.scrollRestoration&&state.options.scrollPos){window.scrollTo(state.options.scrollPos[0],state.options.scrollPos[1])}this.state={numPendingSwitches:0,href:null,options:null}}};Pjax.isSupported=require("./lib/is-supported");if(Pjax.isSupported()){module.exports=Pjax}else{var stupidPjax=noop;for(var key in Pjax.prototype){if(Pjax.prototype.hasOwnProperty(key)&&typeof Pjax.prototype[key]==="function"){stupidPjax[key]=noop}}module.exports=stupidPjax}},{"./lib/abort-request":2,"./lib/events/on":4,"./lib/events/trigger":5,"./lib/execute-scripts":6,"./lib/foreach-els":7,"./lib/foreach-selectors":8,"./lib/is-supported":9,"./lib/parse-options":10,"./lib/proto/attach-form":11,"./lib/proto/attach-link":12,"./lib/proto/handle-response":13,"./lib/proto/log":14,"./lib/proto/parse-element":15,"./lib/send-request":16,"./lib/switches":18,"./lib/switches-selectors":17,"./lib/uniqueid":19,"./lib/util/clone":20,"./lib/util/contains":21,"./lib/util/extend":22,"./lib/util/noop":23}],2:[function(require,module,exports){var noop=require("./util/noop");module.exports=function(request){if(request&&request.readyState<4){request.onreadystatechange=noop;request.abort()}}},{"./util/noop":23}],3:[function(require,module,exports){module.exports=function(el){var code=el.text||el.textContent||el.innerHTML||"";var src=el.src||"";var parent=el.parentNode||document.querySelector("head")||document.documentElement;var script=document.createElement("script");if(code.match("document.write")){if(console&&console.log){console.log("Script contains document.write. Can’t be executed correctly. Code skipped ",el)}return false}script.type="text/javascript";script.id=el.id;if(src!==""){script.src=src;script.async=false}if(code!==""){try{script.appendChild(document.createTextNode(code))}catch(e){script.text=code}}parent.appendChild(script);if((parent instanceof HTMLHeadElement||parent instanceof HTMLBodyElement)&&parent.contains(script)){parent.removeChild(script)}return true}},{}],4:[function(require,module,exports){var forEachEls=require("../foreach-els");module.exports=function(els,events,listener,useCapture){events=typeof events==="string"?events.split(" "):events;events.forEach(function(e){forEachEls(els,function(el){el.addEventListener(e,listener,useCapture)})})}},{"../foreach-els":7}],5:[function(require,module,exports){var forEachEls=require("../foreach-els");module.exports=function(els,events,opts){events=typeof events==="string"?events.split(" "):events;events.forEach(function(e){var event;event=document.createEvent("HTMLEvents");event.initEvent(e,true,true);event.eventName=e;if(opts){Object.keys(opts).forEach(function(key){event[key]=opts[key]})}forEachEls(els,function(el){var domFix=false;if(!el.parentNode&&el!==document&&el!==window){domFix=true;document.body.appendChild(el)}el.dispatchEvent(event);if(domFix){el.parentNode.removeChild(el)}})})}},{"../foreach-els":7}],6:[function(require,module,exports){var forEachEls=require("./foreach-els");var evalScript=require("./eval-script");module.exports=function(el){if(el.tagName.toLowerCase()==="script"){evalScript(el)}forEachEls(el.querySelectorAll("script"),function(script){if(!script.type||script.type.toLowerCase()==="text/javascript"){if(script.parentNode){script.parentNode.removeChild(script)}evalScript(script)}})}},{"./eval-script":3,"./foreach-els":7}],7:[function(require,module,exports){module.exports=function(els,fn,context){if(els instanceof HTMLCollection||els instanceof NodeList||els instanceof Array){return Array.prototype.forEach.call(els,fn,context)}return fn.call(context,els)}},{}],8:[function(require,module,exports){var forEachEls=require("./foreach-els");module.exports=function(selectors,cb,context,DOMcontext){DOMcontext=DOMcontext||document;selectors.forEach(function(selector){forEachEls(DOMcontext.querySelectorAll(selector),cb,context)})}},{"./foreach-els":7}],9:[function(require,module,exports){module.exports=function(){return window.history&&window.history.pushState&&window.history.replaceState&&!navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]\D|WebApps\/.+CFNetwork)/)}},{}],10:[function(require,module,exports){var defaultSwitches=require("./switches");module.exports=function(options){options=options||{};options.elements=options.elements||"a[href], form[action]";options.selectors=options.selectors||["title",".js-Pjax"];options.switches=options.switches||{};options.switchesOptions=options.switchesOptions||{};options.history=typeof options.history==="undefined"?true:options.history;options.analytics=typeof options.analytics==="function"||options.analytics===false?options.analytics:defaultAnalytics;options.scrollTo=typeof options.scrollTo==="undefined"?0:options.scrollTo;options.scrollRestoration=typeof options.scrollRestoration!=="undefined"?options.scrollRestoration:true;options.cacheBust=typeof options.cacheBust==="undefined"?true:options.cacheBust;options.debug=options.debug||false;options.timeout=options.timeout||0;options.currentUrlFullReload=typeof options.currentUrlFullReload==="undefined"?false:options.currentUrlFullReload;if(!options.switches.head){options.switches.head=defaultSwitches.switchElementsAlt}if(!options.switches.body){options.switches.body=defaultSwitches.switchElementsAlt}return options};function defaultAnalytics(){if(window._gaq){_gaq.push(["_trackPageview"])}if(window.ga){ga("send","pageview",{page:location.pathname,title:document.title})}}},{"./switches":18}],11:[function(require,module,exports){var on=require("../events/on");var clone=require("../util/clone");var attrState="data-pjax-state";var formAction=function(el,event){if(isDefaultPrevented(event)){return}var options=clone(this.options);options.requestOptions={requestUrl:el.getAttribute("action")||window.location.href,requestMethod:el.getAttribute("method")||"GET"};var virtLinkElement=document.createElement("a");virtLinkElement.setAttribute("href",options.requestOptions.requestUrl);var attrValue=checkIfShouldAbort(virtLinkElement,options);if(attrValue){el.setAttribute(attrState,attrValue);return}event.preventDefault();if(el.enctype==="multipart/form-data"){options.requestOptions.formData=new FormData(el)}else{options.requestOptions.requestParams=parseFormElements(el)}el.setAttribute(attrState,"submit");options.triggerElement=el;this.loadUrl(virtLinkElement.href,options)};function parseFormElements(el){var requestParams=[];var formElements=el.elements;for(var i=0;i<formElements.length;i++){var element=formElements[i];var tagName=element.tagName.toLowerCase();if(!!element.name&&element.attributes!==undefined&&tagName!=="button"){var type=element.attributes.type;if(!type||type.value!=="checkbox"&&type.value!=="radio"||element.checked){var values=[];if(tagName==="select"){var opt;for(var j=0;j<element.options.length;j++){opt=element.options[j];if(opt.selected&&!opt.disabled){values.push(opt.hasAttribute("value")?opt.value:opt.text)}}}else{values.push(element.value)}for(var k=0;k<values.length;k++){requestParams.push({name:encodeURIComponent(element.name),value:encodeURIComponent(values[k])})}}}}return requestParams}function checkIfShouldAbort(virtLinkElement,options){if(virtLinkElement.protocol!==window.location.protocol||virtLinkElement.host!==window.location.host){return"external"}if(virtLinkElement.hash&&virtLinkElement.href.replace(virtLinkElement.hash,"")===window.location.href.replace(location.hash,"")){return"anchor"}if(virtLinkElement.href===window.location.href.split("#")[0]+"#"){return"anchor-empty"}if(options.currentUrlFullReload&&virtLinkElement.href===window.location.href.split("#")[0]){return"reload"}}var isDefaultPrevented=function(event){return event.defaultPrevented||event.returnValue===false};module.exports=function(el){var that=this;el.setAttribute(attrState,"");on(el,"submit",function(event){formAction.call(that,el,event)})}},{"../events/on":4,"../util/clone":20}],12:[function(require,module,exports){var on=require("../events/on");var clone=require("../util/clone");var attrState="data-pjax-state";var linkAction=function(el,event){if(isDefaultPrevented(event)){return}var options=clone(this.options);var attrValue=checkIfShouldAbort(el,event);if(attrValue){el.setAttribute(attrState,attrValue);return}event.preventDefault();if(this.options.currentUrlFullReload&&el.href===window.location.href.split("#")[0]){el.setAttribute(attrState,"reload");this.reload();return}el.setAttribute(attrState,"load");options.triggerElement=el;this.loadUrl(el.href,options)};function checkIfShouldAbort(el,event){if(event.which>1||event.metaKey||event.ctrlKey||event.shiftKey||event.altKey){return"modifier"}if(el.protocol!==window.location.protocol||el.host!==window.location.host){return"external"}if(el.hash&&el.href.replace(el.hash,"")===window.location.href.replace(location.hash,"")){return"anchor"}if(el.href===window.location.href.split("#")[0]+"#"){return"anchor-empty"}}var isDefaultPrevented=function(event){return event.defaultPrevented||event.returnValue===false};module.exports=function(el){var that=this;el.setAttribute(attrState,"");on(el,"click",function(event){linkAction.call(that,el,event)});on(el,"keyup",function(event){if(event.keyCode===13){linkAction.call(that,el,event)}}.bind(this))}},{"../events/on":4,"../util/clone":20}],13:[function(require,module,exports){var clone=require("../util/clone");var newUid=require("../uniqueid");var trigger=require("../events/trigger");module.exports=function(responseText,request,href,options){options=clone(options||this.options);options.request=request;if(responseText===false){trigger(document,"pjax:complete pjax:error",options);return}var currentState=window.history.state||{};window.history.replaceState({url:currentState.url||window.location.href,title:currentState.title||document.title,uid:currentState.uid||newUid(),scrollPos:[document.documentElement.scrollLeft||document.body.scrollLeft,document.documentElement.scrollTop||document.body.scrollTop]},document.title,window.location.href);var oldHref=href;if(request.responseURL){if(href!==request.responseURL){href=request.responseURL}}else if(request.getResponseHeader("X-PJAX-URL")){href=request.getResponseHeader("X-PJAX-URL")}else if(request.getResponseHeader("X-XHR-Redirected-To")){href=request.getResponseHeader("X-XHR-Redirected-To")}var a=document.createElement("a");a.href=oldHref;var oldHash=a.hash;a.href=href;if(oldHash&&!a.hash){a.hash=oldHash;href=a.href}this.state.href=href;this.state.options=options;try{this.loadContent(responseText,options)}catch(e){trigger(document,"pjax:error",options);if(!this.options.debug){if(console&&console.error){console.error("Pjax switch fail: ",e)}return this.latestChance(href)}else{throw e}}}},{"../events/trigger":5,"../uniqueid":19,"../util/clone":20}],14:[function(require,module,exports){module.exports=function(){if(this.options.debug&&console){if(typeof console.log==="function"){console.log.apply(console,arguments)}else if(console.log){console.log(arguments)}}}},{}],15:[function(require,module,exports){var attrState="data-pjax-state";module.exports=function(el){switch(el.tagName.toLowerCase()){case"a":if(!el.hasAttribute(attrState)){this.attachLink(el)}break;case"form":if(!el.hasAttribute(attrState)){this.attachForm(el)}break;default:throw"Pjax can only be applied on <a> or <form> submit"}}},{}],16:[function(require,module,exports){var updateQueryString=require("./util/update-query-string");module.exports=function(location,options,callback){options=options||{};var queryString;var requestOptions=options.requestOptions||{};var requestMethod=(requestOptions.requestMethod||"GET").toUpperCase();var requestParams=requestOptions.requestParams||null;var formData=requestOptions.formData||null;var requestPayload=null;var request=new XMLHttpRequest;var timeout=options.timeout||0;request.onreadystatechange=function(){if(request.readyState===4){if(request.status===200){callback(request.responseText,request,location,options)}else if(request.status!==0){callback(null,request,location,options)}}};request.onerror=function(e){console.log(e);callback(null,request,location,options)};request.ontimeout=function(){callback(null,request,location,options)};if(requestParams&&requestParams.length){queryString=requestParams.map(function(param){return param.name+"="+param.value}).join("&");switch(requestMethod){case"GET":location=location.split("?")[0];location+="?"+queryString;break;case"POST":requestPayload=queryString;break}}else if(formData){requestPayload=formData}if(options.cacheBust){location=updateQueryString(location,"t",Date.now())}request.open(requestMethod,location,true);request.timeout=timeout;request.setRequestHeader("X-Requested-With","XMLHttpRequest");request.setRequestHeader("X-PJAX","true");request.setRequestHeader("X-PJAX-Selectors",JSON.stringify(options.selectors));if(requestPayload&&requestMethod==="POST"&&!formData){request.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}request.send(requestPayload);return request}},{"./util/update-query-string":24}],17:[function(require,module,exports){var forEachEls=require("./foreach-els");var defaultSwitches=require("./switches");module.exports=function(switches,switchesOptions,selectors,fromEl,toEl,options){var switchesQueue=[];selectors.forEach(function(selector){var newEls=fromEl.querySelectorAll(selector);var oldEls=toEl.querySelectorAll(selector);if(this.log){this.log("Pjax switch",selector,newEls,oldEls)}if(newEls.length!==oldEls.length){throw"DOM doesn’t look the same on new loaded page: ’"+selector+"’ - new "+newEls.length+", old "+oldEls.length}forEachEls(newEls,function(newEl,i){var oldEl=oldEls[i];if(this.log){this.log("newEl",newEl,"oldEl",oldEl)}var callback=switches[selector]?switches[selector].bind(this,oldEl,newEl,options,switchesOptions[selector]):defaultSwitches.outerHTML.bind(this,oldEl,newEl,options);switchesQueue.push(callback)},this)},this);this.state.numPendingSwitches=switchesQueue.length;switchesQueue.forEach(function(queuedSwitch){queuedSwitch()})}},{"./foreach-els":7,"./switches":18}],18:[function(require,module,exports){var on=require("./events/on");module.exports={outerHTML:function(oldEl,newEl){oldEl.outerHTML=newEl.outerHTML;this.onSwitch()},innerHTML:function(oldEl,newEl){oldEl.innerHTML=newEl.innerHTML;if(newEl.className===""){oldEl.removeAttribute("class")}else{oldEl.className=newEl.className}this.onSwitch()},switchElementsAlt:function(oldEl,newEl){oldEl.innerHTML=newEl.innerHTML;if(newEl.hasAttributes()){var attrs=newEl.attributes;for(var i=0;i<attrs.length;i++){oldEl.attributes.setNamedItem(attrs[i].cloneNode())}}this.onSwitch()},replaceNode:function(oldEl,newEl){oldEl.parentNode.replaceChild(newEl,oldEl);this.onSwitch()},sideBySide:function(oldEl,newEl,options,switchOptions){var forEach=Array.prototype.forEach;var elsToRemove=[];var elsToAdd=[];var fragToAppend=document.createDocumentFragment();var animationEventNames="animationend webkitAnimationEnd MSAnimationEnd oanimationend";var animatedElsNumber=0;var sexyAnimationEnd=function(e){if(e.target!==e.currentTarget){return}animatedElsNumber--;if(animatedElsNumber<=0&&elsToRemove){elsToRemove.forEach(function(el){if(el.parentNode){el.parentNode.removeChild(el)}});elsToAdd.forEach(function(el){el.className=el.className.replace(el.getAttribute("data-pjax-classes"),"");el.removeAttribute("data-pjax-classes")});elsToAdd=null;elsToRemove=null;this.onSwitch()}}.bind(this);switchOptions=switchOptions||{};forEach.call(oldEl.childNodes,function(el){elsToRemove.push(el);if(el.classList&&!el.classList.contains("js-Pjax-remove")){if(el.hasAttribute("data-pjax-classes")){el.className=el.className.replace(el.getAttribute("data-pjax-classes"),"");el.removeAttribute("data-pjax-classes")}el.classList.add("js-Pjax-remove");if(switchOptions.callbacks&&switchOptions.callbacks.removeElement){switchOptions.callbacks.removeElement(el)}if(switchOptions.classNames){el.className+=" "+switchOptions.classNames.remove+" "+(options.backward?switchOptions.classNames.backward:switchOptions.classNames.forward)}animatedElsNumber++;on(el,animationEventNames,sexyAnimationEnd,true)}});forEach.call(newEl.childNodes,function(el){if(el.classList){var addClasses="";if(switchOptions.classNames){addClasses=" js-Pjax-add "+switchOptions.classNames.add+" "+(options.backward?switchOptions.classNames.forward:switchOptions.classNames.backward)}if(switchOptions.callbacks&&switchOptions.callbacks.addElement){switchOptions.callbacks.addElement(el)}el.className+=addClasses;el.setAttribute("data-pjax-classes",addClasses);elsToAdd.push(el);fragToAppend.appendChild(el);animatedElsNumber++;on(el,animationEventNames,sexyAnimationEnd,true)}});oldEl.className=newEl.className;oldEl.appendChild(fragToAppend)}}},{"./events/on":4}],19:[function(require,module,exports){module.exports=function(){var counter=0;return function(){var id="pjax"+(new Date).getTime()+"_"+counter;counter++;return id}}()},{}],20:[function(require,module,exports){module.exports=function(obj){if(null===obj||"object"!==typeof obj){return obj}var copy=obj.constructor();for(var attr in obj){if(obj.hasOwnProperty(attr)){copy[attr]=obj[attr]}}return copy}},{}],21:[function(require,module,exports){module.exports=function contains(doc,selectors,el){for(var i=0;i<selectors.length;i++){var selectedEls=doc.querySelectorAll(selectors[i]);for(var j=0;j<selectedEls.length;j++){if(selectedEls[j].contains(el)){return true}}}return false}},{}],22:[function(require,module,exports){module.exports=function(target){if(target==null){return null}var to=Object(target);for(var i=1;i<arguments.length;i++){var source=arguments[i];if(source!=null){for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){to[key]=source[key]}}}}return to}},{}],23:[function(require,module,exports){module.exports=function(){}},{}],24:[function(require,module,exports){module.exports=function(uri,key,value){var re=new RegExp("([?&])"+key+"=.*?(&|$)","i");var separator=uri.indexOf("?")!==-1?"&":"?";if(uri.match(re)){return uri.replace(re,"$1"+key+"="+value+"$2")}else{return uri+separator+key+"="+value}}},{}]},{},[1])(1)});
|
package/source/js/pjax.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
let pjax;
|
|
3
|
-
|
|
4
|
-
function initPjax() {
|
|
5
|
-
try {
|
|
6
|
-
const Pjax = window.Pjax || (() => {});
|
|
7
|
-
pjax = new Pjax({
|
|
8
|
-
selectors: ["[data-pjax]", ".pjax-reload", "head title"],
|
|
9
|
-
cacheBust: false,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
window.addEventListener("popstate", () => {
|
|
13
|
-
if (pjax?.loadUrl) {
|
|
14
|
-
pjax.loadUrl(window.location.href);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
} catch (e) {
|
|
18
|
-
console.warn(`PJAX error: ${e}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
document.addEventListener("DOMContentLoaded", () => initPjax());
|
|
23
|
-
})();
|