mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Redraw view once Raster has finished loading.
This commit is contained in:
parent
83867f01f3
commit
398ee1a338
1 changed files with 9 additions and 8 deletions
|
@ -44,7 +44,12 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
// If it's a string, get the element with this id first.
|
// If it's a string, get the element with this id first.
|
||||||
if (typeof object === 'string') {
|
if (typeof object === 'string') {
|
||||||
var str = object,
|
var str = object,
|
||||||
that = this;
|
that = this,
|
||||||
|
done = function() {
|
||||||
|
that.fire('load');
|
||||||
|
if (that._project.view)
|
||||||
|
that._project.view.draw(true);
|
||||||
|
};
|
||||||
object = document.getElementById(str);
|
object = document.getElementById(str);
|
||||||
if (!object) {
|
if (!object) {
|
||||||
// str could be a URL to load the image from?
|
// str could be a URL to load the image from?
|
||||||
|
@ -55,18 +60,14 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
DomEvent.add(object, {
|
DomEvent.add(object, {
|
||||||
load: function() {
|
load: function() {
|
||||||
that.setImage(object);
|
that.setImage(object);
|
||||||
that.fire('load');
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// If the image is already loaded, fire a 'load' event anyway,
|
// If the image is already loaded, fire a 'load' event anyway,
|
||||||
// so code does not need to make the distinction, and cachig is
|
// so code does not need to make the distinction, and cachig is
|
||||||
// transparently handled too.
|
// transparently handled too.
|
||||||
if (object.naturalWidth) {
|
if (object.naturalWidth)
|
||||||
setTimeout(function() {
|
setTimeout(done, 0);
|
||||||
that.fire('load');
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*#*/ } else if (options.server) {
|
/*#*/ } else if (options.server) {
|
||||||
// If we're running on the server and it's a string,
|
// If we're running on the server and it's a string,
|
||||||
|
|
Loading…
Reference in a new issue