Created
July 20, 2010 09:31
-
-
Save mattparker/482739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note that _disabledRules is also added to constructor. | |
// These are the public API methods. | |
/** | |
* Enable a particular rule (or several) that's previously been disabled. | |
* The selector parameter can be a RegExp; each rule matching the pattern | |
* will be enabled | |
* @param sel {String} String or RegExp to match to selectors to enable | |
* @method enableRule | |
* @return {StyleSheet} the StyleSheet instance | |
* @chainable | |
*/ | |
enableRule : function (sel) { | |
var i, | |
disabled = _disabledRules, | |
toEnable = [], | |
thisToEnable, | |
idx; | |
for (i in disabled) { | |
if (YAHOO.util.Lang.isString(i) && i.match(sel) !== null) { | |
toEnable.push(i); | |
} | |
} | |
for (i=0; i<toEnable.length; i++) { | |
idx = sheet[_rules].length; | |
thisToEnable = disabled[toEnable[i]]; | |
// Re-attach important declaration: Opera seems to lose it. | |
if (thisToEnable.important && !thisToEnable.css.match("!important")) { | |
thisToEnable.css += " !important"; | |
alert("is important " + thisToEnable.css) | |
} | |
this.set(thisToEnable.selectorText,thisToEnable.css); | |
cssRules[i] = disabled[toEnable[i]]; | |
delete disabled[toEnable[i]]; | |
} | |
return this; | |
}, | |
/** | |
* Disable a particular rule (or several) that's currently in the Sheet. | |
* The selector parameter can be a RegExp; each rule matching the pattern | |
* will be disabled | |
* @param sel {String} String or RegExp to match to selectors to disable | |
* @method disableRule | |
* @return {StyleSheet} the StyleSheet instance | |
* @chainable | |
*/ | |
disableRule : function (sel) { | |
var i, j = 0, | |
enabled = cssRules, | |
toDisable = [], | |
idx; | |
for (i in enabled) { | |
if (YAHOO.util.Lang.isString(i) && i.match(sel) !== null && enabled[i].style.cssText) { | |
toDisable.push(i); | |
_disabledRules[i] = { css: enabled[i].style.cssText, | |
important: enabled[i].style.cssText.match("!important"), | |
selectorText: enabled[i].selectorText}; | |
} | |
j++; | |
} | |
for (i=0; i<toDisable.length; i++) { | |
this.unset(toDisable[i]); | |
delete enabled[toDisable[i]]; | |
} | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment