Skip to content

Instantly share code, notes, and snippets.

@mhartington
Created April 22, 2015 00:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhartington/c5107ccd9204b755442b to your computer and use it in GitHub Desktop.
Save mhartington/c5107ccd9204b755442b to your computer and use it in GitHub Desktop.
Dynamically allow ion-items dragging
angular.module('canDragDirective', [ionic])
.directive('isPurchased', function($timeout, $ionicListDelegate) {
return {
restrict: 'A',
link: function($scope, $element) {
$timeout(function() {
var elm = $element[0];
ionic.on('touch', function() {
// Simple way to check if the item is already purchased
if (elm.classList.contains('purchased')) {
// if it is, disable the drag
$ionicListDelegate.canSwipeItems(false);
} else {
// if not, allow the drag
$ionicListDelegate.canSwipeItems(true);
}
//console.log($ionicListDelegate.canSwipeItems());
}, elm);
});
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment