优化pjax刷新
This commit is contained in:
1 parent
cc5887a74d
commit
cda4dbb24b
8 files changed
+65
-24
No files matched your search
@@ -75,6 +75,8 @@
|
||||
if (content) linkify(content);
|
||||
}
|
||||
|
||||
window.initLinkify = run;
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', run);
|
||||
} else {
|
||||
|
||||
@@ -171,5 +171,12 @@ document.addEventListener("pjax:complete", function () {
|
||||
} catch(e) { console.error('initImageFrameReveal error:', e); }
|
||||
}
|
||||
|
||||
// 重载文章动画
|
||||
if (typeof window.initPostScrollspy === 'function') window.initPostScrollspy();
|
||||
// 重载链接卡片
|
||||
if (typeof window.initLinkify === 'function') window.initLinkify();
|
||||
// 重载中英文间距
|
||||
if (typeof window.initPangu === 'function') window.initPangu();
|
||||
|
||||
refreshHeatmap();
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
// pangu.js - Auto insert spaces between CJK and half-width characters
|
||||
(function() {
|
||||
// CJK Unified Ideographs + common ranges
|
||||
var CJK = '⺀-⼀--ゟ゠-ヿ-ㄯ㈀-㋿㐀-䶿一-鿿豈-︰-﹏-';
|
||||
var CJK_RE = new RegExp('([' + CJK + '])', 'g');
|
||||
|
||||
// Insert space between CJK and half-width (letters, digits, symbols)
|
||||
function panguText(text) {
|
||||
// CJK followed by half-width
|
||||
text = text.replace(new RegExp('([' + CJK + '])([a-zA-Z0-9@#$%&=+<>|\\\\])', 'g'), '$1 $2');
|
||||
// Half-width followed by CJK
|
||||
text = text.replace(new RegExp('([a-zA-Z0-9@#$%&=+<>|\\\\])([' + CJK + '])', 'g'), '$1 $2');
|
||||
return text;
|
||||
}
|
||||
|
||||
function panguNode(root) {
|
||||
var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false);
|
||||
var nodes = [];
|
||||
while (walker.nextNode()) {
|
||||
var node = walker.currentNode;
|
||||
// Skip code, pre, script, style, input
|
||||
if (node.parentElement && node.parentElement.closest('code, pre, script, style, input, textarea')) continue;
|
||||
if (node.textContent.length > 1) nodes.push(node);
|
||||
}
|
||||
nodes.forEach(function(node) {
|
||||
var spaced = panguText(node.textContent);
|
||||
if (spaced !== node.textContent) node.textContent = spaced;
|
||||
});
|
||||
}
|
||||
|
||||
function run() {
|
||||
var content = document.querySelector('.post-content');
|
||||
if (content) panguNode(content);
|
||||
}
|
||||
|
||||
window.initPangu = run;
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', run);
|
||||
} else {
|
||||
run();
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user