Skip to content

Commit

Permalink
+ dev
Browse files Browse the repository at this point in the history
  • Loading branch information
RubaXa committed Sep 18, 2017
2 parents cc1eb94 + 5720a6d commit 5602256
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 37 deletions.
18 changes: 16 additions & 2 deletions Gruntfile.js
Expand Up @@ -39,7 +39,20 @@ module.exports = function (grunt) {
}
},

jquery: {}
jquery: {},

testcafe: {
test: {
options: {
files: ['test/e2e/index.js'],
browsers: ['chrome'],
startApp: {
command: 'npm run http-server'
},
skipJsErrors: true //https://github.com/RubaXa/Sortable/issues/1041
}
}
}
});


Expand Down Expand Up @@ -82,7 +95,8 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-version');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-testcafe');

grunt.registerTask('tests', ['jshint']);
grunt.registerTask('default', ['tests', 'version', 'uglify:dist']);
grunt.registerTask('default', ['tests', 'version', 'uglify:dist', 'testcafe']);
};
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -121,31 +121,31 @@ var sortable = new Sortable(el, {

// Element dragging ended
onEnd: function (/**Event*/evt) {
evt.oldIndex; // element's old index within parent
evt.newIndex; // element's new index within parent
var itemEl = evt.item; // dragged HTMLElement
evt.to; // target list
evt.from; // previous list
evt.oldIndex; // element's old index within old parent
evt.newIndex; // element's new index within new parent
},

// Element is dropped into the list from another list
onAdd: function (/**Event*/evt) {
var itemEl = evt.item; // dragged HTMLElement
evt.from; // previous list
// + indexes from onEnd
// same properties as onEnd
},

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

// Called by any change to the list (add / update / remove)
onSort: function (/**Event*/evt) {
// same properties as onUpdate
// same properties as onEnd
},

// Element is removed from the list into another list
onRemove: function (/**Event*/evt) {
// same properties as onUpdate
// same properties as onEnd
},

// Attempt to drag a filtered element
Expand Down
51 changes: 29 additions & 22 deletions Sortable.js
Expand Up @@ -73,7 +73,7 @@
supportDraggable = !!('draggable' in document.createElement('div')),
supportCssPointerEvents = (function (el) {
// false when IE11
if (!!navigator.userAgent.match(/Trident.*rv[ :]?11\./)) {
if (!!navigator.userAgent.match(/(?:Trident.*rv[ :]?11\.|msie)/i)) {
return false;
}
el = document.createElement('x');
Expand Down Expand Up @@ -326,6 +326,10 @@
return; // only left button or enabled
}

// cancel dnd if original target is content editable
if (originalTarget.isContentEditable) {
return;
}

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

Expand All @@ -344,7 +348,7 @@
// Check filter
if (typeof filter === 'function') {
if (filter.call(this, evt, target, this)) {
_dispatchEvent(_this, originalTarget, 'filter', target, el, startIndex);
_dispatchEvent(_this, originalTarget, 'filter', target, el, el, startIndex);
preventOnFilter && evt.preventDefault();
return; // cancel dnd
}
Expand All @@ -354,7 +358,7 @@
criteria = _closest(originalTarget, criteria.trim(), el);

if (criteria) {
_dispatchEvent(_this, criteria, 'filter', target, el, startIndex);
_dispatchEvent(_this, criteria, 'filter', target, el, el, startIndex);
return true;
}
});
Expand Down Expand Up @@ -411,7 +415,7 @@
_this._triggerDragStart(evt, touch);

// Drag start event
_dispatchEvent(_this, rootEl, 'choose', dragEl, rootEl, oldIndex);
_dispatchEvent(_this, rootEl, 'choose', dragEl, rootEl, rootEl, oldIndex);
};

// Disable "draggable"
Expand Down Expand Up @@ -502,7 +506,7 @@
Sortable.active = this;

// Drag start event
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex);
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, rootEl, oldIndex);
} else {
this._nulling();
}
Expand Down Expand Up @@ -915,21 +919,21 @@
_toggleClass(dragEl, this.options.chosenClass, false);

// Drag stop event
_dispatchEvent(this, rootEl, 'unchoose', dragEl, rootEl, oldIndex);
_dispatchEvent(this, rootEl, 'unchoose', dragEl, parentEl, rootEl, oldIndex);

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

if (newIndex >= 0) {
// Add event
_dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(null, parentEl, 'add', dragEl, parentEl, rootEl, oldIndex, newIndex);

// Remove event
_dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'remove', dragEl, parentEl, rootEl, oldIndex, newIndex);

// drag from one list and drop into another
_dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(null, parentEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
}
}
else {
Expand All @@ -939,8 +943,8 @@

if (newIndex >= 0) {
// drag & drop within the same list
_dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'update', dragEl, parentEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
}
}
}
Expand All @@ -951,7 +955,7 @@
newIndex = oldIndex;
}

_dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex);
_dispatchEvent(this, rootEl, 'end', dragEl, parentEl, rootEl, oldIndex, newIndex);

// Save sorting
this.save();
Expand Down Expand Up @@ -1256,7 +1260,7 @@



function _dispatchEvent(sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) {
function _dispatchEvent(sortable, rootEl, name, targetEl, toEl, fromEl, startIndex, newIndex) {
sortable = (sortable || rootEl[expando]);

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

evt.initEvent(name, true, true);

evt.to = rootEl;
evt.to = toEl || rootEl;
evt.from = fromEl || rootEl;
evt.item = targetEl || rootEl;
evt.clone = cloneEl;
Expand Down Expand Up @@ -1421,12 +1425,15 @@
}

function _clone(el) {
return $
? $(el).clone(true)[0]
: (Polymer && Polymer.dom
? Polymer.dom(el).cloneNode(true)
: el.cloneNode(true)
);
if (Polymer && Polymer.dom) {
return Polymer.dom(el).cloneNode(true);
}
else if ($) {
return $(el).clone(true)[0];
}
else {
return el.cloneNode(true);
}
}

function _saveInputCheckedState(root) {
Expand All @@ -1439,7 +1446,7 @@
}
}

// Fixed #973:
// Fixed #973:
_on(document, 'touchmove', function (evt) {
if (Sortable.active) {
evt.preventDefault();
Expand Down

0 comments on commit 5602256

Please sign in to comment.