Permalink
Browse files

* temp fix for keyframes

  • Loading branch information...
1 parent b6638db commit 52fb05ab788fa6938f606a278be52f39c44b2adb @ghostoy committed Jun 22, 2011
Showing with 47 additions and 12 deletions.
  1. +1 −2 lib/CSSKeyframesRule.js
  2. +10 −3 lib/clone.js
  3. +1 −0 lib/index.js
  4. +35 −7 lib/parse.js
View
@@ -23,12 +23,11 @@ CSSOM.CSSKeyframesRule.prototype.type = 8;
// http://www.opensource.apple.com/source/WebCore/WebCore-955.66.1/css/WebKitCSSKeyframesRule.cpp
CSSOM.CSSKeyframesRule.prototype.__defineGetter__("cssText", function() {
-
var cssTexts = [];
for (var i=0, length=this.cssRules.length; i < length; i++) {
cssTexts.push(" " + this.cssRules[i].cssText);
}
- return "@-webkit-Keyframes " + this.name + " { \n" + cssTexts.join("\n") + "\n}"
+ return "@-webkit-keyframes " + this.name + " { \n" + cssTexts.join("\n") + "\n}"
});
View
@@ -3,7 +3,9 @@ var CSSOM = {
CSSStyleSheet: require("./CSSStyleSheet").CSSStyleSheet,
CSSStyleRule: require("./CSSStyleRule").CSSStyleRule,
CSSMediaRule: require("./CSSMediaRule").CSSMediaRule,
- CSSStyleDeclaration: require("./CSSStyleDeclaration").CSSStyleDeclaration
+ CSSStyleDeclaration: require("./CSSStyleDeclaration").CSSStyleDeclaration,
+ CSSKeyframeRule: require('./CSSKeyframeRule').CSSKeyframeRule,
+ CSSKeyframesRule: require('./CSSKeyframesRule').CSSKeyframesRule
};
///CommonJS
@@ -25,11 +27,12 @@ CSSOM.clone = function clone(stylesheet) {
var RULE_TYPES = {
1: CSSOM.CSSStyleRule,
- 4: CSSOM.CSSMediaRule
- //FIXME
+ 4: CSSOM.CSSMediaRule,
//3: CSSOM.CSSImportRule,
//5: CSSOM.CSSFontFaceRule,
//6: CSSOM.CSSPageRule,
+ 8: CSSOM.CSSKeyframesRule,
+ 9: CSSOM.CSSKeyframeRule
};
for (var i=0, rulesLength=rules.length; i < rulesLength; i++) {
@@ -47,6 +50,10 @@ CSSOM.clone = function clone(stylesheet) {
styleClone.length = style.length;
}
+ if ("keyText" in rule) {
+ ruleClone.keyText = rule.keyText;
+ }
+
if ("selectorText" in rule) {
ruleClone.selectorText = rule.selectorText;
}
View
@@ -4,6 +4,7 @@ exports.CSSStyleRule = require("./CSSStyleRule").CSSStyleRule;
exports.CSSImportRule = require("./CSSImportRule").CSSImportRule;
exports.MediaList = require("./MediaList").MediaList;
exports.CSSMediaRule = require("./CSSMediaRule").CSSMediaRule;
+exports.CSSKeyframesRule = require("./CSSKeyframesRule").CSSKeyframesRule;
exports.StyleSheet = require("./StyleSheet").StyleSheet;
exports.CSSStyleSheet = require("./CSSStyleSheet").CSSStyleSheet;
exports.parse = require("./parse").parse;
View
@@ -4,7 +4,7 @@ var CSSOM = {
CSSStyleRule: require("./CSSStyleRule").CSSStyleRule,
CSSImportRule: require("./CSSImportRule").CSSImportRule,
CSSMediaRule: require("./CSSMediaRule").CSSMediaRule,
- CSSStyleDelcaration: require('./CSSDelcaration').CSSStyleDeclaration,
+ CSSStyleDeclaration: require('./CSSStyleDeclaration').CSSStyleDeclaration,
CSSKeyframeRule: require('./CSSKeyframeRule').CSSKeyframeRule,
CSSKeyframesRule: require('./CSSKeyframesRule').CSSKeyframesRule
};
@@ -50,7 +50,7 @@ CSSOM.parse = function parse(token, options) {
// @type CSSStyleSheet|CSSMediaRule
var currentScope = styleSheet;
- var selector, name, value, priority="", styleRule, mediaRule, importRule;
+ var selector, name, value, priority="", styleRule, mediaRule, importRule, keyframesRule, keyframeRule;
for (var character; character = token.charAt(i); i++) {
@@ -136,6 +136,13 @@ CSSOM.parse = function parse(token, options) {
i += "import".length;
buffer += "@import";
break;
+ } else if (token.indexOf("@-webkit-keyframes", i) == i) {
+ state = "keyframesRule-begin";
+ keyframesRule = new CSSOM.CSSKeyframesRule;
+ keyframesRule.__starts = i;
+ i += "-webkit-keyframes".length;
+ buffer = "";
+ break;
} else if (state == "selector") {
state = "atRule";
}
@@ -150,9 +157,22 @@ CSSOM.parse = function parse(token, options) {
state = "before-name";
} else if (state == "atBlock") {
mediaRule.media.mediaText = buffer.trim();
+ mediaRule.parentRule = currentScope;
currentScope = mediaRule;
buffer = "";
state = "before-selector";
+ } else if (state == "keyframesRule-begin") {
+ keyframesRule.name = buffer.trimRight();
+ keyframesRule.parentRule = currentScope;
+ currentScope = keyframesRule;
+ buffer = "";
+ state = "keyframeRule-begin";
+ } else if (state == "keyframeRule-begin") {
+ styleRule = new CSSOM.CSSKeyframeRule;
+ styleRule.keyText = buffer.trimRight();
+ styleRule.__starts = i;
+ buffer = "";
+ state = "before-name";
}
break;
@@ -202,6 +222,7 @@ CSSOM.parse = function parse(token, options) {
break;
case "importRule":
importRule = new CSSOM.CSSImportRule;
+ importRule.parentRule = currentScope;
importRule.cssText = buffer + character;
currentScope.cssRules.push(importRule);
buffer = "";
@@ -221,23 +242,30 @@ CSSOM.parse = function parse(token, options) {
case "before-name":
case "name":
styleRule.__ends = i + 1;
+ styleRule.parentRule = currentScope;
currentScope.cssRules.push(styleRule);
buffer = "";
+ if (currentScope instanceof CSSOM.CSSKeyframesRule) {
+ state = "keyframeRule-begin";
+ } else {
+ state = "before-selector";
+ }
break;
+ case "keyframeRule-begin":
case "before-selector":
case "selector":
// End of media rule.
// Nesting rules aren't supported yet
- if (!mediaRule) {
+ if (!currentScope.parentRule) {
throw "unexpected }";
}
- mediaRule.__ends = i + 1;
- styleSheet.cssRules.push(mediaRule);
- currentScope = styleSheet;
+ currentScope.__ends = i + 1;
+ currentScope.parentRule.cssRules.push(currentScope);
+ currentScope = currentScope.parentRule;
buffer = "";
+ state = "before-selector";
break;
}
- state = "before-selector";
break;
default:

0 comments on commit 52fb05a

Please sign in to comment.