Skip to content

Commit 3591fbb

Browse files
Merge pull request marceljuenemann#8 from marceljuenemann/development
Release version 1.0.1
2 parents d863b4c + de921fc commit 3591fbb

12 files changed

+294
-11
lines changed

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 1.0.1 (2014-08-31)
2+
3+
## Bug Fixes
4+
5+
- **jQuery compatibility**: jQuery wraps browser events in event.originalEvent
6+
7+
## Features
8+
9+
- **dnd-disable-if attribute**: allows to dynamically disable the drag and drop functionality
10+
- **dnd-type and dnd-allowed-types**: allows to restrict an item to specifc lists depending on it's type
11+
12+
## Tested browsers
13+
14+
- Chrome 34 (Ubuntu)
15+
- Chrome 37 (Mac)
16+
- Chrome 37 (Win7)
17+
- Firefox 28 (Win7)
18+
- Firefox 31 (Ubuntu)
19+
- Safari 7.0.6 (Mac)
20+
- Internet Explorer 11 (IE9 & 10 in compatibility mode)
21+
22+
# 1.0.0 (2014-04-11)
23+
24+
Initial release
25+
26+
# Release checklist
27+
28+
- Bump versions
29+
- bower.json
30+
- package.json
31+
- JS files
32+
- Minify (and test)
33+
- Test different OS & browsers (npm start)
34+
- Update README and CHANGELOG
35+
- Merge to master
36+
- Tag release
37+
- Merge to gh-pages

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Angular directives that allow you to build sortable lists with the native HTML5
55
## Demo
66
* [Nested Lists](http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/nested)
77
* [Simple Lists](http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple)
8+
* [Typed Lists](http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/types)
89

910
## Why another drag & drop library?
1011
There are tons of other drag & drop libraries out there, but none of them met my three requirements:
@@ -15,18 +16,17 @@ There are tons of other drag & drop libraries out there, but none of them met my
1516

1617
If this doesn't fit your requirements, check out one of the other awesome drag & drop libraries:
1718

