vendor: 5,646 bytes, lines 1-228
1/* 2 * Lazy Load - jQuery plugin for lazy loading images 3 * 4 * Copyright (c) 2007-2013 Mika Tuupola 5 * 6 * Licensed under the MIT license: 7 * 8 * Project home: 9 * 10 * Version: 1.9.3 11 * 12 */ 13 14(function($, window, document, undefined) { 15 var $window = $(window); 16 17 $.fn.lazyload = function(options) { 18 var elements = this; 19 var $container; 20 var settings = { 21 threshold : 0, 22 failure_limit : 0, 23 event : "scroll", 24 effect : "show", 25 container : window, 26 data_attribute : "original", 27 skip_invisible : true, 28 appear : null, 29 load : null, 30 placeholder: "js/grey.gif" 31 }; 32 33 function update() { 34 var counter = 0; 35 36 elements.each(function() { 37 var $this = $(this); 38 if (settings.skip_invisible && !$this.is(":visible")) { 39 return; 40 } 41 if ($.abovethetop(this, settings) || 42 $.leftofbegin(this, settings)) { 43 /* Nothing. */ 44 } else if (!$.belowthefold(this, settings) && 45 !$.rightoffold(this, settings)) { 46 $this.trigger("appear"); 47 /* if we found an image we'll load, reset the counter */ 48 counter = 0; 49 } else { 50 if (++counter > settings.failure_limit) { 51 return false; 52 } 53 } 54 }); 55 56 } 57 58 if(options) { 59 /* Maintain BC for a couple of versions. */ 60 if (undefined !== options.failurelimit) { 61 options.failure_limit = options.failurelimit; 62 delete options.failurelimit; 63 } 64 if (undefined !== options.effectspeed) { 65 options.effect_speed = options.effectspeed; 66 delete options.effectspeed; 67 } 68 69 $.extend(settings, options); 70 } 71 72 /* Cache container as jQuery as object. */ 73 $container = (settings.container === undefined || 74 settings.container === window) ? $window : $(settings.container); 75 76 /* Fire one scroll event per scroll. Not one scroll event per image. */ 77 if (0 === settings.event.indexOf("scroll")) { 78 $container.bind(settings.event, function() { 79 return update(); 80 }); 81 } 82 83 this.each(function() { 84 var self = this; 85 var $self = $(self); 86 87 self.loaded = false; 88 89 /* If no src attribute given use data:uri. */ 90 if ($self.attr("src") === undefined || $self.attr("src") === false) { 91 if ($self.is("img")) { 92 $self.attr("src", settings.placeholder); 93 } 94 } 95 96 /* When appear is triggered load original image. */ 97 $self.one("appear", function() { 98 if (!this.loaded) { 99 if (settings.appear) { 100 var elements_left = elements.length; 101 settings.appear.call(self, elements_left, settings); 102 } 103 $("<img />") 104 .bind("load", function() { 105 106 var original = $self.attr("data-" + settings.data_attribute); 107 $self.hide(); 108 if ($self.is("img")) { 109 $self.attr("src", original); 110 } else { 111 $self.css("background-image", "url('" + original + "')"); 112 } 113 $self[settings.effect](settings.effect_speed); 114 115 self.loaded = true; 116 117 /* Remove image from array so it is not looped next time. */ 118 var temp = $.grep(elements, function(element) { 119 return !element.loaded; 120 }); 121 elements = $(temp); 122 123 if (settings.load) { 124 var elements_left = elements.length; 125 settings.load.call(self, elements_left, settings); 126 } 127 }) 128 .attr("src", $self.attr("data-" + settings.data_attribute)); 129 } 130 }); 131 132 /* When wanted event is triggered load original image */ 133 /* by triggering appear. */ 134 if (0 !== settings.event.indexOf("scroll")) { 135 $self.bind(settings.event, function() { 136 if (!self.loaded) { 137 $self.trigger("appear"); 138 } 139 }); 140 } 141 }); 142 143 /* Check if something appears when window is resized. */ 144 $window.bind("resize", function() { 145 update(); 146 }); 147 148 /* With IOS5 force loading images when navigating with back button. */ 149 /* Non optimal workaround. */ 150 if ((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)) { 151 $window.bind("pageshow", function(event) { 152 if (event.originalEvent && event.originalEvent.persisted) { 153 elements.each(function() { 154 $(this).trigger("appear"); 155 }); 156 } 157 }); 158 } 159 160 /* Force initial check if images should appear. */ 161 $(document).ready(function() { 162 update(); 163 }); 164 165 return this; 166 }; 167 168 /* Convenience methods in jQuery namespace. */ 169 /* Use as $.belowthefold(element, {threshold : 100, container : window}) */ 170 171 $.belowthefold = function(element, settings) { 172 var fold; 173 174 if (settings.container === undefined || settings.container === window) { 175 fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop(); 176 } else { 177 fold = $(settings.container).offset().top + $(settings.container).height(); 178 } 179 180 return fold <= $(element).offset().top - settings.threshold; 181 }; 182 183 $.rightoffold = function(element, settings) { 184 var fold; 185 186 if (settings.container === undefined || settings.container === window) { 187 fold = $window.width() + $window.scrollLeft(); 188 } else { 189 fold = $(settings.container).offset().left + $(settings.container).width(); 190 } 191 192 return fold <= $(element).offset().left - settings.threshold; 193 }; 194 195 $.abovethetop = function(element, settings) { 196 var fold; 197 198 if (settings.container === undefined || settings.container === window) { 199 fold = $window.scrollTop(); 200 } else { 201 fold = $(settings.container).offset().top; 202 } 203 204 return fold >= $(element).offset().top + settings.threshold + $(element).height(); 205 }; 206 207 $.leftofbegin = function(element, settings) { 208 var fold; 209 210 if (settings.container === undefined || settings.container === window) { 211 fold = $window.scrollLeft(); 212 } else { 213 fold = $(settings.container).offset().left; 214 } 215 216 return fold >= $(element).offset().left + settings.threshold + $(element).width(); 217 }; 218 219 $.inviewport = function(element, settings) { 220 return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) && 221 !$.belowthefold(element, settings) && !$.abovethetop(element, settings); 222 }; 223 224 /* Custom selectors for your convenience. */ 225 /* Use as $("img:below-the-fold").something() or */ 226 /* $("img").filter(":below-the-fold").something() which is faster */ 227 228 $.extend($.expr[":"], {
229 "below-the-fold" : function(a) { return $.belowthefold(a, {threshold : 0}); }, 230 "above-the-top" : function(a) { return !$.belowthefold(a, {threshold : 0}); }, 231 "right-of-screen": function(a) { return $.rightoffold(a, {threshold : 0}); }, 232 "left-of-screen" : function(a) { return !$.rightoffold(a, {threshold : 0}); }, 233 "in-viewport" : function(a) { return $.inviewport(a, {threshold : 0}); }, 234 /* Maintain BC for couple of versions. */ 235 "above-the-fold" : function(a) { return !$.belowthefold(a, {threshold : 0}); }, 236 "right-of-fold" : function(a) { return $.rightoffold(a, {threshold : 0}); }, 237 "left-of-fold" : function(a) { return !$.rightoffold(a, {threshold : 0}); } 238 }); 239 240})(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.