Skip to content

Commit

Permalink
Merge pull request #2386 from tristanlins/hotfix/fx.css.search
Browse files Browse the repository at this point in the history
Regard @media rules in css stylesheets.
  • Loading branch information
arian committed Aug 8, 2012
2 parents 906f2a1 + 3a5e03d commit 1866012
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Source/Fx/Fx.CSS.js
Expand Up @@ -100,11 +100,13 @@ Fx.CSS = new Class({
search: function(selector){
if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector];
var to = {}, selectorTest = new RegExp('^' + selector.escapeRegExp() + '$');
Array.each(document.styleSheets, function(sheet, j){
var href = sheet.href;
if (href && href.contains('://') && !href.contains(document.domain)) return;
var rules = sheet.rules || sheet.cssRules;

var searchStyles = function(rules){
Array.each(rules, function(rule, i){
if (rule.media){
searchStyles(rule.rules || rule.cssRules);
return;
}
if (!rule.style) return;
var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){
return m.toLowerCase();
Expand All @@ -116,6 +118,13 @@ Fx.CSS = new Class({
to[style] = ((/^rgb/).test(value)) ? value.rgbToHex() : value;
});
});
};

Array.each(document.styleSheets, function(sheet, j){
var href = sheet.href;
if (href && href.contains('://') && !href.contains(document.domain)) return;
var rules = sheet.rules || sheet.cssRules;
searchStyles(rules);
});
return Fx.CSS.Cache[selector] = to;
}
Expand Down

0 comments on commit 1866012

Please sign in to comment.