angular-swing icon indicating copy to clipboard operation
angular-swing copied to clipboard

How to change throwOutDistance and trigger the throwout event from an angular app?

Open Jempan opened this issue 10 years ago • 6 comments

Awesome directory - very useful - thanks!!!

I have two questions:

  1. I need a smaller throwOutDistance, what is the best way to change it?
  2. I also need to be able to connect 2 (yes/no)-buttons to the throwout event, how can I do this in an angular app?

Jempan avatar Apr 15 '15 10:04 Jempan

+1

A1iAshoor avatar Apr 16 '15 19:04 A1iAshoor

I did hack the original angular-swing.js file:

Card.throwOutConfidence = function (offset, elementWidth) {
    return Math.min(Math.abs(offset) / (elementWidth/1.5), 1);
};

Card.isThrowOut = function (offset, elementWidth) {
    return Card.throwOutConfidence(offset, (elementWidth/1.5)) == 1;
};

You can also play with these two config values:

config.minThrowOutDistance = config.minThrowOutDistance ? config.minThrowOutDistance : 400;
config.maxThrowOutDistance = config.maxThrowOutDistance ? config.maxThrowOutDistance : 500;

As for the buttons, I'm sure there's another hack for them, if I have the time I'll get back here for more, I'd love to contribute and make this angular friendly but this is just for the sack of making it just work.

A1iAshoor avatar Apr 16 '15 19:04 A1iAshoor

I guess as I understand from your question, you'd like more of yes/no but destroy the card anyway, the way of doing this is straight forward by having this code:

$scope.btnYes = function (index) {
    // make some magic that will tell that the user has chosen YES!
    // remove the card from stack
    $scope.cards.splice(index, 1);
}

$scope.btnNo = function (index) {
    // make some magic that will tell that the user has chosen NO!
    // remove the card from stack
    $scope.cards.splice(index, 1);
}

* I did not test the code yet, but it should work

A1iAshoor avatar Apr 16 '15 19:04 A1iAshoor

I actually first tried changing the config values the other day but that didn´t work as expected, changing Card.throwOutConfidence and Card.isThrowOut as you suggested did the trick and solved my question 1, many thanks!

Jempan avatar Apr 18 '15 05:04 Jempan

How do you implement the config using the angular version?

neekers avatar Jun 05 '15 03:06 neekers

I second this, I'd like to know as well.

thehashrocket avatar Jul 16 '15 00:07 thehashrocket