Skip to content

Commit 5602256

Browse files
committed
+ dev
2 parents cc1eb94 + 5720a6d commit 5602256

File tree

7 files changed

+98
-37
lines changed

7 files changed

+98
-37
lines changed

Gruntfile.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,20 @@ module.exports = function (grunt) {
3939
}
4040
},
4141

42-
jquery: {}
42+
jquery: {},
43+
44+
testcafe: {
45+
test: {
46+
options: {
47+
files: ['test/e2e/index.js'],
48+
browsers: ['chrome'],
49+
startApp: {
50+
command: 'npm run http-server'
51+
},
52+
skipJsErrors: true //https://github.com/RubaXa/Sortable/issues/1041
53+
}
54+
}
55+
}
4356
});
4457

4558

@@ -82,7 +95,8 @@ module.exports = function (grunt) {
8295
grunt.loadNpmTasks('grunt-version');
8396
grunt.loadNpmTasks('grunt-contrib-jshint');
8497
grunt.loadNpmTasks('grunt-contrib-uglify');
98+
grunt.loadNpmTasks('grunt-testcafe');
8599

86100
grunt.registerTask('tests', ['jshint']);
87-
grunt.registerTask('default', ['tests', 'version', 'uglify:dist']);
101+
grunt.registerTask('default', ['tests', 'version', 'uglify:dist', 'testcafe']);
88102
};

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,31 @@ var sortable = new Sortable(el, {
121121

122122
// Element dragging ended
123123
onEnd: function (/**Event*/evt) {
124-
evt.oldIndex; // element's old index within parent
125-
evt.newIndex; // element's new index within parent
124+
var itemEl = evt.item; // dragged HTMLElement
125+
evt.to; // target list
126+
evt.from; // previous list
127+
evt.oldIndex; // element's old index within old parent
128+
evt.newIndex; // element's new index within new parent
126129
},
127130

128131
// Element is dropped into the list from another list
129132
onAdd: function (/**Event*/evt) {
130-
var itemEl = evt.item; // dragged HTMLElement
131-
evt.from; // previous list
132-
// + indexes from onEnd
133+
// same properties as onEnd
133134
},
134135

135136
// Changed sorting within list
136137
onUpdate: function (/**Event*/evt) {
137-
var itemEl = evt.item; // dragged HTMLElement
138-
// + indexes from onEnd
138+
// same properties as onEnd
139139
},
140140

141141
// Called by any change to the list (add / update / remove)
142142
onSort: function (/**Event*/evt) {
143-
// same properties as onUpdate
143+
// same properties as onEnd
144144
},
145145

146146
// Element is removed from the list into another list
147147
onRemove: function (/**Event*/evt) {
148-
// same properties as onUpdate
148+
// same properties as onEnd
149149
},
150150

151151
// Attempt to drag a filtered element

Sortable.js

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
supportDraggable = !!('draggable' in document.createElement('div')),
7474
supportCssPointerEvents = (function (el) {
7575
// false when IE11
76-
if (!!navigator.userAgent.match(/Trident.*rv[ :]?11\./)) {
76+
if (!!navigator.userAgent.match(/(?:Trident.*rv[ :]?11\.|msie)/i)) {
7777
return false;
7878
}
7979
el = document.createElement('x');
@@ -326,6 +326,10 @@
326326
return; // only left button or enabled
327327
}
328328

329+
// cancel dnd if original target is content editable
330+
if (originalTarget.isContentEditable) {
331+
return;
332+
}
329333

330334
target = _closest(target, options.draggable, el);
331335

@@ -344,7 +348,7 @@
344348
// Check filter
345349
if (typeof filter === 'function') {
346350
if (filter.call(this, evt, target, this)) {
347-
_dispatchEvent(_this, originalTarget, 'filter', target, el, startIndex);
351+
_dispatchEvent(_this, originalTarget, 'filter', target, el, el, startIndex);
348352
preventOnFilter && evt.preventDefault();
349353
return; // cancel dnd
350354
}
@@ -354,7 +358,7 @@
354358
criteria = _closest(originalTarget, criteria.trim(), el);
355359

356360
if (criteria) {
357-
_dispatchEvent(_this, criteria, 'filter', target, el, startIndex);
361+
_dispatchEvent(_this, criteria, 'filter', target, el, el, startIndex);
358362
return true;
359363
}
360364
});
@@ -411,7 +415,7 @@
411415
_this._triggerDragStart(evt, touch);
412416

413417
// Drag start event
414-
_dispatchEvent(_this, rootEl, 'choose', dragEl, rootEl, oldIndex);
418+
_dispatchEvent(_this, rootEl, 'choose', dragEl, rootEl, rootEl, oldIndex);
415419
};
416420

417421
// Disable "draggable"
@@ -502,7 +506,7 @@
502506
Sortable.active = this;
503507

504508
// Drag start event
505-
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex);
509+
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, rootEl, oldIndex);
506510
} else {
507511
this._nulling();
508512
}
@@ -915,21 +919,21 @@
915919
_toggleClass(dragEl, this.options.chosenClass, false);
916920

