| 1 |
/* Image loader */ |
| 2 |
function addListener(element, type, expression, bubbling) { |
| 3 |
bubbling = bubbling || false; |
| 4 |
if (window.addEventListener) { // Standard |
| 5 |
element.addEventListener(type, expression, bubbling); |
| 6 |
return true; |
| 7 |
} else if (window.attachEvent) { // IE |
| 8 |
element.attachEvent('on' + type, expression); |
| 9 |
return true; |
| 10 |
} else return false; |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
var ImageLoader = function (url) { |
| 15 |
this.url = url; |
| 16 |
this.image = null; |
| 17 |
this.loadEvent = null; |
| 18 |
}; |
| 19 |
|
| 20 |
ImageLoader.prototype = { |
| 21 |
load: function () { |
| 22 |
this.image = document.createElement('img'); |
| 23 |
var url = this.url; |
| 24 |
var image = this.image; |
| 25 |
var loadEvent = this.loadEvent; |
| 26 |
addListener(this.image, 'load', function (e) { |
| 27 |
if (loadEvent != null) { |
| 28 |
loadEvent(url, image); |
| 29 |
} |
| 30 |
}, false); |
| 31 |
this.image.src = this.url; |
| 32 |
}, |
| 33 |
getImage: function () { |
| 34 |
return this.image; |
| 35 |
} |
| 36 |
}; |
| 37 |
/* End of image loader */ |