From 100d50d0377af63ac62e69dcde7e382097fc9971 Mon Sep 17 00:00:00 2001 From: David Kamphausen Date: Thu, 17 Dec 2015 08:35:23 +0100 Subject: [PATCH] re-indented @dmackermans pr:Add sv-disabled attribute (#33) --- src/angular-sortable-view.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/angular-sortable-view.js b/src/angular-sortable-view.js index aadbbb9..80bf6ca 100644 --- a/src/angular-sortable-view.js +++ b/src/angular-sortable-view.js @@ -39,8 +39,15 @@ var $original; // original element var $target; // last best candidate var isGrid = false; + var isDisabled = false; var onSort = $parse($attrs.svOnSort); + + // not sure if this is efficient? + $scope.$watch($parse($attrs.svDisabled), function(newVal, oldVal) { + isDisabled = newVal; + }); + // ----- hack due to https://github.com/angular/angular.js/issues/8044 $attrs.svOnStart = $attrs.$$element[0].attributes['sv-on-start']; $attrs.svOnStart = $attrs.svOnStart && $attrs.svOnStart.value; @@ -56,6 +63,9 @@ return sortingInProgress; }; + this.sortingDisabled = function() { + return isDisabled; + }; if($attrs.svGrid){ // sv-grid determined explicite isGrid = $attrs.svGrid === "true" ? true : $attrs.svGrid === "false" ? false : null; if(isGrid === null) @@ -391,6 +401,10 @@ touchFix(e); if($controllers[1].sortingInProgress()) return; + + // do nothing if sorting is disabled + if ($controllers[1].sortingDisabled()) return; + if(e.button != 0 && e.type === 'mousedown') return; moveExecuted = false;