Files
openfoodnetwork/app/assets/javascripts/darkswarm/services/navigation.js.coffee
2018-05-26 18:13:35 +01:00

31 lines
745 B
CoffeeScript

Darkswarm.factory 'Navigation', ($location, $window) ->
new class Navigation
path: null
isActive: (path)->
$location.path() == path
navigate: (path)=>
@path = path
$location.path(@path)
toggle: (path = false)=>
@path = path || @path
if $location.path() == @path
$location.path("/")
else
@navigate(path)
goWithoutHashFragments: (path) ->
# Redirects to specified path, without Angular hash fragments such as '#/login'
$window.location.href = $window.location.origin + path
go: (path)->
if path.match /^http/
$window.location.href = path
else
$window.location.pathname = path
reload: ->
$window.location.reload()