Skip to content

Commit

Permalink
Fix #49 CSS @import rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Dec 16, 2017
1 parent a179aba commit 579d039
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 14 deletions.
38 changes: 24 additions & 14 deletions cq-prolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,22 +537,29 @@ function parseRules() {
queries = {};
var rules;
for (var i = 0; i < styleSheets.length; i++) {
if (styleSheets[i].disabled) {
continue;
}
try {
rules = styleSheets[i].cssRules;
if (!rules || !rules.length) {
continue;
}
}
catch(e) {
continue;
}
for (var j = 0; j < rules.length; j++) {
parseRule(rules[j]);
parseStyleSheet(styleSheets[i]);
}
}

/**
* @param {CSSStyleSheet} styleSheet
*/
function parseStyleSheet(styleSheet) {
if (styleSheet.disabled) {
return;
}
try {
var rules = styleSheet.cssRules;
if (!rules || !rules.length) {
return;
}
}
catch(e) {
return;
}
for (var i = 0; i < rules.length; i++) {
parseRule(rules[i]);
}
}

/**
Expand All @@ -565,6 +572,9 @@ function parseRule(rule) {
}
return;
}
if (rule.styleSheet) {
parseStyleSheet(rule.styleSheet);
}
if (rule.type !== 1) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions test-files/visibility-cq.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test.\:container\(visibility\=visible\) {
font-family: visible;
}
49 changes: 49 additions & 0 deletions tests-functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,55 @@ QUnit.test('Opacity Query', function(assert) {

});

QUnit.test('CSS Import rule', function(assert) {

var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = '@import url("../test-files/visibility-cq.css");'
+ '@font-face { font-family: visible; src: local("Times New Roman"), local("Droid Serif") }';
fixture.appendChild(style);

var element = document.createElement('div');
element.innerHTML = '<div class="test">';
fixture.appendChild(element);
var test = element.firstChild;

var done = assert.async();

var start = Date.now();
run();

function run() {
try {
if (!style.sheet.cssRules[0].styleSheet.cssRules[0]) {
throw new Error();
}
}
catch(e) {
if (Date.now() - start > 1000) {
assert.ok(false, 'Timeout');
done();
}
else {
setTimeout(run);
}
return;
}
window.cqApi.reprocess(function () {

var font = function(node) {
return window.getComputedStyle(node).fontFamily;
};

assert.equal(font(test), 'visible', 'Style visible');

done();

});
}

});

QUnit.test('PostCSS skip step 1', function(assert) {

var style = document.createElement('style');
Expand Down

0 comments on commit 579d039

Please sign in to comment.