Created
May 19, 2011 15:47
-
-
Save inertialbit/981076 to your computer and use it in GitHub Desktop.
coffee script ex jquery+lowpro behavior
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
TextareaExpander = $.klass({ | |
contructor: (pixelsToGrowBy, maxHeight) -> | |
@pixelsToGrowBy = pixelsToGrowBy ? 20 | |
@maxHeight = maxHeight ? 999 | |
this.onkeypress | |
onkeypress: (event) -> | |
currentHeight = this.element.height | |
scrollHeight = this.element[0].scrollHeight | |
while currentHeight < scrollHeight and currentHeight < @maxHeight | |
this.element.css({'height': (currentHeight + @pixelsToGrowBy) + 'px'}) | |
currentHeight = this.element.height | |
scrollHeight = this.element[0].scrollHeight | |
}) |
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
(function() { | |
var TextareaExpander; | |
TextareaExpander = $.klass({ | |
contructor: function(pixelsToGrowBy, maxHeight) { | |
this.pixelsToGrowBy = pixelsToGrowBy != null ? pixelsToGrowBy : 20; | |
this.maxHeight = maxHeight != null ? maxHeight : 999; | |
return this.onkeypress; | |
}, | |
onkeypress: function(event) { | |
var currentHeight, scrollHeight, _results; | |
currentHeight = this.element.height; | |
scrollHeight = this.element[0].scrollHeight; | |
_results = []; | |
while (currentHeight < scrollHeight && currentHeight < this.maxHeight) { | |
this.element.css({ | |
'height': (currentHeight + this.pixelsToGrowBy) + 'px' | |
}); | |
currentHeight = this.element.height; | |
_results.push(scrollHeight = this.element[0].scrollHeight); | |
} | |
return _results; | |
} | |
}); | |
}).call(this); |
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
TextareaExpander = $.klass({ | |
initialize: function(pixelsToGrowBy, maxHeight) { | |
this.pixelsToGrowBy = (typeof pixelsToGrowBy == 'undefined') ? 20 : pixelsToGrowBy; | |
this.maxHeight = (typeof maxHeight == 'undefined') ? 999 : maxHeight; | |
// run it once to blow up any textareas on first page load | |
this.onkeypress(); | |
}, | |
onkeypress: function(e) { | |
var curr_h = this.element.height(); | |
var scroll_h = this.element[0].scrollHeight; | |
while(curr_h < scroll_h && curr_h < this.maxHeight) { | |
this.element.css( { 'height': (curr_h + this.pixelsToGrowBy) + 'px' }); | |
curr_h = this.element.height(); | |
scroll_h = this.element[0].scrollHeight; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment