1 |
|
2 | var CSSOM = {};
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | CSSOM.CSSStyleDeclaration = function CSSStyleDeclaration(){
|
11 | this.length = 0;
|
12 | this.parentRule = null;
|
13 |
|
14 |
|
15 | this._importants = {};
|
16 | };
|
17 |
|
18 |
|
19 | CSSOM.CSSStyleDeclaration.prototype = {
|
20 |
|
21 | constructor: CSSOM.CSSStyleDeclaration,
|
22 |
|
23 | /**
|
24 | *
|
25 | * @param {string} name
|
26 | * @see http:
|
27 | * @return {string} the value of the property if it has been explicitly set for this declaration block.
|
28 | * Returns the empty string if the property has not been set.
|
29 | */
|
30 | getPropertyValue: function(name) {
|
31 | return this[name] || "";
|
32 | },
|
33 |
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | setProperty: function(name, value, priority) {
|
42 | if (this[name]) {
|
43 |
|
44 | var index = Array.prototype.indexOf.call(this, name);
|
45 | if (index < 0) {
|
46 | this[this.length] = name;
|
47 | this.length++;
|
48 | }
|
49 | } else {
|
50 |
|
51 | this[this.length] = name;
|
52 | this.length++;
|
53 | }
|
54 | this[name] = value + "";
|
55 | this._importants[name] = priority;
|
56 | },
|
57 |
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | removeProperty: function(name) {
|
66 | if (!(name in this)) {
|
67 | return "";
|
68 | }
|
69 | var index = Array.prototype.indexOf.call(this, name);
|
70 | if (index < 0) {
|
71 | return "";
|
72 | }
|
73 | var prevValue = this[name];
|
74 | this[name] = "";
|
75 |
|
76 |
|
77 | Array.prototype.splice.call(this, index, 1);
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | return prevValue;
|
83 | },
|
84 |
|
85 | getPropertyCSSValue: function() {
|
86 |
|
87 | },
|
88 |
|
89 | |
90 |
|
91 |
|
92 |
|
93 | getPropertyPriority: function(name) {
|
94 | return this._importants[name] || "";
|
95 | },
|
96 |
|
97 |
|
98 | |
99 |
|
100 |
|
101 |
|
102 |
|
103 | getPropertyShorthand: function() {
|
104 |
|
105 | },
|
106 |
|
107 | isPropertyImplicit: function() {
|
108 |
|
109 | },
|
110 |
|
111 |
|
112 | get cssText(){
|
113 | var properties = [];
|
114 | for (var i=0, length=this.length; i < length; ++i) {
|
115 | var name = this[i];
|
116 | var value = this.getPropertyValue(name);
|
117 | var priority = this.getPropertyPriority(name);
|
118 | if (priority) {
|
119 | priority = " !" + priority;
|
120 | }
|
121 | properties[i] = name + ": " + value + priority + ";";
|
122 | }
|
123 | return properties.join(" ");
|
124 | },
|
125 |
|
126 | set cssText(text){
|
127 | var i, name;
|
128 | for (i = this.length; i--;) {
|
129 | name = this[i];
|
130 | this[name] = "";
|
131 | }
|
132 | Array.prototype.splice.call(this, 0, this.length);
|
133 | this._importants = {};
|
134 |
|
135 | var dummyRule = CSSOM.parse('#bogus{' + text + '}').cssRules[0].style;
|
136 | var length = dummyRule.length;
|
137 | for (i = 0; i < length; ++i) {
|
138 | name = dummyRule[i];
|
139 | this.setProperty(dummyRule[i], dummyRule.getPropertyValue(name), dummyRule.getPropertyPriority(name));
|
140 | }
|
141 | }
|
142 | };
|
143 |
|
144 |
|
145 |
|
146 | exports.CSSStyleDeclaration = CSSOM.CSSStyleDeclaration;
|
147 | CSSOM.parse = require('./parse').parse;
|
148 |
|