Skip to content

add disable capability with sv-disabled #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
================

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
<ul>
Expand All @@ -46,7 +46,7 @@ The API is declarative. There are four directives (hooked on attributes) that ne
</ul>
</li>
* `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
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 22 additions & 1 deletion src/angular-sortable-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -466,6 +483,10 @@

// onMousemove(e);
function onMousemove(e){
if (!letsChanceToClick) {
letsChanceToClick = true;
return;
}
touchFix(e);
if(!moveExecuted){
$element.parent().prepend(clone);
Expand Down Expand Up @@ -622,4 +643,4 @@
};
}

})(window, window.angular);
})(window, window.angular);