Browse Source

Merge branch 'dev' of github.com:RubaXa/Sortable into dev

pull/754/merge
Lebedev Konstantin 9 years ago
parent
commit
cfae80664f
  1. 12
      README.md
  2. 28
      Sortable.js
  3. 2
      Sortable.min.js
  4. 2
      jquery.binding.js
  5. 45
      ng-sortable.js

12
README.md

@ -74,6 +74,7 @@ var sortable = new Sortable(el, {
fallbackTolerance: 0 // Specify in pixels how far the mouse should move before it's considered as a drag.
scroll: true, // or HTMLElement
scrollFn: function(offsetX, offsetY, originalEvent) { ... }, // if you have custom scrollbar scrollFn may be used for autoscrolling
scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling.
scrollSpeed: 10, // px
@ -126,12 +127,13 @@ var sortable = new Sortable(el, {
},
// Event when you move an item in the list or between lists
onMove: function (/**Event*/evt) {
onMove: function (/**Event*/evt, /**Event*/originalEvent) {
// Example: http://jsbin.com/tuyafe/1/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // TextRectangle {left, top, right и bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // TextRectangle
originalEvent.clientY; // mouse position
// return false; — for cancel
},
@ -335,6 +337,14 @@ Demo:
---
#### `scrollFn` option
Defines function that will be used for autoscrolling. el.scrollTop/el.scrollLeft is used by default.
Useful when you have custom scrollbar with dedicated scroll function.
---
#### `scrollSensitivity` option
Defines how near the mouse must be to an edge to start scrolling.

28
Sortable.js

@ -39,6 +39,7 @@
scrollEl,
scrollParentEl,
scrollCustomFn,
lastEl,
lastCSS,
@ -99,13 +100,17 @@
winHeight = window.innerHeight,
vx,
vy
vy,
scrollOffsetX,
scrollOffsetY
;
// Delect scrollEl
if (scrollParentEl !== rootEl) {
scrollEl = options.scroll;
scrollParentEl = rootEl;
scrollCustomFn = options.scrollFn;
if (scrollEl === true) {
scrollEl = rootEl;
@ -147,11 +152,18 @@
if (el) {
autoScroll.pid = setInterval(function () {
scrollOffsetY = vy ? vy * speed : 0;
scrollOffsetX = vx ? vx * speed : 0;
if ('function' === typeof(scrollCustomFn)) {
return scrollCustomFn.call(_this, scrollOffsetX, scrollOffsetY, evt);
}
if (el === win) {
win.scrollTo(win.pageXOffset + vx * speed, win.pageYOffset + vy * speed);
win.scrollTo(win.pageXOffset + scrollOffsetX, win.pageYOffset + scrollOffsetY);
} else {
vy && (el.scrollTop += vy * speed);
vx && (el.scrollLeft += vx * speed);
el.scrollTop += scrollOffsetY;
el.scrollLeft += scrollOffsetX;
}
}, 24);
}
@ -681,7 +693,7 @@
_cloneHide(isOwner);
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect) !== false) {
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt) !== false) {
if (!dragEl.contains(el)) {
el.appendChild(dragEl);
parentEl = el; // actualization
@ -708,7 +720,7 @@
isLong = (target.offsetHeight > dragEl.offsetHeight),
halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5,
nextSibling = target.nextElementSibling,
moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect),
moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt),
after
;
@ -1158,7 +1170,7 @@
}
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect) {
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvt) {
var evt,
sortable = fromEl[expando],
onMoveFn = sortable.options.onMove,
@ -1177,7 +1189,7 @@
fromEl.dispatchEvent(evt);
if (onMoveFn) {
retVal = onMoveFn.call(sortable, evt);
retVal = onMoveFn.call(sortable, evt, originalEvt);
}
return retVal;

2
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

2
jquery.binding.js

@ -41,7 +41,7 @@
if (sortable) {
if (options === 'widget') {
return sortable;
retVal = sortable;
}
else if (options === 'destroy') {
sortable.destroy();

45
ng-sortable.js

@ -35,42 +35,45 @@
.constant('ngSortableConfig', {})
.directive('ngSortable', ['$parse', 'ngSortableConfig', function ($parse, ngSortableConfig) {
var removed,
nextSibling,
getSourceFactory = function getSourceFactory(el, scope) {
var ngRepeat = [].filter.call(el.childNodes, function (node) {
nextSibling;
// Export
return {
restrict: 'AC',
scope: { ngSortable: "=?" },
priority: 1001,
compile: function ($element, $attr) {
var ngRepeat = [].filter.call($element[0].childNodes, function (node) {
return (
(node.nodeType === 8) &&
(node.nodeValue.indexOf('ngRepeat:') !== -1)
(node.nodeType === 1) &&
(node.attributes['ng-repeat'])
);
})[0];
if (!ngRepeat) {
// Without ng-repeat
return function () {
return null;
};
return;
}
// tests: http://jsbin.com/kosubutilo/1/edit?js,output
ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/);
var expression = ngRepeat.attributes['ng-repeat'].nodeValue;
var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
var itemsExpr = $parse(ngRepeat[2]);
if (!match) {
return;
}
var rhs = match[2];
return function () {
return function postLink(scope, $el) {
var itemsExpr = $parse(rhs);
var getSource = function getSource() {
return itemsExpr(scope.$parent) || [];
};
};
// Export
return {
restrict: 'AC',
scope: { ngSortable: "=?" },
link: function (scope, $el) {
var el = $el[0],
options = angular.extend(scope.ngSortable || {}, ngSortableConfig),
watchers = [],
getSource = getSourceFactory(el, scope),
offDestroy,
sortable
;
@ -198,6 +201,8 @@
});
offDestroy = scope.$on('$destroy', _destroy);
}
}
};
}]);

Loading…
Cancel
Save