From 2cf6f6566016a870df91bb2937eaafb95fc68b98 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 6 May 2014 15:09:19 -0400 Subject: [PATCH] FIX: Linking to relative hash URLs was reloading the app. --- app/assets/javascripts/discourse/lib/url.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/assets/javascripts/discourse/lib/url.js b/app/assets/javascripts/discourse/lib/url.js index 0f096d2e5..8d833b3c5 100644 --- a/app/assets/javascripts/discourse/lib/url.js +++ b/app/assets/javascripts/discourse/lib/url.js @@ -57,6 +57,17 @@ Discourse.URL = Em.Object.createWithMixins({ return; } + // Scroll to the same page, differnt anchor + if (path.indexOf('#') === 0) { + var $elem = $(path); + if ($elem.length > 0) { + Em.run.schedule('afterRender', function() { + $('html,body').scrollTop($elem.offset().top - $('header').height() - 15); + }); + } + return; + } + var oldPath = window.location.pathname; path = path.replace(/(https?\:)?\/\/[^\/]+/, '');