You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

  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. * Produces a deep copy of stylesheet the instance variables of stylesheet are copied recursively.
  14. * @param {CSSStyleSheet|CSSOM.CSSStyleSheet} stylesheet
  15. * @nosideeffects
  16. * @return {CSSOM.CSSStyleSheet}
  17. */
  18. CSSOM.clone = function clone(stylesheet) {
  19. var cloned = new CSSOM.CSSStyleSheet();
  20. var rules = stylesheet.cssRules;
  21. if (!rules) {
  22. return cloned;
  23. }
  24. for (var i = 0, rulesLength = rules.length; i < rulesLength; i++) {
  25. var rule = rules[i];
  26. var ruleClone = cloned.cssRules[i] = new rule.constructor();
  27. var style = rule.style;
  28. if (style) {
  29. var styleClone = ruleClone.style = new CSSOM.CSSStyleDeclaration();
  30. for (var j = 0, styleLength = style.length; j < styleLength; j++) {
  31. var name = styleClone[j] = style[j];
  32. styleClone[name] = style[name];
  33. styleClone._importants[name] = style.getPropertyPriority(name);
  34. }
  35. styleClone.length = style.length;
  36. }
  37. if (rule.hasOwnProperty('keyText')) {
  38. ruleClone.keyText = rule.keyText;
  39. }
  40. if (rule.hasOwnProperty('selectorText')) {
  41. ruleClone.selectorText = rule.selectorText;
  42. }
  43. if (rule.hasOwnProperty('mediaText')) {
  44. ruleClone.mediaText = rule.mediaText;
  45. }
  46. if (rule.hasOwnProperty('conditionText')) {
  47. ruleClone.conditionText = rule.conditionText;
  48. }
  49. if (rule.hasOwnProperty('cssRules')) {
  50. ruleClone.cssRules = clone(rule).cssRules;
  51. }
  52. }
  53. return cloned;
  54. };
  55. //.CommonJS
  56. exports.clone = CSSOM.clone;
  57. ///CommonJS