From 641c4879160e56acef6b0b6823fb7ab3664d409c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AA=E5=AD=90?= Date: Wed, 24 Jul 2024 16:59:58 +0800 Subject: [PATCH] 0.5.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后台编辑器添加引用文章的按钮 --- functions.php | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 73c662b..45c5a0f 100644 --- a/functions.php +++ b/functions.php @@ -603,4 +603,42 @@ class ContentProcessor { } } -register_shortcodes(); \ No newline at end of file +register_shortcodes(); + +//在编辑器中添加插入文章引用的按钮 +class EditorButton { + public static function render() + { + echo << +$(document).ready(function() { + $('#wmd-button-row').append('
  • '); + + $('#wmd-article-button').click(function() { + var articleId = prompt("请输入要引用的文章ID:"); + if (articleId) { + var text = "[article id=\"" + articleId + "\"]"; + var textarea = $('#text')[0]; + var start = textarea.selectionStart; + var end = textarea.selectionEnd; + var value = textarea.value; + + textarea.value = value.substring(0, start) + text + value.substring(end); + + // 将光标移动到插入的文本之后 + textarea.setSelectionRange(start + text.length, start + text.length); + textarea.focus(); + + // 触发change事件,确保编辑器更新 + $('#text').trigger('change'); + } + }); +}); + +EOF; + } +} + +// 注册钩子 +Typecho_Plugin::factory('admin/write-post.php')->bottom = array('EditorButton', 'render'); +Typecho_Plugin::factory('admin/write-page.php')->bottom = array('EditorButton', 'render');