vendor: 6,292 bytes, lines 1-174
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,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" 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 /* Cache container as jQuery as object. */ 75 $container = (settings.container === undefined || 76 settings.container === window) ? $window : $(settings.container); 77 78 /* Fire one scroll event per scroll. Not one scroll event per image. */ 79 if (0 === settings.event.indexOf("scroll")) { 80 $container.bind(settings.event, function () { 81 return update(); 82 }); 83 } 84 85 this.each(function () { 86 var self = this; 87 var $self = $(self); 88 89 self.loaded = false; 90 91 /* If no src attribute given use data:uri. */ 92 if ($self.attr("src") === undefined || $self.attr("src") === false) { 93 if ($self.is("img")) { 94 $self.attr("src", settings.placeholder); 95 } 96 } 97 98 /* When appear is triggered load original image. */ 99 $self.one("appear", function () { 100 if (!this.loaded) { 101 if (settings.appear) { 102 var elements_left = elements.length; 103 settings.appear.call(self, elements_left, settings); 104 } 105 $("<img />") 106 .bind("load", function () { 107 108 var original = $self.attr("data-" + settings.data_attribute); 109 $self.hide(); 110 if ($self.is("img")) { 111 $self.attr("src", original); 112 } else { 113 $self.css("background-image", "url('" + original + "')"); 114 } 115 $self[settings.effect](settings.effect_speed); 116 117 self.loaded = true; 118 119 /* Remove image from array so it is not looped next time. */ 120 var temp = $.grep(elements, function (element) { 121 return !element.loaded; 122 }); 123 elements = $(temp); 124 125 if (settings.load) { 126 var elements_left = elements.length; 127 settings.load.call(self, elements_left, settings); 128 } 129 }) 130 .bind("error", function(e) { 131 $self.addClass("lazy-error"); 132 }) 133 .attr("src", $self.attr("data-" + settings.data_attribute)); 134 } 135 }); 136 137 /* When wanted event is triggered load original image */ 138 /* by triggering appear. */ 139 if (0 !== settings.event.indexOf("scroll")) { 140 $self.bind(settings.event, function () { 141 if (!self.loaded) { 142 $self.trigger("appear"); 143 } 144 }); 145 } 146 }); 147 148 /* Check if something appears when window is resized. */ 149 $window.bind("resize", function () { 150 update(); 151 }); 152 153 /* With IOS5 force loading images when navigating with back button. */ 154 /* Non optimal workaround. */ 155 if ((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)) { 156 $window.bind("pageshow", function (event) { 157 if (event.originalEvent && event.originalEvent.persisted) { 158 elements.each(function () { 159 $(this).trigger("appear"); 160 }); 161 } 162 }); 163 } 164 165 /* Force initial check if images should appear. */ 166 $(document).ready(function () { 167 update(); 168 }); 169 170 return this; 171 }; 172 173 /* Convenience methods in jQuery namespace. */ 174 /* Use as $.belowthefold(element, {threshold : 100, container : window}
vendor: 2,834 bytes, lines 174-245
174) */ 175 176 $.belowthefold = function (element, settings) { 177 var fold; 178 179 if (settings.container === undefined || settings.container === window) { 180 fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop(); 181 } else { 182 fold = $(settings.container).offset().top + $(settings.container).height(); 183 } 184 185 return fold <= $(element).offset().top - settings.threshold; 186 }; 187 188 $.rightoffold = function (element, settings) { 189 var fold; 190 191 if (settings.container === undefined || settings.container === window) { 192 fold = $window.width() + $window.scrollLeft(); 193 } else { 194 fold = $(settings.container).offset().left + $(settings.container).width(); 195 } 196 197 return fold <= $(element).offset().left - settings.threshold; 198 }; 199 200 $.abovethetop = function (element, settings) { 201 var fold; 202 203 if (settings.container === undefined || settings.container === window) { 204 fold = $window.scrollTop(); 205 } else { 206 fold = $(settings.container).offset().top; 207 } 208 209 return fold >= $(element).offset().top + settings.threshold + $(element).height(); 210 }; 211 212 $.leftofbegin = function (element, settings) { 213 var fold; 214 215 if (settings.container === undefined || settings.container === window) { 216 fold = $window.scrollLeft(); 217 } else { 218 fold = $(settings.container).offset().left; 219 } 220 221 return fold >= $(element).offset().left + settings.threshold + $(element).width(); 222 }; 223 224 $.inviewport = function (element, settings) { 225 return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) && 226 !$.belowthefold(element, settings) && !$.abovethetop(element, settings); 227 }; 228 229 /* Custom selectors for your convenience. */ 230 /* Use as $("img:below-the-fold").something() or */ 231 /* $("img").filter(":below-the-fold").something() which is faster */ 232 233 $.extend($.expr[":"], { 234 "below-the-fold": function (a) { return $.belowthefold(a, { threshold: 0 }); }, 235 "above-the-top": function (a) { return !$.belowthefold(a, { threshold: 0 }); }, 236 "right-of-screen": function (a) { return $.rightoffold(a, { threshold: 0 }); }, 237 "left-of-screen": function (a) { return !$.rightoffold(a, { threshold: 0 }); }, 238 "in-viewport": function (a) { return $.inviewport(a, { threshold: 0 }); }, 239 /* Maintain BC for couple of versions. */ 240 "above-the-fold": function (a) { return !$.belowthefold(a, { threshold: 0 }); }, 241 "right-of-fold": function (a) { return $.rightoffold(a, { threshold: 0 }); }, 242 "left-of-fold": function (a) { return !$.rightoffold(a, { threshold: 0 }); } 243 }); 244 245})(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.