Inserting an HTML - appends it outside when selecting outside editor
See original GitHub issueHello,
i made a summernote plugin to add my custom blocs, it works fine but when i select outside editor, it appends the bloc where i selected,
to insert the bloc i use context.invoke('editor.pasteHTML', $bloc_menu_content.prop('outerHTML'));
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Append HTML to container element without innerHTML
Check out the insertAdjacentHTML() method. The first parameter is where you want the string appended and takes ("beforebegin", "afterbegin", ...
Read more >CRUD in HTML, JavaScript, and jQuery - CODE Magazine
In this first article of a series on working within HTML and the Web API, I'll show you how to add, edit, and...
Read more >.insertBefore() | jQuery API Documentation
A selector, element, array of elements, HTML string, or jQuery object; the matched set of elements will be inserted before the element(s) specified...
Read more >The Embed External Content element - HTML - MDN Web Docs
The HTML element embeds external content at the specified point in the document. This content is provided by an external application or ...
Read more >Defining editable regions in your HTML | Articles - CloudCannon
The value is the class name the editor should add to justify the text. The styles for this class need to be listed...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ok, for other programmers who encountered the same issue. here is my problems and how i solved them :
the issue
like described above i created summernote to add custom blocs to the editor. when i try to insert simple HTML content to the editor with
context.invoke('editor.pasteHTML', '<div></div>'
it goes well. but when it comes to a bloc with options where i have to show the modal (like the gif demo above) the bloc is inserted to the last area where i clicked (even outside of the editor) before i opened the modal , and sometime is inserted to the modal body itself and somtimes is not inserted anywhere at all.the solution
my code was like the following :
note the last three lines of code, i insert the html to the editor and then i hide the modal.
solution part 1
to resolve that issue i insert HTML to the editor after i hided the modal .
now the bloc is inserted inside the editor but it always ends up on top.
solution part 2
to make the plugin insert the bloc to the last clicked area inside the editor i created function to do that, so before i insert the bloc i hide the modal and put the cursor in the last clicked area inside the editor but first i have to save where was the cursor last position .
save the last clicked area inside the editor
i used 3 summernote events : keypress, mousemove and keyup,
recovering editor last focus
using all of that
hide modal then recover editor last focus then insert the bloc
that worked for me i hope the same for you as well 😃 .
NB : tested on Chrome only.
so did i, in both ways
context.invoke('editor.focus'); $(editor).summernote('focus');
but it didn work for me either. i think summernote tried already to keep the focus inside the editor before every command execution :var beforeCommand = this.beforeCommand = function ()
{
context.triggerEvent('before.command', $editable.html());
// keep focus on editable before command execution
self.focus();
};