进行了一些小修复

This commit is contained in:
2026-08-26 17:24:37 +08:00
parent 5121b33ad5
commit bfc16de962
6 changed files with 13 additions and 68 deletions
File diff suppressed because one or more lines are too long
-25
View File
@@ -1,25 +0,0 @@
/**
* Passive event listener polyfill
*
* Patches addEventListener so scroll-blocking events (touchstart, touchmove,
* wheel, mousewheel) default to { passive: true } unless explicitly set to
* false. Eliminates Chrome Violation warnings from third-party libraries.
*/
(function () {
'use strict';
var opts = Object.defineProperty({}, 'passive', {
get: function () { window.__passiveSupported = true; }
});
window.addEventListener('test', null, opts);
if (!window.__passiveSupported) return;
var orig = EventTarget.prototype.addEventListener;
var passiveEvents = { touchstart: 1, touchmove: 1, wheel: 1, mousewheel: 1 };
EventTarget.prototype.addEventListener = function (type, listener, options) {
if (passiveEvents[type] && typeof options !== 'object') {
options = { passive: true, capture: options };
}
orig.call(this, type, listener, options);
};
})();
-1
View File
@@ -27,7 +27,6 @@ class Scripts {
public function init(): void { public function init(): void {
add_action('wp_enqueue_scripts', [$this, 'enqueue_public']); add_action('wp_enqueue_scripts', [$this, 'enqueue_public']);
add_action('admin_enqueue_scripts', [$this, 'enqueue_admin']); add_action('admin_enqueue_scripts', [$this, 'enqueue_admin']);
add_action('admin_enqueue_scripts', [$this, 'enqueue_passive_polyfill'], 1);
add_action('wp_head', [$this, 'inline_css_vars']); add_action('wp_head', [$this, 'inline_css_vars']);
add_action('wp_head', [$this, 'output_custom_codes']); add_action('wp_head', [$this, 'output_custom_codes']);
add_action('wp_body_open', [$this, 'output_loading_overlay'], 1); add_action('wp_body_open', [$this, 'output_loading_overlay'], 1);
-13
View File
@@ -30,19 +30,6 @@ trait ScriptsPart2 {
wp_send_json_success(['logged' => true]); wp_send_json_success(['logged' => true]);
} }
/**
* Passive event listener polyfill — 全局加载,消除 Chrome Violation 警告
*/
public function enqueue_passive_polyfill(): void {
wp_enqueue_script(
'aksrt-passive-events',
get_template_directory_uri() . '/assets/js/passive-events.js',
[],
AKSRT_VERSION,
false
);
}
/** /**
* 加载后台资源 — 仅在 AKSRT 设置页面加载(与前端样式完全隔离) * 加载后台资源 — 仅在 AKSRT 设置页面加载(与前端样式完全隔离)
*/ */
@@ -64,3 +64,16 @@ test('legacy runtime modules use jQuery explicitly without a dollar alias', () =
} }
} }
}); });
test('theme runtime never changes native listener passivity for third-party editors', () => {
const scripts = read('src/Core/Scripts.php');
const scriptsPart2 = read('src/Core/ScriptsPart2.php');
const buildTool = read('tools/build-public-assets.mjs');
const publicRuntime = read('assets/js/build/public.js');
assert.doesNotMatch(scripts, /enqueue_passive_polyfill|aksrt-passive-events/);
assert.doesNotMatch(scriptsPart2, /enqueue_passive_polyfill|aksrt-passive-events/);
assert.doesNotMatch(buildTool, /passive-events\.js/);
assert.doesNotMatch(publicRuntime, /EventTarget\.prototype\.addEventListener|__passiveSupported/);
assert.equal(fs.existsSync(path.join(root, 'assets/js/passive-events.js')), false);
});
-1
View File
@@ -60,7 +60,6 @@ const cssBundles = {
}; };
const publicScripts = [ const publicScripts = [
'assets/js/passive-events.js',
'assets/js/runtime/libs/bootstrap.min.js', 'assets/js/runtime/libs/bootstrap.min.js',
'assets/js/runtime/loader.js', 'assets/js/runtime/loader.js',
'assets/js/lazy-image-attr.js', 'assets/js/lazy-image-attr.js',