1/** 2 * jQuery Unveil 3 * A very lightweight jQuery plugin to lazy load images 4 * http://luis-almeida.github.com/unveil 5 * 6 * Licensed under the MIT license. 7 * Copyright 2013 LuÃs Almeida 8 * https://github.com/luis-almeida 9 */ 10 11;(function($) { 12 13 $.fn.unveil = function(threshold, callback) { 14 15 16 var $w = $(window), 17 th = threshold || 0, 18 retina = window.devicePixelRatio > 1, 19 attrib = retina? "data-src-retina" : "data-src", 20 images = this, 21 loaded; 22 23 // BY SPAB RICE 24 if (!images.parent('.lazy-img').length) { 25 images.wrap( '<span class="lazy-wrapper"><span class="lazy-img"></span></span>' ); 26 images.parents(".lazy-wrapper").append( '<span class="lazy-icon"><span></span></span>' ); 27 images.each(function(){ 28 var wrapperHeight = 400; 29 if (typeof jQuery(this).attr("height") !== typeof undefined && jQuery(this).attr("height") !== false) { 30 var originalHeight = parseInt(jQuery(this).attr("height"),10); 31 var originalWidth = parseInt(jQuery(this).attr("width"),10); 32 jQuery(this).parents(".lazy-wrapper").css("max-width",originalWidth+"px"); 33 if ( 34 jQuery(this).closest(".isotope-grid").data("ratio") || 35 (jQuery(this).closest(".isotope-grid:not(.gallery-container)") && jQuery(this).closest(".item-media")) ) 36 { jQuery(this).parents(".lazy-wrapper").css("max-width","100%"); } 37 // if closest added for isotope grid with double sized element (always take the full width) 38 // and for all item-media images for no gallery conatiner 39 var iRatio = originalWidth/originalHeight; 40 var wrapperWidth = parseInt(jQuery(this).parents(".lazy-wrapper").width(),10); 41 wrapperHeight = parseInt(wrapperWidth / iRatio,10); 42 } 43 jQuery(this).parents(".lazy-wrapper").css({"min-height": wrapperHeight+"px"}); 44 }); 45 } 46 // BY SPAB RICE 47 48 this.one("unveil", function() { 49 var source = this.getAttribute(attrib); 50 source = source || this.getAttribute("data-src"); 51 if (source) { 52 this.setAttribute("src", source); 53 if (this.getAttribute("data-srcset")) { this.setAttribute("srcset", this.getAttribute("data-srcset")); } 54 if (this.getAttribute("data-sizes")) { this.setAttribute("sizes", this.getAttribute("data-sizes")); } 55 // BY SPAB RICE 56 jQuery(this).addClass("lazy-loaded"); 57 jQuery(this).parents(".lazy-wrapper").addClass("loaded"); 58 if (typeof callback === "function") callback.call(this); 59 } 60 }); 61 62 function unveil() { 63 var inview = images.filter(function() { 64 var $e = $(this); 65 if ($e.is(":hidden")) return; 66 67 var wt = $w.scrollTop(), 68 wb = wt + $w.height(), 69 et = $e.offset().top, 70 eb = et + $e.height(); 71 72 return eb >= wt - th && et <= wb + th; 73 }); 74 75 loaded = inview.trigger("unveil"); 76 images = images.not(loaded); 77 } 78 79 $w.on("scroll.unveil resize.unveil lookup.unveil", unveil); 80 81 // add setTimeout to unveil the first visible images after rest has been loaded 82 // unveil(); 83 setTimeout(function(){ unveil(); },1000); 84 85 return this; 86 87 }; 88 89})(window.jQuery || window.Zepto);
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.