diff --git a/datacenterlight/static/datacenterlight/js/main.js b/datacenterlight/static/datacenterlight/js/main.js index 5e919045..dc5a9108 100644 --- a/datacenterlight/static/datacenterlight/js/main.js +++ b/datacenterlight/static/datacenterlight/js/main.js @@ -104,21 +104,33 @@ }); $('.url').click(function(event) { event.preventDefault(); - var href = $(this).attr('href'); + var $this = $(this); + var href = $this.attr('href'); $('.navbar-collapse').removeClass('in'); $('.navbar-collapse').addClass('collapsing'); if (href[0] === "#") { - if ($(href).length) { - $('html, body').animate({ - scrollTop: $(href).offset().top - 50 - }, 1000); - } + scrollToElement(href); } else if (href) { - window.location = href; + var path = $(this).prop('href').split('#'); + var currentPath = window.location.origin + window.location.pathname; + if (!path[1]) { + window.location = href; + } else if (currentPath == path[0]) { + scrollToElement('#' + path[1]); + } } }); } + function scrollToElement(el) { + var $el = $(el); + if ($el.length) { + $('html, body').animate({ + scrollTop: $el.offset().top - 50 + }, 1000); + } + } + function verifiedUrl() { if (window.location.href.indexOf('#success') > -1) { form_success();