Skip to content

Commit

Permalink
ie 31 limit support
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 11, 2014
1 parent 5b66815 commit 44d5dfe
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions css.js
@@ -1,6 +1,6 @@
/*
* Require-CSS RequireJS css! loader plugin
* 0.0.8
* 0.1.1
* Guy Bedford 2013
* MIT
*/
Expand Down Expand Up @@ -60,20 +60,49 @@ define(function() {
cssAPI.pluginBuilder = './css-builder';

// <style> @import load method
var curStyle;
var curStyle, curSheet;
var createStyle = function () {
curStyle = document.createElement('style');
head.appendChild(curStyle);
curSheet = curStyle.styleSheet || curStyle.sheet;
}
var ieCnt = 0;
var ieLoads = [];
var ieCurCallback;

var createIeLoad = function(url) {
ieCnt++;
if (ieCnt == 32) {
createStyle();
ieCnt = 0;
}
curSheet.addImport(url);
curStyle.onload = processIeLoad;
}
var processIeLoad = function() {
ieCurCallback();

var nextLoad = ieLoads.shift();

if (!nextLoad)
return;

ieCurCallback = nextLoad[1];
createIeLoad(nextLoad[0]);
}
var importLoad = function(url, callback) {
createStyle();

var curSheet = curStyle.styleSheet || curStyle.sheet;
if (!curSheet || !curSheet.addImport)
createStyle();

if (curSheet && curSheet.addImport) {
// old IE
curSheet.addImport(url);
curStyle.onload = callback;
if (ieCurCallback) {
ieLoads.push([url, callback]);
}
else {
createIeLoad(url);
ieCurCallback = callback;
}
}
else {
// old Firefox
Expand Down Expand Up @@ -128,4 +157,4 @@ define(function() {
}

return cssAPI;
});
});

0 comments on commit 44d5dfe

Please sign in to comment.