Created
October 4, 2010 05:33
-
-
Save AlyxRen/609279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* $.expressions | |
* (c) Stephen Middleton 2010 | |
* Licensed under the MIT license | |
* <http://www.opensource.org/licenses/mit-license.html> | |
* Makes an easier modifying method to add Psuedo Expressions | |
* Syntax:: | |
* //no variables | |
* $.expressions("hasText", function(ArgumentsArray, LocationInList, List){ | |
* //if returns true, it will be in the list, otherwise it's be filtered out | |
* return $(this).text() !== ""; | |
* }) | |
* //one variable | |
* $.expressions("text", function(ArgumentsArray, LocationInList, List){ | |
* return $(this).text() === ArgumentsArray[0]; | |
* }) | |
* //multiple variables | |
* $.expressions("data-Attr",function(ArgumentsArray, LocationInList, List){ | |
* return $(this).attr("data-"+ArgumentsArray[0]) === ArgumentsArray[1]; | |
* }) | |
*/ | |
(function($){ | |
var cache = {}, | |
add = function(name,fn){ | |
if (typeof fn !== "function" && fn !== null) { | |
throw new TypeError("fn must be Function or Null"); | |
} | |
cache[name] = fn; | |
$.expr[':'][name] = manage; | |
}, | |
remove = function(name){ | |
cache[name] = $.expr[':'][name] = null; | |
}, | |
manage = function(_this,curId,selCall,totalList){ | |
//console.log(cache,selCall[1],cache[selCall[1]],selCall); | |
var vars = !!selCall[3]?selCall[3].split(selCall[2]+","+selCall[2]):[], | |
fn = cache[selCall[1]]; | |
//* | |
if (typeof fn !== "function"){ | |
throw new SyntaxError("Unrecognized Expression: "+selCall[1]); | |
} | |
return fn.call( | |
_this, | |
vars,curId,totalList | |
); | |
//*/ | |
}; | |
$.extend({ | |
expressions: add//function(name,fn){ } | |
}); | |
return true; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment