From ab1fca9fdb883f49303d58a64952d0d34d76b987 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 15 Dec 2014 16:30:23 -0800 Subject: [PATCH] Prevent the page from jumping on tree tab change --- IPython/html/static/tree/js/main.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 194bd385b..2b1f15190 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -140,8 +140,19 @@ require([ }); // set hash on tab click - $("#tabs").find("a").click(function() { - window.location.hash = $(this).attr("href"); + $("#tabs").find("a").click(function(e) { + // Prevent the document from jumping when the active tab is changed to a + // tab that has a lot of content. + e.preventDefault(); + + // Set the hash without causing the page to jump. + // http://stackoverflow.com/a/14690177/2824256 + var hash = $(this).attr("href"); + if(window.history.pushState) { + window.history.pushState(null, null, hash); + } else { + window.location.hash = hash; + } }); // load tab if url hash