Prevent double execution of onLoad event on Raster.

This commit is contained in:
Jürg Lehni 2013-07-03 19:02:29 -07:00
parent e87307af41
commit affb44e0dd

View file

@ -274,11 +274,18 @@ var Raster = Item.extend(/** @lends Raster# */{
var that = this, var that = this,
// src can be an URL or a DOM ID to load the image from // src can be an URL or a DOM ID to load the image from
image = document.getElementById(src) || new Image(); image = document.getElementById(src) || new Image();
function loaded() { function loaded() {
that.fire('load'); that.fire('load');
if (that._project.view) if (that._project.view)
that._project.view.draw(true); that._project.view.draw(true);
} }
if (image.width && image.height) {
// Fire load event delayed, so behavior is the same as when it's
// actually loaded and we give the code time to install event
setTimeout(loaded, 0);
} else if (!image.src) {
// Trigger the onLoad event on the image once it's loaded // Trigger the onLoad event on the image once it's loaded
DomEvent.add(image, { DomEvent.add(image, {
load: function() { load: function() {
@ -286,11 +293,6 @@ var Raster = Item.extend(/** @lends Raster# */{
loaded(); loaded();
} }
}); });
if (image.width && image.height) {
// Fire load event delayed, so behavior is the same as when it's
// actually loaded and we give the code time to install event
setTimeout(loaded, 0);
} else if (!image.src) {
image.src = src; image.src = src;
} }
this.setImage(image); this.setImage(image);