1/*! picturefillOld - Responsive Images that work today. (and mimic the proposed Picture element with span elements). Author: Scott Jehl, Filament Group, 2012 | License: MIT/GPLv2 */ 2 3(function( w ){ 4 5 // Enable strict mode 6 "use strict"; 7 8 w.picturefillOld = function() { 9 var ps = w.document.getElementsByTagName( "span" ); 10 11 // Loop the pictures 12 for( var i = 0, il = ps.length; i < il; i++ ){ 13 if( ps[ i ].getAttribute( "data-picture" ) !== null ){ 14 15 var sources = ps[ i ].getElementsByTagName( "span" ), 16 matches = []; 17 18 // See if which sources match 19 for( var j = 0, jl = sources.length; j < jl; j++ ){ 20 var media = sources[ j ].getAttribute( "data-media" ); 21 // if there's no media specified, OR w.matchMedia is supported 22 if( !media || ( w.matchMedia && w.matchMedia( media ).matches ) ){ 23 matches.push( sources[ j ] ); 24 } 25 } 26 27 // Find any existing img element in the picture element 28 var picImg = ps[ i ].getElementsByTagName( "img" )[ 0 ]; 29 30 if( matches.length ){ 31 var matchedEl = matches.pop(); 32 if( !picImg || picImg.parentNode.nodeName === "NOSCRIPT" ){ 33 picImg = w.document.createElement( "img" ); 34 picImg.alt = ps[ i ].getAttribute( "data-alt" ); 35 } 36 else if( matchedEl === picImg.parentNode ){ 37 // Skip further actions if the correct image is already in place 38 continue; 39 } 40 41 picImg.src = matchedEl.getAttribute( "data-src" ); 42 matchedEl.appendChild( picImg ); 43 picImg.removeAttribute("width"); 44 picImg.removeAttribute("height"); 45 } 46 else if( picImg ){ 47 picImg.parentNode.removeChild( picImg ); 48 } 49 } 50 } 51 }; 52 53 // Run on resize and domready (w.load as a fallback) 54 if( w.addEventListener ){ 55 w.addEventListener( "resize", w.picturefillOld, false ); 56 w.addEventListener( "DOMContentLoaded", function(){ 57 w.picturefillOld(); 58 // Run once only 59 w.removeEventListener( "load", w.picturefillOld, false ); 60 }, false ); 61 w.addEventListener( "load", w.picturefillOld, false ); 62 } 63 else if( w.attachEvent ){ 64 w.attachEvent( "onload", w.picturefillOld ); 65 } 66 67}( this ));
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.