Skip to content

Commit 83836d2

Browse files
No longer require pointer-events: none
1 parent 06df01f commit 83836d2

File tree

5 files changed

+30
-51
lines changed

5 files changed

+30
-51
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Use the dnd-draggable directive to make your element draggable
5656
* `dndDraggingSource` This class will be added to the element after the drag operation was started, meaning it only affects the original element that is still at it's source position, and not the "element" that the user is dragging with his mouse pointer
5757

5858
### dnd-list directive
59-
Use the dnd-list attribute to make your list element a dropzone. Usually you will add a single li element as child with the ng-repeat directive. If you don't do that, we will not be able to position the dropped element correctly. If you want your list to be sortable, also add the dnd-draggable directive to your li element(s). Both the dnd-list and it's direct children must have position: relative CSS style, otherwise the positioning algorithm will not be able to determine the correct placeholder position in all browsers. If you use nested dnd-lists, make sure that all elements excecpt for the dnd-lists and it's direct children have the pointer-events: none CSS style.
59+
Use the dnd-list attribute to make your list element a dropzone. Usually you will add a single li element as child with the ng-repeat directive. If you don't do that, we will not be able to position the dropped element correctly. If you want your list to be sortable, also add the dnd-draggable directive to your li element(s). Both the dnd-list and it's direct children must have position: relative CSS style, otherwise the positioning algorithm will not be able to determine the correct placeholder position in all browsers.
6060

6161
**Attributes**
6262
* `dnd-list` Required attribute. The value has to be the array in which the data of the dropped element should be inserted.
@@ -68,20 +68,16 @@ Use the dnd-list attribute to make your list element a dropzone. Usually you wil
6868
* `dndDragover` This class will be added to the list while an element is being dragged over the list.
6969

7070
### Required CSS styles
71-
* `pointer-events: none` With nested lists it's very important that **only the dnd-list and it's children** react to mouse events.
72-
* `position: relative` Both the dnd-list and it's children require this, so that the directive can determine the mouse position relative to the list and thus calculate the correct drop position.
71+
Both the dnd-list and it's children require relative positioning, so that the directive can determine the mouse position relative to the list and thus calculate the correct drop position.
7372

7473
<pre>
75-
ul[dnd-list] * {
76-
pointer-events: none;
77-
}
78-
7974
ul[dnd-list], ul[dnd-list] > li {
80-
pointer-events: auto;
8175
position: relative;
8276
}
8377
</pre>
8478

79+
*Since 1.2.0 `pointer-events: none` is no longer required*
80+
8581
### Example
8682

8783
Take a look at the code in the [Simple Lists](http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple) example

angular-drag-and-drop-lists.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ angular.module('dndLists', [])
156156
* the dropped element correctly. If you want your list to be sortable, also add the dnd-draggable
157157
* directive to your li element(s). Both the dnd-list and it's direct children must have position: relative
158158
* CSS style, otherwise the positioning algorithm will not be able to determine the correct placeholder
159-
* position in all browsers. If you use nested dnd-lists, make sure that all elements excecpt for the
160-
* dnd-lists and it's direct children have the pointer-events: none CSS style.
159+
* position in all browsers.
161160
*
162161
* Attributes:
163162
* - dnd-list Required attribute. The value has to be the array in which the data of the
@@ -210,17 +209,25 @@ angular.module('dndLists', [])
210209
element.append(placeholder);
211210
}
212211

213-
if (event.target.parentNode === listNode && event.target !== placeholderNode) {
214-
// The element is being dragged over one of our child nodes. Now we have
215-
// to decide at which position to show the placeholder: If the mouse pointer
216-
// is in the upper half of the child element, we place it before the child
217-
// element, otherwise below it. In Chrome we can just use offsetY, but in
218-
// Firefox we have to use layerY, which only works if the child element has
219-
// position relative. In IE this branch is never reached because the dragover
220-
// event is only fired for the listNode, not for it's children
221-
var beforeOrAfter = (event.offsetY || event.layerY) < event.target.offsetHeight / 2;
222-
listNode.insertBefore(placeholderNode, beforeOrAfter ? event.target : event.target.nextSibling);
223-
} else if (event.target === listNode) {
212+
if (event.target !== listNode) {
213+
// Try to find the node direct directly below the list node.
214+
var listItemNode = event.target;
215+
while (listItemNode.parentNode !== listNode && listItemNode.parentNode) {
216+
listItemNode = listItemNode.parentNode;
217+
}
218+
219+
if (listItemNode.parentNode === listNode && listItemNode !== placeholderNode) {
220+
// The element is being dragged over one of our child nodes. Now we have
221+
// to decide at which position to show the placeholder: If the mouse pointer
222+
// is in the upper half of the child element, we place it before the child
223+
// element, otherwise below it. In Chrome we can just use offsetY, but in
224+
// Firefox we have to use layerY, which only works if the child element has
225+
// position relative. In IE this branch is never reached because the dragover
226+
// event is only fired for the listNode, not for it's children
227+
var beforeOrAfter = (event.offsetY || event.layerY) < listItemNode.offsetHeight / 2;
228+
listNode.insertBefore(placeholderNode, beforeOrAfter ? listItemNode : listItemNode.nextSibling);
229+
}
230+
} else {
224231
// This branch is reached when we are dragging directly over the list element.
225232
// Usually we wouldn't need to do anything here, but the IE does not fire it's
226233
// events for the child element, only for the list directly. Therefore we repeat

demo/nested/nested.css

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
/***************************** Required styles *****************************/
22

3-
/**
4-
* With nested lists it's very important that only the droplist and the
5-
* draggable elements react to mouse events. This can be achieved as follows:
6-
*/
7-
ul[dnd-list] * {
8-
pointer-events: none;
9-
}
10-
113
/**
124
* For the correct positioning of the placeholder element, the dnd-list and
135
* it's children must have position: relative
146
*/
15-
ul[dnd-list], ul[dnd-list] > li {
16-
pointer-events: auto;
7+
.nestedDemo ul[dnd-list],
8+
.nestedDemo ul[dnd-list] > li {
179
position: relative;
1810
}
1911

demo/simple/simple.css

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
/**
2-
* With nested lists it's very important that only the droplist and the
3-
* draggable elements react to mouse events. This can be achieved as follows:
4-
*/
5-
ul[dnd-list] * {
6-
pointer-events: none;
7-
}
8-
91
/**
102
* For the correct positioning of the placeholder element, the dnd-list and
113
* it's children must have position: relative
124
*/
13-
ul[dnd-list], ul[dnd-list] > li {
14-
pointer-events: auto;
5+
.simpleDemo ul[dnd-list],
6+
.simpleDemo ul[dnd-list] > li {
157
position: relative;
168
}
179

demo/types/types.css

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
/**
2-
* With nested lists it's very important that only the droplist and the
3-
* draggable elements react to mouse events. This can be achieved as follows:
4-
*/
5-
ul[dnd-list] * {
6-
pointer-events: none;
7-
}
8-
91
/**
102
* For the correct positioning of the placeholder element, the dnd-list and
113
* it's children must have position: relative
124
*/
13-
ul[dnd-list], ul[dnd-list] > li {
14-
pointer-events: auto;
5+
.typesDemo ul[dnd-list],
6+
.typesDemo ul[dnd-list] > li {
157
position: relative;
168
}
179

0 commit comments

Comments
 (0)