summernote - update code when in HTML view
Asked Answered
L

1

6

I am using Summernote WYSIWYG editor and I'm stuck in this issue:
Every time the view changes from Rich Text to HTML I want to make some calculations and update the editors content.
But when the editor changes from Rich Text to HTML .code() doesn't seem to work...
After a while I realised that when the editor is in HTML mode, .code() does not work at all - that's why when pressing "codeview" button from text to html doesn't work...

See this feedle: http://jsfiddle.net/Lpp1Lmhn/4/ (press the "Update" button when in Rich Text and then when in HTML mode)

So the question is:
Is there a way to update the editor's content when in HTML view?

Thank you in advance.

Lepidopteran answered 19/2, 2015 at 13:11 Comment(0)
B
0

Yes you can, but the funny little change you have to make is change ".live" to ".on". here is a link to discussion on the significance of that little 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 fiddle http://jsfiddle.net/2tnua16k/

Betthel answered 21/9, 2017 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.