Skip to content

Commit 9a970e5

Browse files
committed
Expose vendor prefix for @Keyframes (fixes #29)
1 parent 04cb62b commit 9a970e5

File tree

9 files changed

+112
-41
lines changed

9 files changed

+112
-41
lines changed

build/node-parserlib.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
24+
/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
2525
var parserlib = {};
2626
(function(){
2727

@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
931931
THE SOFTWARE.
932932
933933
*/
934-
/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
934+
/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
935935
(function(){
936936
var EventTarget = parserlib.util.EventTarget,
937937
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2999,9 +2999,15 @@ Parser.prototype = function(){
29992999
var tokenStream = this._tokenStream,
30003000
token,
30013001
tt,
3002-
name;
3002+
name,
3003+
prefix = "";
30033004

30043005
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
3006+
token = tokenStream.token();
3007+
if (/^@\-([^\-]+)\-/.test(token.value)) {
3008+
prefix = RegExp.$1;
3009+
}
3010+
30053011
this._readWhitespace();
30063012
name = this._keyframe_name();
30073013

@@ -3011,8 +3017,9 @@ Parser.prototype = function(){
30113017
this.fire({
30123018
type: "startkeyframes",
30133019
name: name,
3014-
line: name.line,
3015-
col: name.col
3020+
prefix: prefix,
3021+
line: token.startLine,
3022+
col: token.startCol
30163023
});
30173024

30183025
this._readWhitespace();
@@ -3028,8 +3035,9 @@ Parser.prototype = function(){
30283035
this.fire({
30293036
type: "endkeyframes",
30303037
name: name,
3031-
line: name.line,
3032-
col: name.col
3038+
prefix: prefix,
3039+
line: token.startLine,
3040+
col: token.startCol
30333041
});
30343042

30353043
this._readWhitespace();
@@ -5556,7 +5564,7 @@ var Tokens = [
55565564
//{ name: "ATKEYWORD"},
55575565

55585566
//CSS3 animations
5559-
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] },
5567+
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
55605568

55615569
//important symbol
55625570
{ name: "IMPORTANT_SYM"},

build/npm/lib/node-parserlib.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
24+
/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
2525
var parserlib = {};
2626
(function(){
2727

@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
931931
THE SOFTWARE.
932932
933933
*/
934-
/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
934+
/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
935935
(function(){
936936
var EventTarget = parserlib.util.EventTarget,
937937
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2999,9 +2999,15 @@ Parser.prototype = function(){
29992999
var tokenStream = this._tokenStream,
30003000
token,
30013001
tt,
3002-
name;
3002+
name,
3003+
prefix = "";
30033004

30043005
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
3006+
token = tokenStream.token();
3007+
if (/^@\-([^\-]+)\-/.test(token.value)) {
3008+
prefix = RegExp.$1;
3009+
}
3010+
30053011
this._readWhitespace();
30063012
name = this._keyframe_name();
30073013

@@ -3011,8 +3017,9 @@ Parser.prototype = function(){
30113017
this.fire({
30123018
type: "startkeyframes",
30133019
name: name,
3014-
line: name.line,
3015-
col: name.col
3020+
prefix: prefix,
3021+
line: token.startLine,
3022+
col: token.startCol
30163023
});
30173024

30183025
this._readWhitespace();
@@ -3028,8 +3035,9 @@ Parser.prototype = function(){
30283035
this.fire({
30293036
type: "endkeyframes",
30303037
name: name,
3031-
line: name.line,
3032-
col: name.col
3038+
prefix: prefix,
3039+
line: token.startLine,
3040+
col: token.startCol
30333041
});
30343042

30353043
this._readWhitespace();
@@ -5556,7 +5564,7 @@ var Tokens = [
55565564
//{ name: "ATKEYWORD"},
55575565

55585566
//CSS3 animations
5559-
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] },
5567+
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
55605568

55615569
//important symbol
55625570
{ name: "IMPORTANT_SYM"},

build/parserlib-core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
24+
/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
2525
var parserlib = {};
2626
(function(){
2727

build/parserlib-css.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
24+
/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
2525
(function(){
2626
var EventTarget = parserlib.util.EventTarget,
2727
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2089,9 +2089,15 @@ Parser.prototype = function(){
20892089
var tokenStream = this._tokenStream,
20902090
token,
20912091
tt,
2092-
name;
2092+
name,
2093+
prefix = "";
20932094

20942095
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
2096+
token = tokenStream.token();
2097+
if (/^@\-([^\-]+)\-/.test(token.value)) {
2098+
prefix = RegExp.$1;
2099+
}
2100+
20952101
this._readWhitespace();
20962102
name = this._keyframe_name();
20972103

@@ -2101,8 +2107,9 @@ Parser.prototype = function(){
21012107
this.fire({
21022108
type: "startkeyframes",
21032109
name: name,
2104-
line: name.line,
2105-
col: name.col
2110+
prefix: prefix,
2111+
line: token.startLine,
2112+
col: token.startCol
21062113
});
21072114

21082115
this._readWhitespace();
@@ -2118,8 +2125,9 @@ Parser.prototype = function(){
21182125
this.fire({
21192126
type: "endkeyframes",
21202127
name: name,
2121-
line: name.line,
2122-
col: name.col
2128+
prefix: prefix,
2129+
line: token.startLine,
2130+
col: token.startCol
21232131
});
21242132

21252133
this._readWhitespace();
@@ -4646,7 +4654,7 @@ var Tokens = [
46464654
//{ name: "ATKEYWORD"},
46474655

46484656
//CSS3 animations
4649-
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] },
4657+
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
46504658

46514659
//important symbol
46524660
{ name: "IMPORTANT_SYM"},

build/parserlib-tests.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,18 @@
13681368
name: "Animation Parsing Tests",
13691369

13701370
testWebKitKeyFrames: function(){
1371-
var parser = new Parser({strict:true});
1371+
var parser = new Parser({strict:true}),
1372+
called = true;
1373+
1374+
parser.addListener("startkeyframes", function(event) {
1375+
Assert.areEqual("webkit", event.prefix);
1376+
Assert.areEqual("movingbox", event.name);
1377+
Assert.areEqual(1, event.line, "Line should be 1");
1378+
Assert.areEqual(1, event.col, "Column should be 1");
1379+
called = true;
1380+
});
13721381
var result = parser.parse("@-webkit-keyframes movingbox{0%{left:90%;}}");
1373-
Assert.isTrue(true); //just don't want an error
1382+
Assert.isTrue(called); //just don't want an error
13741383
},
13751384

13761385
testMozKeyFrames: function(){

build/parserlib.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
24+
/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
2525
var parserlib = {};
2626
(function(){
2727

@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
931931
THE SOFTWARE.
932932
933933
*/
934-
/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
934+
/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
935935
(function(){
936936
var EventTarget = parserlib.util.EventTarget,
937937
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2999,9 +2999,15 @@ Parser.prototype = function(){
29992999
var tokenStream = this._tokenStream,
30003000
token,
30013001
tt,
3002-
name;
3002+
name,
3003+
prefix = "";
30033004

30043005
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
3006+
token = tokenStream.token();
3007+
if (/^@\-([^\-]+)\-/.test(token.value)) {
3008+
prefix = RegExp.$1;
3009+
}
3010+
30053011
this._readWhitespace();
30063012
name = this._keyframe_name();
30073013

@@ -3011,8 +3017,9 @@ Parser.prototype = function(){
30113017
this.fire({
30123018
type: "startkeyframes",
30133019
name: name,
3014-
line: name.line,
3015-
col: name.col
3020+
prefix: prefix,
3021+
line: token.startLine,
3022+
col: token.startCol
30163023
});
30173024

30183025
this._readWhitespace();
@@ -3028,8 +3035,9 @@ Parser.prototype = function(){
30283035
this.fire({
30293036
type: "endkeyframes",
30303037
name: name,
3031-
line: name.line,
3032-
col: name.col
3038+
prefix: prefix,
3039+
line: token.startLine,
3040+
col: token.startCol
30333041
});
30343042

30353043
this._readWhitespace();
@@ -5556,7 +5564,7 @@ var Tokens = [
55565564
//{ name: "ATKEYWORD"},
55575565

55585566
//CSS3 animations
5559-
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] },
5567+
{ name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
55605568

55615569
//important symbol
55625570
{ name: "IMPORTANT_SYM"},

docs/css.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ The `startmedia` event fires when `@media` is encountered and the `endmedia` eve
229229
console.log("Ending page margin " + event.margin);
230230
});
231231

232+
### startkeyframes and endkeyframes events
233+
234+
The `startkeyframes` event fires when `@keyframes` (or any vendor prefixed version) is encountered and the `endkeyframes` event fires just after the closing right brace (`}`) is encountered after `@keyframes`. The `event` object has one property, `name`, which is the name of the animation. Example:
235+
236+
parser.addListener("startkeyframes", function(event){
237+
console.log("Starting animation definition " + event.name);
238+
});
239+
240+
241+
parser.addListener("endkeyframes", function(event){
242+
console.log("Ending animation definition " + event.name);
243+
});
244+
232245
### startrule and endrule events
233246

234247
The `startrule` event fires just after all selectors on a rule have been parsed and the `endrule` event fires just after the closing right brace (`}`) is encountered for the rule. The `event` object has one additional property, `selectors`, which is an array of `parserlib.css.Selector` objects. Example:

src/css/Parser.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,9 +1799,15 @@ Parser.prototype = function(){
17991799
var tokenStream = this._tokenStream,
18001800
token,
18011801
tt,
1802-
name;
1802+
name,
1803+
prefix = "";
18031804

18041805
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
1806+
token = tokenStream.token();
1807+
if (/^@\-([^\-]+)\-/.test(token.value)) {
1808+
prefix = RegExp.$1;
1809+
}
1810+
18051811
this._readWhitespace();
18061812
name = this._keyframe_name();
18071813

@@ -1811,8 +1817,9 @@ Parser.prototype = function(){
18111817
this.fire({
18121818
type: "startkeyframes",
18131819
name: name,
1814-
line: name.line,
1815-
col: name.col
1820+
prefix: prefix,
1821+
line: token.startLine,
1822+
col: token.startCol
18161823
});
18171824

18181825
this._readWhitespace();
@@ -1828,8 +1835,9 @@ Parser.prototype = function(){
18281835
this.fire({
18291836
type: "endkeyframes",
18301837
name: name,
1831-
line: name.line,
1832-
col: name.col
1838+
prefix: prefix,
1839+
line: token.startLine,
1840+
col: token.startCol
18331841
});
18341842

18351843
this._readWhitespace();

tests/css/Parser.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,18 @@
13681368
name: "Animation Parsing Tests",
13691369

13701370
testWebKitKeyFrames: function(){
1371-
var parser = new Parser({strict:true});
1371+
var parser = new Parser({strict:true}),
1372+
called = true;
1373+
1374+
parser.addListener("startkeyframes", function(event) {
1375+
Assert.areEqual("webkit", event.prefix);
1376+
Assert.areEqual("movingbox", event.name);
1377+
Assert.areEqual(1, event.line, "Line should be 1");
1378+
Assert.areEqual(1, event.col, "Column should be 1");
1379+
called = true;
1380+
});
13721381
var result = parser.parse("@-webkit-keyframes movingbox{0%{left:90%;}}");
1373-
Assert.isTrue(true); //just don't want an error
1382+
Assert.isTrue(called); //just don't want an error
13741383
},
13751384

13761385
testMozKeyFrames: function(){

0 commit comments

Comments
 (0)