Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 3168bcc

Browse files
author
AngularUI (via TravisCI)
committed
Travis commit : build 522
1 parent 3068e2f commit 3168bcc

File tree

3 files changed

+108
-58
lines changed

3 files changed

+108
-58
lines changed

bower.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "angular-ui-sortable",
3-
"version": "0.14.4",
3+
"version": "0.17.1",
44
"main": ["./sortable.js"],
55
"dependencies": {
66
"angular": ">=1.2.x",
7-
"jquery": "<3.0.0",
8-
"jquery-ui": ">=1.9"
7+
"jquery": ">=3.1.x",
8+
"jquery-ui": ">=1.12.x"
99
}
1010
}

sortable.js

Lines changed: 103 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* angular-ui-sortable - This directive allows you to jQueryUI Sortable.
3-
* @version v0.14.4 - 2017-04-15
3+
* @version v0.17.1 - 2017-04-15
44
* @link http://angular-ui.github.com
55
* @license MIT
66
*/
@@ -23,10 +23,25 @@ angular.module('ui.sortable', [])
2323
'uiSortableConfig', '$timeout', '$log',
2424
function(uiSortableConfig, $timeout, $log) {
2525
return {
26-
require: '?ngModel',
26+
require:'?ngModel',
2727
scope: {
28-
ngModel: '=',
29-
uiSortable: '='
28+
ngModel:'=',
29+
uiSortable:'=',
30+
////Expression bindings from html.
31+
create:'&uiSortableCreate',
32+
// helper:'&uiSortableHelper',
33+
start:'&uiSortableStart',
34+
activate:'&uiSortableActivate',
35+
// sort:'&uiSortableSort',
36+
// change:'&uiSortableChange',
37+
// over:'&uiSortableOver',
38+
// out:'&uiSortableOut',
39+
beforeStop:'&uiSortableBeforeStop',
40+
update:'&uiSortableUpdate',
41+
remove:'&uiSortableRemove',
42+
receive:'&uiSortableReceive',
43+
deactivate:'&uiSortableDeactivate',
44+
stop:'&uiSortableStop'
3045
},
3146
link: function(scope, element, attrs, ngModel) {
3247
var savedNodes;
@@ -107,7 +122,7 @@ angular.module('ui.sortable', [])
107122
}
108123
return;
109124
}
110-
125+
111126
if (!defaultOptions) {
112127
defaultOptions = angular.element.ui.sortable().options;
113128
}
@@ -195,16 +210,13 @@ angular.module('ui.sortable', [])
195210
return (/left|right/).test(item.css('float')) || (/inline|table-cell/).test(item.css('display'));
196211
}
197212

