Files
openfoodnetwork/app/assets/javascripts/darkswarm/controllers/page_selection_ctrl.js.coffee
Maikel Linke 1d42ce885b Stay on shop page when opening login modal
The login modal changes the URL to `#/login` which interfers with our
shop pages. In order to show the right shop page, we need to know which
pages are valid and where we have been before we clicked on Login.
2020-03-19 15:38:00 +11:00

18 lines
575 B
CoffeeScript

Darkswarm.controller "PageSelectionCtrl", ($scope, $location) ->
$scope.selectedPage = ->
# The path looks like `/contact` for the URL `https://ofn.org/shop#/contact`.
# We remove the slash at the beginning.
page = $location.path()[1..]
if page in $scope.whitelist
$scope.lastPage = page
page
else if page
# The path points to an unrelated path like `/login`. Stay where we were.
$scope.lastPage
else
$scope.whitelist[0]
$scope.whitelistPages = (pages) ->
$scope.whitelist = pages
$scope.lastPage = pages[0]