There are some applications that needs changing the default notification message of a CKEditor plugin. Like this case, I have application that needs to check the size of a file being uploaded against the maximum file size limit allowed on a Drupal site and the upload should abort if it exceeds. Using this upload.abort();
method will display "Upload aborted by the user." notification message which obviously not applicable to the situation. The following code snippet will override the notification generated by uploadwidget plugin:
if (upload.total > maxImageFilesize && maxImageFilesize != 0) {
editor.on('notificationShow', function(evt) {
if (drupalSettings.DrupalCKeditorUploadImage.listenNow) {
// Override the "Upload aborted by the user." notification
// generated by uploadwidget plugin.
evt.data.notification.message = Drupal.t(
'The image file size (@size bytes) exceeds the maximum limit (@max bytes).', {
'@size': upload.total,
'@max': maxImageFilesize
});
evt.data.notification.type = 'warning';
evt.data.notification.element = evt.data.notification._createElement();
}
evt.removeListener();
});
// Cancel the upload.
upload.abort();
}