changeset 1:dd457cc7c596

Improved setting of size of textarea.
author Atul Varma <varmaa@toolness.com>
date Sun, 01 Feb 2009 12:45:55 -0800
parents 2e5a6f077df2
children 1d3d91674bbe
files wiki.css wiki.html wiki.js
diffstat 3 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/wiki.css	Sun Feb 01 12:17:08 2009 -0800
+++ b/wiki.css	Sun Feb 01 12:45:55 2009 -0800
@@ -15,4 +15,5 @@
                  courier new, monospace;
     font-size: 10pt;
     width: 640px;
+    overflow: hidden;
 }
--- a/wiki.html	Sun Feb 01 12:17:08 2009 -0800
+++ b/wiki.html	Sun Feb 01 12:45:55 2009 -0800
@@ -11,6 +11,7 @@
 <div id="content">
 <div class="wiki"><h1>Yo.</h1>
 Hi there <i>dude</i>.</div>
+<div class="wiki">I am gud.</div>
 </div>
 </body>
 <script src="jquery.js"></script>
--- a/wiki.js	Sun Feb 01 12:17:08 2009 -0800
+++ b/wiki.js	Sun Feb 01 12:45:55 2009 -0800
@@ -1,18 +1,25 @@
 function makeEditable() {
   var item = this;
   var newItem = $('<textarea class="wikiedit"></textarea>');
-  console.log($(item).height());
-  $(newItem).css({height: $(item).height()});
   $(newItem).attr("value", $(item).html());
+
+  function setScrollHeight() {
+    var scrollHeight = $(newItem).get(0).scrollHeight;
+    $(newItem).height(scrollHeight);
+  }
+
   $(newItem).blur(
     function() {
       var html = $(newItem).attr("value");
-      console.log(html);
       $(item).html(html);
       $(item).click(makeEditable);
       $(newItem).replaceWith(item);
     });
+
+  $(newItem).keyup(setScrollHeight);
   $(item).replaceWith(newItem);
+  setScrollHeight();
+
   $(newItem).focus();
 }