Permalink
Browse files

streamlined

  • Loading branch information...
1 parent ae678f6 commit c76e84da617bd23b3d949d2518b37b988a92f18c pixelbreaker committed Jun 13, 2011
Showing with 17 additions and 37 deletions.
  1. +15 −35 takeoverloader/jquery.takeoverloader-0.1.js
  2. +2 −2 takeoverloader/jquery.takeoverloader-0.1.min.js
@@ -2,7 +2,7 @@
* jQuery Image Take Over loader v0.1
* http://blog.pixelbreaker.com/javascript/takeover-loader
*
- * Copyright (c) 2009-2010 Gabriel Bucknall
+ * Copyright (c) 2011 Gabriel Bucknall
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
@@ -14,49 +14,29 @@
$.fn.takeoverloader = function( progress, complete )
{
var
- el = this,
- images_ = new Array(),
- numImages_,
+ eligible = this.find('img:not([src=""]):not(.noloader)'),
+ total_ = eligible.length-1,
+ loaded_ = 0,
progress_ = progress || function(){},
complete_ = complete || function(){};
- var getAllImages = function()
+ eligible.each(function()
{
- el.find('img:not([src=""]):not(.noloader)').each(function()
- {
- images_.push( {uri: $(this).attr('src'), el:this} );
- });
- numImages_ = images_.length;
- };
-
- var addListeners = function()
- {
- $.each( images_, function( k, v )
- {
- var imgObj = $(v.el);
- if( v.el.complete )
- addLoaded();
- else
- $(v.el).load(function()
- {
- addLoaded();
- });
- });
- };
+ if( this.complete )
+ stepProgress();
+ else
+ $(this).load( function(){stepProgress();} );
+ });
- var addLoaded = function()
+ var stepProgress = function()
{
- numImages_--;
- progress_( 1-(numImages_/images_.length) );
- if(numImages_==0)
+ loaded_++;
+ progress_( loaded_/total_ );
+ if(loaded_>=total_)
{
- $.each( images_, function( k, v ){ $(v.el).unbind( 'load' ); });
-
+ eligible.unbind( 'load' );
complete_();
}
};
-
- getAllImages();
- addListeners();
}
})( jQuery );
@@ -2,10 +2,10 @@
* jQuery Image Take Over loader v0.1
* http://blog.pixelbreaker.com/javascript/takeover-loader
*
- * Copyright (c) 2009-2010 Gabriel Bucknall
+ * Copyright (c) 2011 Gabriel Bucknall
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Date: 2011-06-11
*/
-(function(a){a.fn.takeoverloader=function(f,g){var h=this,b=[],d,i=f||function(){},j=g||function(){},e=function(){d--;i(1-d/b.length);d==0&&(a.each(b,function(b,c){a(c.el).unbind("load")}),j())};(function(){h.find('img:not([src=""]):not(.noloader)').each(function(){b.push({uri:a(this).attr("src"),el:this})});d=b.length})();(function(){a.each(b,function(b,c){a(c.el);c.el.complete?e():a(c.el).load(function(){e()})})})()}})(jQuery);
+(function(c){c.fn.takeoverloader=function(f,g){var a=this.find('img:not([src=""]):not(.noloader)'),d=a.length-1,b=0,h=f||function(){},i=g||function(){};a.each(function(){this.complete?e():c(this).load(function(){e()})});var e=function(){b++;h(b/d);b>=d&&(a.unbind("load"),i())}}})(jQuery);

0 comments on commit c76e84d

Please sign in to comment.