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