I am using Trumbowyg, a WYSIWYG JavaScript editor which allows rendering images by pasting a URL.
So you paste the URL in the field and then click the Confirm
button and then it appends the image in the editor (you can test it out here)
I want to prevent adding images that are not HTTPS. So if someone inserts a URL that is not HTTPS, I want to prevent appending the image when they click Confirm
.
This is the function for the image URL (from the docs):
insertImage: function () {
var t = this;
t.saveRange();
var options = {
url: {
label: 'URL',
required: true
},
alt: {
label: t.lang.description,
value: t.getRangeText()
}
};
if (t.o.imageWidthModalEdit) {
options.width = {};
}
t.openModalInsert(t.lang.insertImage, options, function (v) { // v are values
t.execCmd('insertImage', v.url);
var $img = $('img[src="' + v.url + '"]:not([alt])', t.$box);
$img.attr('alt', v.alt);
if (t.o.imageWidthModalEdit) {
$img.attr({
width: v.width
});
}
t.syncCode();
t.$c.trigger('tbwchange');
return true;
});
}
Any idea how I can amend this function to only allow HTTPS inputs?