jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/images/basicimagefetcher.js
2016-10-05 03:15:29 -04:00

28 lines
589 B
JavaScript

define(['dom'], function (dom) {
function loadImage(elem, url) {
if (elem.tagName !== "IMG") {
elem.style.backgroundImage = "url('" + url + "')";
return Promise.resolve();
}
return loadImageIntoImg(elem, url);
}
function loadImageIntoImg(elem, url) {
return new Promise(function (resolve, reject) {
dom.addEventListener(elem, 'load', resolve, {
once: true
});
elem.setAttribute("src", url);
});
}
return {
loadImage: loadImage
};
});