Custom Summernote Button to create links with classes

288
March 09, 2018, at 02:05 AM

So I'm thoroughly confused as how to make a custom SummerNote button which will allow me to either add classes to an already inserted HTML element (i.e. links) or even wrap selected text in something like:

<button class="btn btn-primary"> **selected text** </button>

From the Summernote Deep Dive it shows how to create a custom button that inserts static text and I understand how to implement it. However, I can't seem to figure out how to make it dynamic for whatever text is selected. I've tried replacing the 'text' part of the example after context.invoke call but it doesn't convert the text to html, it just prints it.

The need is for creating links as buttons. Ideally I'd wish to access the Insert Link dialog already built into SummerNote to make buttons that will insert links with predefined classes but I'm not sure how complicated that would be.

Does anyone have any suggestions?

var bsButton = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
    contents: 'Btn',
    tooltip: 'Create Button',
    click: function () {
        // invoke insertText method with 'hello' on editor module.
        context.invoke('editor.insertText', '<button class="btn btn-primary"></button>');
    }
});
return button.render();   // return button as jquery object
}

I've reviewed a ton of different posts but I haven't gotten much further than the example for what I'm trying to accomplish. Thanks in advance to anyone who takes the time to help.

Rent Charter Buses Company
READ ALSO
How to use mask with coffeescript

How to use mask with coffeescript

hi i need help to use coffee with rails 51 I'm trying to use a mask for the rg id = rg

203
Slick Slider - Save images on mobile by holding the image

Slick Slider - Save images on mobile by holding the image

I am using SlickSlider (which is an amazing slider) for my gallery page of my site

224
Rails, auto-submit form after input blur returns: ActionController::UnknownFormat

Rails, auto-submit form after input blur returns: ActionController::UnknownFormat

The Goal: Auto submit the form after blur from any input

170