1/*! Lazy Load XT v1.1.0 2016-01-12 2 * http://ressio.github.io/lazy-load-xt 3 * (C) 2016 RESS.io 4 * Licensed under MIT */ 5 6(function ($, window, document, undefined) { 7 var options = $.lazyLoadXT, 8 srcsetSupport = (function () { 9 return 'srcset' in (new Image()); 10 })(), 11 reUrl = /^\s*(\S*)/, 12 reWidth = /\S\s+(\d+)w/, 13 reHeight = /\S\s+(\d+)h/, 14 reDpr = /\S\s+([\d\.]+)x/, 15 infty = [0, Infinity], 16 one = [0, 1], 17 srcsetOptions = { 18 srcsetAttr: 'data-srcset', 19 srcsetExtended: true, 20 srcsetBaseAttr: 'data-srcset-base', 21 srcsetExtAttr: 'data-srcset-ext' 22 }, 23 viewport = { 24 w: 0, 25 h: 0, 26 x: 0 27 }, 28 property, 29 limit; 30 31 for (property in srcsetOptions) { 32 if (options[property] === undefined) { 33 options[property] = srcsetOptions[property]; 34 } 35 } 36 options.selector += ',img[' + options.srcsetAttr + '],source[' + options.srcsetAttr + ']'; 37 38 function mathFilter(array, action) { 39 return Math[action].apply(null, $.map(array, function (item) { 40 return item[property]; 41 })); 42 } 43 44 function compareMax(item) { 45 return item[property] >= viewport[property] || item[property] === limit; 46 } 47 48 function compareMin(item) { 49 return item[property] === limit; 50 } 51 52 function parseSrcset($el) { 53 var srcset = $el.attr(options.srcsetAttr); 54 55 if (!srcset) { 56 return false; 57 } 58 59 var list = $.map(srcset.replace(/(\s[\d.]+[whx]),/g, '$1 @,@ ').split(' @,@ '), function (item) { 60 return { 61 url: reUrl.exec(item)[1], 62 w: parseFloat((reWidth.exec(item) || infty)[1]), 63 h: parseFloat((reHeight.exec(item) || infty)[1]), 64 x: parseFloat((reDpr.exec(item) || one)[1]) 65 }; 66 }); 67 68 if (!list.length) { 69 return false; 70 } 71 72 var documentElement = document.documentElement, 73 whx, 74 src; 75 76 viewport = { 77 w: window.innerWidth || documentElement.clientWidth, 78 h: window.innerHeight || documentElement.clientHeight, 79 x: window.devicePixelRatio || 1 80 }; 81 82 // Notice for DOMtastic users: currently $.grep method is not implemented in DOMtastic 83 84 for (whx in viewport) { 85 property = whx; 86 limit = mathFilter(list, 'max'); 87 list = $.grep(list, compareMax); 88 } 89 90 for (whx in viewport) { 91 property = whx; 92 limit = mathFilter(list, 'min'); 93 list = $.grep(list, compareMin); 94 } 95 96 src = list[0].url; 97 98 if (options.srcsetExtended) { 99 src = ($el.attr(options.srcsetBaseAttr) || '') + src + ($el.attr(options.srcsetExtAttr) || ''); 100 } 101 102 return src; 103 } 104 105 $(document).on('lazyshow', 'img', function (e, $el) { 106 var srcset = $el.attr(options.srcsetAttr); 107 108 if (srcset) { 109 if (!options.srcsetExtended && srcsetSupport) { 110 $el.attr('srcset', srcset); 111 $el.attr('data-srcset', ''); 112 } else { 113 $el.lazyLoadXT.srcAttr = parseSrcset; 114 } 115 } 116 }); 117 118 $(document).on('lazyshow', 'source', function (e, $el) { 119 $(this).removeClass('lazy-hidden'); 120 121 var srcset = $el.attr(options.srcsetAttr); 122 123 if (srcset) { 124 if (!options.srcsetExtended && srcsetSupport) { 125 $el.attr('srcset', srcset); 126 $el.attr('data-srcset', ''); 127 } else { 128 $el.lazyLoadXT.srcAttr = parseSrcset; 129 } 130 } 131 }); 132 133})(window.jQuery || window.Zepto || window.$, 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.