<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Expanding textarea</title>
    <link>http://leparlement.org/Expanding_textarea/vote.rss</link>
    <description>Expanding textarea</description>
    <item>
      <title>Re: Expanding textarea</title>
      <vote>-2</vote>
      <pubDate>2008-01-22 22:23:11+0100</pubDate>
      <link>http://leparlement.org/Re_Expanding_textarea_1/vote.rss</link>
      <comments>http://leparlement.org/Re_Expanding_textarea_1/vote.rss</comments>
      <dc:creator>echarp</dc:creator>
      <description>&lt;p&gt;&lt;span&gt;-1 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/span&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Re: Expanding textarea</title>
      <vote>-2</vote>
      <pubDate>2008-01-18 09:03:40+0100</pubDate>
      <link>http://leparlement.org/Re_Expanding_textarea/vote.rss</link>
      <comments>http://leparlement.org/Re_Expanding_textarea/vote.rss</comments>
      <description>&lt;p&gt;&lt;p&gt;To simplify usage, I&#8217;ve added a small feature: the text area used to write now automatically expands with its content.&lt;/p&gt;


	&lt;p&gt;That is you can write write write, scroll bars shouldn&#8217;t appear. Instead the textarea and surrounding page should vertically increase in size.&lt;/p&gt;


	&lt;p&gt;Technically it&#8217;s simple, and it works in firefox and IE. If any one happens to test it in other browsers, please, drop a comment!&lt;/p&gt;


	&lt;p&gt;For info, here is the javascript code (a lot originally comes from ajaxian):&lt;/p&gt;


	&lt;p&gt;&lt;a class="readMore" href="#" onclick="Element.hide(this); Element.removeClassName(this.parentNode.nextSibling, 'tooLarge'); return false;"&gt;Read more&amp;#8230; / Lire plus&amp;#8230;&lt;/a&gt;
&lt;div class="tooLarge"&gt;&lt;/p&gt;


	&lt;p&gt;Read more&#8230; / Lire plus&#8230;&lt;/p&gt;


	&lt;p&gt;__ Get vertical position&lt;br/&gt;
function findPosY(obj) {
  if (!obj) return 0;
  var curtop = 0;
  if (obj.offsetParent)
    while (1) {
      curtop += obj.offsetTop;
      if (!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}&lt;/p&gt;


	&lt;p&gt;__ Widen the elt until it is moved below or it is wider than its parent elt
__ Used in an &amp;#8220;onfocus&amp;#8221; event&lt;br/&gt;
function widen(elt) {
  if (elt.widened) return;
  elt.widened = true;
}&lt;/p&gt;


	&lt;p&gt;var initialPosition = findPosY(elt);&lt;br/&gt;
var initialParentWidth = elt.parentNode.offsetWidth;
while (initialPosition == findPosY(elt) &amp;#38;&amp;#38; elt.offsetWidth &amp;lt; initialParentWidth) {
  elt.cols = elt.cols + 1;
}
elt.cols = elt.cols &amp;#8211; 1;&lt;/p&gt;


	&lt;p&gt;__ Resize text area accordingly to its content&lt;br/&gt;
function resize(elt) {
  widen(elt);
  var lines = elt.value.split(&amp;#8217;\n&amp;#8217;);
  var newRows = lines.length + 1;
  var oldRows = elt.rows;
}&lt;/p&gt;


	&lt;p&gt;for (var i = 0; i &amp;lt; lines.length; i++) {
  var line = lines[i];
  if (line.length &amp;gt;= elt.cols) newRows += Math.floor(line.length / elt.cols);
}&lt;/p&gt;


	&lt;p&gt;if (newRows &amp;gt; elt.rows) elt.rows = newRows;&lt;br/&gt;
if (newRows &amp;lt; elt.rows) elt.rows = Math.max(5, newRows);&lt;/p&gt;


&lt;/div&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
