fg-loadcss
Advanced tools
Comparing version 0.2.4 to 1.0.0-0
{ | ||
"name": "loadcss", | ||
"main": [ | ||
"loadCSS.js" | ||
"src/loadCSS.js" | ||
], | ||
@@ -6,0 +6,0 @@ "ignore": [ |
{ | ||
"name": "fg-loadcss", | ||
"version": "0.2.4", | ||
"version": "1.0.0-0", | ||
"description": "A function for loading CSS asynchronously", | ||
"main": "loadCSS.js", | ||
"main": "src/loadCSS.js", | ||
"repository": { | ||
@@ -19,3 +19,3 @@ "type": "git", | ||
"grunt-cli": "~0.1.13", | ||
"grunt-contrib-jshint": "~0.11.0", | ||
"grunt-contrib-jshint": "~0.12.0", | ||
"grunt-contrib-qunit": "~0.7.0" | ||
@@ -22,0 +22,0 @@ }, |
@@ -9,3 +9,3 @@ # loadCSS | ||
Place the [`loadCSS` function](https://github.com/filamentgroup/loadCSS/blob/master/loadCSS.js) inline in the `head` of your page (it can also be included in an external JavaScript file if preferable). | ||
Place the [`loadCSS` function](https://github.com/filamentgroup/loadCSS/blob/master/src/loadCSS.js) inline in the `head` of your page (it can also be included in an external JavaScript file if preferable). | ||
@@ -50,3 +50,3 @@ Then call it by passing it a stylesheet URL: | ||
Onload listener support with `link` elements is spotty, so if you need to add an onload callback, include [`onloadCSS` function](https://github.com/filamentgroup/loadCSS/blob/master/onloadCSS.js) on your page and use the `onloadCSS` function: | ||
Onload listener support with `link` elements is spotty, so if you need to add an onload callback, include [`onloadCSS` function](https://github.com/filamentgroup/loadCSS/blob/master/src/onloadCSS.js) on your page and use the `onloadCSS` function: | ||
@@ -152,3 +152,3 @@ ``` javascript | ||
</tr> | ||
</table> | ||
@@ -167,3 +167,1 @@ | ||
Both are very much appreciated - especially bug fixes. As for contributions, the goals of this project are to keep things very simple and utilitarian, so if we don't accept a feature addition, it's not necessarily because it's a bad idea. It just may not meet the goals of the project. Thanks! | ||
@@ -36,3 +36,3 @@ /*global window:true*/ | ||
var ss = loadCSS("files/test.css"); | ||
ss.onloadcssdefined(function(){ | ||
onloadCSS( ss, function(){ | ||
ok("stylesheet loaded successfully"); | ||
@@ -46,3 +46,3 @@ start(); | ||
var ss = loadCSS("../../test/qunit/files/test.css"); | ||
ss.onloadcssdefined(function(){ | ||
onloadCSS( ss, function(){ | ||
ok("stylesheet loaded successfully"); | ||
@@ -57,3 +57,3 @@ start(); | ||
ok(ss.media, initialMedia, "media type begins as" + initialMedia ); | ||
ss.onloadcssdefined(function(){ | ||
onloadCSS( ss, function(){ | ||
equal(ss.media, "all", "media type is all"); | ||
@@ -69,3 +69,3 @@ start(); | ||
ok(ss.media, initialMedia, "media type begins as " + initialMedia ); | ||
ss.onloadcssdefined(function(){ | ||
onloadCSS( ss, function(){ | ||
equal(ss.media, med, "media type is " + med); | ||
@@ -83,3 +83,47 @@ start(); | ||
asyncTest( 'onloadCSS callback fires after css is loaded', function(){ | ||
expect(1); | ||
var getStyles = window.getComputedStyle ? function (node) { return window.getComputedStyle(node, null); } : function (node) { return node.currentStyle; }; | ||
var elem = window.document.createElement("div"); | ||
elem.className = "bar"; | ||
document.body.appendChild( elem ); | ||
var ss = loadCSS("files/test.css?1"); | ||
onloadCSS( ss, function(){ | ||
equal(getStyles(elem).backgroundColor, 'rgb(0, 128, 0)', 'background is green' ); | ||
start(); | ||
} ); | ||
}); | ||
test( 'loadCSS preload polyfill methods ', function(){ | ||
expect(5); | ||
ok( window.loadCSS.relpreload, "loadCSS.relpreload should exist" ); | ||
ok( typeof window.loadCSS.relpreload === "object", "relpreload should be an object" ); | ||
ok( typeof window.loadCSS.relpreload.support === "function", "relpreload.support should be a function" ); | ||
ok( typeof window.loadCSS.relpreload.poly === "function", "relpreload.poly should be a function" ); | ||
ok( typeof window.loadCSS.relpreload.support() === "boolean", "relpreload.support should be a bool" ); | ||
}); | ||
asyncTest( 'rel=preload stylesheet loads via polyfill', function(){ | ||
expect(1); | ||
var preloadElem = document.getElementById("preloadtest"); | ||
var preloadHref = preloadElem.getAttribute("href"); | ||
function loaded(){ | ||
return document.querySelector( 'link[href="'+ preloadHref +'"][rel="stylesheet"]' ) || document.querySelector( 'link[href="'+ preloadElem.href +'"][rel="stylesheet"]' ); | ||
} | ||
window.setTimeout(function(){ | ||
if( window.loadCSS.relpreload.support() ){ | ||
ok( loaded(), "stylesheet is in dom and applied without a polyfill" ); | ||
} | ||
else { | ||
ok( loaded(), "stylesheet is in dom and applied with a polyfill" ); | ||
} | ||
start(); | ||
},3000); | ||
}); | ||
}(window)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
94108
25
2351
164