react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / cssom / lib / CSSStyleDeclaration.js
81143 views//.CommonJS1var CSSOM = {};2///CommonJS345/**6* @constructor7* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration8*/9CSSOM.CSSStyleDeclaration = function CSSStyleDeclaration(){10this.length = 0;11this.parentRule = null;1213// NON-STANDARD14this._importants = {};15};161718CSSOM.CSSStyleDeclaration.prototype = {1920constructor: CSSOM.CSSStyleDeclaration,2122/**23*24* @param {string} name25* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-getPropertyValue26* @return {string} the value of the property if it has been explicitly set for this declaration block.27* Returns the empty string if the property has not been set.28*/29getPropertyValue: function(name) {30return this[name] || "";31},3233/**34*35* @param {string} name36* @param {string} value37* @param {string} [priority=null] "important" or null38* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-setProperty39*/40setProperty: function(name, value, priority) {41if (this[name]) {42// Property already exist. Overwrite it.43var index = Array.prototype.indexOf.call(this, name);44if (index < 0) {45this[this.length] = name;46this.length++;47}48} else {49// New property.50this[this.length] = name;51this.length++;52}53this[name] = value;54this._importants[name] = priority;55},5657/**58*59* @param {string} name60* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration-removeProperty61* @return {string} the value of the property if it has been explicitly set for this declaration block.62* Returns the empty string if the property has not been set or the property name does not correspond to a known CSS property.63*/64removeProperty: function(name) {65if (!(name in this)) {66return "";67}68var index = Array.prototype.indexOf.call(this, name);69if (index < 0) {70return "";71}72var prevValue = this[name];73this[name] = "";7475// That's what WebKit and Opera do76Array.prototype.splice.call(this, index, 1);7778// That's what Firefox does79//this[index] = ""8081return prevValue;82},8384getPropertyCSSValue: function() {85//FIXME86},8788/**89*90* @param {String} name91*/92getPropertyPriority: function(name) {93return this._importants[name] || "";94},959697/**98* element.style.overflow = "auto"99* element.style.getPropertyShorthand("overflow-x")100* -> "overflow"101*/102getPropertyShorthand: function() {103//FIXME104},105106isPropertyImplicit: function() {107//FIXME108},109110// Doesn't work in IE < 9111get cssText(){112var properties = [];113for (var i=0, length=this.length; i < length; ++i) {114var name = this[i];115var value = this.getPropertyValue(name);116var priority = this.getPropertyPriority(name);117if (priority) {118priority = " !" + priority;119}120properties[i] = name + ": " + value + priority + ";";121}122return properties.join(" ");123},124125set cssText(cssText){126var i, name;127for (i = this.length; i--;) {128name = this[i];129this[name] = "";130}131Array.prototype.splice.call(this, 0, this.length);132this._importants = {};133134var dummyRule = CSSOM.parse('#bogus{' + cssText + '}').cssRules[0].style;135var length = dummyRule.length;136for (i = 0; i < length; ++i) {137name = dummyRule[i];138this.setProperty(dummyRule[i], dummyRule.getPropertyValue(name), dummyRule.getPropertyPriority(name));139}140}141};142143144//.CommonJS145exports.CSSStyleDeclaration = CSSOM.CSSStyleDeclaration;146CSSOM.parse = require('./parse').parse; // Cannot be included sooner due to the mutual dependency between parse.js and CSSStyleDeclaration.js147///CommonJS148149150