Skip to content

Commit c56dacf

Browse files
committed
[webpack-contrib#39] Don't use styleSheet to store state of css text
IE9 will actually drop certain things (like media queries) from the cssText property when it is read back out. To fix, store the raw css text in a separately managed array, and use that to form the entire string that should be set on the style element's cssText property. Fixes webpack-contrib#39.
1 parent 9f565cb commit c56dacf

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

addStyles.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,20 @@ function addStyle(obj, options) {
153153
};
154154
}
155155

156-
function replaceText(source, id, replacement) {
157-
var boundaries = ["/** >>" + id + " **/", "/** " + id + "<< **/"];
158-
var start = source.lastIndexOf(boundaries[0]);
159-
var wrappedReplacement = replacement
160-
? (boundaries[0] + replacement + boundaries[1])
161-
: "";
162-
if (source.lastIndexOf(boundaries[0]) >= 0) {
163-
var end = source.lastIndexOf(boundaries[1]) + boundaries[1].length;
164-
return source.slice(0, start) + wrappedReplacement + source.slice(end);
165-
} else {
166-
return source + wrappedReplacement;
167-
}
168-
}
156+
var replaceText = (function () {
157+
var textStore = [];
158+
159+
return function (index, replacement) {
160+
textStore[index] = replacement;
161+
return textStore.filter(Boolean).join('\n');
162+
};
163+
})();
169164

170165
function applyToSingletonTag(styleElement, index, remove, obj) {
171166
var css = remove ? "" : obj.css;
172167

173-
if(styleElement.styleSheet) {
174-
styleElement.styleSheet.cssText = replaceText(styleElement.styleSheet.cssText, index, css);
168+
if (styleElement.styleSheet) {
169+
styleElement.styleSheet.cssText = replaceText(index, css);
175170
} else {
176171
var cssNode = document.createTextNode(css);
177172
var childNodes = styleElement.childNodes;

0 commit comments

Comments
 (0)