Skip to content

Commit

Permalink
Changed render check to a timeout
Browse files Browse the repository at this point in the history
Callbacks could otherwise never fire when updating image.src during a
load. This might be expected while updating a src but we shouldn't check
for it ourselves and always fire the callback.
  • Loading branch information
staaky committed Jun 7, 2015
1 parent d9196e8 commit 63bd11d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 53 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "voila",
"version": "1.3.0",
"version": "1.3.1",
"description": "A jQuery plugin that provides callbacks for images, letting you know when they've loaded.",
"keywords": [
"image",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "voila",
"title": "Voilà",
"version": "1.3.0",
"version": "1.3.1",
"description": "A jQuery plugin that provides callbacks for images, letting you know when they've loaded.",
"keywords": [
"image",
Expand Down
28 changes: 4 additions & 24 deletions src/imageready.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,33 +245,13 @@ $.extend(ImageReady.prototype, {

// used by success() only
waitForRender: function(callback) {
if (this._renderPoll) this._renderPoll.abort();

this._renderPoll = new Poll({
test: $.proxy(function() {
// when using onload, the detached image node shoud have
// the same dimensions as the <img> in the DOM to guarantee
// a complete render.
// IE 11 can have situations where the detached image is loaded
// but rendering hasn't completed on the <img> with the same src,
// this guards against that.
if (this.options.method == 'onload') {
return this.img.naturalWidth == this._onloadImage.naturalWidth
&& this.img.naturalHeight == this._onloadImage.naturalHeight;
} else {
// otherwise we used naturalWidth an might not have a detached
// image that rendered successfully.
return true;
}
}, this),
success: callback
});
this._renderTimeout = setTimeout(callback);
},

stopWaitingForRender: function() {
if (this._renderPoll) {
this._renderPoll.abort();
this._renderPoll = null;
if (this._renderTimeout) {
clearTimeout(this._renderTimeout);
this._renderTimeout = null;
}

if (this._errorRenderTimeout) {
Expand Down
30 changes: 5 additions & 25 deletions voila.pkgd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Voilà - v1.3.0
* Voilà - v1.3.1
* (c) 2015 Nick Stakenburg
*
* http://voila.nickstakenburg.com
Expand Down Expand Up @@ -390,33 +390,13 @@ $.extend(ImageReady.prototype, {

// used by success() only
waitForRender: function(callback) {
if (this._renderPoll) this._renderPoll.abort();

this._renderPoll = new Poll({
test: $.proxy(function() {
// when using onload, the detached image node shoud have
// the same dimensions as the <img> in the DOM to guarantee
// a complete render.
// IE 11 can have situations where the detached image is loaded
// but rendering hasn't completed on the <img> with the same src,
// this guards against that.
if (this.options.method == 'onload') {
return this.img.naturalWidth == this._onloadImage.naturalWidth
&& this.img.naturalHeight == this._onloadImage.naturalHeight;
} else {
// otherwise we used naturalWidth an might not have a detached
// image that rendered successfully.
return true;
}
}, this),
success: callback
});
this._renderTimeout = setTimeout(callback);
},

stopWaitingForRender: function() {
if (this._renderPoll) {
this._renderPoll.abort();
this._renderPoll = null;
if (this._renderTimeout) {
clearTimeout(this._renderTimeout);
this._renderTimeout = null;
}

if (this._errorRenderTimeout) {
Expand Down
4 changes: 2 additions & 2 deletions voila.pkgd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 63bd11d

Please sign in to comment.