fg-loadcss
Advanced tools
Comparing version 2.0.0-2 to 2.0.0-3
{ | ||
"name": "fg-loadcss", | ||
"version": "2.0.0-2", | ||
"version": "2.0.0-3", | ||
"description": "A function for loading CSS asynchronously", | ||
@@ -5,0 +5,0 @@ "main": "src/loadCSS.js", |
@@ -24,2 +24,18 @@ /*! loadCSS. [c]2017 Filament Group, Inc. MIT License */ | ||
// if preload isn't supported, get an asynchronous load by using a non-matching media attribute | ||
// then change that media back to its intended value on load | ||
rp.bindMediaToggle = function( link, media ){ | ||
function enableStylesheet(){ | ||
link.media = media; | ||
} | ||
if( link.addEventListener ){ | ||
link.addEventListener( "load", enableStylesheet ); | ||
} else if( link.attachEvent ){ | ||
link.attachEvent( "onload", enableStylesheet ); | ||
} | ||
// also enable media after 3 seconds, | ||
// which will catch very old browsers (android 2.x, old firefox) that don't support onload on link | ||
setTimeout( enableStylesheet, 3000 ); | ||
}; | ||
// loop through link elements in DOM | ||
@@ -37,18 +53,8 @@ rp.poly = function(){ | ||
var finalMedia = link.media || "all"; | ||
// if preload isn't supported, get an asynchronous load by using a non-matching media attribute | ||
// then change that media back to its intended value on load | ||
var enableStylesheet = function(){ | ||
link.media = finalMedia; | ||
} | ||
if( link.addEventListener ){ | ||
link.addEventListener( "load", enableStylesheet ); | ||
} else if( link.attachEvent ){ | ||
link.attachEvent( "onload", enableStylesheet ); | ||
} | ||
// bind listeners to toggle media back | ||
rp.bindMediaToggle( link, finalMedia ); | ||
// if preload is not supported, kick off an asynchronous request by using a non-matching media query and rel=stylesheet | ||
link.media = "x"; | ||
link.rel = "stylesheet"; | ||
// set rel=preload to stylesheet after 3 seconds, | ||
// which will catch very old browsers (android 2.x, old firefox) that don't support onload on link | ||
setTimeout( enableStylesheet, 3000 ); | ||
// prevent rerunning on link | ||
@@ -55,0 +61,0 @@ link.setAttribute( "data-loadcss", true ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
95941
2395
0