Skip to content

Commit

Permalink
streamlined
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelbreaker committed Jun 13, 2011
1 parent ae678f6 commit c76e84d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
50 changes: 15 additions & 35 deletions takeoverloader/jquery.takeoverloader-0.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 );
4 changes: 2 additions & 2 deletions takeoverloader/jquery.takeoverloader-0.1.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.