Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions example/ionic.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "example",
"email": "",
"app_id": "",
"package_name": ""
}
File renamed without changes.
31 changes: 12 additions & 19 deletions example/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,31 @@
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Ionic Seed App</title>

<!-- ionic css -->
<link href="lib/css/ionic.css" rel="stylesheet">
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- your app's css -->
<link href="css/app.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- angularjs scripts -->
<script src="lib/js/ionic.js"></script>
<script src="lib/js/angular/angular.js"></script>
<script src="lib/js/angular/angular-animate.js"></script>
<script src="lib/js/angular/angular-sanitize.js"></script>
<script src="lib/js/angular/angular-touch.js"></script>
<script src="lib/js/angular-ui/angular-ui-router.js"></script>
<script src="lib/js/ionic-angular.js"></script>
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script -->
<script src="cordova.js"></script>

<!-- your app's script -->
<script src="js/app.js"></script>
<script src="js/ionic.cards.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
</head>

<!--
<!--
'starter' is the name of this angular module (js/app.js)
-->
<body ng-app="starter" animation="slide-left-right-ios7" no-scroll>
<pane ng-controller="CardsCtrl">
<pane ng-controller="CardsCtrl" class="pane">
<header-bar type="bar-transparent" title="'Help out'"></header-bar>

<p style="color:white">Accepted: {{accepted}}, Rejected: {{rejected}}</p>
<swipe-cards>
<swipe-card on-swipe="cardSwiped()" id="start-card">
Swipe down for a new card
Expand All @@ -50,8 +43,8 @@
<img ng-src="{{card.image}}">
</div>
<div class="button-bar">
<button class="button button-clear button-positive" ng-click="goAway()">Answer</button>
<button class="button button-clear button-positive" ng-click="goAway()">Decline</button>
<button class="button button-clear button-positive" ng-click="reject()">No</button>
<button class="button button-clear button-positive" ng-click="accept()">Yes</button>
</div>
</div>
</swipe-card>
Expand Down
21 changes: 17 additions & 4 deletions example/www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'ngTouch', 'ionic.contrib.ui.cards'])
angular.module('starter', ['ionic', 'ionic.contrib.ui.cards'])


.config(function($stateProvider, $urlRouterProvider) {
Expand Down Expand Up @@ -40,7 +40,9 @@ angular.module('starter', ['ionic', 'ngTouch', 'ionic.contrib.ui.cards'])
}
})

