修复了一些问题

This commit is contained in:
kate522 committed 2026-08-25 19:59:43 +08:00
1 parent f5746da0ae
commit c484ee6ef3
5 files changed
+16 -87

No files matched your search

-4
View File
@@ -71,10 +71,6 @@
border: none; border: none;
} }
.aksrt-submit-editor-wrap textarea.wp-editor-area {
opacity: 1;
}
.aksrt-submit-editor-wrap .mce-toolbar-grp { .aksrt-submit-editor-wrap .mce-toolbar-grp {
background: var(--surface-1, #fff); background: var(--surface-1, #fff);
border-bottom: 1px solid var(--color-line, #eceff4); border-bottom: 1px solid var(--color-line, #eceff4);
-54
View File
@@ -100,7 +100,6 @@
if (!this.form) { if (!this.form) {
return; return;
} }
this.hydrateEditor();
this.bindDirty(); this.bindDirty();
this.bindAutoHeight(); this.bindAutoHeight();
this.bindSubmitButtons(); this.bindSubmitButtons();
@@ -114,59 +113,6 @@
this.loadFeaturedFromDom(); this.loadFeaturedFromDom();
}, },
hydrateEditor: function () {
var snapshot = document.getElementById('aksrt-initial-post-content');
var textarea = qs('#post_content') || qs('[name="post_content"]');
var initialContent = snapshot ? snapshot.value : textarea ? textarea.value : '';
if (!initialContent) {
return;
}
var fallbackToTextEditor = function () {
if (window.switchEditors && typeof window.switchEditors.go === 'function') {
window.switchEditors.go('post_content', 'html');
}
if (textarea) {
textarea.value = initialContent;
textarea.style.opacity = '1';
textarea.style.display = 'block';
}
};
var attempts = 0;
var restore = function () {
var editor = window.tinymce && window.tinymce.get('post_content');
if (!editor) {
attempts += 1;
if (attempts < 20) {
setTimeout(restore, 250);
} else {
fallbackToTextEditor();
}
return;
}
var hydrate = function () {
var current = editor.getContent({ format: 'raw' });
if (!current || !current.trim()) {
editor.setContent(initialContent);
editor.save();
}
if (!editor.getContent({ format: 'raw' }).trim()) {
fallbackToTextEditor();
}
};
if (editor.initialized) {
hydrate();
} else {
editor.on('init', hydrate);
}
};
restore();
},
bindDirty: function () { bindDirty: function () {
var self = this; var self = this;
this.form.addEventListener('input', function () { this.form.addEventListener('input', function () {
+5 -9
View File
@@ -16,15 +16,11 @@ trait ScriptsPart1b {
$runtime_uri = $base_uri . '/assets'; $runtime_uri = $base_uri . '/assets';
$fa5_uri = $base_uri . '/assets/fontawesome5'; $fa5_uri = $base_uri . '/assets/fontawesome5';
// The legacy frontend runtime is the single public dependency stack. // Keep the WordPress handle but make its modern core build the only runtime.
wp_deregister_script('jquery'); $wp_scripts = wp_scripts();
wp_register_script( if (isset($wp_scripts->registered['jquery'])) {
'jquery', $wp_scripts->registered['jquery']->deps = ['jquery-core'];
$runtime_uri . '/js/runtime/libs/jquery.min.js', }
[],
'1.9.1',
false
);
wp_enqueue_script('jquery'); wp_enqueue_script('jquery');
wp_enqueue_script( wp_enqueue_script(
+2 -8
View File
@@ -42,12 +42,6 @@ $is_can_new = !empty($ctx['is_can_new']);
<?php else : ?> <?php else : ?>
<div class="aksrt-submit-editor-wrap"> <div class="aksrt-submit-editor-wrap">
<?php <?php
$initial_content = (string) $ctx['current_content'];
if ($initial_content !== '') :
?>
<textarea id="aksrt-initial-post-content" hidden aria-hidden="true" tabindex="-1"><?php echo esc_textarea($initial_content); ?></textarea>
<?php
endif;
$toolbar1 = 'formatselect,bold,italic,bullist,numlist,alignleft,aligncenter,alignright,link,blockquote,code,fullscreen'; $toolbar1 = 'formatselect,bold,italic,bullist,numlist,alignleft,aligncenter,alignright,link,blockquote,code,fullscreen';
$plugins = 'paste,link,lists,fullscreen,wordpress,wplink,charmap'; $plugins = 'paste,link,lists,fullscreen,wordpress,wplink,charmap';
$editor_settings = [ $editor_settings = [
@@ -56,7 +50,7 @@ $is_can_new = !empty($ctx['is_can_new']);
'editor_height' => wp_is_mobile() ? 460 : 470, 'editor_height' => wp_is_mobile() ? 460 : 470,
'media_buttons' => false, 'media_buttons' => false,
'default_editor' => 'tinymce', 'default_editor' => 'tinymce',
'quicktags' => true, 'quicktags' => false,
'teeny' => false, 'teeny' => false,
'tinymce' => [ 'tinymce' => [
'toolbar1' => $toolbar1, 'toolbar1' => $toolbar1,
@@ -65,7 +59,7 @@ $is_can_new = !empty($ctx['is_can_new']);
'placeholder' => (string) ($settings['content_placeholder'] ?? ''), 'placeholder' => (string) ($settings['content_placeholder'] ?? ''),
], ],
]; ];
wp_editor($initial_content, 'post_content', $editor_settings); wp_editor((string) $ctx['current_content'], 'post_content', $editor_settings);
?> ?>
</div> </div>
@@ -21,19 +21,16 @@ test('published post content reaches the front submit editor unchanged', () => {
const editor = read('templates/parts/submit/editor-main.php'); const editor = read('templates/parts/submit/editor-main.php');
assert.match(context, /\$current_content\s*=\s*\$edit_post\s*\?\s*\$edit_post->post_content\s*:\s*'';/); assert.match(context, /\$current_content\s*=\s*\$edit_post\s*\?\s*\$edit_post->post_content\s*:\s*'';/);
assert.match(editor, /\$initial_content\s*=\s*\(string\) \$ctx\['current_content'\]/); assert.match(editor, /wp_editor\(\(string\) \$ctx\['current_content'\], 'post_content', \$editor_settings\);/);
assert.match(editor, /wp_editor\(\$initial_content, 'post_content', \$editor_settings\);/);
}); });
test('front submit restores published content when TinyMCE initializes empty', () => { test('front submit uses the WordPress registered jQuery runtime', () => {
const editor = read('templates/parts/submit/editor-main.php'); const source = read('src/Core/ScriptsPart1b.php');
const runtime = read('assets/js/front-submit.js');
const styles = read('assets/css/frontend/pages/submit.css');
assert.match(editor, /'quicktags'\s*=>\s*true/); assert.match(source, /wp_enqueue_script\('jquery'\);/);
assert.match(editor, /id="aksrt-initial-post-content"/); assert.match(source, /registered\['jquery'\]->deps\s*=\s*\['jquery-core'\]/);
assert.match(runtime, /hydrateEditor:\s*function/); assert.doesNotMatch(source, /wp_deregister_script\('jquery'\)/);
assert.match(runtime, /editor\.setContent\(initialContent\)/); assert.doesNotMatch(source, /wp_register_script\(\s*'jquery'/);
assert.match(runtime, /switchEditors\.go\('post_content', 'html'\)/); assert.doesNotMatch(source, /jquery-migrate/);
assert.match(styles, /textarea\.wp-editor-area\s*\{[^}]*opacity:\s*1/s); assert.doesNotMatch(source, /runtime\/libs\/jquery\.min\.js|['"]1\.9\.1['"]/);
}); });