一位客户要求我制作一个插件来插入电话链接,我知道这可以通过链接插件来完成,但他想要一个专门设计的插件来做到这一点。我已经有了带有弹出窗口的插件,您可以在其中插入所需的数据,这是代码,我想要添加与链接插件相同的功能,因此当用户单击链接的文本时,内容可以是在我的插件的窗口管理器中编辑。
这是我到目前为止的代码:
tinymce.PluginManager.add('phonelink', function(editor, url) {
// Add a button that opens a window
tinymce.DOM.loadCSS(url + '/css/phonelink.css');
editor.addButton('phonelink', {
text: false,
icon: 'phonelink',
onclick: function() {
// Open window
editor.windowManager.open({
title: 'Enlace teléfono',
body: [
{type: 'textbox', name: 'phone', label: 'Teléfono'},
{type: 'textbox', name: 'showtext', label: 'Texto a mostrar'},
{type: 'textbox', name: 'title', label: 'Título'}
],
onsubmit: function(e) {
// Insert content when the window form is submitted
editor.insertContent('<a title="' + e.data.title + '" href="tel:+34' + e.data.phone + '">' + e.data.showtext + '</a>');
}
});
}
});
// Adds a menu item to the tools menu
editor.addMenuItem('phonelink', {
text: 'Teléfono',
context: 'tools',
onclick: function() {
// Open window with a specific url
editor.windowManager.open({
title: 'Enlace teléfono',
body: [
{type: 'textbox', name: 'phone', label: 'Teléfono'},
{type: 'textbox', name: 'showtext', label: 'Texto a mostrar'},
{type: 'textbox', name: 'title', label: 'Título'}
],
onsubmit: function(e) {
// Insert content when the window form is submitted
editor.insertContent('<a title="' + e.data.title + '" href="tel:+34' + e.data.phone + '">' + e.data.showtext + '</a>');
}
});
}
});
});