Skip to content

Commit

Permalink
move svDisabled to be on svRoot, not per element
Browse files Browse the repository at this point in the history
also fixes subtle bug
  • Loading branch information
mnzaki committed May 2, 2017
1 parent a7c5b4f commit f09c970
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/angular-sortable-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
}

var sortingInProgress;
var isDisabled = false;

var ROOTS_MAP = Object.create(null);
// window.ROOTS_MAP = ROOTS_MAP; // for debug purposes

Expand Down Expand Up @@ -56,6 +58,16 @@
return sortingInProgress;
};

if ($attrs.svDisabled) {
$scope.$watch($attrs.svDisabled, function(disabled) {
isDisabled = disabled === true;
});
}

this.isDisabled = function() {
return isDisabled;
};

if($attrs.svGrid){ // sv-grid determined explicite
isGrid = $attrs.svGrid === "true" ? true : $attrs.svGrid === "false" ? false : null;
if(isGrid === null)
Expand Down Expand Up @@ -361,12 +373,7 @@
handle.off('mousedown touchstart', onMousedown);
});

$attrs.$observe('svDisabled', function(disabled) {
disabled = $scope.$eval(disabled);
if (!disabled) handle.on('mousedown touchstart', onMousedown);
else handle.off('mousedown touchstart', onMousedown);
});

handle.on('mousedown touchstart', onMousedown);
$scope.$watch('$ctrl.handle', function(customHandle){
if(customHandle){
handle.off('mousedown touchstart', onMousedown);
Expand Down Expand Up @@ -397,7 +404,7 @@
function onMousedown(e){
touchFix(e);

if($controllers[1].sortingInProgress()) return;
if($controllers[1].isDisabled() || $controllers[1].sortingInProgress()) return;
if(e.button != 0 && e.type === 'mousedown') return;

moveExecuted = false;
Expand Down

0 comments on commit f09c970

Please sign in to comment.