我采用了 here 中的代码片段- 刚刚更改了我的自定义按钮图标路径,但按钮没有出现。控制台没有错误。
/**
* nicExample
* @description: An example button plugin for nicEdit
* @requires: nicCore, nicPane, nicAdvancedButton
* @author: Brian Kirchoff
* @version: 0.9.0
*/
/* START CONFIG */
jQuery("document").ready(function(){
debugger;
var nicExampleOptions = {
buttons : {
'example' : {name : __('Some alt text for the button'), type : 'nicEditorExampleButton'}
}, iconFiles : {'example' : '/assets/emoticons/aa.gif'}
};
var nicEditorExampleButton = nicEditorButton.extend({
mouseClick : function() {
alert('The example save button icon has been clicked!');
}
});
nicEditors.registerPlugin(nicPlugin,nicExampleOptions);
});
我还将我的自定义按钮名称添加到编辑器按钮列表中:
this.instantiate_nicedit_for_textarea = function(textArea){
var nic_editor = new nicEditor({buttonList : ['bold','italic','underline','strikethrough','example'], iconsPath : '/assets/nicEditorIcons.gif'})
nic_editor.addInstance(textArea.id);
var topbar_id = $(textArea).prevAll('div.widget_topbar').last().children('ul').children('li.nic_panel').attr('id');
nic_editor.setPanel(topbar_id);
};
更新:Firefox 18.02、Chrome 22.0.1229.94
最佳答案
基于保存按钮插件,你的代码应该是这样的:
var nicExampleOptions = {
buttons : {
'example' : {name : __('Example'), type : 'nicEditorExampleButton'}
}
};
var nicEditorExampleButton = nicEditorButton.extend({
init : function() {
// your init code
},
mouseClick : function() {
alert('hallo!'); // Your code here
}
});
nicEditors.registerPlugin(nicPlugin,nicExampleOptions);
作为最佳实践,我建议您将这段代码添加到一个单独的文件中,并确保在 nicEdit.js
之后加载它。然后,您可以将该按钮添加到实例的 buttonList。
关于javascript - Nicedit.js - 无法添加自定义按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14815754/