Skip to content

Commit

Permalink
feat(core): Add preliminary support for PJAX
Browse files Browse the repository at this point in the history
  • Loading branch information
PJ-568 committed Apr 25, 2024
1 parent 866c59f commit e7d62c6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
8 changes: 6 additions & 2 deletions layout/common/scripts.jsx
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -32,12 +33,15 @@ module.exports = class extends Component {
return <Fragment>
<script src={cdn('jquery', '3.3.1', 'dist/jquery.min.js')}></script>
<script src={cdn('moment', '2.22.2', 'min/moment-with-locales.min.js')}></script>
{/* <script src={cdn('pjax', '0.2.8', 'min/pjax.min.js')}></script> */}
<script src={pjaxMinJsPath}></script>
{clipboard && <script src={cdn('clipboard', '2.0.4', 'dist/clipboard.min.js')} defer></script>}
<script dangerouslySetInnerHTML={{ __html: `moment.locale("${language}");` }}></script>
<script dangerouslySetInnerHTML={{ __html: embeddedConfig }}></script>
<script src={url_for('/js/column.js')}></script>
<script data-pjax src={url_for('/js/column.js')}></script>
<Plugins site={site} config={config} page={page} helper={helper} head={false} />
<script src={url_for('/js/main.js')} defer></script>
<script data-pjax src={url_for('/js/main.js')} defer></script>
<script src={url_for('/js/pjax.js')}></script>
</Fragment>;
}
};
2 changes: 1 addition & 1 deletion layout/plugin/back_to_top.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BackToTop extends Component {
<a id="back-to-top" title={title} href="javascript:;">
<i class="fas fa-chevron-up"></i>
</a>
<script src={jsUrl} defer></script>
<script data-pjax src={jsUrl} defer></script>
</Fragment>;

}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
36 changes: 36 additions & 0 deletions source/js/pjax.js
Original file line number Diff line number Diff line change
@@ -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());

0 comments on commit e7d62c6

Please sign in to comment.