Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Expose vendor prefix for @keyframes (fixes #29)

  • Loading branch information...
commit 9a970e58786e4f19406e0a20c26a1a05f75c05bc 1 parent 04cb62b
Nicholas C. Zakas nzakas authored
24 build/node-parserlib.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
+/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
var parserlib = {};
(function(){
@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
+/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2999,9 +2999,15 @@ Parser.prototype = function(){
var tokenStream = this._tokenStream,
token,
tt,
- name;
+ name,
+ prefix = "";
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
+ token = tokenStream.token();
+ if (/^@\-([^\-]+)\-/.test(token.value)) {
+ prefix = RegExp.$1;
+ }
+
this._readWhitespace();
name = this._keyframe_name();
@@ -3011,8 +3017,9 @@ Parser.prototype = function(){
this.fire({
type: "startkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -3028,8 +3035,9 @@ Parser.prototype = function(){
this.fire({
type: "endkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -5556,7 +5564,7 @@ var Tokens = [
//{ name: "ATKEYWORD"},
//CSS3 animations
- { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] },
+ { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
//important symbol
{ name: "IMPORTANT_SYM"},
24 build/npm/lib/node-parserlib.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
+/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
var parserlib = {};
(function(){
@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
+/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2999,9 +2999,15 @@ Parser.prototype = function(){
var tokenStream = this._tokenStream,
token,
tt,
- name;
+ name,
+ prefix = "";
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
+ token = tokenStream.token();
+ if (/^@\-([^\-]+)\-/.test(token.value)) {
+ prefix = RegExp.$1;
+ }
+
this._readWhitespace();
name = this._keyframe_name();
@@ -3011,8 +3017,9 @@ Parser.prototype = function(){
this.fire({
type: "startkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -3028,8 +3035,9 @@ Parser.prototype = function(){
this.fire({
type: "endkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -5556,7 +5564,7 @@ var Tokens = [
//{ name: "ATKEYWORD"},
//CSS3 animations
- { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] },
+ { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
//important symbol
{ name: "IMPORTANT_SYM"},
2  build/parserlib-core.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
+/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
var parserlib = {};
(function(){
22 build/parserlib-css.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
+/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2089,9 +2089,15 @@ Parser.prototype = function(){
var tokenStream = this._tokenStream,
token,
tt,
- name;
+ name,
+ prefix = "";
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
+ token = tokenStream.token();
+ if (/^@\-([^\-]+)\-/.test(token.value)) {
+ prefix = RegExp.$1;
+ }
+
this._readWhitespace();
name = this._keyframe_name();
@@ -2101,8 +2107,9 @@ Parser.prototype = function(){
this.fire({
type: "startkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -2118,8 +2125,9 @@ Parser.prototype = function(){
this.fire({
type: "endkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -4646,7 +4654,7 @@ var Tokens = [
//{ name: "ATKEYWORD"},
//CSS3 animations
- { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] },
+ { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
//important symbol
{ name: "IMPORTANT_SYM"},
13 build/parserlib-tests.js
View
@@ -1368,9 +1368,18 @@
name: "Animation Parsing Tests",
testWebKitKeyFrames: function(){
- var parser = new Parser({strict:true});
+ var parser = new Parser({strict:true}),
+ called = true;
+
+ parser.addListener("startkeyframes", function(event) {
+ Assert.areEqual("webkit", event.prefix);
+ Assert.areEqual("movingbox", event.name);
+ Assert.areEqual(1, event.line, "Line should be 1");
+ Assert.areEqual(1, event.col, "Column should be 1");
+ called = true;
+ });
var result = parser.parse("@-webkit-keyframes movingbox{0%{left:90%;}}");
- Assert.isTrue(true); //just don't want an error
+ Assert.isTrue(called); //just don't want an error
},
testMozKeyFrames: function(){
24 build/parserlib.js
View
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
+/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
var parserlib = {};
(function(){
@@ -931,7 +931,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-/* Version v@VERSION@, Build time: 23-July-2012 09:55:09 */
+/* Version v@VERSION@, Build time: 23-July-2012 10:50:53 */
(function(){
var EventTarget = parserlib.util.EventTarget,
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -2999,9 +2999,15 @@ Parser.prototype = function(){
var tokenStream = this._tokenStream,
token,
tt,
- name;
+ name,
+ prefix = "";
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
+ token = tokenStream.token();
+ if (/^@\-([^\-]+)\-/.test(token.value)) {
+ prefix = RegExp.$1;
+ }
+
this._readWhitespace();
name = this._keyframe_name();
@@ -3011,8 +3017,9 @@ Parser.prototype = function(){
this.fire({
type: "startkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -3028,8 +3035,9 @@ Parser.prototype = function(){
this.fire({
type: "endkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -5556,7 +5564,7 @@ var Tokens = [
//{ name: "ATKEYWORD"},
//CSS3 animations
- { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-ms-keyframes" ] },
+ { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
//important symbol
{ name: "IMPORTANT_SYM"},
13 docs/css.md
View
@@ -229,6 +229,19 @@ The `startmedia` event fires when `@media` is encountered and the `endmedia` eve
console.log("Ending page margin " + event.margin);
});
+### startkeyframes and endkeyframes events
+
+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:
+
+ parser.addListener("startkeyframes", function(event){
+ console.log("Starting animation definition " + event.name);
+ });
+
+
+ parser.addListener("endkeyframes", function(event){
+ console.log("Ending animation definition " + event.name);
+ });
+
### startrule and endrule events
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:
18 src/css/Parser.js
View
@@ -1799,9 +1799,15 @@ Parser.prototype = function(){
var tokenStream = this._tokenStream,
token,
tt,
- name;
+ name,
+ prefix = "";
tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
+ token = tokenStream.token();
+ if (/^@\-([^\-]+)\-/.test(token.value)) {
+ prefix = RegExp.$1;
+ }
+
this._readWhitespace();
name = this._keyframe_name();
@@ -1811,8 +1817,9 @@ Parser.prototype = function(){
this.fire({
type: "startkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
@@ -1828,8 +1835,9 @@ Parser.prototype = function(){
this.fire({
type: "endkeyframes",
name: name,
- line: name.line,
- col: name.col
+ prefix: prefix,
+ line: token.startLine,
+ col: token.startCol
});
this._readWhitespace();
13 tests/css/Parser.js
View
@@ -1368,9 +1368,18 @@
name: "Animation Parsing Tests",
testWebKitKeyFrames: function(){
- var parser = new Parser({strict:true});
+ var parser = new Parser({strict:true}),
+ called = true;
+
+ parser.addListener("startkeyframes", function(event) {
+ Assert.areEqual("webkit", event.prefix);
+ Assert.areEqual("movingbox", event.name);
+ Assert.areEqual(1, event.line, "Line should be 1");
+ Assert.areEqual(1, event.col, "Column should be 1");
+ called = true;
+ });
var result = parser.parse("@-webkit-keyframes movingbox{0%{left:90%;}}");
- Assert.isTrue(true); //just don't want an error
+ Assert.isTrue(called); //just don't want an error
},
testMozKeyFrames: function(){
Please sign in to comment.
Something went wrong with that request. Please try again.