Skip to content

Commit a2356c6

Browse files
committed
Merge pull request NV#55 from ksobue/gh-pages
IE9 & IE10 support
2 parents 09065a6 + b115bab commit a2356c6

File tree

8 files changed

+135
-122
lines changed

8 files changed

+135
-122
lines changed

lib/CSSDocumentRule.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ CSSOM.CSSDocumentRule.prototype.type = 10;
2323
//CSSOM.CSSDocumentRule.prototype.insertRule = CSSStyleSheet.prototype.insertRule;
2424
//CSSOM.CSSDocumentRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
2525

26-
CSSOM.CSSDocumentRule.prototype.__defineGetter__("cssText", function() {
26+
Object.defineProperty(CSSOM.CSSDocumentRule.prototype, "cssText", {
27+
get: function() {
2728
var cssTexts = [];
2829
for (var i=0, length=this.cssRules.length; i < length; i++) {
2930
cssTexts.push(this.cssRules[i].cssText);
3031
}
3132
return "@-moz-document " + this.matcher.matcherText + " {" + cssTexts.join("") + "}";
33+
}
3234
});
3335

3436

lib/CSSFontFaceRule.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ CSSOM.CSSFontFaceRule.prototype.type = 5;
2424
//CSSOM.CSSFontFaceRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
2525

2626
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSFontFaceRule.cpp
27-
CSSOM.CSSFontFaceRule.prototype.__defineGetter__("cssText", function() {
28-
return "@font-face {" + this.style.cssText + "}";
27+
Object.defineProperty(CSSOM.CSSFontFaceRule.prototype, "cssText", {
28+
get: function() {
29+
return "@font-face {" + this.style.cssText + "}";
30+
}
2931
});
3032

3133

lib/CSSImportRule.js

Lines changed: 93 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -22,107 +22,109 @@ CSSOM.CSSImportRule = function CSSImportRule() {
2222
CSSOM.CSSImportRule.prototype = new CSSOM.CSSRule;
2323
CSSOM.CSSImportRule.prototype.constructor = CSSOM.CSSImportRule;
2424
CSSOM.CSSImportRule.prototype.type = 3;
25-
CSSOM.CSSImportRule.prototype.__defineGetter__("cssText", function() {
26-
var mediaText = this.media.mediaText;
27-
return "@import url(" + this.href + ")" + (mediaText ? " " + mediaText : "") + ";";
28-
});
2925

30-
CSSOM.CSSImportRule.prototype.__defineSetter__("cssText", function(cssText) {
31-
var i = 0;
26+
Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
27+
get: function() {
28+
var mediaText = this.media.mediaText;
29+
return "@import url(" + this.href + ")" + (mediaText ? " " + mediaText : "") + ";";
30+
},
31+
set: function(cssText) {
32+
var i = 0;
3233

33-
/**
34-
* @import url(partial.css) screen, handheld;
35-
* || |
36-
* after-import media
37-
* |
38-
* url
39-
*/
40-
var state = '';
34+
/**
35+
* @import url(partial.css) screen, handheld;
36+
* || |
37+
* after-import media
38+
* |
39+
* url
40+
*/
41+
var state = '';
4142

42-
var buffer = '';
43-
var index;
44-
var mediaText = '';
45-
for (var character; character = cssText.charAt(i); i++) {
43+
var buffer = '';
44+
var index;
45+
var mediaText = '';
46+
for (var character; character = cssText.charAt(i); i++) {
4647

47-
switch (character) {
48-
case ' ':
49-
case '\t':
50-
case '\r':
51-
case '\n':
52-
case '\f':
53-
if (state === 'after-import') {
54-
state = 'url';
55-
} else {
56-
buffer += character;
57-
}
58-
break;
48+
switch (character) {
49+
case ' ':
50+
case '\t':
51+
case '\r':
52+
case '\n':
53+
case '\f':
54+
if (state === 'after-import') {
55+
state = 'url';
56+
} else {
57+
buffer += character;
58+
}
59+
break;
5960

60-
case '@':
61-
if (!state && cssText.indexOf('@import', i) === i) {
62-
state = 'after-import';
63-
i += 'import'.length;
64-
buffer = '';
65-
}
66-
break;
61+
case '@':
62+
if (!state && cssText.indexOf('@import', i) === i) {
63+
state = 'after-import';
64+
i += 'import'.length;
65+
buffer = '';
66+
}
67+
break;
6768

68-
case 'u':
69-
if (state === 'url' && cssText.indexOf('url(', i) === i) {
70-
index = cssText.indexOf(')', i + 1);
71-
if (index === -1) {
72-
throw i + ': ")" not found';
73-
}
74-
i += 'url('.length;
75-
var url = cssText.slice(i, index);
76-
if (url[0] === url[url.length - 1]) {
77-
if (url[0] === '"' || url[0] === "'") {
78-
url = url.slice(1, -1);
79-
}
80-
}
81-
this.href = url;
82-
i = index;
83-
state = 'media';
84-
}
85-
break;
69+
case 'u':
70+
if (state === 'url' && cssText.indexOf('url(', i) === i) {
71+
index = cssText.indexOf(')', i + 1);
72+
if (index === -1) {
73+
throw i + ': ")" not found';
74+
}
75+
i += 'url('.length;
76+
var url = cssText.slice(i, index);
77+
if (url[0] === url[url.length - 1]) {
78+
if (url[0] === '"' || url[0] === "'") {
79+
url = url.slice(1, -1);
80+
}
81+
}
82+
this.href = url;
83+
i = index;
84+
state = 'media';
85+
}
86+
break;
8687

87-
case '"':
88-
if (state === 'url') {
89-
index = cssText.indexOf('"', i + 1);
90-
if (!index) {
91-
throw i + ": '\"' not found";
92-
}
93-
this.href = cssText.slice(i + 1, index);
94-
i = index;
95-
state = 'media';
96-
}
97-
break;
88+
case '"':
89+
if (state === 'url') {
90+
index = cssText.indexOf('"', i + 1);
91+
if (!index) {
92+
throw i + ": '\"' not found";
93+
}
94+
this.href = cssText.slice(i + 1, index);
95+
i = index;
96+
state = 'media';
97+
}
98+
break;
9899

99-
case "'":
100-
if (state === 'url') {
101-
index = cssText.indexOf("'", i + 1);
102-
if (!index) {
103-
throw i + ': "\'" not found';
104-
}
105-
this.href = cssText.slice(i + 1, index);
106-
i = index;
107-
state = 'media';
108-
}
109-
break;
100+
case "'":
101+
if (state === 'url') {
102+
index = cssText.indexOf("'", i + 1);
103+
if (!index) {
104+
throw i + ': "\'" not found';
105+
}
106+
this.href = cssText.slice(i + 1, index);
107+
i = index;
108+
state = 'media';
109+
}
110+
break;
110111

111-
case ';':
112-
if (state === 'media') {
113-
if (buffer) {
114-
this.media.mediaText = buffer.trim();
115-
}
116-
}
117-
break;
112+
case ';':
113+
if (state === 'media') {
114+
if (buffer) {
115+
this.media.mediaText = buffer.trim();
116+
}
117+
}
118+
break;
118119

119-
default:
120-
if (state === 'media') {
121-
buffer += character;
122-
}
123-
break;
124-
}
125-
}
120+
default:
121+
if (state === 'media') {
122+
buffer += character;
123+
}
124+
break;
125+
}
126+
}
127+
}
126128
});
127129

128130

lib/CSSKeyframeRule.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ CSSOM.CSSKeyframeRule.prototype.type = 9;
2525
//CSSOM.CSSKeyframeRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
2626

2727
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframeRule.cpp
28-
CSSOM.CSSKeyframeRule.prototype.__defineGetter__("cssText", function() {
29-
return this.keyText + " {" + this.style.cssText + "} ";
28+
Object.defineProperty(CSSOM.CSSKeyframeRule.prototype, "cssText", {
29+
get: function() {
30+
return this.keyText + " {" + this.style.cssText + "} ";
31+
}
3032
});
3133

3234

lib/CSSKeyframesRule.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ CSSOM.CSSKeyframesRule.prototype.type = 8;
2323
//CSSOM.CSSKeyframesRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
2424

2525
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframesRule.cpp
26-
CSSOM.CSSKeyframesRule.prototype.__defineGetter__("cssText", function() {
27-
var cssTexts = [];
28-
for (var i=0, length=this.cssRules.length; i < length; i++) {
29-
cssTexts.push(" " + this.cssRules[i].cssText);
30-
}
31-
return "@" + (this._vendorPrefix || '') + "keyframes " + this.name + " { \n" + cssTexts.join("\n") + "\n}";
26+
Object.defineProperty(CSSOM.CSSKeyframesRule.prototype, "cssText", {
27+
get: function() {
28+
var cssTexts = [];
29+
for (var i=0, length=this.cssRules.length; i < length; i++) {
30+
cssTexts.push(" " + this.cssRules[i].cssText);
31+
}
32+
return "@" + (this._vendorPrefix || '') + "keyframes " + this.name + " { \n" + cssTexts.join("\n") + "\n}";
33+
}
3234
});
3335

3436

lib/CSSMediaRule.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ CSSOM.CSSMediaRule.prototype.type = 4;
2525
//CSSOM.CSSMediaRule.prototype.deleteRule = CSSStyleSheet.prototype.deleteRule;
2626

2727
// http://opensource.apple.com/source/WebCore/WebCore-658.28/css/CSSMediaRule.cpp
28-
CSSOM.CSSMediaRule.prototype.__defineGetter__("cssText", function() {
29-
var cssTexts = [];
30-
for (var i=0, length=this.cssRules.length; i < length; i++) {
31-
cssTexts.push(this.cssRules[i].cssText);
32-
}
33-
return "@media " + this.media.mediaText + " {" + cssTexts.join("") + "}";
28+
Object.defineProperty(CSSOM.CSSMediaRule.prototype, "cssText", {
29+
get: function() {
30+
var cssTexts = [];
31+
for (var i=0, length=this.cssRules.length; i < length; i++) {
32+
cssTexts.push(this.cssRules[i].cssText);
33+
}
34+
return "@media " + this.media.mediaText + " {" + cssTexts.join("") + "}";
35+
}
3436
});
3537

3638

lib/CSSStyleRule.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@ CSSOM.CSSStyleRule.prototype = new CSSOM.CSSRule;
2222
CSSOM.CSSStyleRule.prototype.constructor = CSSOM.CSSStyleRule;
2323
CSSOM.CSSStyleRule.prototype.type = 1;
2424

25-
CSSOM.CSSStyleRule.prototype.__defineGetter__("cssText", function() {
26-
var text;
27-
if (this.selectorText) {
28-
text = this.selectorText + " {" + this.style.cssText + "}";
29-
} else {
30-
text = "";
25+
Object.defineProperty(CSSOM.CSSStyleRule.prototype, "cssText", {
26+
get: function() {
27+
var text;
28+
if (this.selectorText) {
29+
text = this.selectorText + " {" + this.style.cssText + "}";
30+
} else {
31+
text = "";
32+
}
33+
return text;
34+
},
35+
set: function(cssText) {
36+
var rule = CSSOM.CSSStyleRule.parse(cssText);
37+
this.style = rule.style;
38+
this.selectorText = rule.selectorText;
3139
}
32-
return text;
33-
});
34-
35-
CSSOM.CSSStyleRule.prototype.__defineSetter__("cssText", function(cssText) {
36-
var rule = CSSOM.CSSStyleRule.parse(cssText);
37-
this.style = rule.style;
38-
this.selectorText = rule.selectorText;
3940
});
4041

4142

lib/CSSValueExpression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ instanceof /a/
253253
254254
*/
255255
CSSOM.CSSValueExpression.prototype._parseJSRexExp = function(token, idx) {
256-
var before = token.substring(0, idx).trimRight(),
256+
var before = token.substring(0, idx).replace(/\s+$/, ""),
257257
legalRegx = [
258258
/^$/,
259259
/\($/,

0 commit comments

Comments
 (0)