【问题标题】:How to change enter behaviour in summernote如何在summernote中更改输入行为
【发布时间】:2018-07-26 22:48:08
【问题描述】:

我有这个旧代码

// myenter.js, enter key is binded to insertParagraph command.
    $.summernote.addPlugin({
      name : 'myenter',
      events : {
        // redefine insertParagraph 
        'insertParagraph' : function(event, editor, layoutInfo) {
      //you can use summernote enter 
      //layoutInfo.holder().summernote('insertParagraph');   

      // also you can use your enter key 
      layoutInfo.holder().summernote('insertNode', document.createTextNode("\r\n")); 

     // to stop enter key 
     //e.preventDefault();
    }
  }
});

$('.summernote').summernote({ height : 300 });

但现在添加插件的方法已经改变,我希望通过此代码使用新版本的此功能

$.extend($.summernote.plugins, {
    'myenter': function (context) {
        console.log('myenter');
    }
});

但它根本没有被调用

我曾尝试通过以下方式获得相同的功能 summernote.onEntersummernote.keyPress 但它给出了错误..

【问题讨论】:

  • 您能否详细说明您的代码“不起作用”的原因?你期待什么,实际发生了什么?如果您遇到异常/错误,请发布它发生的行和异常/错误详细信息。请edit这些详细信息,否则我们可能无法提供帮助。

标签: summernote


【解决方案1】:
$.extend($.summernote.plugins, {
    'brenter': function (context) {
        this.events = {
            'summernote.enter': function (we, e) {
                // insert 2 br tags (if only one br tag is inserted the cursor won't go to the next line)
                document.execCommand('insertHTML', false, '<br><br>');
                e.preventDefault();
            }
        };
    }
}

【讨论】:

  • 你能补充一些解释吗?
【解决方案2】:

我设法像这样修复它:

$('#summernote').summernote('destroy');

$.extend($.summernote.plugins, {
    'brenter': function (context) {
         this.events = {
            'summernote.enter': function (we, e) {
                //get hold of the enter event and trigger a shift+enter keypress

                e.trigger($.Event("keydown", {
                    keyCode: 13, // ENTER
                    shiftKey: true
                }));

                //stop the normal event from happening
                e.preventDefault();
             }
         };
     }
});

// then do summernote as normal...
$('#summernote').summernote({

【讨论】:

    猜你喜欢
    • 2015-08-26
    • 2011-04-13
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    相关资源
    最近更新 更多