Skip to content

Commit

Permalink
Merge pull request #4 from RubaXa/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
sp-kilobug committed Jun 27, 2015
2 parents 38f732c + 71f4362 commit cb140f1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 36 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ var sortable = new Sortable(el, {
ghostClass: "sortable-ghost", // Class name for the drop placeholder
dataIdAttr: 'data-id',

forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in
fallbackClass: "sortable-fallback" // Class name for the cloned DOM Element when using forceFallback
fallbackOnBody: false // Appends the cloned DOM Element into the Document's Body

scroll: true, // or HTMLElement
scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling.
scrollSpeed: 10, // px
Expand Down Expand Up @@ -253,6 +257,18 @@ Sortable.create(list, {
---


#### `forceFallback` option
If set to `true`, the Fallback for non HTML5 Browser will be used, even if we are using an HTML5 Browser.
This gives us the possiblity to test the behaviour for older Browsers even in newer Browser, or make the Drag 'n Drop feel more consistent between Desktop , Mobile and old Browsers.

On top of that, the Fallback always generates a copy of that DOM Element and appends the class `fallbackClass` definied in the options. This behaviour controls the look of this 'dragged' Element.

Demo: http://jsbin.com/xinuyenabi/edit?html,css,js,output


---


#### `scroll` option
If set to `true`, the page (or sortable-area) scrolls when coming to an edge.

Expand Down
97 changes: 64 additions & 33 deletions Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
tapEvt,
touchEvt,

moved,

/** @const */
RSPACE = /\s+/g,

Expand Down Expand Up @@ -176,7 +178,10 @@
dropBubble: false,
dragoverBubble: false,
dataIdAttr: 'data-id',
delay: 0
delay: 0,
forceFallback: false,
fallbackClass: 'sortable-fallback',
fallbackOnBody: false
};


Expand Down Expand Up @@ -323,8 +328,12 @@
_on(ownerDocument, 'touchcancel', _this._onDrop);

if (options.delay) {
// If the user moves the pointer before the delay has been reached:
// If the user moves the pointer or let go the click or touch
// before the delay has been reached:
// disable the delayed drag
_on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
_on(ownerDocument, 'touchend', _this._disableDelayedDrag);
_on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
_on(ownerDocument, 'mousemove', _this._disableDelayedDrag);
_on(ownerDocument, 'touchmove', _this._disableDelayedDrag);

Expand All @@ -339,7 +348,9 @@
var ownerDocument = this.el.ownerDocument;

clearTimeout(this._dragStartTimer);

_off(ownerDocument, 'mouseup', this._disableDelayedDrag);
_off(ownerDocument, 'touchend', this._disableDelayedDrag);
_off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
_off(ownerDocument, 'mousemove', this._disableDelayedDrag);
_off(ownerDocument, 'touchmove', this._disableDelayedDrag);
},
Expand All @@ -355,7 +366,7 @@

this._onDragStart(tapEvt, 'touch');
}
else if (!supportDraggable) {
else if (!supportDraggable || this.options.forceFallback) {
this._onDragStart(tapEvt, true);
}
else {
Expand Down Expand Up @@ -422,13 +433,21 @@

_onTouchMove: function (/**TouchEvent*/evt) {
if (tapEvt) {
// only set the status to dragging, when we are actually dragging
if(!Sortable.active) {
this._dragStarted();
}
// as well as creating the ghost element on the document body
this._appendGhost();
var touch = evt.touches ? evt.touches[0] : evt,
dx = touch.clientX - tapEvt.clientX,
dy = touch.clientY - tapEvt.clientY,
translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)';

touchEvt = touch;

moved = true;

_css(ghostEl, 'webkitTransform', translate3d);
_css(ghostEl, 'mozTransform', translate3d);
_css(ghostEl, 'msTransform', translate3d);
Expand All @@ -438,26 +457,17 @@
}
},


_onDragStart: function (/**Event*/evt, /**boolean*/useFallback) {
var dataTransfer = evt.dataTransfer,
options = this.options;

this._offUpEvents();

if (activeGroup.pull == 'clone') {
cloneEl = dragEl.cloneNode(true);
_css(cloneEl, 'display', 'none');
rootEl.insertBefore(cloneEl, dragEl);
}

if (useFallback) {
_appendGhost: function() {
if(!ghostEl) {
var rect = dragEl.getBoundingClientRect(),
css = _css(dragEl),
ghostRect;

ghostEl = dragEl.cloneNode(true);

_toggleClass(ghostEl, this.options.ghostClass, false);
_toggleClass(ghostEl, this.options.fallbackClass, true);

_css(ghostEl, 'top', rect.top - parseInt(css.marginTop, 10));
_css(ghostEl, 'left', rect.left - parseInt(css.marginLeft, 10));
_css(ghostEl, 'width', rect.width);
Expand All @@ -466,12 +476,28 @@
_css(ghostEl, 'position', 'fixed');
_css(ghostEl, 'zIndex', '100000');

rootEl.appendChild(ghostEl);
this.options.fallbackOnBody && document.body.appendChild(ghostEl) || rootEl.appendChild(ghostEl);

// Fixing dimensions.
ghostRect = ghostEl.getBoundingClientRect();
_css(ghostEl, 'width', rect.width * 2 - ghostRect.width);
_css(ghostEl, 'height', rect.height * 2 - ghostRect.height);
}
},

_onDragStart: function (/**Event*/evt, /**boolean*/useFallback) {
var dataTransfer = evt.dataTransfer,
options = this.options;

this._offUpEvents();

if (activeGroup.pull == 'clone') {
cloneEl = dragEl.cloneNode(true);
_css(cloneEl, 'display', 'none');
rootEl.insertBefore(cloneEl, dragEl);
}

if (useFallback) {

if (useFallback === 'touch') {
// Bind touch events
Expand All @@ -493,9 +519,9 @@
}

_on(document, 'drop', this);
setTimeout(this._dragStarted, 0);
}

setTimeout(this._dragStarted, 0);

},

_onDragOver: function (/**Event*/evt) {
Expand Down Expand Up @@ -665,9 +691,10 @@
this._offUpEvents();

if (evt) {
evt.preventDefault();
!options.dropBubble && evt.stopPropagation();

if(moved) {
evt.preventDefault();
!options.dropBubble && evt.stopPropagation();
}
ghostEl && ghostEl.parentNode.removeChild(ghostEl);

if (dragEl) {
Expand Down Expand Up @@ -725,6 +752,8 @@
tapEvt =
touchEvt =

moved =

lastEl =
lastCSS =

Expand Down Expand Up @@ -996,17 +1025,19 @@
onMoveFn = sortable.options.onMove,
retVal;

if (onMoveFn) {
evt = document.createEvent('Event');
evt.initEvent('move', true, true);
evt = document.createEvent('Event');
evt.initEvent('move', true, true);

evt.to = toEl;
evt.from = fromEl;
evt.dragged = dragEl;
evt.draggedRect = dragRect;
evt.related = targetEl || toEl;
evt.relatedRect = targetRect || toEl.getBoundingClientRect();
evt.to = toEl;
evt.from = fromEl;
evt.dragged = dragEl;
evt.draggedRect = dragRect;
evt.related = targetEl || toEl;
evt.relatedRect = targetRect || toEl.getBoundingClientRect();

fromEl.dispatchEvent(evt);

if (onMoveFn) {
retVal = onMoveFn.call(sortable, evt);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sortablejs",
"exportName": "Sortable",
"version": "1.2.1",
"version": "1.2.2",
"devDependencies": {
"grunt": "*",
"grunt-version": "*",
Expand Down
5 changes: 3 additions & 2 deletions react-sortable-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
onUpdate: 'handleUpdate',
onRemove: 'handleRemove',
onSort: 'handleSort',
onFilter: 'handleFilter'
onFilter: 'handleFilter',
onMove: 'handleMove'
};


Expand Down Expand Up @@ -90,7 +91,7 @@


// Bind callbacks so that "this" refers to the component
'onStart onEnd onAdd onSort onUpdate onRemove onFilter'.split(' ').forEach(function (/** string */name) {
'onStart onEnd onAdd onSort onUpdate onRemove onFilter onMove'.split(' ').forEach(function (/** string */name) {
copyOptions[name] = function (evt) {
if (name === 'onStart') {
_nextSibling = evt.item.nextElementSibling;
Expand Down

0 comments on commit cb140f1

Please sign in to comment.