javascript - summernote的plugin问题
ringa_lee
ringa_lee 2017-04-10 16:00:12
[JavaScript讨论组]

最近一个项目用到可编辑p,公司使用的是bootstrap作为主要框架,故选用了summernote插件
现需要实现自定义按钮功能,类似点击插入表情(我这是要点击插入一条预设规则、运算符等)
summernote给出了plugin,链接在此summernote。

也给出了实例,链接在此自定义plugin:hello
但是当我将代码原封不动搬下来的时候,得到的结果是报错:如图

那个renderer到底是什么?
我在这行前面加了一个console,这个summernote对象的具体情况如图所示

我的代码结构是这样的:

//先引入
$(document).ready(function() {
    setSummernote();
});
//初始化
function setSummernote(){
    $("#summernote").summernote({
        lang: 'zh-CN',
        height:300,
        focus:true,
        toolbar:[
            ['group', ['hello']]
        ]
    });
//此行报错,我不知道这个renderer是什么。
    var tmpl = $.summernote.renderer.getTemplate();
    var editor = $.summernote.eventHandler.getEditor();
    
    // add hello plugin 
    $.summernote.addPlugin({
      // plugin's name
      name: 'hello',
    
      init : function(layoutInfo) { // run init method when summernote was initialized
        // layoutInfo.holder() is current summernote's jquery instance.
        var $note = layoutInfo.holder();
    
        // you can use jquery custom event.
        $note.on('summernote.update', function(customEvent, nativeEvent) {
           var $boldButton = $(this).summernote('toolbar.get', 'bold');
           $boldButton.toggleClass('active').css({
             color : 'red'
           });
        });
    
        $note.on('summernote.blur', function(customEvent, nativeEvent) {
          var $boldButton = $(this).summernote('toolbar.get', 'bold');
          $boldButton.removeClass('active').css({
            color : 'inherit'
          });
        });          
        $note.summernote('insertText', 'plugin start.');
      },
              
      buttons: { // define button that be added in the toolbar
        // "hello" button (key is a button's name)
        hello: function () {
              
          // create button template 
          return tmpl.iconButton('fa fa-header', {
            // set event's name to used as callback when this button is clicked
            // add data-event='hello' in button element
            event : 'hello',
            title: 'hello',
            hide: true
          });
        }
      },
    
      events: { // events
        // run callback when hello button is clicked
        hello: function (event, editor, layoutInfo, value) {
          // Get current editable node
          var $editable = layoutInfo.editable();
    
          // Call insertText with 'hello'
          editor.insertText($editable, 'hello ');
              
          // or 
          layoutInfo.holder().summernote("insertText", "Hello");
        }
      }
    });
}
ringa_lee
ringa_lee

ringa_lee

全部回复(1)
ringa_lee

答案是:0.5.8这个版本不支持renderer
此贴终结

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号