From d44cd83e11313d5a60ff88999971cc7be4e48c39 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Thu, 2 Jun 2016 00:56:38 +0100 Subject: [PATCH] Start of a slideable side nav --- .../app/controllers/application.coffee | 5 +- .../scripts/app/controllers/sidebar.coffee | 77 ++++++++++++++++++- resources/views/shared/_app_layout.blade.php | 2 +- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/resources/assets/scripts/app/controllers/application.coffee b/resources/assets/scripts/app/controllers/application.coffee index 1e42efe3..5995a974 100644 --- a/resources/assets/scripts/app/controllers/application.coffee +++ b/resources/assets/scripts/app/controllers/application.coffee @@ -21,7 +21,6 @@ module.exports = angular.module('ponyfm').controller "application", [ $scope.$state = $state $scope.$stateParams = $stateParams $scope.isPinnedPlaylistSelected = false - $scope.menuActive = false $scope.notifActive = false $loadingElement = null loadingStateName = null @@ -34,7 +33,7 @@ module.exports = angular.module('ponyfm').controller "application", [ console.log 'SW register failed', err $scope.menuToggle = () -> - $scope.menuActive = !$scope.menuActive + $rootScope.$broadcast('sidebarToggled') $scope.notifActive = false $scope.notifPulloutToggle = () -> @@ -76,7 +75,7 @@ module.exports = angular.module('ponyfm').controller "application", [ statesPreloaded = {} $scope.$on '$stateChangeStart', (e, newState, newParams, oldState, oldParams) -> - $scope.menuActive = false + $rootScope.$broadcast('sidebarHide') $scope.notifActive = false $scope.isPinnedPlaylistSelected = false diff --git a/resources/assets/scripts/app/controllers/sidebar.coffee b/resources/assets/scripts/app/controllers/sidebar.coffee index 6331fba0..9ef54a7e 100644 --- a/resources/assets/scripts/app/controllers/sidebar.coffee +++ b/resources/assets/scripts/app/controllers/sidebar.coffee @@ -15,9 +15,23 @@ # along with this program. If not, see . module.exports = angular.module('ponyfm').controller "sidebar", [ - '$scope', '$modal', 'playlists' - ($scope, $modal, playlists) -> + '$scope', '$modal', 'playlists', '$rootScope' + ($scope, $modal, playlists, $rootScope) -> $scope.playlists = playlists.pinnedPlaylists + $scope.menuVisible = false + $scope.menuActive = false + $scope.menuAnimated = true + $scope.navStyle = {} + + $rootScope.$on('sidebarToggled', () -> + $scope.menuVisible = !$scope.menuVisible + $scope.menuActive = $scope.menuVisible + ) + + $rootScope.$on('sidebarHide', () -> + $scope.menuVisible = false + $scope.menuActive = false + ) $scope.createPlaylist = () -> $modal @@ -58,4 +72,63 @@ module.exports = angular.module('ponyfm').controller "sidebar", [ controller: 'credits', show: true + # Swipable side nav code + startX = 0 + currentX = 0 + touchingNav = false + + onStart = (e) -> + if !$scope.menuVisible + return + + startX = e.touches[0].pageX + currentX = startX + touchingNav = true + $scope.menuAnimated = false + requestAnimationFrame(update) + + onMove = (e) -> + if !touchingNav + return + + currentX = e.touches[0].pageX + translateX = Math.min(0, currentX - startX) + + if translateX < 0 + e.preventDefault() + + onEnd = (e) -> + if !touchingNav + return + + touchingNav = false + translateX = Math.min(0, currentX - startX) + $scope.menuAnimated = true + + if translateX < 0 + hideNav() + + hideNav = () -> + $scope.navStyle.transform = '' + $scope.menuAnimated = true + $scope.menuVisible = false + $scope.menuActive = false + $scope.$apply() + + update = () -> + if !touchingNav + return + + requestAnimationFrame(update) + + translateX = 170 + Math.min(0, currentX - startX) + $scope.navStyle.transform = 'translateX(' + translateX + 'px)' + $scope.$apply() + + addEventListeners = () -> + document.addEventListener('touchstart', onStart) + document.addEventListener('touchmove', onMove) + document.addEventListener('touchend', onEnd) + + addEventListeners() ] diff --git a/resources/views/shared/_app_layout.blade.php b/resources/views/shared/_app_layout.blade.php index 235730f5..40a1cbee 100644 --- a/resources/views/shared/_app_layout.blade.php +++ b/resources/views/shared/_app_layout.blade.php @@ -75,7 +75,7 @@
-