Skip to content

Commit

Permalink
Added support for arbitrary @-VENDOR-keyframes support
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 17, 2011
1 parent bc69cd9 commit 421bbd1
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 40 deletions.
7 changes: 5 additions & 2 deletions lib/lexer.js
Expand Up @@ -444,9 +444,12 @@ Lexer.prototype = {

atrule: function() {
var captures;
if (captures = /^@(import|(-\w+-)?keyframes|charset|page) */.exec(this.str)) {
if (captures = /^@(import|(?:-(\w+)-)?keyframes|charset|page) */.exec(this.str)) {
this.skip(captures);
return new Token(captures[1]);
var vendor = captures[2]
, type = captures[1];
if (vendor) type = 'keyframes';
return new Token(type, vendor);
}
},

Expand Down
8 changes: 5 additions & 3 deletions lib/nodes/keyframes.js
Expand Up @@ -12,17 +12,19 @@
var Node = require('./node');

/**
* Initialize a new `Keyframes` with the given `name`.
* Initialize a new `Keyframes` with the given `name`,
* and optional vendor `prefix`.
*
* @param {String} name
* @param {String} prefix
* @api public
*/

var Keyframes = module.exports = function Keyframes(name){
var Keyframes = module.exports = function Keyframes(name, prefix){
Node.call(this);
this.name = name;
this.frames = [];
this.prefix = 'official';
this.prefix = prefix || 'official';
};

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/parser.js
Expand Up @@ -732,10 +732,10 @@ Parser.prototype = {
*/

keyframes: function() {
this.accept('-webkit-keyframes') || this.expect('keyframes');
var pos
, _ = this.css
, keyframes = new nodes.Keyframes(this.id());
, tok = this.expect('keyframes')
, keyframes = new nodes.Keyframes(this.id(), tok.val);

// css-style
if (this.css = this.accept('{')) {
Expand Down
5 changes: 3 additions & 2 deletions lib/visitor/evaluator.js
Expand Up @@ -191,13 +191,14 @@ Evaluator.prototype.visitKeyframes = function(keyframes){
frame.block = this.visit(frame.block);
return frame;
}, this);
console.log(keyframes.prefix);

if ('official' != keyframes.prefix) return keyframes;

this.vendors.forEach(function(prefix){
var node = keyframes.clone();
node.prefix = prefix;
node.fabricated = true;
this.root.push(node);
this.currentBlock.push(node);
}, this);

return nodes.null;
Expand Down
32 changes: 16 additions & 16 deletions test/cases/css.keyframes.css
@@ -1,14 +1,19 @@
@-webkit-keyframes bouce {
@-webkit-keyframes something {
0% {
foo: bar;
color: #f00;
}

50% {
foo: bar;
100% {
color: #00f;
}
}
@-webkit-keyframes fade {
0% {
opacity: 0;
}

100% {
foo: bar;
opacity: 1;
}
}
@-webkit-keyframes bouce {
Expand Down Expand Up @@ -37,21 +42,16 @@
foo: bar;
}
}
@-webkit-keyframes something {
@-webkit-keyframes bouce {
0% {
color: #f00;
foo: bar;
}

100% {
color: #00f;
}
}
@-webkit-keyframes fade {
0% {
opacity: 0;
50% {
foo: bar;
}

100% {
opacity: 1;
foo: bar;
}
}
}
31 changes: 16 additions & 15 deletions test/cases/css.keyframes.styl
@@ -1,6 +1,22 @@

vendors = webkit

animate(name) {
@keyframes name {
from { color: red; }
to { color: blue; }
}
}

animate(something)

@-webkit-keyframes fade
from
opacity 0
to
opacity 1


@keyframes bouce {
from {
foo: bar;
Expand Down Expand Up @@ -30,18 +46,3 @@ vendors = webkit

to { foo: bar; }
}

animate(name) {
@keyframes name {
from { color: red; }
to { color: blue; }
}
}

animate(something)

@-webkit-keyframes fade
from
opacity 0
to
opacity 1
9 changes: 9 additions & 0 deletions test/cases/keyframes.css
@@ -0,0 +1,9 @@
@-moz-keyframes foo {
0% {
color: #000;
}

100% {
color: #fff;
}
}
6 changes: 6 additions & 0 deletions test/cases/keyframes.styl
@@ -0,0 +1,6 @@

@-moz-keyframes foo
from
color: black
to
color: white

0 comments on commit 421bbd1

Please sign in to comment.