[kupu-checkins] r48020 - kupu/trunk/kupu/common

duncan at codespeak.net duncan at codespeak.net
Fri Oct 26 10:57:49 CEST 2007


Author: duncan
Date: Fri Oct 26 10:57:45 2007
New Revision: 48020

Modified:
   kupu/trunk/kupu/common/kupueditor.js
Log:
Fix for Plone issue #7099: Kupu error on multi-schemata archetypes content
Replaced Firefox designmode timer with an onresize event handler for the iframe.


Modified: kupu/trunk/kupu/common/kupueditor.js
==============================================================================
--- kupu/trunk/kupu/common/kupueditor.js	(original)
+++ kupu/trunk/kupu/common/kupueditor.js	Fri Oct 26 10:57:45 2007
@@ -95,6 +95,7 @@
     
     this._designModeSetAttempts = 0;
     this._initialized = false;
+    this._wantDesignMode = false;
 
     // some properties to save the selection, required for IE to remember 
     // where in the iframe the selection was
@@ -506,43 +507,48 @@
 
     this._initializeEventHandlers = function() {
         /* attache the event handlers to the iframe */
+        var win = this.getDocument().getWindow();
+        var idoc = this.getInnerDocument();
+        // Set design mode on resize event:
+        this._addEventHandler(win, 'resize', this._resizeHandler, this);
         // Initialize DOM2Event compatibility
         // XXX should come back and change to passing in an element
-        this._addEventHandler(this.getInnerDocument(), "click", this.updateStateHandler, this);
-        this._addEventHandler(this.getInnerDocument(), "dblclick", this.updateStateHandler, this);
-        this._addEventHandler(this.getInnerDocument(), "keyup", this.updateStateHandler, this);
-        this._addEventHandler(this.getInnerDocument(), "keyup", function() {this.content_changed = true;}, this);
-        this._addEventHandler(this.getInnerDocument(), "mouseup", this.updateStateHandler, this);
+        this._addEventHandler(idoc, "click", this.updateStateHandler, this);
+        this._addEventHandler(idoc, "dblclick", this.updateStateHandler, this);
+        this._addEventHandler(idoc, "keyup", this.updateStateHandler, this);
+        this._addEventHandler(idoc, "keyup", function() {this.content_changed = true;}, this);
+        this._addEventHandler(idoc, "mouseup", this.updateStateHandler, this);
         if (this.getBrowserName() == "IE") {
-            this._addEventHandler(this.getInnerDocument(), "selectionchange", this.onSelectionChange, this);
+            this._addEventHandler(idoc, "selectionchange", this.onSelectionChange, this);
         }
     };
 
+    this._resizeHandler = function() {
+        // Use the resize event to trigger setting design mode
+        if (this._wantDesignMode) {
+            this._setDesignModeWhenReady();
+        }
+    }
     this._setDesignModeWhenReady = function() {
-        /* Rather dirty polling loop to see if Mozilla is done doing it's
-            initialization thing so design mode can be set.
-        */
-        this._designModeSetAttempts++;
-        if (this._designModeSetAttempts > 25) {
-            alert(_('Couldn\'t set design mode. Kupu will not work on this browser.'));
-            return;
-        };
+        /* Try to set design mode, but if we fail then just wait for a
+         * resize event.
+         */
         var success = false;
         try {
             this._setDesignMode();
             success = true;
         } catch (e) {
-            // register a function to the timer_instance because 
-            // window.setTimeout can't refer to 'this'...
-            timer_instance.registerFunction(this, this._setDesignModeWhenReady, 100);
         };
         if (success) {
+            this._wantDesignMode = false;
             // provide an 'afterInit' method on KupuEditor.prototype
             // for additional bootstrapping (after editor init)
             if (this.afterInit) {
                 this.afterInit();
             };
-        };
+        } else {
+            this._wantDesignMode = true; // Enable the resize trigger
+        }
     };
 
     this._setDesignMode = function() {


More information about the kupu-checkins mailing list