Created
February 15, 2013 05:17
-
-
Save znz/4958688 to your computer and use it in GitHub Desktop.
jQuery Mobile を参考にして作った textarea 自動拡大
This file contains hidden or 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
do ($ = jQuery) -> | |
jQuery.fn.autogrow = (options) -> | |
settings = $.extend { | |
extraLineHeight: 15 | |
timeoutBuffer: 100 | |
}, options | |
self = this | |
timerId = self.removeData('timerId') | |
if timerId | |
clearTimeout timerId | |
handler = -> | |
self.each (i,e) -> | |
scrollHeight = e.scrollHeight | |
clientHeight = e.clientHeight | |
if clientHeight < scrollHeight | |
$(e).height(scrollHeight + settings.extraLineHeight) | |
self.removeData('timerId') | |
self.data('timerId', setTimeout(handler, settings.timeoutBuffer)) | |
$(document).on 'keyup.autogrow', 'textarea', -> | |
$(this).autogrow() | |
$('textarea').autogrow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment