show: make highlight legible
[debiancodesearch.git] / static / cssrelpreload.js
blob92141a147320dffc7e5c2751c2c9f12683f40475
1 /*! CSS rel=preload polyfill. Depends on loadCSS function. [c]2016 @scottjehl, Filament Group, Inc. Licensed MIT  */
2 (function( w ){
3   // rel=preload support test
4   if( !w.loadCSS ){
5     return;
6   }
7   var rp = loadCSS.relpreload = {};
8   rp.support = function(){
9     try {
10       return w.document.createElement( "link" ).relList.supports( "preload" );
11     } catch (e) {
12       return false;
13     }
14   };
16   // loop preload links and fetch using loadCSS
17   rp.poly = function(){
18     var links = w.document.getElementsByTagName( "link" );
19     for( var i = 0; i < links.length; i++ ){
20       var link = links[ i ];
21       if( link.rel === "preload" && link.getAttribute( "as" ) === "style" ){
22         w.loadCSS( link.href, link );
23         link.rel = null;
24       }
25     }
26   };
28   // if link[rel=preload] is not supported, we must fetch the CSS manually using loadCSS
29   if( !rp.support() ){
30     rp.poly();
31     var run = w.setInterval( rp.poly, 300 );
32     if( w.addEventListener ){
33       w.addEventListener( "load", function(){
34         w.clearInterval( run );
35       } );
36     }
37     if( w.attachEvent ){
38       w.attachEvent( "onload", function(){
39         w.clearInterval( run );
40       } )
41     }
42   }
43 }( this ));