From 941feb1dbfb8318ec7c9cbed2ff2c73406f10346 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 27 Jan 2009 01:32:21 -0800 Subject: [PATCH] A non-ideal solution, but now repositioning iframe periodically after a resize in case the div its tracking has moved. --- static/js/Editor.js | 37 +++++++++++++++++++++---------------- static/js/Wiki.js | 24 +++++++++++++++--------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/static/js/Editor.js b/static/js/Editor.js index 9554df8..0cc4055 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -239,14 +239,6 @@ Editor.prototype.claim_iframe = function ( position_after ) { if ( this.iframe ) return; - // hack to prevent iframe from being incorrectly positioned if there is a closing (and thus - // moving) message or error box - if ( getElementsByTagAndClassName( "div", "message" ).length > 0 || - getElementsByTagAndClassName( "div", "error" ).length > 0 ) { - setTimeout( function() { self.claim_iframe( position_after ); }, 25 ); - return; - } - // claim the reusable iframe for this note, stealing it from the note that's using it (if any) this.iframe = Editor.shared_iframe.iframe; this.iframe.setAttribute( "id", iframe_id ); @@ -260,14 +252,6 @@ Editor.prototype.claim_iframe = function ( position_after ) { this.note_controls = getElement( "note_controls_" + this.id ); this.connect_note_controls( true ); - // give the invisible iframe the exact same position as the div it will replace. subtract the - // position of the center_content_area container, which is relatively positioned - position = getElementPosition( this.div ); - container_position = getElementPosition( "center_content_area" ); - position.x -= container_position.x; - position.y -= container_position.y; - setElementPosition( this.iframe, position ); - // give the iframe the note's current contents and then resize it based on the size of the div var range = this.add_selection_bookmark(); this.set_iframe_contents( this.contents() ); @@ -656,6 +640,27 @@ Editor.prototype.resize = function ( get_height_from_div ) { size = { "h": height }; setElementDimensions( this.iframe, size ); setElementDimensions( this.div, size ); + + var self = this; + this.reposition(); +} + +Editor.prototype.reposition = function ( repeat ) { + // give the iframe the exact same position as the div it replaces. subtract the position of the + // center_content_area container, which is relatively positioned + var position = getElementPosition( this.div ); + var orig_position = getElementPosition( this.iframe ); + if ( repeat && position.x == orig_position.x && position.y == orig_position.y ) + return; + + var container_position = getElementPosition( "center_content_area" ); + position.x -= container_position.x; + position.y -= container_position.y; + + setElementPosition( this.iframe, position ); + + var self = this; + setTimeout( function () { self.reposition( true ); }, 50 ); } Editor.prototype.key_pressed = function ( event ) { diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 2e4517e..fca24cd 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -2522,6 +2522,7 @@ Wiki.prototype.move_current_notebook_down = function ( event ) { } Wiki.prototype.display_message = function ( text, nodes, position_after ) { + var self = this; this.clear_messages(); this.clear_pulldowns(); @@ -2536,7 +2537,7 @@ Wiki.prototype.display_message = function ( text, nodes, position_after ) { "title": "dismiss this message" } ); appendChildNodes( inner_div, ok_button ); - connect( ok_button, "onclick", this.clear_messages ); + connect( ok_button, "onclick", function () { self.clear_messages(); } ); var div = DIV( { "class": "message" }, inner_div ); div.nodes = nodes; @@ -2550,11 +2551,13 @@ Wiki.prototype.display_message = function ( text, nodes, position_after ) { insertSiblingNodesAfter( "notes_top", div ); this.scroll_to( div ); + this.resize_editor(); return div; } Wiki.prototype.display_error = function ( text, nodes, position_after ) { + var self = this; this.clear_messages(); this.clear_pulldowns(); @@ -2569,7 +2572,7 @@ Wiki.prototype.display_error = function ( text, nodes, position_after ) { "title": "dismiss this message" } ); appendChildNodes( inner_div, ok_button ); - connect( ok_button, "onclick", this.clear_messages ); + connect( ok_button, "onclick", function () { self.clear_messages(); } ); var div = DIV( { "class": "error" }, inner_div ); div.nodes = nodes; @@ -2583,6 +2586,7 @@ Wiki.prototype.display_error = function ( text, nodes, position_after ) { insertSiblingNodesAfter( "notes_top", div ); this.scroll_to( div ); + this.resize_editor(); return div; } @@ -2596,10 +2600,11 @@ Wiki.prototype.scroll_to = function ( node ) { } Wiki.prototype.clear_messages = function () { - var results = getElementsByTagAndClassName( "div", "message" ); + var message_results = getElementsByTagAndClassName( "div", "message" ); + var error_results = getElementsByTagAndClassName( "div", "error" ); - for ( var i in results ) { - var result = results[ i ]; + for ( var i in message_results ) { + var result = message_results[ i ]; // only close the message if it's been open at least a quarter second if ( new Date() - result.init_time < 250 ) @@ -2614,10 +2619,8 @@ Wiki.prototype.clear_messages = function () { } } ); } - var results = getElementsByTagAndClassName( "div", "error" ); - - for ( var i in results ) { - var result = results[ i ]; + for ( var i in error_results ) { + var result = error_results[ i ]; if ( new Date() - result.init_time < 250 ) continue @@ -2628,6 +2631,9 @@ Wiki.prototype.clear_messages = function () { } catch ( e ) { } } } ); } + + if ( message_results.length || error_results.length ) + this.resize_editor(); } Wiki.prototype.clear_pulldowns = function ( ephemeral_only ) {