2016-10-05 00:15:29 -07:00
|
|
|
define(['dom'], function (dom) {
|
2016-10-12 11:23:09 -07:00
|
|
|
'use strict';
|
2016-01-16 11:29:08 -07:00
|
|
|
|
|
|
|
function loadImage(elem, url) {
|
|
|
|
|
|
|
|
if (elem.tagName !== "IMG") {
|
|
|
|
|
2016-04-23 20:04:04 -07:00
|
|
|
elem.style.backgroundImage = "url('" + url + "')";
|
2016-10-05 00:15:29 -07:00
|
|
|
return Promise.resolve();
|
2016-01-16 11:29:08 -07:00
|
|
|
|
|
|
|
}
|
2016-10-05 00:15:29 -07:00
|
|
|
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);
|
|
|
|
});
|
2016-01-16 11:29:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
loadImage: loadImage
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|