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');