From c0c8b07addf153c963289f1159f74ef9677b335c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 11 Nov 2016 17:11:39 +1100 Subject: [PATCH] Let shopping tabs listen to URL changes When clicking on a shopping tab like "contact", it changed the URL. But changing the URL did not change the tab. Listening to URL changes enables manual manipulation of the URL and simple links to "#/contact" to open the contact tab. --- .../controllers/shopping_tabs_controller.js.coffee | 6 +++++- app/views/shop/_messages.html.haml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/shopping_tabs_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/shopping_tabs_controller.js.coffee index 8daac0212c..b99d169c5b 100644 --- a/app/assets/javascripts/darkswarm/controllers/shopping_tabs_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/shopping_tabs_controller.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.controller "ShoppingTabsCtrl", ($scope, $controller, Navigation) -> +Darkswarm.controller "ShoppingTabsCtrl", ($scope, $controller, Navigation, $location) -> angular.extend this, $controller('TabsCtrl', {$scope: $scope}) $scope.tabs = @@ -6,3 +6,7 @@ Darkswarm.controller "ShoppingTabsCtrl", ($scope, $controller, Navigation) -> producers: { active: Navigation.isActive('/producers') } contact: { active: Navigation.isActive('/contact') } groups: { active: Navigation.isActive('/groups') } + + $scope.$on '$locationChangeStart', (event, url) -> + tab = $location.path().replace(/^\//, '') + $scope.tabs[tab]?.active = true diff --git a/app/views/shop/_messages.html.haml b/app/views/shop/_messages.html.haml index 9e5d3b8e82..8debaff82e 100644 --- a/app/views/shop/_messages.html.haml +++ b/app/views/shop/_messages.html.haml @@ -10,7 +10,7 @@ register: ('' + t('.register') + '').html_safe} - else = t '.require_customer_html', - {contact: ('' + t('.contact') + '').html_safe, + {contact: link_to(t('.contact'), '#contact'), enterprise: current_distributor.name} - elsif @order_cycles and @order_cycles.empty? - if current_distributor.preferred_shopfront_closed_message.present?