18-
* [angular-ui-tree](https://github.com/JimLiu/angular-ui-tree): Very similar to this library, but does not use the HTML5 API. Therefore you need to write some more markup and to see what you are dragging it will create another DOM node that you have to style.
19+
* [angular-ui-tree](https://github.com/JimLiu/angular-ui-tree): Very similar to this library, but does not use the HTML5 API. Therefore you need to write some more markup to see what you are dragging and it will create another DOM node that you have to style. However, if you plan to support touch devices this is probably your best choice.
1920
* [angular-dragdrop](https://github.com/ganarajpr/angular-dragdrop): One of many libraries with the same name. This one uses the HTML5 API, but if you want to build (nested) sortable lists, you're on your own, because it does not calculate the correct element position for you.
2021
* [more...](https://www.google.de/search?q=angular+drag+and+drop)
2122

2223

2324
## Supported browsers
2425

25-
Tested in recent versions of
26-
* Chrome
27-
* Firefox
28-
* Safari
29-
* IE >= 9
26+
Internet Explorer 8 or lower is *not supported*, but all modern browsers are (see changelog for tested versions).
27+
28+
Note that *touch devices* are *not supported*, because the HTML5 drag & drop standard doesn't cover those.
29+
3030

3131
## Usage
3232

@@ -48,6 +48,8 @@ Use the dnd-draggable directive to make your element draggable
4848
* HTML5 also specifies the `link` option, but this library does not actively support it yet, so use it at your own risk.
4949
* `dnd-moved` Callback that is invoked when the element was moved. Usually you will remove your element from the original list in this callback, since the directive is not doing that for you automatically.
5050
* `dnd-copied` Same as dnd-moved, just that it is called when the element was copied instead of moved.
51+
* `dnd-type` Use this attribute if you have different kinds of items in your application and you want to limit which items can be dropped into which lists. Combine with dnd-allowed-types on the dnd-list(s). This attribute should evaluate to a string, although this restriction is not enforced (at the moment).
52+
* `dnd-disable-if` You can use this attribute to dynamically disable the draggability of the element. This is useful if you have certain list items that you don't want to be draggable, or if you want to disable drag & drop completely without having two different code branches (e.g. only allow for admins). *Note*: If your element is not draggable, the user is probably able to select text or images inside of it. Since a selection is always draggable, this breaks your UI. You most likely want to disable user selection via CSS (see [user-select](http://stackoverflow.com/a/4407335)).
5153

5254
**CSS classes**
5355
* `dndDragging` This class will be added to the element while the element is being dragged. It will affect both the element you see while dragging and the source element that stays at it's position. Do not try to hide the source element with this class, because that will abort the drag operation.
@@ -58,6 +60,8 @@ Use the dnd-list attribute to make your list element a dropzone. Usually you wil
5860

5961
**Attributes**
6062
* `dnd-list` Required attribute. The value has to be the array in which the data of the dropped element should be inserted.
63+
* `dnd-allowed-types` Optional array of allowed item types. When used, only items that had a matching dnd-type attribute will be dropable.
64+
* `dnd-disable-if` Optional boolean expresssion. When it evaluates to true, no dropping into the list is possible. Note that this also disables rearranging items inside the list.
6165

6266
**CSS classes**
6367
* `dndPlaceholder` When an element is dragged over the list, a new placeholder child element will be added. This element is of type li and has the class dndPlaceholder set.

angular-drag-and-drop-lists.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* angular-drag-and-drop-lists v1.0.0
2+
* angular-drag-and-drop-lists v1.0.1
33
*
44
* Copyright (c) 2014 Marcel Juenemann mail@marcel-junemann.de
55
* https://github.com/marceljuenemann/angular-drag-and-drop-lists
@@ -32,6 +32,17 @@ angular.module('dndLists', [])
3232
* is not doing that for you automatically.
3333
* - dnd-copied Same as dnd-moved, just that it is called when the element was copied
3434
* instead of moved.
35+
* - dnd-type Use this attribute if you have different kinds of items in your application
36+
* and you want to limit which items can be dropped into which lists. Combine with
37+
* dnd-allowed-types on the dnd-list(s). This attribute should evaluate to a string,
38+
* although this restriction is not enforced (at the moment).
39+
* - dnd-disable-if You can use this attribute to dynamically disable the draggability of the element.
40+
* This is useful if you have certain list items that you don't want to be draggable,
41+
* or if you want to disable drag & drop completely without having two different
42+
* code branches (e.g. only allow for admins). **Note**: If your element is not
43+
* draggable, the user is probably able to select text or images inside of it. Since
44+
* a selection is always draggable, this breaks your UI. You most likely want to
45+
* disable user selection via CSS (see user-select).
3546
*
3647
* CSS classes:
3748
* - dndDragging This class will be added to the element while the element is being dragged.
@@ -48,11 +59,20 @@ angular.module('dndLists', [])
4859
// Set the HTML5 draggable attribute on the element
4960
element.attr("draggable", "true");
5061

62+
// If the dnd-disable-if attribute is set, we have to watch that
63+
if (attr.dndDisableIf) {
64+
scope.$watch(attr.dndDisableIf, function(disabled) {
65+
element.attr("draggable", !disabled);
66+
});
67+
}
68+
5169
/**
5270
* When the drag operation is started we have to prepare the dataTransfer object,
5371
* which is the primary way we communicate with the target element
5472
*/
5573
element.on('dragstart', function(event) {
74+
event = event.originalEvent || event;
75+
5676
// Serialize the data associated with this element. IE only supports the Text drag type
5777
event.dataTransfer.setData("Text", angular.toJson(scope.$eval(attr.dndDraggable)));
5878

@@ -67,6 +87,10 @@ angular.module('dndLists', [])
6787
dndDropEffectWorkaround.dropEffect = "none";
6888
dndDragTypeWorkaround.isDragging = true;
6989

90+
// Save type of item in global state. Usually, this would go into the dataTransfer
91+
// typename, but we have to use "Text" there to support IE
92+
dndDragTypeWorkaround.dragType = attr.dndType ? scope.$eval(attr.dndType) : undefined;
93+
7094
event.stopPropagation();
7195
});
7296

@@ -76,6 +100,8 @@ angular.module('dndLists', [])
76100
* we will invoke the callbacks specified with the dnd-moved or dnd-copied attribute.
77101
*/
78102
element.on('dragend', function(event) {
103+
event = event.originalEvent || event;
104+
79105
// If the dropEffect is none it means that the drag action was aborted or
80106
// that the browser does not support this field. In either case we use
81107
// the fallback which was initialized to none
@@ -107,6 +133,8 @@ angular.module('dndLists', [])
107133
* specified with the dnd-selected attribute.
108134
*/
109135
element.on('click', function(event) {
136+
event = event.originalEvent || event;
137+
110138
scope.$apply(function() {
111139
$parse(attr.dndSelected)(scope);
112140
});
@@ -118,7 +146,7 @@ angular.module('dndLists', [])
118146
* Workaround to make element draggable in IE9
119147
*/
120148
element.on('selectstart', function() {
121-
this.dragDrop();
149+
if (this.dragDrop) this.dragDrop();
122150
return false;
123151
});
124152
};
@@ -136,6 +164,10 @@ angular.module('dndLists', [])
136164
* Attributes:
137165
* - dnd-list Required attribute. The value has to be the array in which the data of the
138166
* dropped element should be inserted.
167+
* - dnd-allowed-types Optional array of allowed item types. When used, only items that had a matching
168+
* dnd-type attribute will be dropable.
169+
* - dnd-disable-if Optional boolean expresssion. When it evaluates to true, no dropping into
170+
* the list is possible. Note that this also disables rearranging items inside the list.
139171
*
140172
* CSS classes:
141173
* - dndPlaceholder When an element is dragged over the list, a new placeholder child element will be
@@ -156,11 +188,24 @@ angular.module('dndLists', [])
156188
* is being dragged over our list, or over an child element.
157189
*/
158190
element.on('dragover', function(event) {
191+
event = event.originalEvent || event;
192+
159193
// Disallow drop if it comes from an external source or is not text.
160194
// Usually we would use a custom drag type for this, but IE doesn't support that.
161195
if (!dndDragTypeWorkaround.isDragging) return true;
162196
if (!isDropAllowed(event.dataTransfer.types)) return true;
163197

198+
// Now check the dnd-allowed-types against the type of the incoming element
199+
if (attr.dndAllowedTypes) {
200+
var allowed = scope.$eval(attr.dndAllowedTypes);
201+
if (angular.isArray(allowed) && allowed.indexOf(dndDragTypeWorkaround.dragType) === -1) {
202+
return true;
203+
}
204+
}
205+
206+
// Check whether droping is disabled completely
207+
if (attr.dndDisableIf && scope.$eval(attr.dndDisableIf)) return true;
208+
164209
// First of all, make sure that the placeholder is shown
165210
// This is especially important if the list is empty
166211
if (placeholderNode.parentNode != listNode) {
@@ -220,6 +265,8 @@ angular.module('dndLists', [])
220265
* one child element per array element.
221266
*/
222267
element.on('drop', function(event) {
268+
event = event.originalEvent || event;
269+
223270
// Unserialize the data that was serialized in dragstart. According to the HTML5 specs,
224271
// the "Text" drag type will be converted to text/plain, but IE does not do that.
225272
var transferredObject = JSON.parse(event.dataTransfer.getData("Text")
@@ -260,6 +307,8 @@ angular.module('dndLists', [])
260307
* is still dragging over the list. If you know a better way of doing this, please tell me!
261308
*/
262309
element.on('dragleave', function(event) {
310+
event = event.originalEvent || event;
311+
263312
element.removeClass("dndDragover");
264313
$timeout(function() {
265314
if (!element.hasClass("dndDragover")) {

angular-drag-and-drop-lists.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-drag-and-drop-lists",
33
"main": "angular-drag-and-drop-lists.js",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"homepage": "https://github.com/marceljuenemann/angular-drag-and-drop-lists",
66
"authors": [
77
"Marcel Juenemann <mail@marcel-juenemann.de>"

demo/framework/demo-framework.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ angular.module("demo", ["ngRoute", "dndLists"])
99
templateUrl: 'nested/nested-frame.html',
1010
controller: 'NestedListsDemoController'
1111
})
12+
.when('/types', {
13+
templateUrl: 'types/types-frame.html',
14+
controller: 'TypesDemoController'
15+
})
1216
.otherwise({redirectTo: '/nested'});
1317
})
1418

@@ -21,6 +25,7 @@ angular.module("demo", ["ngRoute", "dndLists"])
2125
scope.options = [
2226
{label: "Nested Containers", href: "#/nested"},
2327
{label: "Simple Demo", href: "#/simple"},
28+
{label: "Item Types", href: "#/types"},
2429
{label: "Github", href: "https://github.com/marceljuenemann/angular-drag-and-drop-lists"}
2530
];
2631

0 commit comments

Comments
 (0)