diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bd2909..86db340 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +Version 0.0.17 - 2016/10/28 +================ + + * add disabled capability onto unique element + +Version 0.0.16 - 2016/10/27 +================ + + * add disabled capability + Version 0.0.15 - 2016/01/18 ================ diff --git a/README.md b/README.md index 8e1b683..a814202 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -angular-sortable-view v0.0.15 [![Bower version](https://badge.fury.io/bo/angular-sortable-view.svg)](http://badge.fury.io/bo/angular-sortable-view) +angular-sortable-view v0.0.17 [![Bower version](https://badge.fury.io/bo/angular-sortable-view.svg)](http://badge.fury.io/bo/angular-sortable-view) ================= Fully declarative (multi)sortable for AngularJS @@ -19,7 +19,7 @@ This library requires ***no dependencies whatsoever*** (except angular.js of cou The API is declarative. There are four directives (hooked on attributes) that need to be nested properly: - * `sv-root` - this is where all the logic is happening. If multiple lists should be connected with each other so that elements can be moved between them and they have a common ancestor, put this attribute on that element. If not and you still want the multi-sortable behaviour a value for that attribue must be provided. That value will be used as an identifier to connect those roots together. + * `sv-root` - this is where all the logic is happening. If multiple lists should be connected with each other so that elements can be moved between them and they have a common ancestor, put this attribute on that element. If not and you still want the multi-sortable behaviour a value for that attribue must be provided. That value will be used as an identifier to connect those roots together. Optionnally you can add `sv-disabled=boolean` to deactive dragging. **Optional attributes:** * `sv-on-sort` - The expression passed as a value of that attribute will be evaluated when elements order has changed after sorting. Several parameters can be injected there like: `sv-on-sort="foo($item, $partFrom, $partTo, $indexFrom, $indexTo)"` where: * `sv-part` - this attribute should be placed on an element that is a container for the `ngRepeat`'ed elements. Its value should be the same as the right hand side expression in `ng-repeat` attribute. - * `sv-element` - this attribute should be placed on the same element as `ng-repeat` attribute. Its (optional) value should be an expression that evaluates to the options object. + * `sv-element` - this attribute should be placed on the same element as `ng-repeat` attribute. Its (optional) value should be an expression that evaluates to the options object. Optionnally you can add `sv-disabled=boolean` to deactive dragging on this element. * `sv-handle` - this attribute is optional. If needed it can be placed on an element within the sortable element. This element will be the handle for sorting operations. * `sv-helper` - the element with this attribute will serve as a custom helper for sorting operations * `sv-placeholder` - the element with this attribute will serve as a custom placeholder for sorting operations diff --git a/bower.json b/bower.json index 8e50c47..668a983 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-sortable-view", - "version": "0.0.15", + "version": "0.0.17", "homepage": "http://kamilkp.github.io/angular-sortable-view/", "authors": [ "Kamil Pękala " diff --git a/package.json b/package.json index 8da6f09..ec294fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-sortable-view", - "version": "0.0.15", + "version": "0.0.17", "description": "Fully declarative (multi)sortable for AngularJS", "main": "./src/angular-sortable-view.js", "homepage": "http://kamilkp.github.io/angular-sortable-view", diff --git a/src/angular-sortable-view.js b/src/angular-sortable-view.js index 05694f0..1184c7a 100644 --- a/src/angular-sortable-view.js +++ b/src/angular-sortable-view.js @@ -51,6 +51,14 @@ var onStart = $parse($attrs.svOnStart); var onStop = $parse($attrs.svOnStop); + var disabled; + $scope.$watch($attrs.svDisabled, function() { + disabled = $scope.$eval($attrs.svDisabled) || false; + }); + + this.isDisabled = function() { + return disabled; + }; this.sortingInProgress = function(){ return sortingInProgress; @@ -353,6 +361,12 @@ return $scope.$index; } }; + + var elemDisabled; + $scope.$watch($attrs.svDisabled, function() { + elemDisabled = $scope.$eval($attrs.svDisabled) || false; + }); + $controllers[1].addToSortableElements(sortableElement); $scope.$on('$destroy', function(){ $controllers[1].removeFromSortableElements(sortableElement); @@ -386,14 +400,17 @@ var html = angular.element(document.documentElement); var moveExecuted; + var letsChanceToClick; function onMousedown(e){ touchFix(e); + if($controllers[1].isDisabled() || elemDisabled) return; if($controllers[1].sortingInProgress()) return; if(e.button != 0 && e.type === 'mousedown') return; moveExecuted = false; + letsChanceToClick = false; var opts = $parse($attrs.svElement)($scope); opts = angular.extend({}, { tolerance: 'pointer', @@ -466,6 +483,10 @@ // onMousemove(e); function onMousemove(e){ + if (!letsChanceToClick) { + letsChanceToClick = true; + return; + } touchFix(e); if(!moveExecuted){ $element.parent().prepend(clone); @@ -622,4 +643,4 @@ }; } -})(window, window.angular); \ No newline at end of file +})(window, window.angular);