Skip to content

Instantly share code, notes, and snippets.

@rpbaltazar
Created April 6, 2018 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpbaltazar/479cf52385480a6bfad7b3e0f67aba3d to your computer and use it in GitHub Desktop.
Save rpbaltazar/479cf52385480a6bfad7b3e0f67aba3d to your computer and use it in GitHub Desktop.
Text box auto resize
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