From 6629562e6ef9c7d9e675f4d14cbffbc8e357e1c2 Mon Sep 17 00:00:00 2001 From: Vit Brunner Date: Tue, 16 Dec 2014 21:59:47 +0100 Subject: [PATCH] Use html5 pushstate --- source/scripts/controllers.js.coffee | 10 ++++++---- source/scripts/services/route.js.coffee | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/source/scripts/controllers.js.coffee b/source/scripts/controllers.js.coffee index c1c05d7..3a38ec2 100644 --- a/source/scripts/controllers.js.coffee +++ b/source/scripts/controllers.js.coffee @@ -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, '/') ] diff --git a/source/scripts/services/route.js.coffee b/source/scripts/services/route.js.coffee index 7dad13a..3770a0f 100644 --- a/source/scripts/services/route.js.coffee +++ b/source/scripts/services/route.js.coffee @@ -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('/') + + @ ]