Files
2025-06-24 14:14:35 +02:00

87 lines
3.0 KiB
JavaScript

tinymce.PluginManager.add('addiframe', function(editor, url) {
editor.addButton('addiframe', {
title: 'Insert Iframe',
icon: "desktop",
context: "tools",
onclick: function () {
editor.windowManager.open({
title: 'Insert Iframe Bellow',
width : 400,
height : 300,
body: [
{
type: 'textbox',
size: 20,
name: 'url',
label: 'Url'
},
{
type: 'textbox',
size: 10,
name: 'width',
label: 'Width',
value: '100'
},
{
type: 'textbox',
size: 10,
name: 'height',
label: 'Height',
value: '100'
},
{
type: 'textbox',
size: 10,
name: 'class',
label: 'Class Attribute',
value: 'responsiveIframe'
},
{
type: 'textbox',
size: 10,
name: 'id',
label: 'Id Attribute'
},
{
type: 'textbox',
multiline: true,
size: 25,
name: 'embedcode',
label: 'Or Embed Code',
placeholder: 'Paste your iframe code here...'
},
],
onsubmit: function(e) {
var url = e.data.url;
var width = e.data.width;
var height = e.data.height;
var classAttr = e.data.class;
var idAttr = e.data.id;
var iframe = e.data.embedcode;
if (url.trim() == "" && iframe.trim() !== "" ) {
var regEx = /(src|width|height)=["']([^"']*)["']/gi;
iframe.replace(regEx, function(all, type, value) {
switch (type) {
case 'src':
url = value;
break;
case 'width':
width = value;
break;
case 'height':
height = value;
break;
}
});
}
var code = '<iframe url="'+url+'" width="'+width+'" height="'+height+'" class="'+classAttr+'" id="'+idAttr+'"></iframe>';
editor.insertContent(code);
}
});
}
});
});