Enable control over body scroll with BodyScroll service

This commit is contained in:
Matt-Yorkley
2020-06-12 12:34:52 +02:00
parent ed086c2db5
commit a6edc1c973
5 changed files with 23 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
Darkswarm.controller "CartDropdownCtrl", ($scope, Cart) ->
Darkswarm.controller "CartDropdownCtrl", ($scope, Cart, BodyScroll) ->
$scope.Cart = Cart
$scope.showCartSidebar = false
$scope.toggleCartSidebar = ->
$scope.showCartSidebar = !$scope.showCartSidebar
BodyScroll.toggle()

View File

@@ -0,0 +1,9 @@
Darkswarm.directive "bodyScroll", ($rootScope, BodyScroll) ->
restrict: 'A'
scope: true
link: (scope, elem, attrs) ->
$rootScope.$on "toggleBodyScroll", ->
if BodyScroll.disabled
elem.addClass "disable-scroll"
else
elem.removeClass "disable-scroll"

View File

@@ -0,0 +1,7 @@
angular.module("Darkswarm").factory "BodyScroll", ($rootScope) ->
new class BodyScroll
disabled: false
toggle: ->
@disabled = !@disabled
$rootScope.$broadcast "toggleBodyScroll"