Use html5 pushstate

This commit is contained in:
Vit Brunner
2014-12-16 21:59:47 +01:00
parent 998254be24
commit 6629562e6e
2 changed files with 12 additions and 5 deletions
+6 -4
View File
@@ -10,13 +10,15 @@ angular.module("sideBySide.controllers", [])
scroll = () ->
setTimeout () ->
element = document.getElementById($location.hash())
$document.scrollTo(element, 10, 200) if element
if ('section' of route.params)
section = 'section-' + route.params['section']
element = document.getElementById(section)
$document.scrollTo(element, 10, 200) if element
, 1
$rootScope.$on 'duScrollspy:becameActive', ($event, $element) ->
if (not $scope.meta[0].Loading)
$location.hash($element.prop('id')).replace()
$location.path route.update('section', $element.prop('id').replace('section-', ''))
$rootScope.$apply()
$scope.$watchCollection () ->
@@ -47,5 +49,5 @@ angular.module("sideBySide.controllers", [])
$scope.pick = false
poems.load route.appUrl + '/' + route.params.base
poems.load route.appUrl + '/' + route.params.base.replace(/\./g, '/')
]
+6 -1
View File
@@ -10,8 +10,13 @@ angular.module("sideBySide").service "route", ['$location', ($location) ->
, {})
@params.base = '' if 'base' not of @params
@params.base = @params.base.replace(/\./g, '/')
@appUrl = $location.absUrl()
.substring(0, $location.absUrl().length - $location.url().length)
@update = (key, value) ->
@params[key] = value
(property + ':' + value for property, value of @params).join('/')
@
]