react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / cssom / lib / CSSStyleSheet.js
81143 views//.CommonJS1var CSSOM = {2StyleSheet: require("./StyleSheet").StyleSheet,3CSSStyleRule: require("./CSSStyleRule").CSSStyleRule4};5///CommonJS678/**9* @constructor10* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleSheet11*/12CSSOM.CSSStyleSheet = function CSSStyleSheet() {13CSSOM.StyleSheet.call(this);14this.cssRules = [];15};161718CSSOM.CSSStyleSheet.prototype = new CSSOM.StyleSheet;19CSSOM.CSSStyleSheet.prototype.constructor = CSSOM.CSSStyleSheet;202122/**23* Used to insert a new rule into the style sheet. The new rule now becomes part of the cascade.24*25* sheet = new Sheet("body {margin: 0}")26* sheet.toString()27* -> "body{margin:0;}"28* sheet.insertRule("img {border: none}", 0)29* -> 030* sheet.toString()31* -> "img{border:none;}body{margin:0;}"32*33* @param {string} rule34* @param {number} index35* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleSheet-insertRule36* @return {number} The index within the style sheet's rule collection of the newly inserted rule.37*/38CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {39if (index < 0 || index > this.cssRules.length) {40throw new RangeError("INDEX_SIZE_ERR");41}42var cssRule = CSSOM.parse(rule).cssRules[0];43cssRule.parentStyleSheet = this;44this.cssRules.splice(index, 0, cssRule);45return index;46};474849/**50* Used to delete a rule from the style sheet.51*52* sheet = new Sheet("img{border:none} body{margin:0}")53* sheet.toString()54* -> "img{border:none;}body{margin:0;}"55* sheet.deleteRule(0)56* sheet.toString()57* -> "body{margin:0;}"58*59* @param {number} index within the style sheet's rule list of the rule to remove.60* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleSheet-deleteRule61*/62CSSOM.CSSStyleSheet.prototype.deleteRule = function(index) {63if (index < 0 || index >= this.cssRules.length) {64throw new RangeError("INDEX_SIZE_ERR");65}66this.cssRules.splice(index, 1);67};686970/**71* NON-STANDARD72* @return {string} serialize stylesheet73*/74CSSOM.CSSStyleSheet.prototype.toString = function() {75var result = "";76var rules = this.cssRules;77for (var i=0; i<rules.length; i++) {78result += rules[i].cssText + "\n";79}80return result;81};828384//.CommonJS85exports.CSSStyleSheet = CSSOM.CSSStyleSheet;86CSSOM.parse = require('./parse').parse; // Cannot be included sooner due to the mutual dependency between parse.js and CSSStyleSheet.js87///CommonJS888990