Created
January 24, 2012 20:10
-
-
Save uzulla/1672273 to your computer and use it in GitHub Desktop.
JQuery add-on that add an If statement
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
//JQuery add-on that add an If statement | |
$.fn.ift = function(){ | |
var flag = arguments[0]; | |
var func = arguments[1]; | |
var else_func = arguments[2]; | |
if(flag && $.isFunction(func)){ | |
func.call(this, this); | |
}else if(!flag && $.isFunction(else_func)){ | |
else_func.call(this, this); | |
} | |
return this; | |
} | |
/* | |
example. | |
$('body') | |
.ift(true, function(){$(this).css('background-color','blue')} ) | |
.ift((1!=1), function(){$(this).css('background-color','gray')} ) | |
.ift( | |
some.isValid(), | |
function(){$(this).css('background-color','green')}, | |
function(){$(this).css('background-color','red')} | |
); | |
also, coffeescript. | |
$('<span />') | |
.ift( | |
src.pin==1 | |
()-> $(this).addClass('check').text('!') # then | |
()-> $(this).addClass('nocheck').text('-') #else | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment