【发布时间】:2016-10-06 04:14:12
【问题描述】:
在 WordPress 中,我的编辑器中有一个可操作的简码按钮,我希望能够在单击后在光标的最后一个位置周围添加两个简码标签(一个开头和一个结尾),但我一直无法找到关于该主题的先前问答,我参考了 Command Identifiers 的 TinyMCE 文档。这是我的 shortcode.js 文件:
(function() {
tinymce.PluginManager.add('foobar', function(editor, url) {
editor.addButton('foobar', {
title : 'This is just a test',
text : '<foobar>',
icon : false,
onclick : function() {
editor.execCommand(
"mceInsertContent",
false,
'[foobar][/foobar]'
);
}
});
});
})(jQuery);
所以一旦点击按钮<foobar>,它就会生成:
<foobar></foobar>cursor is here
光标位于</foobar> 之后。我在编辑器中使用了错误的方法吗?这可能是一个相关的问题,但如果我想构建另一个短代码,它会添加三行,甚至有办法,例如:
<foobar>
<!-- Cursor lands here
</foobar>
在 tinyMCE 中控制光标位置的适当命令是什么?
【问题讨论】:
标签: jquery wordpress button tinymce shortcode