51 lines
1.8 KiB
JavaScript
51 lines
1.8 KiB
JavaScript
if (!document.getElementsByClassName) {
|
|
document.getElementsByClassName = function(className) {
|
|
return document.querySelectorAll("." + className);
|
|
}
|
|
}
|
|
|
|
if (!window.addEventListener) {
|
|
window.addEventListener = window.attachEvent;
|
|
}
|
|
|
|
function toArray(iter) {
|
|
var arr = [];
|
|
for (var i = 0; i < iter.length; i++) arr.push(iter[i]);
|
|
return arr;
|
|
}
|
|
|
|
// Fix images not updating on Opera 12.1 - 12.16 (earlier versions still broken)
|
|
// https://stackoverflow.com/a/71828058/8618686
|
|
if(window.opera && Object.defineProperty) {
|
|
/* if browser is opera presto, updating image elements' sources will not upload the DOM visual.
|
|
So we need to do some hacking. Only thing that works is to remove and reAppend the relevant node... */
|
|
Object.defineProperty(HTMLImageElement.prototype, "src", {
|
|
enumerable: true,
|
|
configurable: true,
|
|
get: function() {
|
|
return this.getAttribute("src");
|
|
},
|
|
set: function(newSrc)
|
|
{
|
|
/*max-size confinement is required for presto if parent is display flex. Image will go out of its available size otherwise*/
|
|
this.style.maxHeight = this.style.height;
|
|
this.style.maxWidth = this.style.width;
|
|
|
|
this.setAttribute("src", newSrc);
|
|
|
|
/*we have to put this node back to exactly where we rip it from*/
|
|
var parent = this.parentNode;
|
|
if(this.nextElementSibling != null)
|
|
{
|
|
var reference = this.nextElementSibling;
|
|
parent.removeChild(this);
|
|
reference.insertAdjacentElement("beforebegin", this);
|
|
}
|
|
else if (parent)
|
|
{
|
|
parent.removeChild(this);
|
|
parent.appendChild(this);
|
|
}
|
|
}
|
|
});
|
|
} |