Parley
view release on metacpan or search on metacpan
root/static/yui/stylesheet/stylesheet.js view on Meta::CPAN
* <p>Set style properties for a provided selector string.
* If the selector includes commas, it will be split into individual
* selectors and applied accordingly. If the selector string does not
* have a corresponding rule in the sheet, it will be added.</p>
*
* <p>The object properties in the second parameter must be the JavaScript
* names of style properties. E.g. fontSize rather than font-size.</p>
*
* <p>The float style property will be set by any of "float",
* "styleFloat", or "cssFloat".</p>
*
* @method set
* @param sel {String} the selector string to apply the changes to
* @param css {Object} Object literal of style properties and new values
* @return {StyleSheet} the StyleSheet instance
* @chainable
*/
set : function (sel,css) {
var rule = cssRules[sel],
multi = sel.split(/\s*,\s*/),i,
idx;
// IE's addRule doesn't support multiple comma delimited selectors
if (multi.length > 1) {
for (i = multi.length - 1; i >= 0; --i) {
this.set(multi[i], css);
}
return this;
}
// Some selector values can cause IE to hang
if (!StyleSheet.isValidSelector(sel)) {
return this;
}
// Opera throws an error if there's a syntax error in assigned
// cssText. Avoid this using a worker style collection, then
// assigning the resulting cssText.
if (rule) {
rule.style.cssText = StyleSheet.toCssText(css,rule.style.cssText);
} else {
idx = sheet[_rules].length;
css = StyleSheet.toCssText(css);
// IE throws an error when attempting to addRule(sel,'',n)
// which would crop up if no, or only invalid values are used
if (css) {
_insertRule(sel, css, idx);
// Safari replaces the rules collection, but maintains the
// rule instances in the new collection when rules are
// added/removed
cssRules[sel] = sheet[_rules][idx];
}
}
return this;
},
/**
* <p>Unset style properties for a provided selector string, removing
* their effect from the style cascade.</p>
*
* <p>If the selector includes commas, it will be split into individual
* selectors and applied accordingly. If there are no properties
* remaining in the rule after unsetting, the rule is removed.</p>
*
* <p>The style property or properties in the second parameter must be the
* <p>JavaScript style property names. E.g. fontSize rather than font-size.</p>
*
* <p>The float style property will be unset by any of "float",
* "styleFloat", or "cssFloat".</p>
*
* @method unset
* @param sel {String} the selector string to apply the changes to
* @param css {String|Array} style property name or Array of names
* @return {StyleSheet} the StyleSheet instance
* @chainable
*/
unset : function (sel,css) {
var rule = cssRules[sel],
multi = sel.split(/\s*,\s*/),
remove = !css,
rules, i;
// IE's addRule doesn't support multiple comma delimited selectors
// so rules are mapped internally by atomic selectors
if (multi.length > 1) {
for (i = multi.length - 1; i >= 0; --i) {
this.unset(multi[i], css);
}
return this;
}
if (rule) {
if (!remove) {
if (!lang.isArray(css)) {
css = [css];
}
workerStyle.cssText = rule.style.cssText;
for (i = css.length - 1; i >= 0; --i) {
_unsetProperty(workerStyle,css[i]);
}
if (workerStyle.cssText) {
rule.style.cssText = workerStyle.cssText;
} else {
remove = true;
}
}
if (remove) { // remove the rule altogether
rules = sheet[_rules];
for (i = rules.length - 1; i >= 0; --i) {
if (rules[i] === rule) {
delete cssRules[sel];
_deleteRule(i);
break;
}
}
}
( run in 1.001 second using v1.01-cache-2.11-cpan-5837b0d9d2c )