From db101b2c2f722e76888f090e2c4c2e28adc60720 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 11 Mar 2008 10:40:43 +0000 Subject: [PATCH] Don't call ScrollTo for display of messages/errors if the error/message is fully visible within the window. --- NEWS | 3 +++ static/js/Wiki.js | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index a44af7b..3c4f87c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.2.10: March 11, 2008 + * More intelligent scrolling when displaying messages and errors. + 1.2.9: March 10, 2008 * Show list of all notes on startup if there are no startup notes and the notebook isn't empty. diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 003b0d3..d9ace60 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -1540,7 +1540,7 @@ Wiki.prototype.display_message = function ( text, nodes, position_after ) { else appendChildNodes( "notes", div ); - new ScrollTo( div ); + this.scroll_to( div ); return div; } @@ -1580,11 +1580,19 @@ Wiki.prototype.display_error = function ( text, nodes, position_after ) { else appendChildNodes( "notes", div ); - new ScrollTo( div ); + this.scroll_to( div ); return div; } +Wiki.prototype.scroll_to = function ( node ) { + // if the message is already completely on-screen, then there's no need to scroll + var viewport_position = getViewportPosition(); + if ( getElementPosition( node ).y < viewport_position.y || + getElementPosition( node ).y + getElementDimensions( node ).h > viewport_position.y + getViewportDimensions().h ) + new ScrollTo( node ); +} + Wiki.prototype.clear_messages = function () { var results = getElementsByTagAndClassName( "div", "message" );