vendor: 6,913 bytes, lines 1-164
1(function($, window, document, undefined) { 2 var $window = $(window); 3 $.fn.lazyload = function(options) { 4 var elements = this, 5 $container, 6 settings = { 7 threshold : 10, 8 failure_limit : 0, 9 event : "scroll", 10 effect : "show", 11 container : window, 12 data_attribute : "original", 13 skip_invisible : true, 14 appear : null, 15 load : null, 16 placeholder : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" 17 }; 18 function update() { 19 var counter = 0; 20 elements.each(function() { 21 var $this = $(this); 22 if (settings.skip_invisible && !$this.is(":visible")) { 23 return; 24 } 25 if ($.abovethetop(this, settings) || 26 $.leftofbegin(this, settings)) { 27 /* Nothing. */ 28 } else if (!$.belowthefold(this, settings) && 29 !$.rightoffold(this, settings)) { 30 $this.trigger("appear"); 31 /* if image is found, load and reset the counter */ 32 counter = 0; 33 } else { 34 if (++counter > settings.failure_limit) { 35 return false; 36 } 37 } 38 }); 39 } 40 if(options) { 41 if (undefined !== options.failurelimit) { 42 options.failure_limit = options.failurelimit; 43 delete options.failurelimit; 44 } 45 if (undefined !== options.effectspeed) { 46 options.effect_speed = options.effectspeed; 47 delete options.effectspeed; 48 } 49 $.extend(settings, options); 50 } 51 52 $container = (settings.container === undefined || 53 settings.container === window) ? $window : $(settings.container); 54 if (0 === settings.event.indexOf("scroll")) { 55 $container.bind(settings.event, function() { 56 return update(); 57 }); 58 } 59 this.each(function() { 60 var self = this; 61 var $self = $(self); 62 self.loaded = false; 63 if ($self.attr("src") === undefined || $self.attr("src") === false) { 64 if ($self.is("img")) { 65 $self.attr("src", settings.placeholder); 66 } 67 } 68 $self.one("appear", function() { 69 if (!this.loaded) { 70 if (settings.appear) { 71 var elements_left = elements.length; 72 settings.appear.call(self, elements_left, settings); 73 } 74 $("<img />").bind("load", function() { 75 var original = $self.attr("data-" + settings.data_attribute); 76 $self.hide(); 77 if ($self.is("img")) { 78 $self.attr("src", original); 79 } else { 80 $self.css("background-image", "url('" + original + "')"); 81 } 82 $self[settings.effect](settings.effect_speed); 83 self.loaded = true; 84 var temp = $.grep(elements, function(element) { 85 return !element.loaded; 86 }); 87 elements = $(temp); 88 if (settings.load) { 89 var elements_left = elements.length; 90 settings.load.call(self, elements_left, settings); 91 } 92 }) 93 .attr("src", $self.attr("data-" + settings.data_attribute)); 94 } 95 }); 96 if (0 !== settings.event.indexOf("scroll")) { 97 $self.bind(settings.event, function() { 98 if (!self.loaded) { 99 $self.trigger("appear"); 100 } 101 }); 102 } 103 }); 104 $window.bind("resize", function() { 105 update(); 106 }); 107 /* for iphone. */ 108 if ((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)) { 109 $window.bind("pageshow", function(event) { 110 if (event.originalEvent && event.originalEvent.persisted) { 111 elements.each(function() { 112 $(this).trigger("appear"); 113 }); 114 } 115 }); 116 } 117 /* Force initial check if images should appear. */ 118 $(document).ready(function() { 119 update(); 120 }); 121 return this; 122 }; 123 124 $.belowthefold = function(element, settings) { 125 var fold; 126 if (settings.container === undefined || settings.container === window) { 127 fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop(); 128 } else { 129 fold = $(settings.container).offset().top + $(settings.container).height(); 130 } 131 return fold <= $(element).offset().top - settings.threshold; 132 }; 133 $.rightoffold = function(element, settings) { 134 var fold; 135 if (settings.container === undefined || settings.container === window) { 136 fold = $window.width() + $window.scrollLeft(); 137 } else { 138 fold = $(settings.container).offset().left + $(settings.container).width(); 139 } 140 return fold <= $(element).offset().left - settings.threshold; 141 }; 142 $.abovethetop = function(element, settings) { 143 var fold; 144 if (settings.container === undefined || settings.container === window) { 145 fold = $window.scrollTop(); 146 } else { 147 fold = $(settings.container).offset().top; 148 } 149 return fold >= $(element).offset().top + settings.threshold + $(element).height(); 150 }; 151 $.leftofbegin = function(element, settings) { 152 var fold; 153 if (settings.container === undefined || settings.container === window) { 154 fold = $window.scrollLeft(); 155 } else { 156 fold = $(settings.container).offset().left; 157 } 158 return fold >= $(element).offset().left + settings.threshold + $(element).width(); 159 }; 160 $.inviewport = function(element, settings) { 161 return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) && 162 !$.belowthefold(element, settings) && !$.abovethetop(element, settings); 163 }; 164 $.extend($.expr[":"], {
165 "below-the-fold" : function(a) { return $.belowthefold(a, {threshold : 0}); }, 166 "above-the-top" : function(a) { return !$.belowthefold(a, {threshold : 0}); }, 167 "right-of-screen": function(a) { return $.rightoffold(a, {threshold : 0}); }, 168 "left-of-screen" : function(a) { return !$.rightoffold(a, {threshold : 0}); }, 169 "in-viewport" : function(a) { return $.inviewport(a, {threshold : 0}); }, 170 "above-the-fold" : function(a) { return !$.belowthefold(a, {threshold : 0}); }, 171 "right-of-fold" : function(a) { return $.rightoffold(a, {threshold : 0}); }, 172 "left-of-fold" : function(a) { return !$.rightoffold(a, {threshold : 0}); } 173 }); 174})(jQuery, window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.