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