Add isunit function. fixes #1298

This commit is contained in:
agatronic
2013-04-29 20:03:00 +01:00
committed by Luke Page
parent 4997ce9ced
commit 572b45a94b
3 changed files with 8 additions and 3 deletions

View File

@@ -291,13 +291,16 @@ tree.functions = {
return this._isa(n, tree.URL);
},
ispixel: function (n) {
return (n instanceof tree.Dimension) && n.unit.is('px') ? tree.True : tree.False;
return this.isunit(n, 'px');
},
ispercentage: function (n) {
return (n instanceof tree.Dimension) && n.unit.is('%') ? tree.True : tree.False;
return this.isunit(n, '%');
},
isem: function (n) {
return (n instanceof tree.Dimension) && n.unit.is('em') ? tree.True : tree.False;
return this.isunit(n, 'em');
},
isunit: function (n, unit) {
return (n instanceof tree.Dimension) && n.unit.is(unit.value || unit) ? tree.True : tree.False;
},
_isa: function (n, Type) {
return (n instanceof Type) ? tree.True : tree.False;

View File

@@ -107,6 +107,7 @@
pixel: true;
percent: true;
em: true;
cat: true;
}
#alpha {
alpha: rgba(153, 94, 51, 0.6);

View File

@@ -116,6 +116,7 @@
pixel: ispixel(32px);
percent: ispercentage(32%);
em: isem(32em);
cat: isunit(32cat, cat);
}
}