Skip to content

Commit

Permalink
Rename window.CKEDITOR to window.CKEDITORINSTANCES
Browse files Browse the repository at this point in the history
CKEditor with the browser install exports a global variable of
`CKEDITOR`. It makes more sense to allow CKEDITOR to have this
name space and rename our collection of CKEditor instances.
  • Loading branch information
craigkai committed Jan 22, 2025
1 parent 3ff496a commit 1219bf5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ function initializeSelectElements(elt) {
elt.querySelectorAll('select.selectpicker:not(.tomselected)').forEach(initializeSelectElement);
}

function ReplaceAllTextareas(elt) {
window.CKEDITOR ||= { "instances": {} };
async function ReplaceAllTextareas(elt) {
window.CKEDITORINSTANCES ||= { "instances": {} };

elt ||= document;
// replace all content and signature message boxes
Expand Down Expand Up @@ -419,7 +419,7 @@ function ReplaceAllTextareas(elt) {
ClassicEditor
.create( textArea, initArgs )
.then(editor => {
CKEDITOR.instances[editor.sourceElement.name] = editor;
CKEDITORINSTANCES.instances[editor.sourceElement.name] = editor;
// the height of element(.ck-editor__editable_inline) is reset on focus,
// here we set height of its parent(.ck-editor__main) instead.
editor.ui.view.editable.element.parentNode.style.height = height;
Expand Down Expand Up @@ -736,8 +736,8 @@ jQuery(function() {

document.body.addEventListener('htmx:configRequest', function(evt) {
for ( const param in evt.detail.parameters ) {
if ( evt.detail.parameters[param + 'Type'] === 'text/html' && CKEDITOR.instances[param] ) {
evt.detail.parameters[param] = CKEDITOR.instances[param].getData();
if ( evt.detail.parameters[param + 'Type'] === 'text/html' && CKEDITORINSTANCES.instances[param] ) {
evt.detail.parameters[param] = CKEDITORINSTANCES.instances[param].getData();
}
}
});
Expand Down Expand Up @@ -784,7 +784,7 @@ jQuery(function() {

evt.detail.historyElt.querySelector('#hx-boost-spinner').classList.add('d-none');
evt.detail.historyElt.querySelectorAll('textarea.richtext').forEach(function(elt) {
CKEDITOR.instances[elt.name].destroy();
CKEDITORINSTANCES.instances[elt.name].destroy();
});
evt.detail.historyElt.querySelectorAll('.hasDatepicker').forEach(function(elt) {
elt.classList.remove('hasDatepicker');
Expand Down Expand Up @@ -1123,8 +1123,8 @@ htmx.onLoad(function(elt) {
plainMessageBox.addClass('mark-changed');
let interval;
interval = setInterval(function() {
if (CKEDITOR.instances && CKEDITOR.instances[messageBoxName]) {
const richTextEditor = CKEDITOR.instances[messageBoxName];
if (CKEDITORINSTANCES.instances && CKEDITORINSTANCES.instances[messageBoxName]) {
const richTextEditor = CKEDITORINSTANCES.instances[messageBoxName];
richTextEditor.model.document.on( 'change:data', () => {
mark_changed(plainMessageBox.attr('name'));
});
Expand Down Expand Up @@ -1643,9 +1643,9 @@ jQuery(function () {

document.querySelectorAll('#dynamic-modal form textarea.richtext').forEach((textarea) => {
const name = textarea.name;
if ( CKEDITOR.instances[name] ) {
if ( CKEDITOR.instances[name].getData() !== textarea.value ) {
CKEDITOR.instances[name].updateSourceElement();
if ( CKEDITORINSTANCES.instances[name] ) {
if ( CKEDITORINSTANCES.instances[name].getData() !== textarea.value ) {
CKEDITORINSTANCES.instances[name].updateSourceElement();
jQuery(textarea.closest('form')).data('changed', true);
}
}
Expand Down

0 comments on commit 1219bf5

Please sign in to comment.