我尝试禁用编程标准的“保存”按钮保存插件TinyMCE的 - 禁用标准保存按钮
tinymce.init
({
selector: '#editorMain',
plugins: "save,code,textcolor,charmap,searchreplace,paste,wordcount",
height: 400,
setup: function(editor) {
editor.on('keyup',function(e){
console.log(getStats('editorMain').chars);
var body = tinymce.get('editorMain').getBody();
var currentValue=tinymce.trim(body.innerText || body.textContent);
var currentCharsCount=getStats('editorMain').chars;
var limit=10;
var diff=limit - currentCharsCount;
if (diff>-1)
{
$("#chars_left").html(diff + " characters left");
}
else
{
$("#chars_left").html("Your comment is too long");
// here should we disable the save button
}
});
},
我用Google搜索的解决方案,并发现,在3.x版本有叫做对象“ ControlManager”。这在第4版(一个我目前使用)
据应实行做以下的文档被删除:
// In TinyMCE 4 you can use the simpler stateSelector setting
editor.addButton('SomeButton', {
text: 'My button',
stateSelector: 'a'
});
,但怎么能这样工作,为“保存”按钮?保存按钮出现在我使用“保存”插件时,这不必以编程方式添加。
我的确想要的功能,我只需要禁用保存按钮取决于字符在文本区域的数量,这意味着:默认激活,如果限制达到停用。 – laloune
类'tinymce.ui.MenuButton'(或它的父类之一)可能是你在找什么。这个类有设置禁用方法/获取在控制禁用状态:'禁用(状态:布尔)' – DFriend
的保存插件有一个'save_enablewhendirty'选项,设置为true时,禁用按钮,直到修改制成。有了这一套,你也许能够绑定到编辑变化事件,然后使用'editor.isNotDirty'迫使编辑器的状态清洗,直至达到最大字符数。但是强制NotDirty可能会混淆撤销/重做状态。所以,你可能不得不写一个自定义插件来代替保存。如果你走的滚你 - 拥有 - 插件路径望着保存插件的源代码可能是一个很好的起点。 – DFriend