1
|
/*
|
2
|
* Based on nativesortable - Copyright (c) Brian Grinstead - https://github.com/bgrins/nativesortable
|
3
|
*/
|
4
|
(function(addon) {
|
5
|
|
6
|
var component;
|
7
|
|
8
|
if (window.UIkit) {
|
9
|
component = addon(UIkit);
|
10
|
}
|
11
|
|
12
|
if (typeof define == "function" && define.amd) {
|
13
|
define("uikit-sortable", ["uikit"], function(){
|
14
|
return component || addon(UIkit);
|
15
|
});
|
16
|
}
|
17
|
|
18
|
})(function(UI){
|
19
|
|
20
|
"use strict";
|
21
|
|
22
|
//var supportsTouch = ('ontouchstart' in window) || (window.DocumentTouch && document instanceof DocumentTouch);
|
23
|
var draggingPlaceholder, currentlyDraggingElement, currentlyDraggingTarget, dragging, moving, clickedlink, delayIdle, touchedlists, moved, overElement;
|
24
|
|
25
|
var dragEvents = ['touchmove', 'mousemove', 'mouseout'];
|
26
|
var dragMoveEvents = ['touchmove', 'mousemove'];
|
27
|
var dragStartEvents = ['touchstart', 'mousedown'];
|
28
|
|
29
|
function closestSortable(ele) {
|
30
|
|
31
|
ele = UI.$(ele);
|
32
|
|
33
|
do {
|
34
|
if (ele.data('sortable')) {
|
35
|
return ele;
|
36
|
}
|
37
|
ele = UI.$(ele).parent();
|
38
|
} while(ele.length);
|
39
|
|
40
|
return ele;
|
41
|
}
|
42
|
|
43
|
UI.component('sortable', {
|
44
|
|
45
|
defaults: {
|
46
|
|
47
|
animation : 150,
|
48
|
threshold : 10,
|
49
|
|
50
|
childClass : 'uk-sortable-item',
|
51
|
placeholderClass : 'uk-sortable-placeholder',
|
52
|
overClass : 'uk-sortable-over',
|
53
|
draggingClass : 'uk-sortable-dragged',
|
54
|
dragMovingClass : 'uk-sortable-moving',
|
55
|
baseClass : 'uk-sortable',
|
56
|
noDragClass : 'uk-sortable-nodrag',
|
57
|
emptyClass : 'uk-sortable-empty',
|
58
|
dragCustomClass : '',
|
59
|
handleClass : false,
|
60
|
group : false,
|
61
|
|
62
|
stop : function() {},
|
63
|
start : function() {},
|
64
|
change : function() {}
|
65
|
},
|
66
|
|
67
|
boot: function() {
|
68
|
|
69
|
// auto init
|
70
|
UI.ready(function(context) {
|
71
|
|
72
|
UI.$("[data-uk-sortable]", context).each(function(){
|
73
|
|
74
|
var ele = UI.$(this);
|
75
|
|
76
|
if(!ele.data("sortable")) {
|
77
|
UI.sortable(ele, UI.Utils.options(ele.attr("data-uk-sortable")));
|
78
|
}
|
79
|
});
|
80
|
});
|
81
|
|
82
|
UI.$html.on('mousemove touchmove', function(e) {
|
83
|
|
84
|
if (delayIdle) {
|
85
|
|
86
|
var src = e.originalEvent.targetTouches ? e.originalEvent.targetTouches[0] : e;
|
87
|
|
88
|
if (Math.abs(src.pageX - delayIdle.pos.x) > delayIdle.threshold || Math.abs(src.pageY - delayIdle.pos.y) > delayIdle.threshold) {
|
89
|
delayIdle.apply(src);
|
90
|
}
|
91
|
}
|
92
|
|
93
|
if (draggingPlaceholder) {
|
94
|
|
95
|
if (!moving) {
|
96
|
moving = true;
|
97
|
draggingPlaceholder.show();
|
98
|
|
99
|
draggingPlaceholder.$current.addClass(draggingPlaceholder.$sortable.options.placeholderClass);
|
100
|
draggingPlaceholder.$sortable.element.children().addClass(draggingPlaceholder.$sortable.options.childClass);
|
101
|
|
102
|
UI.$html.addClass(draggingPlaceholder.$sortable.options.dragMovingClass);
|
103
|
}
|
104
|
|
105
|
var offset = draggingPlaceholder.data('mouse-offset');
|
106
|
var left = parseInt((e.originalEvent.touches && e.originalEvent.touches[0] ? e.originalEvent.touches[0].pageX : e.originalEvent.pageX), 10) + offset.left;
|
107
|
var top = parseInt((e.originalEvent.touches && e.originalEvent.touches[0] ? e.originalEvent.touches[0].pageY : e.originalEvent.pageY), 10) + offset.top;
|
108
|
|
109
|
draggingPlaceholder.css({'left': left, 'top': top });
|
110
|
|
111
|
// adjust document scrolling
|
112
|
|
113
|
if (top + (draggingPlaceholder.height()/3) > document.body.offsetHeight) {
|
114
|
return;
|
115
|
}
|
116
|
|
117
|
if (top < UI.$win.scrollTop()) {
|
118
|
UI.$win.scrollTop(UI.$win.scrollTop() - Math.ceil(draggingPlaceholder.height()/3));
|
119
|
} else if ( (top + (draggingPlaceholder.height()/3)) > (window.innerHeight + UI.$win.scrollTop()) ) {
|
120
|
UI.$win.scrollTop(UI.$win.scrollTop() + Math.ceil(draggingPlaceholder.height()/3));
|
121
|
}
|
122
|
}
|
123
|
});
|
124
|
|
125
|
UI.$html.on('mouseup touchend', function(e) {
|
126
|
|
127
|
delayIdle = clickedlink = false;
|
128
|
|
129
|
// dragging?
|
130
|
if (!currentlyDraggingElement || !draggingPlaceholder) {
|
131
|
// completely reset dragging attempt. will cause weird delay behavior elsewise
|
132
|
currentlyDraggingElement = draggingPlaceholder = null;
|
133
|
return;
|
134
|
}
|
135
|
|
136
|
// inside or outside of sortable?
|
137
|
var sortable = closestSortable(currentlyDraggingElement),
|
138
|
component = draggingPlaceholder.$sortable,
|
139
|
ev = { type: e.type };
|
140
|
|
141
|
if (sortable[0]) {
|
142
|
component.dragDrop(ev, component.element);
|
143
|
}
|
144
|
component.dragEnd(ev, component.element);
|
145
|
});
|
146
|
},
|
147
|
|
148
|
init: function() {
|
149
|
|
150
|
var $this = this,
|
151
|
element = this.element[0];
|
152
|
|
153
|
touchedlists = [];
|
154
|
|
155
|
this.checkEmptyList();
|
156
|
|
157
|
this.element.data('sortable-group', this.options.group ? this.options.group : UI.Utils.uid('sortable-group'));
|
158
|
|
159
|
var handleDragStart = delegate(function(e) {
|
160
|
|
161
|
if (e.data && e.data.sortable) {
|
162
|
return;
|
163
|
}
|
164
|
|
165
|
var $target = UI.$(e.target),
|
166
|
$link = $target.is('a[href]') ? $target:$target.parents('a[href]');
|
167
|
|
168
|
if ($target.is(':input')) {
|
169
|
return;
|
170
|
}
|
171
|
|
172
|
e.preventDefault();
|
173
|
|
174
|
if (!e.touches && $link.length) {
|
175
|
|
176
|
$link.one('click', function(e){
|
177
|
e.preventDefault();
|
178
|
}).one('mouseup', function(){
|
179
|
if(!moved) $link.trigger('click');
|
180
|
});
|
181
|
}
|
182
|
|
183
|
e.data = e.data || {};
|
184
|
|
185
|
e.data.sortable = element;
|
186
|
|
187
|
return $this.dragStart(e, this);
|
188
|
});
|
189
|
|
190
|
var handleDragEnter = delegate(UI.Utils.debounce(function(e) {
|
191
|
return $this.dragEnter(e, this);
|
192
|
}), 40);
|
193
|
|
194
|
var handleDragLeave = delegate(function(e) {
|
195
|
|
196
|
// Prevent dragenter on a child from allowing a dragleave on the container
|
197
|
var previousCounter = $this.dragenterData(this);
|
198
|
$this.dragenterData(this, previousCounter - 1);
|
199
|
|
200
|
// This is a fix for child elements firing dragenter before the parent fires dragleave
|
201
|
if (!$this.dragenterData(this)) {
|
202
|
UI.$(this).removeClass($this.options.overClass);
|
203
|
$this.dragenterData(this, false);
|
204
|
}
|
205
|
});
|
206
|
|
207
|
var handleTouchMove = delegate(function(e) {
|
208
|
|
209
|
if (!currentlyDraggingElement ||
|
210
|
currentlyDraggingElement === this ||
|
211
|
currentlyDraggingTarget === this) {
|
212
|
return true;
|
213
|
}
|
214
|
|
215
|
$this.element.children().removeClass($this.options.overClass);
|
216
|
currentlyDraggingTarget = this;
|
217
|
|
218
|
$this.moveElementNextTo(currentlyDraggingElement, this);
|
219
|
|
220
|
return prevent(e);
|
221
|
});
|
222
|
|
223
|
// Bind/unbind standard mouse/touch events as a polyfill.
|
224
|
function addDragHandlers() {
|
225
|
//useCapture false is default
|
226
|
dragEvents.forEach(function (eDrag) {
|
227
|
element.addEventListener(eDrag, handleTouchMove, false);
|
228
|
});
|
229
|
}
|
230
|
|
231
|
function removeDragHandlers() {
|
232
|
//useCapture false is default
|
233
|
dragEvents.forEach(function (eDrag) {
|
234
|
element.removeEventListener(eDrag, handleTouchMove, false);
|
235
|
});
|
236
|
}
|
237
|
|
238
|
this.addDragHandlers = addDragHandlers;
|
239
|
this.removeDragHandlers = removeDragHandlers;
|
240
|
|
241
|
function handleDragMove(e) {
|
242
|
|
243
|
if (!currentlyDraggingElement) {
|
244
|
return;
|
245
|
}
|
246
|
|
247
|
$this.dragMove(e, $this);
|
248
|
}
|
249
|
|
250
|
function delegate(fn) {
|
251
|
|
252
|
return function(e) {
|
253
|
|
254
|
var touch, target, context;
|
255
|
|
256
|
if (e) {
|
257
|
touch = (e.touches && e.touches[0]) || { };
|
258
|
target = touch.target || e.target;
|
259
|
|
260
|
// Fix event.target for a touch event
|
261
|
if ((e.touches && e.touches[0]) && document.elementFromPoint) {
|
262
|
target = document.elementFromPoint(touch.pageX - document.body.scrollLeft, touch.pageY - document.body.scrollTop);
|
263
|
}
|
264
|
|
265
|
overElement = UI.$(target);
|
266
|
}
|
267
|
|
268
|
if (UI.$(target).hasClass($this.options.childClass)) {
|
269
|
fn.apply(target, [e]);
|
270
|
} else if (target !== element) {
|
271
|
|
272
|
// If a child is initiating the event or ending it, then use the container as context for the callback.
|
273
|
context = moveUpToChildNode(element, target);
|
274
|
|
275
|
if (context) {
|
276
|
fn.apply(context, [e]);
|
277
|
}
|
278
|
}
|
279
|
};
|
280
|
}
|
281
|
|
282
|
dragMoveEvents.forEach(function (eDrag) {
|
283
|
window.addEventListener(eDrag, handleDragMove, false);
|
284
|
});
|
285
|
|
286
|
dragStartEvents.forEach(function (eDrag) {
|
287
|
element.addEventListener(eDrag, handleDragStart, false);
|
288
|
});
|
289
|
},
|
290
|
|
291
|
dragStart: function(e, elem) {
|
292
|
|
293
|
moved = false;
|
294
|
moving = false;
|
295
|
dragging = false;
|
296
|
|
297
|
var $this = this,
|
298
|
target = UI.$(e.target);
|
299
|
|
300
|
if (!e.touches && e.button==2) {
|
301
|
return;
|
302
|
}
|
303
|
|
304
|
if ($this.options.handleClass) {
|
305
|
|
306
|
var handle = target.hasClass($this.options.handleClass) ? target : target.closest('.'+$this.options.handleClass, $this.element);
|
307
|
|
308
|
if (!handle.length) {
|
309
|
//e.preventDefault();
|
310
|
return;
|
311
|
}
|
312
|
}
|
313
|
|
314
|
if (target.is('.'+$this.options.noDragClass) || target.closest('.'+$this.options.noDragClass).length) {
|
315
|
return;
|
316
|
}
|
317
|
|
318
|
// prevent dragging if taget is a form field
|
319
|
if (target.is(':input')) {
|
320
|
return;
|
321
|
}
|
322
|
|
323
|
currentlyDraggingElement = elem;
|
324
|
|
325
|
// init drag placeholder
|
326
|
if (draggingPlaceholder) {
|
327
|
draggingPlaceholder.remove();
|
328
|
}
|
329
|
|
330
|
var $current = UI.$(currentlyDraggingElement);
|
331
|
var offset = $current.offset();
|
332
|
|
333
|
delayIdle = {
|
334
|
|
335
|
pos : { x: (e.touches && e.touches[0] ? e.touches[0].pageX : e.pageX), y: (e.touches && e.touches[0] ? e.touches[0].pageY : e.pageY) },
|
336
|
threshold : $this.options.threshold,
|
337
|
apply : function(evt) {
|
338
|
|
339
|
draggingPlaceholder = UI.$('<div class="'+([$this.options.draggingClass, $this.options.dragCustomClass].join(' '))+'"></div>').css({
|
340
|
display : 'none',
|
341
|
top : offset.top,
|
342
|
left : offset.left,
|
343
|
width : $current.width(),
|
344
|
height : $current.height(),
|
345
|
padding : $current.css('padding')
|
346
|
}).data({
|
347
|
'mouse-offset': {
|
348
|
'left' : offset.left - parseInt(evt.pageX, 10),
|
349
|
'top' : offset.top - parseInt(evt.pageY, 10)
|
350
|
},
|
351
|
'origin' : $this.element,
|
352
|
'index' : $current.index()
|
353
|
}).append($current.html()).appendTo('body');
|
354
|
|
355
|
draggingPlaceholder.$current = $current;
|
356
|
draggingPlaceholder.$sortable = $this;
|
357
|
|
358
|
$current.data({
|
359
|
'start-list': $current.parent(),
|
360
|
'start-index': $current.index(),
|
361
|
'sortable-group': $this.options.group
|
362
|
});
|
363
|
|
364
|
$this.addDragHandlers();
|
365
|
|
366
|
$this.options.start(this, currentlyDraggingElement);
|
367
|
$this.trigger('start.uk.sortable', [$this, currentlyDraggingElement]);
|
368
|
|
369
|
moved = true;
|
370
|
delayIdle = false;
|
371
|
}
|
372
|
};
|
373
|
},
|
374
|
|
375
|
dragMove: function(e, elem) {
|
376
|
var pageX = e.touches && e.touches[0] ? e.touches[0].pageX : e.pageX;
|
377
|
var pageY = e.touches && e.touches[0] ? e.touches[0].pageY : e.pageY;
|
378
|
overElement = UI.$(document.elementFromPoint
|
379
|
(
|
380
|
pageX - (document.body.scrollLeft || document.scrollLeft || 0),
|
381
|
pageY - (document.body.scrollTop || document.documentElement.scrollTop || 0)
|
382
|
));
|
383
|
|
384
|
var overRoot = overElement.closest('.'+this.options.baseClass);
|
385
|
var groupOver = overRoot.data("sortable-group");
|
386
|
var $current = UI.$(currentlyDraggingElement);
|
387
|
var currentRoot = $current.parent();
|
388
|
var groupCurrent = $current.data("sortable-group");
|
389
|
var overChild;
|
390
|
|
391
|
if (overRoot[0] !== currentRoot[0] && groupCurrent !== undefined && groupOver === groupCurrent) {
|
392
|
|
393
|
overRoot.data('sortable').addDragHandlers();
|
394
|
|
395
|
touchedlists.push(overRoot);
|
396
|
overRoot.children().addClass(this.options.childClass);
|
397
|
|
398
|
// swap root
|
399
|
if (overRoot.children().length > 0) {
|
400
|
overChild = overElement.closest('.'+this.options.childClass);
|
401
|
|
402
|
if (overChild.length) {
|
403
|
overChild.before($current);
|
404
|
} else {
|
405
|
overRoot.append($current);
|
406
|
}
|
407
|
|
408
|
} else { // empty list
|
409
|
overElement.append($current);
|
410
|
}
|
411
|
|
412
|
UIkit.$doc.trigger('mouseover');
|
413
|
}
|
414
|
|
415
|
this.checkEmptyList();
|
416
|
this.checkEmptyList(currentRoot);
|
417
|
},
|
418
|
|
419
|
dragEnter: function(e, elem) {
|
420
|
|
421
|
if (!currentlyDraggingElement || currentlyDraggingElement === elem) {
|
422
|
return true;
|
423
|
}
|
424
|
|
425
|
var previousCounter = this.dragenterData(elem);
|
426
|
|
427
|
this.dragenterData(elem, previousCounter + 1);
|
428
|
|
429
|
// Prevent dragenter on a child from allowing a dragleave on the container
|
430
|
if (previousCounter === 0) {
|
431
|
|
432
|
var currentlist = UI.$(elem).parent(),
|
433
|
startlist = UI.$(currentlyDraggingElement).data("start-list");
|
434
|
|
435
|
if (currentlist[0] !== startlist[0]) {
|
436
|
|
437
|
var groupOver = currentlist.data('sortable-group'),
|
438
|
groupCurrent = UI.$(currentlyDraggingElement).data("sortable-group");
|
439
|
|
440
|
if ((groupOver || groupCurrent) && (groupOver != groupCurrent)) {
|
441
|
return false;
|
442
|
}
|
443
|
}
|
444
|
|
445
|
UI.$(elem).addClass(this.options.overClass);
|
446
|
this.moveElementNextTo(currentlyDraggingElement, elem);
|
447
|
}
|
448
|
|
449
|
return false;
|
450
|
},
|
451
|
|
452
|
dragEnd: function(e, elem) {
|
453
|
|
454
|
var $this = this;
|
455
|
|
456
|
// avoid triggering event twice
|
457
|
if (currentlyDraggingElement) {
|
458
|
// TODO: trigger on right element?
|
459
|
this.options.stop(elem);
|
460
|
this.trigger('stop.uk.sortable', [this]);
|
461
|
}
|
462
|
|
463
|
currentlyDraggingElement = null;
|
464
|
currentlyDraggingTarget = null;
|
465
|
|
466
|
touchedlists.push(this.element);
|
467
|
touchedlists.forEach(function(el, i) {
|
468
|
UI.$(el).children().each(function() {
|
469
|
if (this.nodeType === 1) {
|
470
|
UI.$(this).removeClass($this.options.overClass)
|
471
|
.removeClass($this.options.placeholderClass)
|
472
|
.removeClass($this.options.childClass);
|
473
|
$this.dragenterData(this, false);
|
474
|
}
|
475
|
});
|
476
|
});
|
477
|
|
478
|
touchedlists = [];
|
479
|
|
480
|
UI.$html.removeClass(this.options.dragMovingClass);
|
481
|
|
482
|
this.removeDragHandlers();
|
483
|
|
484
|
if (draggingPlaceholder) {
|
485
|
draggingPlaceholder.remove();
|
486
|
draggingPlaceholder = null;
|
487
|
}
|
488
|
},
|
489
|
|
490
|
dragDrop: function(e, elem) {
|
491
|
|
492
|
if (e.type === 'drop') {
|
493
|
|
494
|
if (e.stopPropagation) {
|
495
|
e.stopPropagation();
|
496
|
}
|
497
|
|
498
|
if (e.preventDefault) {
|
499
|
e.preventDefault();
|
500
|
}
|
501
|
}
|
502
|
|
503
|
this.triggerChangeEvents();
|
504
|
},
|
505
|
|
506
|
triggerChangeEvents: function() {
|
507
|
|
508
|
// trigger events once
|
509
|
if (!currentlyDraggingElement) return;
|
510
|
|
511
|
var $current = UI.$(currentlyDraggingElement),
|
512
|
oldRoot = draggingPlaceholder.data("origin"),
|
513
|
newRoot = $current.closest('.'+this.options.baseClass),
|
514
|
triggers = [],
|
515
|
el = UI.$(currentlyDraggingElement);
|
516
|
|
517
|
// events depending on move inside lists or across lists
|
518
|
if (oldRoot[0] === newRoot[0] && draggingPlaceholder.data('index') != $current.index() ) {
|
519
|
triggers.push({sortable: this, mode: 'moved'});
|
520
|
} else if (oldRoot[0] != newRoot[0]) {
|
521
|
triggers.push({sortable: UI.$(newRoot).data('sortable'), mode: 'added'}, {sortable: UI.$(oldRoot).data('sortable'), mode: 'removed'});
|
522
|
}
|
523
|
|
524
|
triggers.forEach(function (trigger, i) {
|
525
|
if (trigger.sortable) {
|
526
|
trigger.sortable.element.trigger('change.uk.sortable', [trigger.sortable, el, trigger.mode]);
|
527
|
}
|
528
|
});
|
529
|
},
|
530
|
|
531
|
dragenterData: function(element, val) {
|
532
|
|
533
|
element = UI.$(element);
|
534
|
|
535
|
if (arguments.length == 1) {
|
536
|
return parseInt(element.data('child-dragenter'), 10) || 0;
|
537
|
} else if (!val) {
|
538
|
element.removeData('child-dragenter');
|
539
|
} else {
|
540
|
element.data('child-dragenter', Math.max(0, val));
|
541
|
}
|
542
|
},
|
543
|
|
544
|
moveElementNextTo: function(element, elementToMoveNextTo) {
|
545
|
|
546
|
dragging = true;
|
547
|
|
548
|
var $this = this,
|
549
|
list = UI.$(element).parent().css('min-height', ''),
|
550
|
next = isBelow(element, elementToMoveNextTo) ? elementToMoveNextTo : elementToMoveNextTo.nextSibling,
|
551
|
children = list.children(),
|
552
|
count = children.length;
|
553
|
|
554
|
if (!$this.options.animation) {
|
555
|
elementToMoveNextTo.parentNode.insertBefore(element, next);
|
556
|
UI.Utils.checkDisplay($this.element.parent());
|
557
|
return;
|
558
|
}
|
559
|
|
560
|
list.css('min-height', list.height());
|
561
|
|
562
|
children.stop().each(function(){
|
563
|
var ele = UI.$(this),
|
564
|
offset = ele.position();
|
565
|
|
566
|
offset.width = ele.width();
|
567
|
|
568
|
ele.data('offset-before', offset);
|
569
|
});
|
570
|
|
571
|
elementToMoveNextTo.parentNode.insertBefore(element, next);
|
572
|
|
573
|
UI.Utils.checkDisplay($this.element.parent());
|
574
|
|
575
|
children = list.children().each(function() {
|
576
|
var ele = UI.$(this);
|
577
|
ele.data('offset-after', ele.position());
|
578
|
}).each(function() {
|
579
|
var ele = UI.$(this),
|
580
|
before = ele.data('offset-before');
|
581
|
ele.css({'position':'absolute', 'top':before.top, 'left':before.left, 'min-width':before.width });
|
582
|
});
|
583
|
|
584
|
children.each(function(){
|
585
|
|
586
|
var ele = UI.$(this),
|
587
|
before = ele.data('offset-before'),
|
588
|
offset = ele.data('offset-after');
|
589
|
|
590
|
ele.css('pointer-events', 'none').width();
|
591
|
|
592
|
setTimeout(function(){
|
593
|
ele.animate({'top':offset.top, 'left':offset.left}, $this.options.animation, function() {
|
594
|
ele.css({'position':'','top':'', 'left':'', 'min-width': '', 'pointer-events':''}).removeClass($this.options.overClass).removeData('child-dragenter');
|
595
|
count--;
|
596
|
if (!count) {
|
597
|
list.css('min-height', '');
|
598
|
UI.Utils.checkDisplay($this.element.parent());
|
599
|
}
|
600
|
});
|
601
|
}, 0);
|
602
|
});
|
603
|
},
|
604
|
|
605
|
serialize: function() {
|
606
|
|
607
|
var data = [], item, attribute;
|
608
|
|
609
|
this.element.children().each(function(j, child) {
|
610
|
item = {};
|
611
|
for (var i = 0; i < child.attributes.length; i++) {
|
612
|
attribute = child.attributes[i];
|
613
|
if (attribute.name.indexOf('data-') === 0) {
|
614
|
item[attribute.name.substr(5)] = UI.Utils.str2json(attribute.value);
|
615
|
}
|
616
|
}
|
617
|
data.push(item);
|
618
|
});
|
619
|
|
620
|
return data;
|
621
|
},
|
622
|
|
623
|
checkEmptyList: function(list) {
|
624
|
|
625
|
list = list ? UI.$(list) : this.element;
|
626
|
|
627
|
if (this.options.emptyClass) {
|
628
|
list[!list.children().length ? 'addClass':'removeClass'](this.options.emptyClass);
|
629
|
}
|
630
|
}
|
631
|
});
|
632
|
|
633
|
// helpers
|
634
|
|
635
|
function isBelow(el1, el2) {
|
636
|
|
637
|
var parent = el1.parentNode;
|
638
|
|
639
|
if (el2.parentNode != parent) {
|
640
|
return false;
|
641
|
}
|
642
|
|
643
|
var cur = el1.previousSibling;
|
644
|
|
645
|
while (cur && cur.nodeType !== 9) {
|
646
|
if (cur === el2) {
|
647
|
return true;
|
648
|
}
|
649
|
cur = cur.previousSibling;
|
650
|
}
|
651
|
|
652
|
return false;
|
653
|
}
|
654
|
|
655
|
function moveUpToChildNode(parent, child) {
|
656
|
var cur = child;
|
657
|
if (cur == parent) { return null; }
|
658
|
|
659
|
while (cur) {
|
660
|
if (cur.parentNode === parent) {
|
661
|
return cur;
|
662
|
}
|
663
|
|
664
|
cur = cur.parentNode;
|
665
|
if ( !cur || !cur.ownerDocument || cur.nodeType === 11 ) {
|
666
|
break;
|
667
|
}
|
668
|
}
|
669
|
return null;
|
670
|
}
|
671
|
|
672
|
function prevent(e) {
|
673
|
if (e.stopPropagation) {
|
674
|
e.stopPropagation();
|
675
|
}
|
676
|
if (e.preventDefault) {
|
677
|
e.preventDefault();
|
678
|
}
|
679
|
e.returnValue = false;
|
680
|
}
|
681
|
|
682
|
return UI.sortable;
|
683
|
});
|