javascript - Summernote custom dialog and button -
i try implement summertnote editor. here js code:
$(document).ready(function() { //summernote //var te_markdown = document.getelementbyid("code-markdown");. var textarea = document.getelementbyid("code"); var hellobutton = function (context) { var ui = $.summernote.ui; // create button var button = ui.button({ contents: '<i class="fa fa-child"/> hello', tooltip: 'ciao!', click: function () { // invoke inserttext method 'hello' on editor module. context.invoke('editor.inserttext', 'hello'); } }); return button.render(); // return button jquery object } function autoformat() { var totallines = editor.linecount(); editor.autoformatrange({line:0, ch:0}, {line:totallines}); } $('#st-editor').summernote({ lang: 'it-it', // set italian language height: 350, // set editor height width: 350, // set editor width minheight: null, // set minimum height of editor maxheight: null, // set maximum height of editor dialogsfade: true, // set fade on dialog prettifyhtml: false, toolbar: [ ['mybutton', ['hello']] ], buttons: { hello: hellobutton }, codemirror: { // codemirror options mode: "text/html", linenumbers: true, linewrapping: true, extrakeys: {"ctrl-q": function(cm){ cm.foldcode(cm.getcursor()); }}, foldgutter: true, theme: 'monokai', gutters: ["codemirror-linenumbers", "codemirror-foldgutter"] } }, focus: true set focus editable area after initializing summernote }); i code here: http://summernote.org/deep-dive/#custom-button so, in example want put "hello" string clicking button gives me error "typeerror: context undefined". can me?
thanks
instead of
context.invoke('editor.inserttext', 'hello'); use
$('#st-editor').summernote('editor.inserttext', 'hello'); works if have 1 editor of course. i'm still searching how context thingy passed. maybe oninit, couldn't working yet.
Comments
Post a Comment