tinymce.PluginManager.add("ccm-cms-insertimage", function(editor, url) {
console.log("Adding plugin ccm-cms-insertimage...");
editor.addButton(
"insertimage",
{
icon: "image",
onclick: function() {
openDialog(editor);
},
tooltip: "Insert image",
},
);
editor.addMenuItem(
"insert-image",
{
text: "Insert image",
context: "tools",
onclick: function() {
openDialog(editor);
},
},
);
});
function openDialog(editor) {
console.log("Opening dialog");
// const selectedImage = {
//
// selectedUuid: undefined,
//
// get imageUuid() {
// this.selectedUuid;
// },
// set imageUuid(value) {
// this.selectedUuid = value;
// console.log(`Set imageUuid to ${this.selectedUuid}`);
// editor.windowManager
// },
// };
let imageUuid = undefined;
editor.windowManager.open({
body: [
{
items: [
{
direction: "row",
items: [
{
// disabled: true,
// label: "Image",
// name: "imageUuid",
// type: "textbox",
// value: "foobar",
border: "1 1 1 1",
minWidth: 150,
minHeight: 150,
name: "imageViewer",
type: "container",
},
{
name: "browse",
onclick: (event) => {
openBrowseDialog(editor, (uuid) => {
console.log(`Selected image ${uuid}`);
// editor.windowManager.getWindows()[0].find("#imageUuid").value(uuid);
imageUuid = uuid;
const contextPrefix = editor.getParam("contextprefix");
const contentSection = editor.getParam("contentsection");
const imageViewer = editor
.windowManager
.getWindows()[0]
.find("#imageViewer")
.toArray()[0];
imageViewer
.innerHtml(``);
});
},
text: "Browse",
type: "button",
},
],
label: "Selected image",
layout: "flex",
type: "container",
},
{
label: "Caption",
name: "caption",
type: "textbox",
},
{
label: "Width",
name: "width",
size: 4,
type: "textbox",
},
{
label: "Height",
name: "height",
size: 4,
type: "textbox",
},
{
name: "lightbox",
text: "Lightbox?",
type: "Checkbox",
},
{
border: "1 1 1 1",
name: "imagePanel",
type: "container",
},
],
minHeight: 200,
minWidth: 400,
name: "insertimage_dialog_container",
onPostRender: function() {
// console.log(`imageUuid = ${this.find("#imageUuid").value()}`);
const imageUuid = this.find("#imageUuid").value();
console.log(`imageUuid = ${imageUuid}`);
// this.find("#imagePanel").innerHTML = `
${imageUuid}`;
this.find("#imagePanel").append([
{
html: `${imageUuid}`,
// text: `${imageUuid}`,
// type: "label",
type: "container",
}
]);
console.log(this.find("#imagePanel"));
},
type: "form",
},
],
onsubmit: function(event) {
// console.log(selectedImage.imageUuid);
},
title: "Insert image",
});
console.log("Dialog opened.");
}
function openBrowseDialog(editor, selectImage) {
editor.windowManager.open({
body: [
{
// items: [
// {
// html: 'Found ${data.length} images\