From 0238c27111553926ce1ba301cf722bb07c14316a Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 9 Nov 2007 08:24:40 +0000 Subject: [PATCH] If the editor being highlighted is already completely on-screen (within the viewport), then there's no need to scroll. --- static/js/Editor.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/static/js/Editor.js b/static/js/Editor.js index a9405e2..a6b3d1c 100644 --- a/static/js/Editor.js +++ b/static/js/Editor.js @@ -200,14 +200,19 @@ Editor.prototype.highlight = function ( scroll ) { if ( scroll == undefined ) scroll = true; + if ( scroll ) { + // if the editor is already completely on-screen, then there's no need to scroll + var viewport_position = getViewportPosition(); + if ( getElementPosition( this.note_controls ).y < viewport_position.y || + getElementPosition( this.iframe ).y + getElementDimensions( this.iframe ).h > viewport_position.y + getViewportDimensions().h ) + new ScrollTo( this.note_controls ); + } + if ( /Opera/.test( navigator.userAgent ) ) { // MochiKit's Highlight for iframes is broken in Opera - if ( scroll ) ScrollTo( this.note_controls ); pulsate( this.iframe, options = { "pulses": 1, "duration": 0.5 } ); } else if ( this.iframe.contentDocument ) { // browsers such as Firefox - if ( scroll ) ScrollTo( this.note_controls ); Highlight( this.iframe, options = { "queue": { "scope": "highlight", "limit": 1 } } ); } else { // browsers such as IE - if ( scroll ) ScrollTo( this.note_controls ); if ( this.document && this.document.body ) Highlight( this.document.body, options = { "queue": { "scope": "highlight", "limit": 1 } } ); }