Browse Source

+ support IE9

old-browser
RubaXa 10 years ago
parent
commit
c9051c24e1
  1. 37
      Sortable.js
  2. 2
      Sortable.min.js

37
Sortable.js

@ -48,7 +48,9 @@
win = window, win = window,
document = win.document, document = win.document,
parseInt = win.parseInt, parseInt = win.parseInt,
supportIEdnd = !!document.createElement('div').dragDrop,
supportDraggable = !!('draggable' in document.createElement('div')),
_silent = false, _silent = false,
@ -154,7 +156,6 @@
// Bind events // Bind events
_on(el, 'mousedown', this._onTapStart); _on(el, 'mousedown', this._onTapStart);
_on(el, 'touchstart', this._onTapStart); _on(el, 'touchstart', this._onTapStart);
supportIEdnd && _on(el, 'selectstart', this._onTapStart);
_on(el, 'dragover', this._onDragOver); _on(el, 'dragover', this._onDragOver);
_on(el, 'dragenter', this._onDragOver); _on(el, 'dragenter', this._onDragOver);
@ -229,9 +230,6 @@
// Prepare `dragstart` // Prepare `dragstart`
if (target && !dragEl && (target.parentNode === el)) { if (target && !dragEl && (target.parentNode === el)) {
// IE 9 Support
(type === 'selectstart') && target.dragDrop();
tapEvt = evt; tapEvt = evt;
rootEl = this.el; rootEl = this.el;
@ -254,7 +252,7 @@
clientY: touch.clientY clientY: touch.clientY
}; };
this._onDragStart(tapEvt, true); this._onDragStart(tapEvt, 'touch');
evt.preventDefault(); evt.preventDefault();
} }
@ -267,6 +265,10 @@
_on(document, 'dragover', this); _on(document, 'dragover', this);
if (!supportDraggable) {
_on(document, 'mousemove', this);
this._onDragStart(tapEvt, true);
}
try { try {
if (document.selection) { if (document.selection) {
@ -316,10 +318,10 @@
_onTouchMove: function (/**TouchEvent*/evt) { _onTouchMove: function (/**TouchEvent*/evt) {
if (tapEvt) { if (tapEvt) {
var touch = evt.touches[0], var touch = evt.touches ? evt.touches[0] : evt,
dx = touch.clientX - tapEvt.clientX, dx = touch.clientX - tapEvt.clientX,
dy = touch.clientY - tapEvt.clientY, dy = touch.clientY - tapEvt.clientY,
translate3d = 'translate3d(' + dx + 'px,' + dy + 'px,0)'; translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)';
touchEvt = touch; touchEvt = touch;
@ -334,7 +336,7 @@
}, },
_onDragStart: function (/**Event*/evt, /**boolean*/isTouch) { _onDragStart: function (/**Event*/evt, /**boolean*/useFallback) {
var dataTransfer = evt.dataTransfer, var dataTransfer = evt.dataTransfer,
options = this.options; options = this.options;
@ -346,7 +348,7 @@
rootEl.insertBefore(cloneEl, dragEl); rootEl.insertBefore(cloneEl, dragEl);
} }
if (isTouch) { if (useFallback) {
var rect = dragEl.getBoundingClientRect(), var rect = dragEl.getBoundingClientRect(),
css = _css(dragEl), css = _css(dragEl),
ghostRect; ghostRect;
@ -368,10 +370,16 @@
_css(ghostEl, 'width', rect.width * 2 - ghostRect.width); _css(ghostEl, 'width', rect.width * 2 - ghostRect.width);
_css(ghostEl, 'height', rect.height * 2 - ghostRect.height); _css(ghostEl, 'height', rect.height * 2 - ghostRect.height);
// Bind touch events if (useFallback === 'touch') {
_on(document, 'touchmove', this._onTouchMove); // Bind touch events
_on(document, 'touchend', this._onDrop); _on(document, 'touchmove', this._onTouchMove);
_on(document, 'touchcancel', this._onDrop); _on(document, 'touchend', this._onDrop);
_on(document, 'touchcancel', this._onDrop);
} else {
// Old brwoser
_on(document, 'mousemove', this._onTouchMove);
_on(document, 'mouseup', this._onDrop);
}
this._loopId = setInterval(this._emulateDragOver, 150); this._loopId = setInterval(this._emulateDragOver, 150);
} }
@ -774,7 +782,6 @@
_off(el, 'mousedown', this._onTapStart); _off(el, 'mousedown', this._onTapStart);
_off(el, 'touchstart', this._onTapStart); _off(el, 'touchstart', this._onTapStart);
_off(el, 'selectstart', this._onTapStart);
_off(el, 'dragover', this._onDragOver); _off(el, 'dragover', this._onDragOver);
_off(el, 'dragenter', this._onDragOver); _off(el, 'dragenter', this._onDragOver);

2
Sortable.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save