-
- // Set popover link input to image url then fire change event
- // to ensure the new value sticks
- win.document.getElementById(field_name).value = image.url;
- if ("createEvent" in document) {
- let evt = document.createEvent("HTMLEvents");
- evt.initEvent("change", false, true);
- win.document.getElementById(field_name).dispatchEvent(evt);
- } else {
- win.document.getElementById(field_name).fireEvent("onchange");
- }
-
- // Replace the actively selected content with the linked image
- const imageUrl = image.thumbs.display || image.url;
- let html = `<a href="${image.url}" target="_blank">`;
- html += `<img src="${imageUrl}" alt="${image.name}">`;
- html += '</a>';
- win.tinyMCE.activeEditor.execCommand('mceInsertContent', false, html);