Browse Source

Merge pull request #15 from RubaXa/dev

* update from RubaXa
pull/527/head
sp-kilobug 9 years ago
parent
commit
9e9e8463d0
  1. 11
      CONTRIBUTING.md
  2. 25
      Sortable.js
  3. 2
      Sortable.min.js
  4. 27
      knockout-sortable.js

11
CONTRIBUTING.md

@ -1,18 +1,23 @@
# Contribution Guidelines
### Issue
1. Try [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch, perhaps the problem has been solved;
2. [Use the search](https://github.com/RubaXa/Sortable/search?q=problem), maybe already have an answer;
3. If not found, create example on [jsbin.com (draft)](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem.
---
### Pull Request
1. Before PR run `grunt`;
2. Only into [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch.
### Setup
Pieced together from [gruntjs](http://gruntjs.com/getting-started)
1. Fork repo on [github](https://github.com)
2. Clone locally
3. from local repro ```npm install```
4. Install grunt-cli globally ```sudo -H npm install -g grunt-cli```

25
Sortable.js

@ -36,6 +36,7 @@
lastEl,
lastCSS,
lastParentCSS,
oldIndex,
newIndex,
@ -573,7 +574,7 @@
target = _closest(evt.target, options.draggable, el);
dragRect = dragEl.getBoundingClientRect();
parentEl = target && target.parentNode || parentEl; // actualization
if (revert) {
_cloneHide(true);
@ -590,7 +591,7 @@
if ((el.children.length === 0) || (el.children[0] === ghostEl) ||
(el === evt.target) && (target = _ghostInBottom(el, evt))
(el === evt.target) && (target = _ghostIsLast(el, evt))
) {
if (target) {
if (target.animated) {
@ -611,13 +612,15 @@
if (lastEl !== target) {
lastEl = target;
lastCSS = _css(target);
lastParentCSS = _css(target.parentNode);
}
var targetRect = target.getBoundingClientRect(),
width = targetRect.right - targetRect.left,
height = targetRect.bottom - targetRect.top,
floating = /left|right|inline/.test(lastCSS.cssFloat + lastCSS.display),
floating = /left|right|inline/.test(lastCSS.cssFloat + lastCSS.display)
|| (lastParentCSS.display == 'flex' && lastParentCSS['flex-direction'].indexOf('row') === 0),
isWide = (target.offsetWidth > dragEl.offsetWidth),
isLong = (target.offsetHeight > dragEl.offsetHeight),
halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5,
@ -725,6 +728,7 @@
if (rootEl !== parentEl) {
newIndex = _index(dragEl);
if (newIndex != -1) {
// drag from one list and drop into another
_dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
@ -760,7 +764,7 @@
this.save();
}
}
// Nulling
rootEl =
dragEl =
@ -776,6 +780,7 @@
touchEvt =
moved =
newIndex =
lastEl =
lastCSS =
@ -950,7 +955,9 @@
function _globalDragOver(/**Event*/evt) {
evt.dataTransfer.dropEffect = 'move';
if (evt.dataTransfer) {
evt.dataTransfer.dropEffect = 'move';
}
evt.preventDefault();
}
@ -1081,11 +1088,11 @@
/** @returns {HTMLElement|false} */
function _ghostInBottom(el, evt) {
function _ghostIsLast(el, evt) {
var lastEl = el.lastElementChild,
rect = lastEl.getBoundingClientRect();
rect = lastEl.getBoundingClientRect();
return (evt.clientY - (rect.top + rect.height) > 5) && lastEl; // min delta
return ((evt.clientY - (rect.top + rect.height) > 5) || (evt.clientX - (rect.right + rect.width) > 5)) && lastEl; // min delta
}
@ -1185,7 +1192,7 @@
Sortable.create = function (el, options) {
return new Sortable(el, options);
};
// Export
Sortable.version = '1.2.2';

2
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

27
knockout-sortable.js

@ -1,4 +1,17 @@
(function () {
(function (factory) {
"use strict";
if (typeof define === "function" && define.amd) {
// AMD anonymous module
define(["knockout"], factory);
} else if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
// CommonJS module
var ko = require("knockout");
factory(ko);
} else {
// No module loader (plain <script> tag) - put directly in global namespace
factory(window.ko);
}
})(function (ko) {
"use strict";
var init = function (element, valueAccessor, allBindings, viewModel, bindingContext, sortableOptions) {
@ -67,7 +80,13 @@
//Unwrapping this allows us to manipulate the actual array
var fromArray = from(),
//It's not certain that the items actual index is the same as the index reported by sortable due to filtering etc.
originalIndex = fromArray.indexOf(itemVM);
originalIndex = fromArray.indexOf(itemVM),
newIndex = e.newIndex;
if (e.item.previousElementSibling)
newIndex = fromArray.indexOf(ko.dataFor(e.item.previousElementSibling));
if (originalIndex > newIndex)
newIndex = newIndex + 1;
//Remove sortables "unbound" element
e.item.parentNode.removeChild(e.item);
@ -85,7 +104,7 @@
from.valueHasMutated();
}
//Insert the item on its new position
to().splice(e.newIndex, 0, itemVM);
to().splice(newIndex, 0, itemVM);
//Make sure to tell knockout that we've modified the actual array.
to.valueHasMutated();
};
@ -158,4 +177,4 @@
}
};
})();
});

Loading…
Cancel
Save