diff js/tutorial.js @ 78:17ce8b6be452

Added a 'now you try' section and a 'where to go from here' section to the tutorial.
author Atul Varma <varmaa@toolness.com>
date Mon, 20 Apr 2009 14:30:27 -0700
parents 9a771b8a1702
children 86158b61b732
line wrap: on
line diff
--- a/js/tutorial.js	Mon Apr 20 13:38:36 2009 -0700
+++ b/js/tutorial.js	Mon Apr 20 14:30:27 2009 -0700
@@ -15,18 +15,34 @@
     var oneCodeCharacter = $('<span class="example-code">M</span>');
     $(document.body).append(oneCodeCharacter);
     var charWidth = oneCodeCharacter.width();
+    var charHeight = oneCodeCharacter.height();
+    var columnWidth = charWidth * CHARS_PER_ROW;
     $(oneCodeCharacter).remove();
 
     // Set the width of the content to be the maximum number of
     // characters of code that can fit on a line.
-    $('#content').css({width: charWidth * CHARS_PER_ROW});
+    $('#content').width(columnWidth);
+
+    // Set up the code editor.
+    $('.try-code').width(columnWidth);
+    var tryCodeLines = $('.try-code').text().split('\n').length + 1;
+    $('.try-code').height(charHeight * tryCodeLines);
+
+    function executeTryCode() {
+      $('#try-my-view').text('');
+      var code = $('.try-code').val();
+      eval(code);
+      eval('tryMyView();');
+    }
+
+    $('.try-code').blur(executeTryCode);
     $('#content').fadeIn();
 
     // Iterate through all the code snippets and trim them.
     var allCode = '';
     $('.example-code').each(
       function() {
-        var code = $(this).text();
+        var code = $(this).val() || $(this).text();
         allCode += code;
         $(this).text(jQuery.trim(code));
       });