Skip to content
Snippets Groups Projects

Issue #3391779: Re-attach maxlength counter behavior after text format change.

Files
2
+ 26
2
(function ($, Drupal) {
(function ($, Drupal, once) {
// Make variables local.
var ml = ml || {};
@@ -29,6 +29,30 @@
ml.ckeditor5(Drupal.CKEditor5Instances.get(eid), options);
});
}
// Set up a mutation observer to re-attach this behavior when the text
// format has been changed. Observer will act on changes to the
// 'data-ckeditor5-id' attribute on the field.
// @see Drupal.editors.ckeditor5.attach() and setElementId() in Drupal core ckeditor5.js
if (Drupal.hasOwnProperty('CKEditor5Instances')) {
const observerOptions = {
attributes: true,
attributeFilter: ['data-ckeditor5-id']
};
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const eid = mutation.target.dataset.ckeditor5Id;
if (!Drupal.CKEditor5Instances.has(eid)) {
observer.disconnect();
Drupal.behaviors.maxlength.detach(context);
Drupal.behaviors.maxlength.attach(context);
// Remove `maxlengthbinding` set by ml.ckeditor5().
once.remove('maxlengthbinding', mutation.target);
}
});
});
observer.observe(this, observerOptions);
}
});
},
detach: function(context, settings) {
@@ -371,4 +395,4 @@
});
}
})(jQuery, Drupal);
})(jQuery, Drupal, once);
Loading