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"

View File

@@ -163,3 +163,7 @@ a.button.large {
padding-right: 0;
padding-left: 0;
}
.disable-scroll {
overflow: hidden;
}

View File

@@ -18,7 +18,7 @@
= stylesheet_link_tag "darkswarm/all"
= csrf_meta_tags
%body{class: body_classes, ng: {app: "Darkswarm"}}
%body{class: body_classes, "body-scroll" => true , ng: {app: "Darkswarm"}}
/ [if lte IE 8]
= render partial: "shared/ie_warning"
= javascript_include_tag "iehack"