Skip to content
Snippets Groups Projects
Commit 0adbe4c9 authored by Mark Quirvien Cristobal's avatar Mark Quirvien Cristobal Committed by Edmund Dunn
Browse files

Issue #3267416 by vhin0210, kbriand, nayana_mvr, DeepaliJ, msbtterswrth,...

Issue #3267416 by vhin0210, kbriand, nayana_mvr, DeepaliJ, msbtterswrth, vlyalko, godotislate: Count down not working for ckeditor5
parent c18d87aa
No related branches found
No related tags found
No related merge requests found
......@@ -154,6 +154,58 @@
});
});
}
if (window.hasOwnProperty("CKEditor5")) {
var ckeditor5Init = function() {
// Loop through each of the textfield settings.
$.each(settings.textfieldCounter ,function (fieldDefinitionKey, fieldSettings) {
// Use the fieldDefinitionKey to get the HTML ID, which is used to
// reference the editor.
var textfield = $("." + fieldDefinitionKey + "[id]:first");
var editor = Drupal.CKEditor5Instances.get($(textfield).attr('data-ckeditor5-id'));
if (editor) {
var countOnKey = function(evt, data) {
var countHTML, maxlength, text, currentLength, remaining;
countHTML = fieldSettings.countHTMLCharacters;
maxlength = fieldSettings.maxlength;
text = $.trim(editor.getData());
if (countHTML) {
currentLength = text.length;
}
else {
// The following is done to retrieve the current length:
// 1) The content is inserted into a DIV as HTML.
// 2) $.text() is used to retrieve just the text of the element.
// 3) The context is trimmed.
// 4) Multiple consecutive newlines are replaced with a single
// newline, so as to only count a linebreak as a single
// character.
currentLength = $("<div/>").html(text).text().trim().replace(/(\r?\n|\r)+/g, "\n").length;
}
remaining = maxlength - currentLength;
// Set the current count on the counter.
textfield.siblings(".textfield_counter_counter:first").children(".current_count:first").text(currentLength);
// Set the remaining count on the counter.
textfield.siblings(".textfield_counter_counter:first").children(".remaining_count:first").text(remaining);
// Set the classes on the parent.
checkClasses(textfield.parent(), remaining);
};
editor.editing.view.document.on('keydown', countOnKey);
editor.editing.view.document.on('keyup', countOnKey);
}
});
};
var ckeditor5Timeout = setTimeout(function() {
ckeditor5Init();
clearTimeout(ckeditor5Timeout);
}, 300);
}
}
Drupal.behaviors.textfieldCounterTextarea = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment