Cart dropdown now closes when clicking outside it.

This commit is contained in:
Matt-Yorkley
2019-08-05 21:04:54 +01:00
parent 02ec0634b3
commit 8a069787d1
4 changed files with 21 additions and 9 deletions

View File

@@ -1,8 +0,0 @@
Darkswarm.directive "cart", ->
# Toggles visibility of the "cart" popover
restrict: 'A'
link: (scope, elem, attr)->
scope.open = false
elem.bind 'click', ->
scope.$apply ->
scope.open = !scope.open

View File

@@ -0,0 +1,19 @@
Darkswarm.directive "cartToggle", ($document) ->
# Toggles visibility of the "cart" popover
restrict: 'A'
link: (scope, elem, attr)->
scope.open = false
$document.bind 'click', (event) ->
cart_button = elem[0]
element_and_parents = [event.target, event.target.parentElement, event.target.parentElement.parentElement]
cart_button_clicked = (element_and_parents.indexOf(cart_button) != -1)
if cart_button_clicked
scope.$apply ->
scope.open = !scope.open
else
scope.$apply ->
scope.open = false
return

View File

@@ -1,5 +1,5 @@
%span.cart-span{"ng-controller" => "CartCtrl", "ng-class" => "{ dirty: Cart.dirty || Cart.empty(), 'pure-dirty': Cart.dirty }"}
%a#cart.icon{cart: true}
%a#cart.icon{"cart-toggle" => true}
%span
= t '.cart'
%span.count

View File

@@ -112,6 +112,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
# that we are not filling in the quantity on the outgoing row
page.should_not have_selector "tr.product-cart"
within('product:not(.ng-leave)') { fill_in "variants[#{variant.id}]", with: 1 }
show_cart
within("li.cart") { page.should have_content with_currency(19.99) }
end