From 55362cd4b143e546a5f0298ea8139d6f3bec98ef Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 7 Jan 2009 12:39:48 -0800 Subject: [PATCH] Now properly stripping off / adding "static_note_contents" span when switching between iframe/div. --- static/css/style.css | 3 ++- static/js/Editor.js | 49 ++++++++++++++++++++++++++++---------------- static/js/Wiki.js | 16 +++++++++++++-- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/static/css/style.css b/static/css/style.css index c9f3a84..969d774 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -541,7 +541,7 @@ h1 { .static_note_div { -moz-border-radius: 5px; display: block; - padding: 0.5em 1em 1em 1.5em; + padding: 1em 1em 1em 1.5em; font-family: sans-serif; overflow: hidden; border: 2px solid #999999; @@ -559,6 +559,7 @@ h1 { .static_note_contents h3 { padding-bottom: 0.25em; border-bottom: 1px solid #dddddd; + margin-top: 0em; margin-bottom: 0.75em; } diff --git a/static/js/Editor.js b/static/js/Editor.js index 704e025..805fc75 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -145,13 +145,17 @@ Editor.prototype.create_iframe = function ( position_after ) { // if there is already a static note open for this editor, replace its div with the new iframe var static_note = getElement( "static_note_" + this.id ); if ( static_note ) { - var note_holder = getElement( "note_holder_" + this.id ); this.note_controls = getElement( "note_controls_" + this.id ); this.connect_note_controls( true ); - this.div = null; + + disconnectAll( this.div ); swapDOM( static_note, this.iframe ); insertSiblingNodesBefore( this.iframe, this.note_controls ); + + this.init_iframe(); + + this.div = null; } else { this.create_note_controls(); this.connect_note_controls(); @@ -165,9 +169,11 @@ Editor.prototype.create_iframe = function ( position_after ) { insertSiblingNodesAfter( position_after, note_holder ); else appendChildNodes( "notes", note_holder ); + + this.init_iframe(); } - this.init_document(); + this.finish_init(); } Editor.prototype.create_div = function ( position_after ) { @@ -184,19 +190,23 @@ Editor.prototype.create_div = function ( position_after ) { return; } + var static_contents = createDOM( "span", { "class": "static_note_contents" } ); + static_contents.innerHTML = this.contents(); this.div = createDOM( - "div", { "class": "static_note_div", "id": "static_note_" + this.id } + "div", { "class": "static_note_div", "id": "static_note_" + this.id }, static_contents ); - this.div.innerHTML = this.initial_text; // if there is already an iframe open for this editor, replace it with the new static note div if ( getElement( "note_" + this.id ) ) { - var note_holder = getElement( "note_holder_" + this.id ); + disconnectAll( this.iframe.contentWindow ); + disconnectAll( this.document.body ); + disconnectAll( this.document ); + + swapDOM( this.iframe, this.div ); + insertSiblingNodesBefore( this.div, this.note_controls ); + this.iframe = null; this.document = null; - - replaceChildNodes( note_holder, this.div ); - insertSiblingNodesBefore( this.div, this.note_controls ); } else { this.create_note_controls(); this.connect_note_controls(); @@ -218,8 +228,7 @@ Editor.prototype.create_div = function ( position_after ) { signal( self, "init_complete" ); } -// second stage of construction after create_iframe(), invoked by iframe onload. do not call directly -Editor.prototype.init_document = function () { +Editor.prototype.init_iframe = function () { var self = this; // necessary so that the member functions of this editor object are used if ( this.iframe.contentDocument ) { // browsers such as Firefox @@ -243,14 +252,11 @@ Editor.prototype.init_document = function () { this.document.open(); this.document.write( '' + - '' + this.initial_text + '' + '' + this.contents() + '' ); this.document.close(); - - this.finish_init(); } -// third and final stage of construction, invoked by init_document(). do not call directly Editor.prototype.finish_init = function () { if ( !this.initial_text ) { this.initial_text = "

"; @@ -809,9 +815,16 @@ Editor.prototype.focus = function () { } Editor.prototype.contents = function () { - if ( !this.document || !this.document.body ) - return ""; - 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 || ""; } // return true if the given state_name is currently enabled, optionally using a given list of node diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 37df3d0..3dbe97f 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -272,10 +272,16 @@ Wiki.prototype.populate = function ( startup_notes, current_notes, note_read_wri // don't actually create an editor if a particular list of notes was provided in the result if ( current_notes.length == 0 ) { + var static_note = getElement( "static_note_" + startup_note.object_id ); + if ( !static_note ) continue; + var static_contents = getFirstElementByTagAndClassName( "span", "static_note_contents", static_note ); + if ( !static_contents ) continue; + var contents_text = static_contents.innerHTML; + var editor = this.create_editor( startup_note.object_id, // grab this note's contents from the static notes area - getElement( "static_note_" + startup_note.object_id ).innerHTML, + contents_text, startup_note.deleted_from_id, startup_note.revision, startup_note.creation, @@ -300,9 +306,15 @@ Wiki.prototype.populate = function ( startup_notes, current_notes, note_read_wri else var read_write = this.notebook.read_write; + var static_note = getElement( "static_note_" + startup_note.object_id ); + if ( !static_note ) continue; + var static_contents = getFirstElementByTagAndClassName( "span", "static_note_contents", static_note ); + if ( !static_contents ) continue; + var contents_text = static_contents.innerHTML; + this.create_editor( note.object_id, - getElement( "static_note_" + note.object_id ).innerHTML, + contents_text, note.deleted_from_id, note.revision, note.creation,