]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/plugins-imagemanager.js
f1ea120502a4ee99286e82fe94fc56ce5247b8d9
[bookstack] / resources / js / wysiwyg / plugins-imagemanager.js
1 /**
2  * @param {Editor} editor
3  */
4 function register(editor) {
5     // Custom Image picker button
6     editor.ui.registry.addButton('imagemanager-insert', {
7         title: 'Insert image',
8         icon: 'image',
9         tooltip: 'Insert image',
10         onAction() {
11             /** @type {ImageManager} * */
12             const imageManager = window.$components.first('image-manager');
13             imageManager.show(image => {
14                 const imageUrl = image.thumbs?.display || image.url;
15                 let html = `<a href="${image.url}" target="_blank">`;
16                 html += `<img src="${imageUrl}" alt="${image.name}">`;
17                 html += '</a>';
18                 editor.execCommand('mceInsertContent', false, html);
19             }, 'gallery');
20         },
21     });
22 }
23
24 /**
25  * @return {register}
26  */
27 export function getPlugin() {
28     return register;
29 }