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

Commit 3068e2f

Browse files
author
AngularUI (via TravisCI)
committed
Travis commit : build 521
1 parent 11bb2b8 commit 3068e2f

File tree

3 files changed

+64
-112
lines changed

3 files changed

+64
-112
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.17.0",
3+
"version": "0.14.4",
44
"main": ["./sortable.js"],
55
"dependencies": {
66
"angular": ">=1.2.x",
7-
"jquery": ">=3.1.x",
8-
"jquery-ui": ">=1.12.x"
7+
"jquery": "<3.0.0",
8+
"jquery-ui": ">=1.9"
99
}
1010
}

sortable.js

Lines changed: 59 additions & 107 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.17.0 - 2017-03-08
3+
* @version v0.14.4 - 2017-04-15
44
* @link http://angular-ui.github.com
55
* @license MIT
66
*/
@@ -23,28 +23,14 @@ 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:'=',
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'
28+
ngModel: '=',
29+
uiSortable: '='
4530
},
4631
link: function(scope, element, attrs, ngModel) {
4732
var savedNodes;
33+
var helper;
4834

4935
function combineCallbacks(first, second){
5036
var firstIsFunc = typeof first === 'function';
@@ -121,7 +107,7 @@ angular.module('ui.sortable', [])
121107
}
122108
return;
123109
}
124-
110+
125111
if (!defaultOptions) {
126112
defaultOptions = angular.element.ui.sortable().options;
127113
}
@@ -194,13 +180,12 @@ angular.module('ui.sortable', [])
194180
return helperOption === 'clone' || (typeof helperOption === 'function' && ui.item.sortable.isCustomHelperUsed());
195181
}
196182

197-
function getSortingHelper (element, ui, savedNodes) {
183+
function getSortingHelper (element, ui/*, savedNodes*/) {
198184
var result = null;
199185
if (hasSortingHelper(element, ui) &&
200186
element.sortable( 'option', 'appendTo' ) === 'parent') {
201187
// The .ui-sortable-helper element (that's the default class name)
202-
// is placed last.
203-
result = savedNodes.last();
188+
result = helper;
204189
}
205190
return result;
206191
}
@@ -210,13 +195,16 @@ angular.module('ui.sortable', [])
210195
return (/left|right/).test(item.css('float')) || (/inline|table-cell/).test(item.css('display'));
211196
}
212197

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

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

243231
var callbacks = {
244-
create: null,
245-
start: 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,
254232
receive: null,
255-
deactivate: null,
256-
stop: null
233+
remove: null,
234+
start: null,
235+
stop: null,
236+
update: null
257237
};
258238

259239
var wrappers = {
@@ -295,8 +275,7 @@ angular.module('ui.sortable', [])
295275
ui.item.sortable = {
296276
model: ngModel.$modelValue[index],
297277
index: index,
298-
source: element,
299-
sourceList: ui.item.parent(),
278+
source: ui.item.parent(),
300279
sourceModel: ngModel.$modelValue,
301280
cancel: function () {
302281
ui.item.sortable._isCanceled = true;
@@ -313,33 +292,17 @@ angular.module('ui.sortable', [])
313292
angular.forEach(ui.item.sortable, function(value, key) {
314293
ui.item.sortable[key] = undefined;
315294
});
316-
},
317-
_connectedSortables: [],
318-
_getElementContext: function (element) {
319-
return getElementContext(this._connectedSortables, element);
320295
}
321296
};
322297
};
323298

324299
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-
338300
// We need to make a copy of the current element's contents so
339301
// we can restore it after sortable has messed it up.
340302
// This is inside activate (instead of start) in order to save
341303
// both lists when dragging between connected lists.
342-
savedNodes = savedNodesOrigin.contents();
304+
savedNodes = element.contents();
305+
helper = ui.helper;
343306

344307
// If this list has a placeholder (the connected lists won't),
345308
// don't inlcude it in saved nodes.
@@ -348,20 +311,29 @@ angular.module('ui.sortable', [])
348311
var excludes = getPlaceholderExcludesludes(element, placeholder);
349312
savedNodes = savedNodes.not(excludes);
350313
}
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;
351324
};
352325

