fix(runtime): remove stale aksrt namespace dependency
This commit is contained in:
1 parent
03dd4ea707
commit
9d458dd99a
4 files changed
+51
-12
No files matched your search
@@ -88,7 +88,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleDelete(commentEl, commentId) {
|
function handleDelete(commentEl, commentId) {
|
||||||
var msg = (window.aksrt && aksrt.__) ? aksrt.__('comment_confirm_delete', '确定要删除这条评论吗?') : '确定要删除这条评论吗?';
|
var msg = '确定要删除这条评论吗?';
|
||||||
var doDelete = function () {
|
var doDelete = function () {
|
||||||
restPost('/comment/delete', { comment_id: commentId })
|
restPost('/comment/delete', { comment_id: commentId })
|
||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
@@ -118,9 +118,7 @@
|
|||||||
.catch(function () { notyf('网络错误', 'danger'); });
|
.catch(function () { notyf('网络错误', 'danger'); });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (window.aksrt && aksrt.confirm) {
|
if (window.confirm(msg)) {
|
||||||
aksrt.confirm(msg).then(function (ok) { if (ok) doDelete(); });
|
|
||||||
} else if (window.confirm(msg)) {
|
|
||||||
doDelete();
|
doDelete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,7 +189,7 @@
|
|||||||
themeInitialized = true;
|
themeInitialized = true;
|
||||||
|
|
||||||
var stored = getStoredTheme();
|
var stored = getStoredTheme();
|
||||||
var configuredMode = (window.aksrtData && aksrtData.themeMode) || "light";
|
var configuredMode = (window.aksrtData && window.aksrtData.themeMode) || "light";
|
||||||
if (stored === "dark" || stored === "light") {
|
if (stored === "dark" || stored === "light") {
|
||||||
applyTheme(stored);
|
applyTheme(stored);
|
||||||
} else {
|
} else {
|
||||||
@@ -262,12 +262,6 @@
|
|||||||
bindToggle("dropdown-theme-toggle");
|
bindToggle("dropdown-theme-toggle");
|
||||||
bindToggle("float-theme-toggle");
|
bindToggle("float-theme-toggle");
|
||||||
bindToggle("theme-toggle-mobile");
|
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") {
|
if (document.readyState === "loading") {
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1 +1 @@
|
|||||||
(function($,window2,document2){"use strict";function closeNotyf($element){$element.addClass("notyn-out"),window2.setTimeout(function(){$element.remove()},1e3)}function notyf2(message,type,time,id){var $body=jQuery(document2.body);jQuery(".notyn").length||$body.append('<div class="notyn"></div>'),type=type||"success",type==="error"&&(type="danger"),time=time||5e3,time=time<100?time*1e3:time;var idAttribute=id?' id="'+id+'"':"",$notification=jQuery('<div class="noty1"'+idAttribute+'><div class="notyf '+type+'">'+message+"</div></div>"),shouldClose=!id;id&&jQuery("#"+id).length?(jQuery("#"+id).find(".notyf").removeClass().addClass("notyf "+type).html(message),$notification=jQuery("#"+id),shouldClose=!0):jQuery(".notyn").append($notification),shouldClose&&window2.setTimeout(function(){closeNotyf($notification)},time)}jQuery(document2.body).on("click",".noty1",function(){closeNotyf(jQuery(this))}),window2.notyf=notyf2})(jQuery,window,document),(function(window2){"use strict";var allowedKinds={identity:!0,badges:!0,orders:!0,vip:!0},allowedEvents={click:!0,shell:!0,"first-content":!0,ready:!0,"action-start":!0,"action-end":!0,unauthorized:!0,error:!0},sessions=Object.create(null),sequence=0,maxSessions=100;function normalize(value,fallback){var normalized=String(value||fallback||"").toLowerCase().replace(/[^a-z0-9-]/g,"");return normalized||fallback}function now(){return window2.performance&&typeof window2.performance.now=="function"?window2.performance.now():0}function markName(session,event){return"aksrt-modal-"+session.kind+"-"+session.id+"-"+event}function emit(session,event){if(!(!window2.performance||typeof window2.performance.mark!="function")){var name=markName(session,event);if(window2.performance.mark(name),session.marks[event]=name,typeof window2.performance.measure=="function"&&session.marks.click&&event!=="click")try{window2.performance.measure("aksrt-modal-"+session.kind+"-"+session.id+"-click-to-"+event,session.marks.click,name)}catch{}}}function start(kind){var safeKind=normalize(kind,"unknown");allowedKinds[safeKind]||(safeKind="unknown"),sequence+=1;var id=String(sequence),session={id,kind:safeKind,startedAt:now(),marks:Object.create(null)};sessions[id]=session,emit(session,"click");for(var ids=Object.keys(sessions);ids.length>maxSessions;)delete sessions[ids.shift()];return id}function mark(id,event){var session=sessions[String(id||"")],safeEvent=normalize(event,"error");!session||!allowedEvents[safeEvent]||emit(session,safeEvent)}function finish(id){mark(id,"ready")}function fail(id){mark(id,"error")}window2.AksrtModalTelemetry={start,mark,finish,error:fail}})(window),(function(window2){"use strict";function data(){return window2.aksrtData||window2.aksrt||{}}function createIdempotencyKey(){if(window2.crypto&&typeof window2.crypto.randomUUID=="function")return window2.crypto.randomUUID();if(!window2.crypto||typeof window2.crypto.getRandomValues!="function")throw new Error("当前浏览器无法生成安全的操作标识");var bytes=new Uint8Array(16);window2.crypto.getRandomValues(bytes),bytes[6]=bytes[6]&15|64,bytes[8]=bytes[8]&63|128;var hex=Array.prototype.map.call(bytes,function(value){return value.toString(16).padStart(2,"0")}).join("");return hex.slice(0,8)+"-"+hex.slice(8,12)+"-"+hex.slice(12,16)+"-"+hex.slice(16,20)+"-"+hex.slice(20)}function restBase(){var config=data(),raw=config.restUrl||config.apiUrl||config.rest_url||"",siteUrl=config.siteUrl||config.homeUrl||window2.location.origin+"/";return window2.location.protocol==="https:"&&siteUrl.substring(0,5)==="http:"&&(siteUrl="https:"+siteUrl.substring(5)),raw?String(raw).replace(/\/$/,""):String(siteUrl).replace(/\/$/,"")+"/index.php?rest_route=/aksrt/v1"}function appendQuery(url2,query){if(!query)return url2;var parts=[];return typeof query=="string"?parts=query.replace(/^\?/,"").split("&").filter(Boolean):typeof query=="object"&&Object.keys(query).forEach(function(key){query[key]===void 0||query[key]===null||parts.push(encodeURIComponent(key)+"="+encodeURIComponent(String(query[key])))}),parts.length?url2+(url2.indexOf("?")>=0?"&":"?")+parts.join("&"):url2}function url(path,query){path=String(path||"");var inlineQuery="",queryIndex=path.indexOf("?");if(queryIndex>=0&&(inlineQuery=path.slice(queryIndex+1),path=path.slice(0,queryIndex)),/^https?:\/\//i.test(path))return appendQuery(path,query||inlineQuery);path.charAt(0)!=="/"&&(path="/"+path);var base=restBase(),result=(base.indexOf("rest_route=")>=0,base+path);return appendQuery(result,query||inlineQuery)}function headers(options){var config=data(),source=options&&options.headers||{},result={},nonce=config.restNonce||config.nonce||"";return Object.keys(source).forEach(function(key){result[key]=source[key]}),result.Accept||(result.Accept="application/json, text/html;q=0.9, */*;q=0.8"),nonce&&!result["X-WP-Nonce"]&&(result["X-WP-Nonce"]=nonce),options&&options.body!==void 0&&options.body!==null&&!(window2.FormData&&options.body instanceof window2.FormData)&&!result["Content-Type"]&Line truncated
|
(function($,window2,document2){"use strict";function closeNotyf($element){$element.addClass("notyn-out"),window2.setTimeout(function(){$element.remove()},1e3)}function notyf2(message,type,time,id){var $body=jQuery(document2.body);jQuery(".notyn").length||$body.append('<div class="notyn"></div>'),type=type||"success",type==="error"&&(type="danger"),time=time||5e3,time=time<100?time*1e3:time;var idAttribute=id?' id="'+id+'"':"",$notification=jQuery('<div class="noty1"'+idAttribute+'><div class="notyf '+type+'">'+message+"</div></div>"),shouldClose=!id;id&&jQuery("#"+id).length?(jQuery("#"+id).find(".notyf").removeClass().addClass("notyf "+type).html(message),$notification=jQuery("#"+id),shouldClose=!0):jQuery(".notyn").append($notification),shouldClose&&window2.setTimeout(function(){closeNotyf($notification)},time)}jQuery(document2.body).on("click",".noty1",function(){closeNotyf(jQuery(this))}),window2.notyf=notyf2})(jQuery,window,document),(function(window2){"use strict";var allowedKinds={identity:!0,badges:!0,orders:!0,vip:!0},allowedEvents={click:!0,shell:!0,"first-content":!0,ready:!0,"action-start":!0,"action-end":!0,unauthorized:!0,error:!0},sessions=Object.create(null),sequence=0,maxSessions=100;function normalize(value,fallback){var normalized=String(value||fallback||"").toLowerCase().replace(/[^a-z0-9-]/g,"");return normalized||fallback}function now(){return window2.performance&&typeof window2.performance.now=="function"?window2.performance.now():0}function markName(session,event){return"aksrt-modal-"+session.kind+"-"+session.id+"-"+event}function emit(session,event){if(!(!window2.performance||typeof window2.performance.mark!="function")){var name=markName(session,event);if(window2.performance.mark(name),session.marks[event]=name,typeof window2.performance.measure=="function"&&session.marks.click&&event!=="click")try{window2.performance.measure("aksrt-modal-"+session.kind+"-"+session.id+"-click-to-"+event,session.marks.click,name)}catch{}}}function start(kind){var safeKind=normalize(kind,"unknown");allowedKinds[safeKind]||(safeKind="unknown"),sequence+=1;var id=String(sequence),session={id,kind:safeKind,startedAt:now(),marks:Object.create(null)};sessions[id]=session,emit(session,"click");for(var ids=Object.keys(sessions);ids.length>maxSessions;)delete sessions[ids.shift()];return id}function mark(id,event){var session=sessions[String(id||"")],safeEvent=normalize(event,"error");!session||!allowedEvents[safeEvent]||emit(session,safeEvent)}function finish(id){mark(id,"ready")}function fail(id){mark(id,"error")}window2.AksrtModalTelemetry={start,mark,finish,error:fail}})(window),(function(window2){"use strict";function data(){return window2.aksrtData||window2.aksrt||{}}function createIdempotencyKey(){if(window2.crypto&&typeof window2.crypto.randomUUID=="function")return window2.crypto.randomUUID();if(!window2.crypto||typeof window2.crypto.getRandomValues!="function")throw new Error("当前浏览器无法生成安全的操作标识");var bytes=new Uint8Array(16);window2.crypto.getRandomValues(bytes),bytes[6]=bytes[6]&15|64,bytes[8]=bytes[8]&63|128;var hex=Array.prototype.map.call(bytes,function(value){return value.toString(16).padStart(2,"0")}).join("");return hex.slice(0,8)+"-"+hex.slice(8,12)+"-"+hex.slice(12,16)+"-"+hex.slice(16,20)+"-"+hex.slice(20)}function restBase(){var config=data(),raw=config.restUrl||config.apiUrl||config.rest_url||"",siteUrl=config.siteUrl||config.homeUrl||window2.location.origin+"/";return window2.location.protocol==="https:"&&siteUrl.substring(0,5)==="http:"&&(siteUrl="https:"+siteUrl.substring(5)),raw?String(raw).replace(/\/$/,""):String(siteUrl).replace(/\/$/,"")+"/index.php?rest_route=/aksrt/v1"}function appendQuery(url2,query){if(!query)return url2;var parts=[];return typeof query=="string"?parts=query.replace(/^\?/,"").split("&").filter(Boolean):typeof query=="object"&&Object.keys(query).forEach(function(key){query[key]===void 0||query[key]===null||parts.push(encodeURIComponent(key)+"="+encodeURIComponent(String(query[key])))}),parts.length?url2+(url2.indexOf("?")>=0?"&":"?")+parts.join("&"):url2}function url(path,query){path=String(path||"");var inlineQuery="",queryIndex=path.indexOf("?");if(queryIndex>=0&&(inlineQuery=path.slice(queryIndex+1),path=path.slice(0,queryIndex)),/^https?:\/\//i.test(path))return appendQuery(path,query||inlineQuery);path.charAt(0)!=="/"&&(path="/"+path);var base=restBase(),result=(base.indexOf("rest_route=")>=0,base+path);return appendQuery(result,query||inlineQuery)}function headers(options){var config=data(),source=options&&options.headers||{},result={},nonce=config.restNonce||config.nonce||"";return Object.keys(source).forEach(function(key){result[key]=source[key]}),result.Accept||(result.Accept="application/json, text/html;q=0.9, */*;q=0.8"),nonce&&!result["X-WP-Nonce"]&&(result["X-WP-Nonce"]=nonce),options&&options.body!==void 0&&options.body!==null&&!(window2.FormData&&options.body instanceof window2.FormData)&&!result["Content-Type"]&Line truncated
|
||||||
@@ -4,6 +4,7 @@ const assert = require('node:assert/strict');
|
|||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const test = require('node:test');
|
const test = require('node:test');
|
||||||
|
const vm = require('node:vm');
|
||||||
|
|
||||||
const root = path.resolve(__dirname, '..', '..');
|
const root = path.resolve(__dirname, '..', '..');
|
||||||
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
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['"]\)/);
|
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', () => {
|
test('routed modules use one namespaced auto_fun owner and no registry', () => {
|
||||||
for (const file of routed) {
|
for (const file of routed) {
|
||||||
const source = read(file);
|
const source = read(file);
|
||||||
|
|||||||
Reference in new issue
Block a user