From bd3f626872ac306095930768c1eaab70f976bf37 Mon Sep 17 00:00:00 2001 From: stveep Date: Wed, 2 Aug 2017 22:52:20 +0100 Subject: [PATCH] Call toScroll after any new panel is . Also added an actual delay as it still scrolled to the 'old' location.. 10 ms was too short to allow the location to update after the old panel closes (on Chrome), 50 ms seems ok. --- .../checkout/accordion_controller.js.coffee | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee index 78f77e3356..91161c6f8c 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee @@ -3,23 +3,22 @@ Darkswarm.controller "AccordionCtrl", ($scope, localStorageService, $timeout, $d value = if localStorageService.get(key) then {} else { details: true, billing: false, shipping: false, payment: false } localStorageService.bind $scope, "accordion", value, key $scope.accordionSections = ["details", "billing", "shipping", "payment"] + # Scrolling is confused by our position:fixed top bar - add an offset to scroll + # to the correct location, plus 5px buffer + offset_height = $("nav.top-bar").height() + 5 $scope.show = (section)-> $scope.accordion[section] = true + # If we call scrollTo() directly after show(), when one of the accordions above the + # scroll location is closed by show(), scrollTo() will scroll to the old location of + # the element. Putting this in a 50 ms timeout is enough delay for the DOM to + # have updated. + $timeout (-> + $document.scrollTo $("##{section}"), offset_height, 500), 50 $scope.$on 'purchaseFormInvalid', (event, form) -> # Scroll to first invalid section for section in $scope.accordionSections if not form[section].$valid $scope.show section - - # If we call scrollTo() directly after show(), when one of the accordions above the - # scroll location is closed by show(), scrollTo() will scroll to the old location of - # the element. Putting this in a zero-length timeout is enough delay for the DOM to - # have updated. - $timeout -> - # Scrolling is confused by our position:fixed top bar - add an offset to scroll - # to the correct location, plus 5px buffer - offset_height = $("nav.top-bar").height() + 5 - $document.scrollTo $("##{section}"), offset_height, 500 break