0
使用tinyMCE 4.2,每当用户点击编辑器内的任何地方时,我需要更改(自定义)工具栏按钮的文本。TinyMCE 4更改编辑器上的工具栏按钮文本点击
这是相关代码:
tinymce.init({
//code ommitted...
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages navigationbutton glossary",
setup: function(editor){
//add "Glossary" button
editor.addButton('glossary', {
name: 'glossary',
text: 'Glossary',
onclick: function(){
/*
//commented on purpose
var button = this;
var updatedButtonText = "Some updated button text";
button.text = updatedButtonText;
*/
}
});//end addButton
editor.on('click', function(){
var updatedButtonText = "Some updated button text";
//update the button text:
editor.buttons.glossary.text = updatedButtonText; //doesn't work
window.parent.tinyMCE.activeEditor.buttons.glossary.text = updatedButtonText; //doesn't work either
//confirm changes:
console.log(editor.buttons.glossary.text); //correctly prints "Some updated button text"
console.log(window.parent.tinyMCE.activeEditor.buttons.glossary.text); //correctly prints "Some updated button text" as well
});
}//end setup
});//end tinymce.init
所以,真正的问题是,虽然按钮对象的text
属性是变化的,这种变化不仅仅体现在编辑器,按钮上的文字仍然是“词汇表” 。 有趣的是,如果我通过按钮的onclick
函数完成同样的操作(所以如果我取消注释注释代码块),那么它可以按预期完美工作 - 按钮文本在编辑器中更新。
我花了几个小时在TinyMCE 4的文档中试图找到一些相关信息,但显然是徒劳的。有任何想法吗?
哇,我并不期待那样。所以如果在**按钮的''onclick'函数中'text'属性被改变,它确实会更新按钮,但如果在**编辑器中**时更改了'text'属性,它将不会更新它'onclick'功能?因为如果是这样的话,它对我来说没有什么意义,为什么它会这样设计...... – pazof
即使我将按钮的代码放在按钮自己的onClick中,我也无法获取按钮的文本以在UI中进行更改事件。 (它会在JavaScript对象中更改,但不会在工具栏上直观显示)您可以让JS小提琴显示工作吗? –