javascript - Nicedit.js - 无法添加自定义按钮

标签 javascript nicedit

我采用了 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/

相关文章:

javascript - 使用 JavaScript 裁剪图像

javascript - 在 javascript 中设置 <TD> 的 valign 属性

javascript - JSON是否存储格式化文本并保持格式

jquery - TinyMCE - 我们能否拥有一个工具栏面板来控制多个实例?

javascript - 将 Ember.js 与外部代码(例如,Android 的 WebView)集成的最佳方式

javascript - 在 JavaScript 属性名称中搜索字符

javascript - 如何更改类onclick?

php - Nicedit 本地上传图片失败

drop-down-menu - nicEdit 不显示所选字体大小和系列

javascript - 在javascript中编码/解码html标签