353326
callbacks.update = function(e, ui) {
354327
// Save current drop position but only if this is not a second
355328
// update that happens when moving between lists because then
356329
// the value will be overwritten with the old value
357-
if (!ui.item.sortable.received) {
330+
if(!ui.item.sortable.received) {
358331
ui.item.sortable.dropindex = getItemIndex(ui.item);
359-
var droptarget = ui.item.closest('[ui-sortable], [data-ui-sortable], [x-ui-sortable]');
332+
var droptarget = ui.item.parent();
360333
ui.item.sortable.droptarget = droptarget;
361-
ui.item.sortable.droptargetList = ui.item.parent();
362334

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

366338
// Cancel the sort (let ng-repeat do the sort for us)
367339
// Don't cancel if this is the received list because it has
@@ -381,65 +353,61 @@ angular.module('ui.sortable', [])
381353
// That way it will be garbage collected.
382354
savedNodes = savedNodes.not(sortingHelper);
383355
}
384-
var elementContext = ui.item.sortable._getElementContext(element);
385-
savedNodes.appendTo(elementContext.savedNodesOrigin);
356+
savedNodes.appendTo(element);
386357

387358
// If this is the target connected list then
388359
// it's safe to clear the restored nodes since:
389360
// update is currently running and
390361
// stop is not called for the target list.
391-
if (ui.item.sortable.received) {
362+
if(ui.item.sortable.received) {
392363
savedNodes = null;
393364
}
394365

395366
// If received is true (an item was dropped in from another list)
396367
// then we add the new item to this list otherwise wait until the
397368
// stop event where we will know if it was a sort or item was
398369
// moved here from another list
399-
if (ui.item.sortable.received && !ui.item.sortable.isCanceled()) {
370+
if(ui.item.sortable.received && !ui.item.sortable.isCanceled()) {
400371
scope.$apply(function () {
401372
ngModel.$modelValue.splice(ui.item.sortable.dropindex, 0,
402373
ui.item.sortable.moved);
403374
});
404-
scope.$emit('ui-sortable:moved', ui);
405375
}
406376
};
407377

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

417386
scope.$apply(function () {
418387
ngModel.$modelValue.splice(
419388
ui.item.sortable.dropindex, 0,
420389
ngModel.$modelValue.splice(ui.item.sortable.index, 1)[0]);
421390
});
422-
scope.$emit('ui-sortable:moved', ui);
423-
} else if (!wasMoved &&
424-
!angular.equals(element.contents().toArray(), savedNodes.toArray())) {
425-
// if the item was not moved
426-
// and the DOM element order has changed,
427-
// then restore the elements
391+
} else {
392+
// if the item was not moved, then restore the elements
428393
// so that the ngRepeat's comment are correct.
429-
430-
var sortingHelper = getSortingHelper(element, ui, savedNodes);
431-
if (sortingHelper && sortingHelper.length) {
432-
// Restore all the savedNodes except from the sorting helper element.
433-
// That way it will be garbage collected.
434-
savedNodes = savedNodes.not(sortingHelper);
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);
435404
}
436-
var elementContext = ui.item.sortable._getElementContext(element);
437-
savedNodes.appendTo(elementContext.savedNodesOrigin);
438405
}
439406

440-
// It's now safe to clear the savedNodes
407+
// It's now safe to clear the savedNodes and helper
441408
// since stop is the last callback.
442409
savedNodes = null;
410+
helper = null;
443411
};
444412

445413
callbacks.receive = function(e, ui) {
@@ -467,21 +435,6 @@ angular.module('ui.sortable', [])
467435
}
468436
};
469437

470-
// setup attribute handlers
471-
angular.forEach(callbacks, function(value, key) {
472-
callbacks[key] = combineCallbacks(callbacks[key],
473-
function () {
474-
var attrHandler = scope[key];
475-
var attrHandlerFn;
476-
if (typeof attrHandler === 'function' &&
477-
('uiSortable' + key.substring(0,1).toUpperCase() + key.substring(1)).length &&
478-
typeof (attrHandlerFn = attrHandler()) === 'function') {
479-
attrHandlerFn.apply(this, arguments);
480-
}
481-
});
482-
});
483-
484-
485438
wrappers.helper = function (inner) {
486439
if (inner && typeof inner === 'function') {
487440
return function (e, item) {
@@ -490,8 +443,7 @@ angular.module('ui.sortable', [])
490443
item.sortable = {
491444
model: ngModel.$modelValue[index],
492445
index: index,
493-
source: element,
494-
sourceList: item.parent(),
446+
source: item.parent(),
495447
sourceModel: ngModel.$modelValue,
496448
_restore: function () {
497449
angular.forEach(item.sortable, function(value, key) {
@@ -517,7 +469,7 @@ angular.module('ui.sortable', [])
517469
var sortableWidgetInstance = getSortableWidgetInstance(element);
518470
if (!!sortableWidgetInstance) {
519471
var optsDiff = patchUISortableOptions(newVal, oldVal, sortableWidgetInstance);
520-
472+
521473
if (optsDiff) {
522474
element.sortable('option', optsDiff);
523475
}
@@ -533,7 +485,7 @@ angular.module('ui.sortable', [])
533485
} else {
534486
$log.info('ui.sortable: ngModel not provided!', element);
535487
}
536-
488+
537489
// Create sortable
538490
element.sortable(opts);
539491
}

0 commit comments

Comments
 (0)