Skip to content

Instantly share code, notes, and snippets.

@bkardell
Created May 15, 2012 16:42
Show Gist options
  • Save bkardell/2703151 to your computer and use it in GitHub Desktop.
Save bkardell/2703151 to your computer and use it in GitHub Desktop.
My math hitches with name changes proposed by Mike Wilcox
Hitch.add([
{
name: '-math-gt',
filter: function(match,argsString){
var args = argsString.split(",");
var value = match.getAttribute(args[0]);
if(!isNaN(value) && !isNaN(args[1])){
return (value > parseInt(args[1],10));
}
return false;
}
},{
name: '-math-lt',
filter: function(match,argsString){
var args = argsString.split(",");
var value = match.getAttribute(args[0]);
if(!isNaN(value) && !isNaN(args[1])){
return (value < parseInt(args[1],10));
}
return false;
}
},
{
name: '-math-max',
filter: function(match,argsString,c){
var v1, vTemp, temp, biggest, el, args = argsString.split(",");
v1 = match.getAttribute(args[0]);
if(v1 && !isNaN(v1)){
for(var i=0;i<c.siblings.length;i++){
temp = c.siblings[i];
vTemp = temp.getAttribute(args[0]);
if(vTemp && !isNaN(vTemp)){
vTemp = parseInt(vTemp, 10);
if(!biggest || vTemp > biggest){
el = temp;
biggest = vTemp;
};
}
}
return match === el;
}
return false;
}
},
{
name: '-math-min',
filter: function(match,argsString,c){
var v1, vTemp, temp, smallest, el, args = argsString.split(",");
v1 = match.getAttribute(args[0]);
if(v1 && !isNaN(v1)){
for(var i=0;i<c.siblings.length;i++){
temp = c.siblings[i];
vTemp = temp.getAttribute(args[0]);
if(vTemp && !isNaN(vTemp)){
vTemp = parseInt(vTemp, 10);
if(!smallest || vTemp < smallest){
el = temp;
smallest = vTemp;
};
}
}
return match === el;
}
return false;
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment