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" );