Skip to content

Commit 6c943ec

Browse files
committed
If a url is pasted in editor (tinymce) check if it's possible to use oembed to embed widget
1 parent 17f5fc3 commit 6c943ec

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

public/js/libs/tinymce-options.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var noWrapNodes = "p > img,p > video, p > figure";
1+
var noWrapNodes = "p > img, p > video, p > figure, p > iframe";
22
var wrapNodes = ['B','I','SPAN', 'TABLE', 'P', 'H1', 'H2', 'H3', 'H4'];
33

44
function fixWrapper(doc){
@@ -99,6 +99,30 @@ let tinyMceOptions = {
9999
selector: "textarea.html",
100100
body_class: "container",
101101
init_instance_callback : make_wysiwyg,
102+
paste_preprocess: (editor, args) => {
103+
if (args.content.startsWith('http')) {
104+
let url = args.content;
105+
args.content = '';
106+
getOembed(url, 800, 600, true).then(response => {
107+
if (response && response.html) {
108+
editor.insertContent( '<div class="iframe" data-url="' + url + '" data-component-iframe>' + response.html.replace('<iframe ','<iframe class="align-center" ') + '</div>' );
109+
let arr = editor.contentDocument.getElementsByTagName('script');
110+
111+
for (let n = 0; n < arr.length; n++) {
112+
let script = arr[n];
113+
if (!script.hasAttribute("type")) continue;//process only new scripts that have the tinymce attribute
114+
let newScript = editor.contentDocument.createElement("script");
115+
newScript.src = script.src;
116+
script.replaceWith(newScript);
117+
}
118+
} else {
119+
editor.insertContent(url);
120+
}
121+
}).catch(error => {
122+
//editor.insertContent(url);
123+
});
124+
}
125+
},
102126
setup: function (editor) {
103127
//set changes to false to avoid saving unchanged revisions if text is not changed
104128
let has_changes = document.getElementById(editor.id)?.parentNode.querySelector(".has_changes");

0 commit comments

Comments
 (0)