Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

streamlined

  • Loading branch information...
commit c76e84da617bd23b3d949d2518b37b988a92f18c 1 parent ae678f6
pixelbreaker authored
50 takeoverloader/jquery.takeoverloader-0.1.js
@@ -2,7 +2,7 @@
2 2 * jQuery Image Take Over loader v0.1
3 3 * http://blog.pixelbreaker.com/javascript/takeover-loader
4 4 *
5   - * Copyright (c) 2009-2010 Gabriel Bucknall
  5 + * Copyright (c) 2011 Gabriel Bucknall
6 6 * Dual licensed under the MIT or GPL Version 2 licenses.
7 7 * http://jquery.org/license
8 8 *
@@ -14,49 +14,29 @@
14 14 $.fn.takeoverloader = function( progress, complete )
15 15 {
16 16 var
17   - el = this,
18   - images_ = new Array(),
19   - numImages_,
  17 + eligible = this.find('img:not([src=""]):not(.noloader)'),
  18 + total_ = eligible.length-1,
  19 + loaded_ = 0,
20 20 progress_ = progress || function(){},
21 21 complete_ = complete || function(){};
22 22
23   - var getAllImages = function()
  23 + eligible.each(function()
24 24 {
25   - el.find('img:not([src=""]):not(.noloader)').each(function()
26   - {
27   - images_.push( {uri: $(this).attr('src'), el:this} );
28   - });
29   - numImages_ = images_.length;
30   - };
31   -
32   - var addListeners = function()
33   - {
34   - $.each( images_, function( k, v )
35   - {
36   - var imgObj = $(v.el);
37   - if( v.el.complete )
38   - addLoaded();
39   - else
40   - $(v.el).load(function()
41   - {
42   - addLoaded();
43   - });
44   - });
45   - };
  25 + if( this.complete )
  26 + stepProgress();
  27 + else
  28 + $(this).load( function(){stepProgress();} );
  29 + });
46 30
47   - var addLoaded = function()
  31 + var stepProgress = function()
48 32 {
49   - numImages_--;
50   - progress_( 1-(numImages_/images_.length) );
51   - if(numImages_==0)
  33 + loaded_++;
  34 + progress_( loaded_/total_ );
  35 + if(loaded_>=total_)
52 36 {
53   - $.each( images_, function( k, v ){ $(v.el).unbind( 'load' ); });
54   -
  37 + eligible.unbind( 'load' );
55 38 complete_();
56 39 }
57 40 };
58   -
59   - getAllImages();
60   - addListeners();
61 41 }
62 42 })( jQuery );
4 takeoverloader/jquery.takeoverloader-0.1.min.js
@@ -2,10 +2,10 @@
2 2 * jQuery Image Take Over loader v0.1
3 3 * http://blog.pixelbreaker.com/javascript/takeover-loader
4 4 *
5   - * Copyright (c) 2009-2010 Gabriel Bucknall
  5 + * Copyright (c) 2011 Gabriel Bucknall
6 6 * Dual licensed under the MIT or GPL Version 2 licenses.
7 7 * http://jquery.org/license
8 8 *
9 9 * Date: 2011-06-11
10 10 */
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);
  11 +(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.
Something went wrong with that request. Please try again.