| 1 | //.CommonJS
|
|---|
| 2 | var CSSOM = {
|
|---|
| 3 | CSSStyleSheet: require("./CSSStyleSheet").CSSStyleSheet,
|
|---|
| 4 | CSSStyleRule: require("./CSSStyleRule").CSSStyleRule,
|
|---|
| 5 | CSSMediaRule: require("./CSSMediaRule").CSSMediaRule,
|
|---|
| 6 | CSSSupportsRule: require("./CSSSupportsRule").CSSSupportsRule,
|
|---|
| 7 | CSSStyleDeclaration: require("./CSSStyleDeclaration").CSSStyleDeclaration,
|
|---|
| 8 | CSSKeyframeRule: require('./CSSKeyframeRule').CSSKeyframeRule,
|
|---|
| 9 | CSSKeyframesRule: require('./CSSKeyframesRule').CSSKeyframesRule
|
|---|
| 10 | };
|
|---|
| 11 | ///CommonJS
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | /**
|
|---|
| 15 | * Produces a deep copy of stylesheet — the instance variables of stylesheet are copied recursively.
|
|---|
| 16 | * @param {CSSStyleSheet|CSSOM.CSSStyleSheet} stylesheet
|
|---|
| 17 | * @nosideeffects
|
|---|
| 18 | * @return {CSSOM.CSSStyleSheet}
|
|---|
| 19 | */
|
|---|
| 20 | CSSOM.clone = function clone(stylesheet) {
|
|---|
| 21 |
|
|---|
| 22 | var cloned = new CSSOM.CSSStyleSheet();
|
|---|
| 23 |
|
|---|
| 24 | var rules = stylesheet.cssRules;
|
|---|
| 25 | if (!rules) {
|
|---|
| 26 | return cloned;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | for (var i = 0, rulesLength = rules.length; i < rulesLength; i++) {
|
|---|
| 30 | var rule = rules[i];
|
|---|
| 31 | var ruleClone = cloned.cssRules[i] = new rule.constructor();
|
|---|
| 32 |
|
|---|
| 33 | var style = rule.style;
|
|---|
| 34 | if (style) {
|
|---|
| 35 | var styleClone = ruleClone.style = new CSSOM.CSSStyleDeclaration();
|
|---|
| 36 | for (var j = 0, styleLength = style.length; j < styleLength; j++) {
|
|---|
| 37 | var name = styleClone[j] = style[j];
|
|---|
| 38 | styleClone[name] = style[name];
|
|---|
| 39 | styleClone._importants[name] = style.getPropertyPriority(name);
|
|---|
| 40 | }
|
|---|
| 41 | styleClone.length = style.length;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | if (rule.hasOwnProperty('keyText')) {
|
|---|
| 45 | ruleClone.keyText = rule.keyText;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | if (rule.hasOwnProperty('selectorText')) {
|
|---|
| 49 | ruleClone.selectorText = rule.selectorText;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | if (rule.hasOwnProperty('mediaText')) {
|
|---|
| 53 | ruleClone.mediaText = rule.mediaText;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | if (rule.hasOwnProperty('conditionText')) {
|
|---|
| 57 | ruleClone.conditionText = rule.conditionText;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | if (rule.hasOwnProperty('cssRules')) {
|
|---|
| 61 | ruleClone.cssRules = clone(rule).cssRules;
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | return cloned;
|
|---|
| 66 |
|
|---|
| 67 | };
|
|---|
| 68 |
|
|---|
| 69 | //.CommonJS
|
|---|
| 70 | exports.clone = CSSOM.clone;
|
|---|
| 71 | ///CommonJS
|
|---|