fix(runtime): remove stale aksrt namespace dependency
This commit is contained in:
@@ -88,7 +88,7 @@
|
||||
}
|
||||
|
||||
function handleDelete(commentEl, commentId) {
|
||||
var msg = (window.aksrt && aksrt.__) ? aksrt.__('comment_confirm_delete', '确定要删除这条评论吗?') : '确定要删除这条评论吗?';
|
||||
var msg = '确定要删除这条评论吗?';
|
||||
var doDelete = function () {
|
||||
restPost('/comment/delete', { comment_id: commentId })
|
||||
.then(function (result) {
|
||||
@@ -118,9 +118,7 @@
|
||||
.catch(function () { notyf('网络错误', 'danger'); });
|
||||
};
|
||||
|
||||
if (window.aksrt && aksrt.confirm) {
|
||||
aksrt.confirm(msg).then(function (ok) { if (ok) doDelete(); });
|
||||
} else if (window.confirm(msg)) {
|
||||
if (window.confirm(msg)) {
|
||||
doDelete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
themeInitialized = true;
|
||||
|
||||
var stored = getStoredTheme();
|
||||
var configuredMode = (window.aksrtData && aksrtData.themeMode) || "light";
|
||||
var configuredMode = (window.aksrtData && window.aksrtData.themeMode) || "light";
|
||||
if (stored === "dark" || stored === "light") {
|
||||
applyTheme(stored);
|
||||
} else {
|
||||
@@ -262,12 +262,6 @@
|
||||
bindToggle("dropdown-theme-toggle");
|
||||
bindToggle("float-theme-toggle");
|
||||
bindToggle("theme-toggle-mobile");
|
||||
|
||||
aksrt.toggleTheme = function (event) {
|
||||
var next = document.body.classList.contains("theme-dark") ? "light" : "dark";
|
||||
setStoredTheme(next);
|
||||
runThemeTransition(next, event);
|
||||
};
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -4,6 +4,7 @@ const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const test = require('node:test');
|
||||
const vm = require('node:vm');
|
||||
|
||||
const root = path.resolve(__dirname, '..', '..');
|
||||
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
||||
@@ -44,6 +45,52 @@ test('main owns the one global auto_fun boot', () => {
|
||||
assert.match(main, /jQuery\(document\)\.trigger\(['"]auto_fun['"]\)/);
|
||||
});
|
||||
|
||||
test('theme and comments do not depend on the removed aksrt namespace APIs', () => {
|
||||
const theme = read('assets/js/core/theme.js');
|
||||
const comments = read('assets/js/comment-ajax.js');
|
||||
const runtime = read('assets/js/runtime/main.min.js');
|
||||
|
||||
assert.match(theme, /window\.aksrtData\.themeMode/);
|
||||
assert.doesNotMatch(theme, /(?:window\.)?aksrt\.toggleTheme/);
|
||||
assert.doesNotMatch(comments, /(?:window\.)?aksrt\.(?:__|confirm)/);
|
||||
assert.doesNotMatch(runtime, /(?:window\.)?aksrt\.(?:toggleTheme|__|confirm)/);
|
||||
});
|
||||
|
||||
test('theme initializes when the removed aksrt namespace is absent', () => {
|
||||
const classList = { toggle() {}, contains() { return false; } };
|
||||
const document = {
|
||||
readyState: 'complete',
|
||||
cookie: '',
|
||||
body: { classList, setAttribute() {} },
|
||||
documentElement: { classList, setAttribute() {} },
|
||||
head: { appendChild() {} },
|
||||
querySelector() { return null; },
|
||||
querySelectorAll() { return []; },
|
||||
getElementById() { return null; },
|
||||
createElement() { return { setAttribute() {} }; },
|
||||
dispatchEvent() {},
|
||||
};
|
||||
const window = {
|
||||
document,
|
||||
location: { protocol: 'https:' },
|
||||
localStorage: { getItem() { return null; }, setItem() {} },
|
||||
matchMedia() { return { matches: false }; },
|
||||
setTimeout,
|
||||
innerWidth: 1280,
|
||||
innerHeight: 720,
|
||||
};
|
||||
|
||||
assert.doesNotThrow(() => vm.runInNewContext(read('assets/js/core/theme.js'), {
|
||||
window,
|
||||
document,
|
||||
localStorage: window.localStorage,
|
||||
CustomEvent: class {},
|
||||
Date,
|
||||
Math,
|
||||
}));
|
||||
assert.equal(window.aksrt, undefined);
|
||||
});
|
||||
|
||||
test('routed modules use one namespaced auto_fun owner and no registry', () => {
|
||||
for (const file of routed) {
|
||||
const source = read(file);
|
||||
|
||||
Reference in New Issue
Block a user