198-
function getElementScope(elementScopes, element) {
199-
var result = null;
213+
function getElementContext(elementScopes, element) {
200214
for (var i = 0; i < elementScopes.length; i++) {
201-
var x = elementScopes[i];
202-
if (x.element[0] === element[0]) {
203-
result = x.scope;
204-
break;
215+
var c = elementScopes[i];
216+
if (c.element[0] === element[0]) {
217+
return c;
205218
}
206219
}
207-
return result;
208220
}
209221

210222
function afterStop(e, ui) {
@@ -229,11 +241,19 @@ angular.module('ui.sortable', [])
229241
};
230242

231243
var callbacks = {
232-
receive: null,
233-
remove: null,
244+
create: null,
234245
start: null,
235-
stop: null,
236-
update: null
246+
activate: null,
247+
// sort: null,
248+
// change: null,
249+
// over: null,
250+
// out: null,
251+
beforeStop: null,
252+
update: null,
253+
remove: null,
254+
receive: null,
255+
deactivate: null,
256+
stop: null
237257
};
238258

239259
var wrappers = {
@@ -275,7 +295,8 @@ angular.module('ui.sortable', [])
275295
ui.item.sortable = {
276296
model: ngModel.$modelValue[index],
277297
index: index,
278-
source: ui.item.parent(),
298+
source: element,
299+
sourceList: ui.item.parent(),
279300
sourceModel: ngModel.$modelValue,
280301
cancel: function () {
281302
ui.item.sortable._isCanceled = true;
@@ -292,16 +313,33 @@ angular.module('ui.sortable', [])
292313
angular.forEach(ui.item.sortable, function(value, key) {
293314
ui.item.sortable[key] = undefined;
294315
});
316+
},
317+
_connectedSortables: [],
318+
_getElementContext: function (element) {
319+
return getElementContext(this._connectedSortables, element);
295320
}
296321
};
297322
};
298323

299324
callbacks.activate = function(e, ui) {
325+
var isSourceContext = ui.item.sortable.source === element;
326+
var savedNodesOrigin = isSourceContext ?
327+
ui.item.sortable.sourceList :
328+
element;
329+
var elementContext = {
330+
element: element,
331+
scope: scope,
332+
isSourceContext: isSourceContext,
333+
savedNodesOrigin: savedNodesOrigin
334+
};
335+
// save the directive's scope so that it is accessible from ui.item.sortable
336+
ui.item.sortable._connectedSortables.push(elementContext);
337+
300338
// We need to make a copy of the current element's contents so
301339
// we can restore it after sortable has messed it up.
302340
// This is inside activate (instead of start) in order to save
303341
// both lists when dragging between connected lists.
304-
savedNodes = element.contents();
342+
savedNodes = savedNodesOrigin.contents();
305343
helper = ui.helper;
306344

307345
// If this list has a placeholder (the connected lists won't),
@@ -311,29 +349,20 @@ angular.module('ui.sortable', [])
311349
var excludes = getPlaceholderExcludesludes(element, placeholder);
312350
savedNodes = savedNodes.not(excludes);
313351
}
314-
315-
// save the directive's scope so that it is accessible from ui.item.sortable
316-
var connectedSortables = ui.item.sortable._connectedSortables || [];
317-
318-
connectedSortables.push({
319-
element: element,
320-
scope: scope
321-
});
322-
323-
ui.item.sortable._connectedSortables = connectedSortables;
324352
};
325353

326354
callbacks.update = function(e, ui) {
327355
// Save current drop position but only if this is not a second
328356
// update that happens when moving between lists because then
329357
// the value will be overwritten with the old value
330-
if(!ui.item.sortable.received) {
358+
if (!ui.item.sortable.received) {
331359
ui.item.sortable.dropindex = getItemIndex(ui.item);
332-
var droptarget = ui.item.parent();
360+
var droptarget = ui.item.closest('[ui-sortable], [data-ui-sortable], [x-ui-sortable]');
333361
ui.item.sortable.droptarget = droptarget;
362+
ui.item.sortable.droptargetList = ui.item.parent();
334363

335-
var droptargetScope = getElementScope(ui.item.sortable._connectedSortables, droptarget);
336-
ui.item.sortable.droptargetModel = droptargetScope.ngModel;
364+
var droptargetContext = ui.item.sortable._getElementContext(droptarget);
365+
ui.item.sortable.droptargetModel = droptargetContext.scope.ngModel;
337366

338367
// Cancel the sort (let ng-repeat do the sort for us)
339368
// Don't cancel if this is the received list because it has
@@ -353,55 +382,60 @@ angular.module('ui.sortable', [])
353382
// That way it will be garbage collected.
354383
savedNodes = savedNodes.not(sortingHelper);
355384
}
356-
savedNodes.appendTo(element);
385+
var elementContext = ui.item.sortable._getElementContext(element);
386+
savedNodes.appendTo(elementContext.savedNodesOrigin);
357387

358388
// If this is the target connected list then
359389
// it's safe to clear the restored nodes since:
360390
// update is currently running and
361391
// stop is not called for the target list.
362-
if(ui.item.sortable.received) {
392+
if (ui.item.sortable.received) {
363393
savedNodes = null;
364394
}
365395

366396
// If received is true (an item was dropped in from another list)
367397
// then we add the new item to this list otherwise wait until the
368398
// stop event where we will know if it was a sort or item was
369399
// moved here from another list
370-
if(ui.item.sortable.received && !ui.item.sortable.isCanceled()) {
400+
if (ui.item.sortable.received && !ui.item.sortable.isCanceled()) {
371401
scope.$apply(function () {
372402
ngModel.$modelValue.splice(ui.item.sortable.dropindex, 0,
373403
ui.item.sortable.moved);
374404
});
405+
scope.$emit('ui-sortable:moved', ui);
375406
}
376407
};
377408

378409
callbacks.stop = function(e, ui) {
379410
// If the received flag hasn't be set on the item, this is a
380411
// normal sort, if dropindex is set, the item was moved, so move
381412
// the items in the list.
382-
if(!ui.item.sortable.received &&
383-
('dropindex' in ui.item.sortable) &&
384-
!ui.item.sortable.isCanceled()) {
413+
var wasMoved = ('dropindex' in ui.item.sortable) &&
414+
!ui.item.sortable.isCanceled();
415+
416+
if (wasMoved && !ui.item.sortable.received) {
385417

386418
scope.$apply(function () {
387419
ngModel.$modelValue.splice(
388420
ui.item.sortable.dropindex, 0,
389421
ngModel.$modelValue.splice(ui.item.sortable.index, 1)[0]);
390422
});
391-
} else {
392-
// if the item was not moved, then restore the elements
423+
scope.$emit('ui-sortable:moved', ui);
424+
} else if (!wasMoved &&
425+
!angular.equals(element.contents().toArray(), savedNodes.toArray())) {
426+
// if the item was not moved
427+
// and the DOM element order has changed,
428+
// then restore the elements
393429
// so that the ngRepeat's comment are correct.
394-
if ((!('dropindex' in ui.item.sortable) || ui.item.sortable.isCanceled()) &&
395-
!angular.equals(element.contents(), savedNodes)) {
396-
397-
var sortingHelper = getSortingHelper(element, ui, savedNodes);
398-
if (sortingHelper && sortingHelper.length) {
399-
// Restore all the savedNodes except from the sorting helper element.
400-
// That way it will be garbage collected.
401-
savedNodes = savedNodes.not(sortingHelper);
402-
}
403-
savedNodes.appendTo(element);
430+
431+
var sortingHelper = getSortingHelper(element, ui, savedNodes);
432+
if (sortingHelper && sortingHelper.length) {
433+
// Restore all the savedNodes except from the sorting helper element.
434+
// That way it will be garbage collected.
435+
savedNodes = savedNodes.not(sortingHelper);
404436
}
437+
var elementContext = ui.item.sortable._getElementContext(element);
438+
savedNodes.appendTo(elementContext.savedNodesOrigin);
405439
}
406440

407441
// It's now safe to clear the savedNodes and helper
@@ -435,6 +469,21 @@ angular.module('ui.sortable', [])
435469
}
436470
};
437471

472+
// setup attribute handlers
473+
angular.forEach(callbacks, function(value, key) {
474+
callbacks[key] = combineCallbacks(callbacks[key],
475+
function () {
476+
var attrHandler = scope[key];
477+
var attrHandlerFn;
478+
if (typeof attrHandler === 'function' &&
479+
('uiSortable' + key.substring(0,1).toUpperCase() + key.substring(1)).length &&
480+
typeof (attrHandlerFn = attrHandler()) === 'function') {
481+
attrHandlerFn.apply(this, arguments);
482+
}
483+
});
484+
});
485+
486+
438487
wrappers.helper = function (inner) {
439488
if (inner && typeof inner === 'function') {
440489
return function (e, item) {
@@ -443,7 +492,8 @@ angular.module('ui.sortable', [])
443492
item.sortable = {
444493
model: ngModel.$modelValue[index],
445494
index: index,
446-
source: item.parent(),
495+
source: element,
496+
sourceList: item.parent(),
447497
sourceModel: ngModel.$modelValue,
448498
_restore: function () {
449499
angular.forEach(item.sortable, function(value, key) {
@@ -469,7 +519,7 @@ angular.module('ui.sortable', [])
469519
var sortableWidgetInstance = getSortableWidgetInstance(element);
470520
if (!!sortableWidgetInstance) {
471521
var optsDiff = patchUISortableOptions(newVal, oldVal, sortableWidgetInstance);
472-
522+
473523
if (optsDiff) {
474524
element.sortable('option', optsDiff);
475525
}
@@ -485,7 +535,7 @@ angular.module('ui.sortable', [])
485535
} else {
486536
$log.info('ui.sortable: ngModel not provided!', element);
487537
}
488-
538+
489539
// Create sortable
490540
element.sortable(opts);
491541
}

0 commit comments

Comments
 (0)