Skip to content

Instantly share code, notes, and snippets.

@MaxLazar
Created December 24, 2020 05:52
Show Gist options
  • Save MaxLazar/2e59c100b5e6089eb802cd252287da6c to your computer and use it in GitHub Desktop.
Save MaxLazar/2e59c100b5e6089eb802cd252287da6c to your computer and use it in GitHub Desktop.
Return Source Back to RTE Again (ExpressionEngine 6 + CKEditor 5)
/*
To inject JS code into CP you can use MX CP CSS & JS addon
https://expressionengine.com/add-ons/mx-cp-css-js
warning - it just a quick workaround, not a solution. You should know what you do. Good luck! :)
*/
let btnRTE = '<div class="mx_extra"><a class="button button--default button--xsmall left show_editor" href="#" style="display:none">Editor</a> <a class="button button--default button--xsmall left show_code" href="#" >Source</a></div>';
$('.rte-textarea').after(btnRTE);
$('.grid-rte').append(btnRTE);
$('.panel-body').on('click', '.show_editor', function (e){
e.preventDefault();
let fieldControl = $(this).parent().parent();
let element = fieldControl.find('textarea');
new Rte(element.attr('id'), element.attr('config'));
fieldControl.find('.show_editor').hide();
fieldControl.find('.show_code').show();
});
$('.panel-body').on('click', '.show_code', function (e){
e.preventDefault();
let fieldControl = $(this).parent().parent();
console.log(fieldControl.find('.ck-editor__editable:first'));
fieldControl.find('.ck-editor__editable')[0].ckeditorInstance.destroy();
fieldControl.find('.show_editor').show();
fieldControl.find('.show_code').hide();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment