From 9d30d7431a1e1bba27977e17fae077bffca24995 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Fri, 9 Sep 2016 14:35:15 -0400 Subject: [PATCH] Supporter page: Make supporter type selections act like tabs. * Scroll to the type selection when the visitor follows a link to a specific type. * Don't scroll the page when the user changes their selection. --- www/conservancy/static/js/supporter-page.js | 22 +++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/www/conservancy/static/js/supporter-page.js b/www/conservancy/static/js/supporter-page.js index 139bb53f..fc8cb0c3 100644 --- a/www/conservancy/static/js/supporter-page.js +++ b/www/conservancy/static/js/supporter-page.js @@ -218,18 +218,24 @@ $(document).ready(function() { } }); $("#form-correction-needed").removeClass("form-error-show").addClass("form-error"); + return false; }; $(".supporter-type-selector a").bind("click", selectSupportType); - var selectSupportTypeFromHash = function() { - var urlHash = window.location.hash; - if ((urlHash !== "#monthly") && (urlHash !== "#renewal")) { - urlHash = "#annual"; - } - $(".supporter-type-selector a[href=" + urlHash + "]").click(); + var supportTypeSelector = function(supportTypeHash) { + return $(".supporter-type-selector a[href=" + supportTypeHash + "]"); }; - $(window).bind("hashchange", selectSupportTypeFromHash); - selectSupportTypeFromHash(); + var selectSupportTypeFromHash = function() { + return supportTypeSelector(window.location.hash).click(); + }; + var $window = $(window); + $window.bind("hashchange", selectSupportTypeFromHash); + var $selectorLink = selectSupportTypeFromHash(); + if ($selectorLink.length === 0) { + supportTypeSelector("#annual").click(); + } else { + $window.scrollTop($selectorLink.offset().top); + } $( ".footnote-mark" ).tooltip({ items: "a",