Created
July 28, 2011 20:03
-
-
Save SteveSanderson/1112418 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
ko.bindingHandlers.hasFocus = { | |
init: function(element, valueAccessor) { | |
$(element).focus(function() { | |
var value = valueAccessor(); | |
value(true); | |
}); | |
$(element).blur(function() { | |
var value = valueAccessor(); | |
value(false); | |
}); | |
} | |
}; | |
ko.bindingHandlers.fadeVisible = { | |
init: function (element, valueAccessor) { | |
// Initially set the element to be instantly visible/hidden depending on the value | |
var value = valueAccessor(); | |
$(element).toggle(ko.utils.unwrapObservable(value)); // Use "unwrapObservable" so we can handle values that may or may not be observable | |
}, | |
update: function (element, valueAccessor) { | |
// Whenever the value subsequently changes, slowly fade the element in or out | |
var value = valueAccessor(); | |
ko.utils.unwrapObservable(value) ? $(element).fadeIn() : $(element).fadeOut(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment