vendor: 3,373 bytes, lines 1-111
1/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */ 2/* This file is meant as a standalone workflow for 3- testing support for link[rel=preload] 4- enabling async CSS loading in browsers that do not support rel=preload 5- applying rel preload css once loaded, whether supported or not. 6*/ 7(function( w ){ 8 "use strict"; 9 // rel=preload support test 10 if( !w.loadCSS ){ 11 w.loadCSS = function(){}; 12 } 13 // define on the loadCSS obj 14 var rp = loadCSS.relpreload = {}; 15 // rel=preload feature support test 16 // runs once and returns a function for compat purposes 17 rp.support = (function(){ 18 var ret; 19 try { 20 ret = w.document.createElement( "link" ).relList.supports( "preload" ); 21 } catch (e) { 22 ret = false; 23 } 24 return function(){ 25 return ret; 26 }; 27 })(); 28 29 // if preload isn't supported, get an asynchronous load by using a non-matching media attribute 30 // then change that media back to its intended value on load 31 rp.bindMediaToggle = function( link ){ 32 // remember existing media attr for ultimate state, or default to 'all' 33 var finalMedia = link.media || "all"; 34 35 function enableStylesheet(){ 36 // unbind listeners 37 if( link.addEventListener ){ 38 link.removeEventListener( "load", enableStylesheet ); 39 } else if( link.attachEvent ){ 40 link.detachEvent( "onload", enableStylesheet ); 41 } 42 link.setAttribute( "onload", null ); 43 link.media = finalMedia; 44 } 45 46 // bind load handlers to enable media 47 if( link.addEventListener ){ 48 link.addEventListener( "load", enableStylesheet ); 49 } else if( link.attachEvent ){ 50 link.attachEvent( "onload", enableStylesheet ); 51 } 52 53 // Set rel and non-applicable media type to start an async request 54 // note: timeout allows this to happen async to let rendering continue in IE 55 setTimeout(function(){ 56 link.rel = "stylesheet"; 57 link.media = "only x"; 58 }); 59 // also enable media after 3 seconds, 60 // which will catch very old browsers (android 2.x, old firefox) that don't support onload on link 61 setTimeout( enableStylesheet, 3000 ); 62 }; 63 64 // loop through link elements in DOM 65 rp.poly = function(){ 66 // double check this to prevent external calls from running 67 if( rp.support() ){ 68 return; 69 } 70 var links = w.document.getElementsByTagName( "link" ); 71 for( var i = 0; i < links.length; i++ ){ 72 var link = links[ i ]; 73 // qualify links to those with rel=preload and as=style attrs 74 if( link.rel === "preload" && link.getAttribute( "as" ) === "style" && !link.getAttribute( "data-loadcss" ) ){ 75 // prevent rerunning on link 76 link.setAttribute( "data-loadcss", true ); 77 // bind listeners to toggle media back 78 rp.bindMediaToggle( link ); 79 } 80 } 81 }; 82 83 // if unsupported, run the polyfill 84 if( !rp.support() ){ 85 // run once at least 86 rp.poly(); 87 88 // rerun poly on an interval until onload 89 var run = w.setInterval( rp.poly, 500 ); 90 if( w.addEventListener ){ 91 w.addEventListener( "load", function(){ 92 rp.poly(); 93 w.clearInterval( run ); 94 } ); 95 } else if( w.attachEvent ){ 96 w.attachEvent( "onload", function(){ 97 rp.poly(); 98 w.clearInterval( run ); 99 } ); 100 } 101 } 102 103 104 // commonjs 105 if( typeof exports !== "undefined" ){ 106 exports.loadCSS = loadCSS; 107 } 108 else { 109 w.loadCSS = loadCSS; 110 } 111}( typeof global !== "undefined" ? global : 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.