Summernote also support custom button. If you want to create your own button, you can simply define and use with options.
Create button object using $.summernote.ui. This button objects have below properties.
contents: contents to be displayed on the button
tooltip: tooltip text when mouse over
click: callback function be called when mouse is clicked
Example for inserting text ‘Welcome’.
var welcomeBtn = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
contents: '<i class="fa fa-child"/> WELCOME',
tooltip: 'welcome',
click: function () {
// invoke insertText method with 'welcome' on editor module.
context.invoke('editor.insertText', 'welcome');
}
});
return button.render(); // return button as jquery object
}
now you can define custom button on toolbar options.
$('.summernote').summernote({
toolbar: [
['mybutton', ['welcome']]
],
buttons: {
welcome: welcomeBtn
}
});
Similarly for custom dropDown button you can do something like this:
var emojiBtn = function (context) {
var ui = $.summernote.ui;
var emojiList = ui.buttonGroup([
ui.button({
className: 'dropdown-toggle',
contents: '<span class="fa fa-smile-o"></span> <span class="caret"></span>',
tooltip: "Insert Greetings",
data: {
toggle: 'dropdown'
}
}),
ui.dropdown({
className: 'dropdown-style',
contents: "<ol><li>smile</li><li>sleepy</li><li>angry</li></ol>",
callback: function ($dropdown) {
$dropdown.find('li').each(function () {
$(this).click(function() {
context.invoke("editor.insertText", $(this).html());
});
});
}
})
]).render();
}
if you want to display some prepopulated list into your dropdown then you can do something like this..
var emojiBtn = function (context) {
var ui = $.summernote.ui;
var list = $('#elements-list').val();
var button = ui.buttonGroup([
ui.button({
className: 'dropdown-toggle',
contents: '<span class="fa fa-smile-o"></span> <span class="caret"></span>',
tooltip: "Insert Greetings",
data: {
toggle: 'dropdown'
}
}),
ui.dropdown({
className: 'drop-default summernote-list',
contents: "<ul>"+list+"</ul>",
callback: function ($dropdown) {
$dropdown.find('li').each(function () {
$(this).click(function() {
context.invoke("editor.insertText", $(this).html());
});
});
}
})
]);
return button.render();
}