917921
// Drag stop event
918-
_dispatchEvent(this, rootEl, 'unchoose', dragEl, rootEl, oldIndex);
922+
_dispatchEvent(this, rootEl, 'unchoose', dragEl, parentEl, rootEl, oldIndex);
919923

920924
if (rootEl !== parentEl) {
921925
newIndex = _index(dragEl, options.draggable);
922926

923927
if (newIndex >= 0) {
924928
// Add event
925-
_dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex);
929+
_dispatchEvent(null, parentEl, 'add', dragEl, parentEl, rootEl, oldIndex, newIndex);
926930

927931
// Remove event
928-
_dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex);
932+
_dispatchEvent(this, rootEl, 'remove', dragEl, parentEl, rootEl, oldIndex, newIndex);
929933

930934
// drag from one list and drop into another
931-
_dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
932-
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
935+
_dispatchEvent(null, parentEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
936+
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
933937
}
934938
}
935939
else {
@@ -939,8 +943,8 @@
939943

940944
if (newIndex >= 0) {
941945
// drag & drop within the same list
942-
_dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex);
943-
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
946+
_dispatchEvent(this, rootEl, 'update', dragEl, parentEl, rootEl, oldIndex, newIndex);
947+
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
944948
}
945949
}
946950
}
@@ -951,7 +955,7 @@
951955
newIndex = oldIndex;
952956
}
953957

954-
_dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex);
958+
_dispatchEvent(this, rootEl, 'end', dragEl, parentEl, rootEl, oldIndex, newIndex);
955959

956960
// Save sorting
957961
this.save();
@@ -1256,7 +1260,7 @@
12561260

12571261

12581262

1259-
function _dispatchEvent(sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) {
1263+
function _dispatchEvent(sortable, rootEl, name, targetEl, toEl, fromEl, startIndex, newIndex) {
12601264
sortable = (sortable || rootEl[expando]);
12611265

12621266
var evt = document.createEvent('Event'),
@@ -1265,7 +1269,7 @@
12651269

12661270
evt.initEvent(name, true, true);
12671271

1268-
evt.to = rootEl;
1272+
evt.to = toEl || rootEl;
12691273
evt.from = fromEl || rootEl;
12701274
evt.item = targetEl || rootEl;
12711275
evt.clone = cloneEl;
@@ -1421,12 +1425,15 @@
14211425
}
14221426

14231427
function _clone(el) {
1424-
return $
1425-
? $(el).clone(true)[0]
1426-
: (Polymer && Polymer.dom
1427-
? Polymer.dom(el).cloneNode(true)
1428-
: el.cloneNode(true)
1429-
);
1428+
if (Polymer && Polymer.dom) {
1429+
return Polymer.dom(el).cloneNode(true);
1430+
}
1431+
else if ($) {
1432+
return $(el).clone(true)[0];
1433+
}
1434+
else {
1435+
return el.cloneNode(true);
1436+
}
14301437
}
14311438

14321439
function _saveInputCheckedState(root) {
@@ -1439,7 +1446,7 @@
14391446
}
14401447
}
14411448

1442-
// Fixed #973:
1449+
// Fixed #973:
14431450
_on(document, 'touchmove', function (evt) {
14441451
if (Sortable.active) {
14451452
evt.preventDefault();

0 commit comments

Comments
 (0)