我想在 tinymce v5 的插入/编辑链接对话框/弹出窗口中添加一个自定义按钮。
我只得到了这个用于调用函数的设置选项的代码。
function tinyMceEditLink(editor) {
console.log("tinyMceEditLink");
editor.on("click", function(e) {
console.log("this click");
});
}
Run Code Online (Sandbox Code Playgroud)
我会第一个承认这有点 hacky,但你可以尝试:
function tinyMceEditLink(editor) {
editor.windowManager.oldOpen = editor.windowManager.open; // save for later
editor.windowManager.open = function (t, r) { // replace with our own function
var modal = this.oldOpen.apply(this, [t, r]); // call original
if (t.title === "Insert/Edit Link") {
$('.tox-dialog__footer-end').append(
'<button title="Custom button" type="button" data-alloy-tabstop="true" tabindex="-1" class="tox-button" id="custom_button">Custom button</button>'
);
$('#custom_button').on('click', function () {
//Replace this with your custom function
console.log('Running custom function')
});
}
return modal; // Template plugin is dependent on this return value
};
}
Run Code Online (Sandbox Code Playgroud)
这将为您提供以下结果:
设置:
tinymce.init({
selector: "#mytextarea", // change this value according to your HTML
plugins: "link",
menubar: "insert",
toolbar: "link",
setup: function(editor) {
// Register our custom button callback function
editor.on('init',function(e) {
tinyMceEditLink(editor);
});
// Register some other event callbacks...
editor.on('click', function (e) {
console.log('Editor was clicked');
});
editor.on('keyup', function (e) {
console.log('Someone typed something');
});
}
});
Run Code Online (Sandbox Code Playgroud)
提示:
$('.tox-dialog__footer-end')...,$('.tox-dialog__footer-start')...则可以替换为。.tox-dialog__footer类的更改可能会破坏这一点。| 归档时间: |
|
| 查看次数: |
1938 次 |
| 最近记录: |