From 51a568c39c8965ff984bf71cb9f9e5478440ed4f Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 22 Jan 2009 22:33:32 -0800 Subject: [PATCH] Several fixes for shared iframe releasing / focus interaction. --- static/js/Editor.js | 20 ++++++++++++++------ static/js/Wiki.js | 9 +++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/static/js/Editor.js b/static/js/Editor.js index 4186cca..1fdff31 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -215,7 +215,7 @@ Editor.prototype.claim_iframe = function ( position_after, click_position ) { this.iframe.setAttribute( "name", iframe_id ); if ( this.iframe.editor ) - this.iframe.editor.blur(); + this.iframe.editor.release_iframe(); this.iframe.editor = this; // setup the note controls @@ -983,11 +983,16 @@ Editor.prototype.focus = function ( suppress_signal ) { } Editor.prototype.blur = function () { + this.scrape_title(); + + removeElementClass( this.iframe || this.div, "focused_note_frame" ); +} + +Editor.prototype.release_iframe = function () { if ( !this.iframe ) return; - this.scrape_title(); - var div = null; + var contents = this.contents(); disconnectAll( this.iframe.contentWindow ); disconnectAll( this.iframe ); @@ -996,6 +1001,9 @@ Editor.prototype.blur = function () { this.iframe.editor = null; this.document = null; + var static_contents = getFirstElementByTagAndClassName( "span", "static_note_contents", this.div ); + static_contents.innerHTML = contents; + if ( this.div ) removeElementClass( this.div, "invisible" ); addElementClass( this.iframe, "invisible" ); @@ -1003,15 +1011,15 @@ Editor.prototype.blur = function () { } Editor.prototype.contents = function () { + if ( this.iframe && this.document && this.document.body ) + return this.document.body.innerHTML; + if ( this.div ) { var static_contents = getFirstElementByTagAndClassName( "span", "static_note_contents", this.div ); if ( static_contents ) return static_contents.innerHTML; } - if ( this.document && this.document.body ) - return this.document.body.innerHTML; - return this.initial_text || ""; } diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 140d60a..cfa806d 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -1010,6 +1010,10 @@ Wiki.prototype.editor_focused = function ( editor, synchronous ) { this.focused_editor.blur(); this.clear_pulldowns(); + // if there is no focused editor anymore, release the iframe of the previously focused editor + if ( editor == null ) + this.focused_editor.release_iframe(); + // if the formerly focused editor is completely empty, then remove it as the user leaves it and switches to this editor if ( this.focused_editor.empty() ) { signal( this, "note_removed", this.focused_editor.id ); @@ -1024,6 +1028,7 @@ Wiki.prototype.editor_focused = function ( editor, synchronous ) { this.focused_editor = editor; this.update_toolbar(); + } Wiki.prototype.make_byline = function ( username, creation, note_id ) { @@ -1431,7 +1436,7 @@ Wiki.prototype.hide_editor = function ( event, editor ) { if ( editor == this.focused_editor ) this.focused_editor = null; if ( this.focused_editor ) - this.focused_editor.blur(); + this.editor_focused( null ); if ( !editor ) { editor = this.focused_editor; @@ -1470,7 +1475,7 @@ Wiki.prototype.delete_editor = function ( event, editor ) { this.clear_pulldowns(); if ( this.focused_editor ) - this.focused_editor.blur(); + this.editor_focused( null ); if ( !editor ) { editor = this.focused_editor;