Created
April 6, 2018 02:10
-
-
Save rpbaltazar/479cf52385480a6bfad7b3e0f67aba3d to your computer and use it in GitHub Desktop.
Text box auto resize
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.autoResize = | |
init: (element, _valueAccessor, allBindings) -> | |
$(element).addClass("resizable") | |
observable = allBindings().textInput | |
updateHeight = (element) -> | |
$(element).css("height", "1px") | |
totalHeight = element.scrollHeight | |
$(element).css("height", "#{totalHeight}px") | |
if ko.isObservable(observable) | |
observable.subscribe((newValue) -> | |
updateHeight element | |
) | |
else | |
$(element).on ("input"), (evt) -> | |
updateHeight this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment