Created
January 11, 2009 04:04
-
-
Save neerajsingh0101/45630 to your computer and use it in GitHub Desktop.
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
<%= text_area 'comment', 'comment', "rows" => 10,:cols => 55, :class => 'autoexpand_textarea' %> |
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
// http://jroller.com/rmcmahon/entry/resizingtextarea_with_prototype | |
// Usage: <% apply_behaviour "textarea", "new ResizingTextArea(this);" %> | |
var ResizingTextArea = Class.create(); | |
ResizingTextArea.prototype = { | |
defaultRows: 1, | |
initialize: function(field) | |
{ | |
this.defaultRows = Math.max(field.rows, 1); | |
this.resizeNeeded = this.resizeNeeded.bindAsEventListener(this); | |
Event.observe(field, "click", this.resizeNeeded); | |
Event.observe(field, "keyup", this.resizeNeeded); | |
}, | |
resizeNeeded: function(event) | |
{ | |
var t = Event.element(event); | |
var lines = t.value.split('\n'); | |
var newRows = lines.length + 1; | |
var oldRows = t.rows; | |
for (var i = 0; i < lines.length; i++) | |
{ | |
var line = lines[i]; | |
if (line.length >= t.cols) newRows += Math.floor(line.length / t.cols); | |
} | |
if (newRows > t.rows) t.rows = newRows; | |
if (newRows < t.rows) t.rows = Math.max(this.defaultRows, newRows); | |
} | |
} | |
Event.addBehavior({ | |
'.autoexpand_textarea:focus':function(e) { | |
new ResizingTextArea(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
<%= javascript_include_tag "prototype", "effects","lowpro","application", :cache => "cache/all" %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment