From 73e8ea878c34753fc555916116bb4adbeeb22192 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 24 Jan 2009 14:21:07 -0800 Subject: [PATCH] Now only setting the shared iframe's node once. Also fixed brief Firefox text selection flashing when selecting text in a div. --- static/js/Editor.js | 55 ++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/static/js/Editor.js b/static/js/Editor.js index ce42eea..e69b132 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -28,6 +28,27 @@ function Shared_iframe() { } else { // browsers such as IE this.iframe.contentWindow.document.designMode = "On"; } + + if ( this.iframe.contentDocument ) { // browsers such as Firefox + var document = this.iframe.contentDocument; + } else { // browsers such as IE + var document = this.iframe.contentWindow.document; + } + + document.open(); + var padding = '1.5em'; + if ( GECKO ) + padding = '1.5em 1.5em 1em 1.5em'; + else if ( MSIE ) + padding = '1.5em 1.5em 2.25em 1.5em'; + else if ( WEBKIT ) + padding = '0.4em 1.5em 1em 1.5em'; + + document.write( + '' + + '' + ); + document.close(); } @@ -247,12 +268,15 @@ Editor.prototype.claim_iframe = function ( position_after ) { self.position_cursor( range ); self.connect_handlers(); signal( self, "focused", self ); + self.focus( true ); } - // this small delay gives the browser enough lag time after set_iframe_contents() to process the HTML - // FIXME: with this lag time, any selected text briefly flashes. without this lag, selection text doesn't - // flash, but if there is no selected text, then the text cursor doesn't show up - setTimeout( finish_init, 1 ); + // this small delay gives Firefox enough lag time after set_iframe_contents() to display the + // blinking text cursor at the end of the iframe contents + if ( GECKO && !range ) + setTimeout( finish_init, 1 ); + else + finish_init(); } Editor.prototype.set_iframe_contents = function ( contents_text ) { @@ -262,27 +286,12 @@ Editor.prototype.set_iframe_contents = function ( contents_text ) { this.document = this.iframe.contentWindow.document; } - this.document.open(); - if ( !contents_text ) { - // hack: add a zero-width space to make the horizontal line under title show up in the - // correct position, even before there is a title + // hack: add a zero-width space to make the horizontal line under title show up in the + // correct position, even before there is a title + if ( !contents_text ) contents_text = "

​"; - } - var padding = '1.5em'; - if ( GECKO ) - padding = '1.5em 1.5em 1em 1.5em'; - else if ( MSIE ) - padding = '1.5em 1.5em 2.25em 1.5em'; - else if ( WEBKIT ) - padding = '0.4em 1.5em 1em 1.5em'; - - // TODO: maybe just replace the document body if the is already set up? - this.document.write( - '' + - '' + contents_text + '' - ); - this.document.close(); + this.document.body.innerHTML = contents_text; } Editor.prototype.focus_default_text_field = function () {