Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed custom selector to work correctly with img elements with inva…

…lid src attributes
  • Loading branch information...
commit c5dcf7390909850cac67232bef1d3ad0f0e0ed45 1 parent 95aec2b
@alexanderdickson authored
Showing with 11 additions and 6 deletions.
  1. +1 −1  README.md
  2. +10 −5 jquery.waitforimages.js
View
2  README.md
@@ -1,4 +1,4 @@
-#waitForImages 1.3.4#
+#waitForImages 1.4#
Copyright (c) 2011 Alex Dickson [@alexdickson](http://twitter.com/alexdickson)
View
15 jquery.waitforimages.js
@@ -1,5 +1,5 @@
/*
- * waitForImages 1.3.4
+ * waitForImages 1.4
* -----------------
* Provides a callback when all images have loaded in your given selector.
* http://www.alexanderdickson.com/
@@ -27,13 +27,18 @@
// Custom selector to find `img` elements that have a valid `src` attribute and have not already loaded.
$.expr[':'].uncached = function(obj) {
- // Firefox will always return `true` even if the image has not been downloaded.
- // Doing it this way works in Firefox.
+ // Ensure we are dealing with an `img` element with a valid `src` attribute.
+ if ( ! $(obj).is('img[src!=""]')) {
+ return false;
+ }
+
+ // Firefox's `complete` property will always be`true` even if the image has not been downloaded.
+ // Doing it this way works in Firefox.
var img = document.createElement('img');
img.src = obj.src;
- return $(obj).is('img[src!=""]') && ! img.complete;
+ return ! img.complete;
};
-
+
$.fn.waitForImages = function(finishedCallback, eachCallback, waitForAll) {
// Handle options object.
Please sign in to comment.
Something went wrong with that request. Please try again.