Skip to content

Instantly share code, notes, and snippets.

@inertialbit
Created May 19, 2011 15:47
Show Gist options
  • Save inertialbit/981076 to your computer and use it in GitHub Desktop.
Save inertialbit/981076 to your computer and use it in GitHub Desktop.
coffee script ex jquery+lowpro behavior
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
})
(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);
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