fg-loadcss
Advanced tools
Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "loadcss", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "loadCSS.js" |
@@ -22,5 +22,7 @@ /*! | ||
ss.media = "only x"; | ||
// DEPRECATED | ||
if( callback ) { | ||
ss.onload = callback; | ||
} | ||
// inject link | ||
@@ -30,6 +32,6 @@ ref.parentNode.insertBefore( ss, ref ); | ||
// It is designed to poll until document.styleSheets includes the new sheet. | ||
function toggleMedia(){ | ||
ss.onloadcssdefined = function( cb ){ | ||
var defined; | ||
for( var i = 0; i < sheets.length; i++ ){ | ||
if( sheets[ i ].href && sheets[ i ].href.indexOf( ss.href ) > -1 ){ | ||
if( sheets[ i ].href && sheets[ i ].href.indexOf( href ) > -1 ){ | ||
defined = true; | ||
@@ -39,10 +41,14 @@ } | ||
if( defined ){ | ||
ss.media = media || "all"; | ||
cb(); | ||
} | ||
else { | ||
setTimeout( toggleMedia ); | ||
setTimeout(function() { | ||
ss.onloadcssdefined( cb ); | ||
}); | ||
} | ||
} | ||
toggleMedia(); | ||
}; | ||
ss.onloadcssdefined(function() { | ||
ss.media = media || "all"; | ||
}); | ||
return ss; | ||
} | ||
} |
{ | ||
"name": "fg-loadcss", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "A function for loading CSS asynchronously", | ||
@@ -5,0 +5,0 @@ "main": "loadCSS.js", |
@@ -32,3 +32,15 @@ # loadCSS | ||
#### Using with `onload` | ||
Include [`onloadCSS` function](https://github.com/filamentgroup/loadCSS/blob/master/onloadCSS.js) on your page. | ||
``` javascript | ||
function onloadCSS( ss, callback ){ ... } | ||
var stylesheet = loadCSS( "path/to/mystylesheet.css" ); | ||
onloadCSS( stylesheet, function() { | ||
console.log( "Stylesheet has asynchronously loaded." ); | ||
}); | ||
``` | ||
#### Contributions and bug fixes | ||
@@ -35,0 +47,0 @@ |
Sorry, the diff of this file is not supported yet
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
12855
9
81
84