var Swing = require('swing');

angular
    .module('gajus.swing', [])
    .directive('swingStack', function () {
        return {
            restrict: 'A',
            scope: {},
            controller: function () {
                var stack;

                stack = Swing.Stack();

                this.add = function (cardElement) {
                    return stack.createCard(cardElement);
                };
            }
        };
    })
    .directive('swingCard', function () {
        return {
            restrict: 'A',
            require: '^swingStack',
            scope: {
                swingOnThrowout: '&',
                swingOnThrowoutleft: '&',
                swingOnThrowoutright: '&',
                swingOnThrowin: '&',
                swingOnDragstart: '&',
                swingOnDragmove: '&',
                swingOnDragend: '&'
            },
            link: function (scope, element, attrs, swingStack) {
                var card = swingStack.add(element[0]),
                    events = ['throwout', 'throwoutleft', 'throwoutright', 'throwin', 'dragstart', 'dragmove', 'dragend'];

                // Map all Swing events to the scope expression.
                // Map eventObject variable name to the expression wrapper fn.
                // @see https://docs.angularjs.org/api/ng/service/$compile#comprehensive-directive-api
                angular.forEach(events, function (eventName) {
                    card.on(eventName, function (eventObject) {
                        scope['swingOn' + eventName.charAt(0).toUpperCase() + eventName.slice(1)]({eventName: eventName, eventObject: eventObject});
                    });
                });
            }
        };
    });
@@ -170,16 +170,112 @@
 scope: %7B
+%0A                minThrowoutDistance: '@',%0A                maxThrowoutDistance: '@'%0A            
 %7D,%0A     
@@ -295,32 +295,38 @@
 ller: function (
+$scope
 ) %7B%0A            
@@ -340,16 +340,32 @@
  stack;%0A
+                
 %0A       
@@ -393,16 +393,188 @@
 g.Stack(
+%7B%0A                    minThrowOutDistance: Number($scope.minThrowoutDistance),%0A                    maxThrowOutDistance: Number($scope.maxThrowoutDistance)%0A                %7D
 );%0A%0A    
@@ -2000,12 +2000,13 @@
   %7D;%0A    %7D);
+%0A

support for minThrowoutDistance and maxThrowoutDistance