.controller('CardsCtrl', function($scope, $ionicSwipeCardDelegate) {
.controller('CardsCtrl', function($scope, $ionicSwipeCardDelegate, $rootScope) {
$rootScope.accepted = 0;
$rootScope.rejected = 0;
var cardTypes = [
{ title: 'Swipe down to clear the card', image: 'img/pic.png' },
{ title: 'Where is this?', image: 'img/pic.png' },
Expand All @@ -56,6 +58,11 @@ angular.module('starter', ['ionic', 'ngTouch', 'ionic.contrib.ui.cards'])
};

$scope.cardDestroyed = function(index) {
if (this.swipeCard.positive === true) {
$scope.$root.accepted++;
} else {
$scope.$root.rejected++;
}
$scope.cards.splice(index, 1);
};

Expand All @@ -66,9 +73,15 @@ angular.module('starter', ['ionic', 'ngTouch', 'ionic.contrib.ui.cards'])
}
})

.controller('CardCtrl', function($scope, $ionicSwipeCardDelegate) {
$scope.goAway = function() {
.controller('CardCtrl', function($scope, $ionicSwipeCardDelegate, $rootScope) {
$scope.accept = function () {
var card = $ionicSwipeCardDelegate.getSwipebleCard($scope);
$rootScope.accepted++;
card.swipe(true);
}
$scope.reject = function() {
var card = $ionicSwipeCardDelegate.getSwipebleCard($scope);
$rootScope.rejected++;
card.swipe();
};
});
44 changes: 25 additions & 19 deletions example/www/js/ionic.cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,37 @@
/**
* Swipe a card out programtically
*/
swipe: function() {
this.transitionOut();
swipe: function(positive) {
this.transitionOut(positive);
},

/**
* Fly the card out or animate back into resting position.
* Fly the card up or down.
*/
transitionOut: function() {
transitionOut: function(positive) {
var self = this;
if((positive === true) || (this.x > 0)) {
// Fly right
var rotateTo = (this.rotationAngle + (this.rotationDirection * 0.6)) || (Math.random() * -0.4);
var duration = this.rotationAngle ? 0.2 : 0.5;
this.el.style[TRANSITION] = '-webkit-transform ' + duration + 's ease-in-out';
this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(' + (window.innerWidth * 1.5) + 'px,' + this.y + 'px, 0) rotate(' + rotateTo + 'rad)';
this.onSwipe && this.onSwipe();

if(this.y < 0) {
this.el.style[TRANSITION] = '-webkit-transform 0.2s ease-in-out';
this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(' + this.x + ',' + (this.startY) + 'px, 0)';
self.positive = true;
// Trigger destroy after card has swiped out
setTimeout(function() {
self.el.style[TRANSITION] = 'none';
}, 200);
self.onDestroy && self.onDestroy(true);
}, duration * 1000);
} else {
// Fly out
// Fly left
var rotateTo = (this.rotationAngle + (this.rotationDirection * 0.6)) || (Math.random() * 0.4);
var duration = this.rotationAngle ? 0.2 : 0.5;
this.el.style[TRANSITION] = '-webkit-transform ' + duration + 's ease-in-out';
this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(' + this.x + ',' + (window.innerHeight * 1.5) + 'px, 0) rotate(' + rotateTo + 'rad)';
this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(' + (window.innerWidth * -1.5) + 'px,' + this.y + 'px, 0) rotate(' + rotateTo + 'rad)';
this.onSwipe && this.onSwipe();

self.positive = false;
// Trigger destroy after card has swiped out
setTimeout(function() {
self.onDestroy && self.onDestroy();
Expand All @@ -208,15 +215,15 @@
} else {
self._transformOriginLeft();
}
window.rAF(function() { self._doDragStart(e) });
window._rAF(function() { self._doDragStart(e) });
}, this.el);

ionic.onGesture('drag', function(e) {
window.rAF(function() { self._doDrag(e) });
window._rAF(function() { self._doDrag(e) });
}, this.el);

ionic.onGesture('dragend', function(e) {
window.rAF(function() { self._doDragEnd(e) });
window._rAF(function() { self._doDragEnd(e) });
}, this.el);
},

Expand All @@ -234,7 +241,7 @@
_doDragStart: function(e) {
var width = this.el.offsetWidth;
var point = window.innerWidth / 2 + this.rotationDirection * (width / 2)
var distance = Math.abs(point - e.gesture.touches[0].pageX);// - window.innerWidth/2);
var distance = Math.abs(point - e.gesture.touches[0].pageY);// - window.innerWidth/2);
console.log(distance);

this.touchDistance = distance * 10;
Expand All @@ -243,15 +250,15 @@
},

_doDrag: function(e) {
var o = e.gesture.deltaY / 3;
var o = e.gesture.deltaX / 3;

this.rotationAngle = Math.atan(o/this.touchDistance) * this.rotationDirection;

if(e.gesture.deltaY < 0) {
if(e.gesture.deltaX < 0) {
this.rotationAngle = 0;
}

this.y = this.startY + (e.gesture.deltaY * 0.4);
this.x = this.startX + (e.gesture.deltaX * 0.4);

this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(' + this.x + 'px, ' + this.y + 'px, 0) rotate(' + (this.rotationAngle || 0) + 'rad)';
},
Expand Down Expand Up @@ -311,7 +318,6 @@
controller: function($scope, $element) {
var swipeController = new SwipeableCardController({
});

$rootScope.$on('swipeCard.pop', function(isAnimated) {
swipeController.popCard(isAnimated);
});
Expand Down
18 changes: 0 additions & 18 deletions example/www/lib/css/ionic.min.css

This file was deleted.

Binary file removed example/www/lib/fonts/ionicons.ttf
Binary file not shown.
Binary file removed example/www/lib/fonts/ionicons.woff
Binary file not shown.
Loading