diff wiki.js @ 15:c94bd26e0e67

Fixed a bug whereby if the user tried editing an element while already editing a different one, weird things would happen.
author Atul Varma <varmaa@toolness.com>
date Sun, 01 Feb 2009 18:35:33 -0800
parents f8354a940524
children 20b6dbeb6250
line wrap: on
line diff
--- a/wiki.js	Sun Feb 01 17:18:51 2009 -0800
+++ b/wiki.js	Sun Feb 01 18:35:33 2009 -0800
@@ -36,6 +36,8 @@
 
 var App = {
   PART_SEPARATOR: "\n\n",
+  creole: null,
+  editingElement: null,
   eventHandlers: {}
 };
 
@@ -58,6 +60,11 @@
 };
 
 App.enterEditMode = function enterEditMode(parts, level, cursorPos) {
+  if (App.editingElement) {
+    $(App.editingElement).blur();
+    App.editingElement = null;
+  }
+
   var editablePart = $('<textarea class="wiki-edit"></textarea>').get(0);
   $(editablePart).attr("value", App.getMarkup(parts));
 
@@ -97,6 +104,8 @@
     editablePart.selectionStart = cursorPos;
     editablePart.selectionEnd = cursorPos;
   }
+
+  App.editingElement = editablePart;
   $(editablePart).focus();
 };
 
@@ -127,7 +136,7 @@
 };
 
 App.eventHandlers.onLoad = function onLoad() {
-  var creole = new Parse.Simple.Creole(
+  App.creole = new Parse.Simple.Creole(
     {interwiki: {
        WikiCreole: 'http://www.wikicreole.org/wiki/',
        Wikipedia: 'http://en.wikipedia.org/wiki/'
@@ -135,8 +144,6 @@
      linkFormat: ''
     });
 
-  App.creole = creole;
-
   jQuery.get("wiki.txt",
              {},
              function(text) {