From e7d62c6f606cc415ba74f474f94158ae4256b099 Mon Sep 17 00:00:00 2001 From: PJ568 Date: Thu, 25 Apr 2024 11:58:18 +0800 Subject: [PATCH] feat(core): Add preliminary support for PJAX Implements #1277 Related #1269 #992 #722 #649 #507 --- layout/common/scripts.jsx | 8 ++++++-- layout/plugin/back_to_top.jsx | 2 +- package.json | 1 + source/js/pjax.js | 36 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 source/js/pjax.js diff --git a/layout/common/scripts.jsx b/layout/common/scripts.jsx index 42fe538e3..0bf1a45ac 100644 --- a/layout/common/scripts.jsx +++ b/layout/common/scripts.jsx @@ -1,6 +1,7 @@ const { Component, Fragment } = require('inferno'); const { toMomentLocale } = require('hexo/dist/plugins/helper/date'); const Plugins = require('./plugins'); +const pjaxMinJsPath = require.resolve('pjax/pjax.min.js'); module.exports = class extends Component { render() { @@ -32,12 +33,15 @@ module.exports = class extends Component { return + {/* */} + {clipboard && } - + - + + ; } }; diff --git a/layout/plugin/back_to_top.jsx b/layout/plugin/back_to_top.jsx index c3b6e8d71..4581815cc 100644 --- a/layout/plugin/back_to_top.jsx +++ b/layout/plugin/back_to_top.jsx @@ -9,7 +9,7 @@ class BackToTop extends Component { - + ; } diff --git a/package.json b/package.json index c03923ff0..b999c1600 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "inferno": "^8.2.3", "inferno-create-element": "^8.2.3", "moment": "^2.30.1", + "pjax": "^0.2.8", "semver": "^7.5.4" } } diff --git a/source/js/pjax.js b/source/js/pjax.js new file mode 100644 index 000000000..2fec27d50 --- /dev/null +++ b/source/js/pjax.js @@ -0,0 +1,36 @@ +// eslint-disable-next-line no-unused-vars +let pjax; + +function initPjax() { + try { + // eslint-disable-next-line no-undef + pjax = new Pjax({ + selectors: [ + 'head title', + '.columns', + '.navbar-start', + '.navbar-end', + '.searchbox', + '#back-to-top', + '[data-pjax]', + '.pjax-reload' + ] + }); + } catch (e) { + console.warn('PJAX error: ' + e); + } +} + +// // Listen for start of Pjax +// document.addEventListener('pjax:send', function() { +// return; +// // TODO pace start loading animation +// }) + +// // Listen for completion of Pjax +// document.addEventListener('pjax:complete', function() { +// return; +// // TODO pace stop loading animation +// }) + +window.addEventListener('DOMContentLoaded', () => initPjax()); \ No newline at end of file