So, here is what I did, even if maybe its dirty.
Add a new module which attaches a custom library to forms:
function mymodule_form_alter(&$form, $form_state) {
$form['#attached']['library'][] = 'mymodule/form';
}
In the mymodule.libraries.yml
:
form:
version: 1.x
js:
js/mymodule.js: {}
dependencies:
- core/ckeditor
- ckeditor/drupal.ckeditor
- imce/drupal.imce
- imce/drupal.imce.ckeditor
And in the mymodule.js
I pretty much just re-write the imce sendto
function:
if (undefined !== CKEDITOR && CKEDITOR.imce.sendto) {
CKEDITOR.imce.sendto = function (File, win) {
var imce = win.imce;
var editor = CKEDITOR.instances[imce.getQuery('ck_id')];
if (editor) {
var i;
var text;
var lines = [];
var selection = imce.getSelection();
var is_img = imce.getQuery('type') === 'image';
for (i in selection) {
if (!imce.owns(selection, i)) {
continue;
}
File = selection[i];
// Image
if (is_img && File.width) {
lines.push('<img class="img-responsive" src="' + File.getUrl() + '" />');
}
// Link
else {
// Use the selected text/image for the first link
text = !lines.length && CKEDITOR.imce.getSelectedHtml(editor) || File.formatName();
lines.push('<a href="' + File.getUrl() + '">' + text + '</a>');
}
}
editor.insertHtml(lines.join('<br />'));
}
win.close();
};
}
Hope this is helpful to somebody. And maybe there is another, better way of doing this - glad for any input!