Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created June 24, 2009 22:41
Show Gist options
  • Save swannodette/135566 to your computer and use it in GitHub Desktop.
Save swannodette/135566 to your computer and use it in GitHub Desktop.
Fx.CSS.implement({
search: function(selector){
if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector];
var to = {};
function extract(sheet, j){
var href = sheet.href;
if (href && href.contains('://') && !href.contains(document.domain)) return;
var rules = sheet.rules || sheet.cssRules;
Array.each(sheet.imports, extract);
Array.each(rules, function(rule, i){
if (rule.styleSheet) extract(rule.styleSheet);
if (!rule.style) return;
var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){
return m.toLowerCase();
}) : null;
if (!selectorText || !selectorText.test('^' + selector + '$')) return;
Element.Styles.each(function(value, style){
if (!rule.style[style] || Element.ShortStyles[style]) return;
value = String(rule.style[style]);
to[style] = (value.test(/^rgb/)) ? value.rgbToHex() : value;
});
});
}
Array.each(document.styleSheets, extract);
return Fx.CSS.Cache[selector] = to;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment