Browse Source

* support group.put for touch

pull/168/head
RubaXa 10 years ago
parent
commit
3e32753867
  1. 46
      Sortable.js

46
Sortable.js

@ -104,7 +104,8 @@
setData: function (dataTransfer, dragEl) { setData: function (dataTransfer, dragEl) {
dataTransfer.setData('Text', dragEl.textContent); dataTransfer.setData('Text', dragEl.textContent);
} }
}; },
group;
// Set default options // Set default options
@ -116,11 +117,12 @@
if (!options.group.name) { if (!options.group.name) {
options.group = { name: options.group }; options.group = { name: options.group };
} }
group = options.group;
['pull', 'put'].forEach(function (key) { ['pull', 'put'].forEach(function (key) {
if (!(key in options.group)) { if (!(key in group)) {
options.group[key] = true; group[key] = true;
} }
}); });
@ -133,7 +135,7 @@
// Export group name // Export group name
el[expando] = options.group.name; el[expando] = group.name + ' ' + (group.put.join ? group.put.join(' ') : '');
// Bind all private methods // Bind all private methods
@ -249,8 +251,8 @@
_on(document, 'touchend', this._onDrop); _on(document, 'touchend', this._onDrop);
_on(document, 'touchcancel', this._onDrop); _on(document, 'touchcancel', this._onDrop);
_on(dragEl, 'dragend', this);
_on(rootEl, 'dragstart', this._onDragStart); _on(rootEl, 'dragstart', this._onDragStart);
_on(rootEl, 'dragend', this._onDrop);
_on(document, 'dragover', this); _on(document, 'dragover', this);
@ -282,29 +284,19 @@
_css(ghostEl, 'display', 'none'); _css(ghostEl, 'display', 'none');
var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY), var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY),
parent = target, parent = target.parentNode,
groupName = this.options.group.name, groupName = this.options.group.name,
i = touchDragOverListeners.length; i = touchDragOverListeners.length;
if (parent) { if (parent && (' ' + parent[expando] + ' ').indexOf(groupName) > -1) {
do { while (i--) {
if (parent[expando] === groupName) { touchDragOverListeners[i]({
while (i--) { clientX: touchEvt.clientX,
touchDragOverListeners[i]({ clientY: touchEvt.clientY,
clientX: touchEvt.clientX, target: target,
clientY: touchEvt.clientY, rootEl: parent
target: target, });
rootEl: parent
});
}
break;
}
target = parent; // store last element
} }
/* jshint boss:true */
while (parent = parent.parentNode);
} }
_css(ghostEl, 'display', ''); _css(ghostEl, 'display', '');
@ -579,7 +571,6 @@
_off(document, 'drop', this); _off(document, 'drop', this);
_off(document, 'dragover', this); _off(document, 'dragover', this);
_off(el, 'dragend', this._onDrop);
_off(el, 'dragstart', this._onDragStart); _off(el, 'dragstart', this._onDragStart);
this._offUpEvents(); this._offUpEvents();
@ -591,8 +582,11 @@
ghostEl && ghostEl.parentNode.removeChild(ghostEl); ghostEl && ghostEl.parentNode.removeChild(ghostEl);
if (dragEl) { if (dragEl) {
_off(dragEl, 'dragend', this);
// get the index of the dragged element within its parent // get the index of the dragged element within its parent
var newIndex = _index(dragEl); var newIndex = _index(dragEl);
_disableDraggable(dragEl); _disableDraggable(dragEl);
_toggleClass(dragEl, this.options.ghostClass, false); _toggleClass(dragEl, this.options.ghostClass, false);
@ -647,7 +641,7 @@
this._onDrag(evt); this._onDrag(evt);
_globalDragOver(evt); _globalDragOver(evt);
} }
else if (type === 'drop') { else if (type === 'drop' || type === 'dragend') {
this._onDrop(evt); this._onDrop(evt);
} }
}, },

Loading…
Cancel
Save