Skip to content

Commit

Permalink
Merge pull request #1287 from PJ-568/master
Browse files Browse the repository at this point in the history
feat(core): Add preliminary support for PJAX
  • Loading branch information
ppoffice authored May 1, 2024
2 parents a494912 + fefc77d commit c409f60
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/schema/common/plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"outdated_browser": {
"$ref": "/plugin/outdated_browser.json"
},
"pjax": {
"$ref": "/plugin/pjax.json"
},
"progressbar": {
"$ref": "/plugin/progressbar.json"
},
Expand Down
7 changes: 7 additions & 0 deletions include/schema/plugin/pjax.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/plugin/pjax.json",
"description": "Enable PJAX",
"type": "boolean",
"default": true
}
4 changes: 2 additions & 2 deletions layout/common/head.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ module.exports = class extends Component {
{rss ? <link rel="alternate" href={url_for(rss)} title={config.title} type="application/atom+xml" /> : null}
{favicon ? <link rel="icon" href={url_for(favicon)} /> : null}
<link rel="stylesheet" href={iconcdn()} />
{hlTheme ? <link rel="stylesheet" href={cdn('highlight.js', '11.7.0', 'styles/' + hlTheme + '.css')} /> : null}
{hlTheme ? <link data-pjax rel="stylesheet" href={cdn('highlight.js', '11.7.0', 'styles/' + hlTheme + '.css')} /> : null}
<link rel="stylesheet" href={fontCssUrl[variant]} />
<link rel="stylesheet" href={url_for('/css/' + variant + '.css')} />
<link data-pjax rel="stylesheet" href={url_for('/css/' + variant + '.css')} />
<Plugins site={site} config={config} helper={helper} page={page} head={true} />

{adsenseClientId ? <script data-ad-client={adsenseClientId}
Expand Down
4 changes: 2 additions & 2 deletions layout/common/scripts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ module.exports = class extends Component {
{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>
</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
18 changes: 18 additions & 0 deletions layout/plugin/pjax.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { Component, Fragment } = require('inferno');

class Pjax extends Component {
render() {
if (this.props.head) {
return null;
}
const { helper } = this.props;
const { url_for, cdn } = helper;

return <Fragment>
<script src={cdn('pjax', '0.2.8', 'pjax.min.js')}></script>
<script src={url_for('/js/pjax.js')}></script>
</Fragment>;
}
}

module.exports = Pjax;
38 changes: 38 additions & 0 deletions source/js/pjax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function() {
// eslint-disable-next-line no-unused-vars
let pjax;

function initPjax() {
try {
const Pjax = window.Pjax || function() {};
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
// })

document.addEventListener('DOMContentLoaded', () => initPjax());
}());

0 comments on commit c409f60

Please sign in to comment.