Ticket #2529108 (accepted enhancement)

Reporter


Matt Parker
Opened: 07/26/10
Last modified: 03/11/12
Status: accepted
Type: enhancement

Owner


Luke Smith
Target Release:
Priority: P4 (low)
Summary: Stylesheet enableRule and disableRule - new methods
Description:

Duplicate of http://yuilibrary.com/projects/yui2/ticket/2529061 (but that's for YUI2).

The following snippet are additional public methods for Stylesheet. disableRule(match) allows you to temporarily turn off some of the rules in the Stylesheet; match is a string or RegExp to compare to
the selectors in the Stylesheet. enableRule(match) turns them back on again.

Although this is in YUI2.8, it might be good to have in 3 too - I'll file a separate ticket.

This doesn't fix the !important bug issues with Opera (http://yuilibrary.com/forum/viewtopic.php?f=89&t=4304&start=0&hilit=stylesheet)

There's also an extra var _disabledRules in the constructor.

[code]
/**

  • 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]];

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,
selectorText: enabled[i].selectorText};
}

j++;
}

for (i=0; i<toDisable.length; i++) {

this.unset(toDisable[i]);
delete enabled[toDisable[i]];

}

return this;

}
[/code]

Type: enhancement Observed in Version: 3.1.1
Component: StyleSheet Severity: S4 (low)
Assigned To: Luke Smith Target Release:
Location: Library Code Priority: P4 (low)
Tags: Relates To: #2529061
Browsers: Firefox 3.x - PC,IE - All
URL:
Test Information:

Change History

Luke Smith

YUI Contributor

Posted: 08/9/10
  • location changed to Library Code
  • milestone changed to 3.NEXT
  • priority changed to P4 (low)
  • status changed from new to accepted

StyleSheet is due for an architectural overhaul, so I'll put this in there when I do that refactoring.

Jenny Donnelly

YUI Developer

Posted: 11/30/11

Resolving as "expired" due to lack of activity. Please feel free to reopen if this issue is still important to you.

Jenny Donnelly

YUI Developer

Posted: 12/5/11
  • resolution changed to expired
  • status changed from accepted to closed

Luke Smith

YUI Contributor

Posted: 03/11/12
  • milestone changed from 3.NEXT
  • resolution changed from expired
  • status changed from closed to reopened

This is still a valid enhancement. Though there are limited resources to do this, there's no need for it to be closed.

The !important issue is being tracked in ticket #2528707

Luke Smith

YUI Contributor

Posted: 03/11/12
  • status changed from reopened to accepted