Summernote - update code when viewing HTML

I am using the Summernote WYSIWYG editor and I am stuck with this problem:
Every time a view changes from Rich Text to HTML, I want to do some calculations and update the contents of the editors.
But when the editor changes from Rich Text to HTML . Code () doesn't seem to work ...
After some time, I realized that when the editor is in HTML mode, .code() does not work at all - why when I click the "codeview" button from text in html it does not work ...

Watch this feed: http://jsfiddle.net/Lpp1Lmhn/4/ (click the refresh button when in Rich Text and then in HTML mode)

So the question is:
Is there any way to update editor content while viewing HTML?

Thanks in advance.

+6
source share
1 answer

Yes you can, but a funny little change you need to make is to change .live to .on. here is a link to a discussion of the significance of this small change.

 $(document).ready(function(){ $('#editor').summernote({ height:200, toolbar: [ ['text', ['bold', 'italic', 'underline']], ['misc', ['codeview']] ] }); $('[data-event="codeview"]').on('click', function(){ $('#editor').code($('#editor').code()+'a'); }); $('#btn').click(function(){ $('#editor').code($('#editor').code()+'a'); }); }); 

and you can visit the working script http://jsfiddle.net/2tnua16k/

0
source

Source: https://habr.com/ru/post/982737/


All Articles