Browse Source

Add imagesLoaded by Paul Irish et al, thanks simshaun

Jay Salvat 13 years ago
parent
commit
13300004df
1 changed files with 42 additions and 1 deletions
  1. 42 1
      jquery.vegas.js

+ 42 - 1
jquery.vegas.js

@@ -62,7 +62,7 @@
                 'left': '0px',
                 'left': '0px',
                 'top': '0px'
                 'top': '0px'
             })
             })
-            .load( function() {
+            .imagesLoadedForVegas( function() {
                 if ( $new == $current ) {
                 if ( $new == $current ) {
                     return;
                     return;
                 }
                 }
@@ -427,4 +427,45 @@
             // opacity:     float
             // opacity:     float
         }
         }
     }
     }
+
+    /*!
+     * jQuery imagesLoaded plugin v1.0.3
+     * http://github.com/desandro/imagesloaded
+     *
+     * MIT License. by Paul Irish et al.
+     */
+    $.fn.imagesLoadedForVegas = function( callback ) {
+        var $this = this,
+            $images = $this.find('img').add( $this.filter('img') ),
+            len = $images.length,
+            blank = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
+
+        function triggerCallback() {
+          callback.call( $this, $images );
+        }
+
+        function imgLoaded() {
+          if ( --len <= 0 && this.src !== blank ){
+            setTimeout( triggerCallback );
+            $images.unbind( 'load error', imgLoaded );
+          }
+        }
+
+        if ( !len ) {
+          triggerCallback();
+        }
+
+        $images.bind( 'load error',  imgLoaded ).each( function() {
+          // cached images don't fire load sometimes, so we reset src.
+          if (this.complete || this.complete === undefined){
+            var src = this.src;
+            // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
+            // data uri bypasses webkit log warning (thx doug jones)
+            this.src = blank;
+            this.src = src;
+          }
+        });
+
+        return $this;
+      };
 })( jQuery );
 })( jQuery );