2
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.com/yui/license.html
8
8
YUI.add('sortable', function(Y) {
119
119
if (e.drag.get(NODE) == e.drop.get(NODE)) {
122
// is drop a child of drag?
123
if (e.drag.get(NODE).contains(e.drop.get(NODE))) {
126
var same = false, dir, oldNode, newNode, dropsort, dropNode,
127
moveType = this.get('moveType').toLowerCase();
123
switch (this.get('moveType').toLowerCase()) {
129
if (e.drag.get(NODE).get(PARENT_NODE).contains(e.drop.get(NODE))) {
132
if (same && moveType == 'move') {
125
var dir = ((this._up) ? 'before' : 'after');
126
e.drop.get(NODE).insert(e.drag.get(NODE), dir);
137
dir = ((this._up) ? 'before' : 'after');
138
dropNode = e.drop.get(NODE);
139
if (Y.Sortable._test(dropNode, this.get(CONT))) {
140
dropNode.append(e.drag.get(NODE));
142
dropNode.insert(e.drag.get(NODE), dir);
129
146
Y.DD.DDM.swapNode(e.drag, e.drop);
133
var dropsort = Y.Sortable.getSortable(e.drop.get(NODE).get(PARENT_NODE)),
150
dropsort = Y.Sortable.getSortable(e.drop.get(NODE).get(PARENT_NODE));
140
156
Y.DD.DDM.getDrop(e.drag.get(NODE)).addToGroup(dropsort.get(ID));
143
if (e.drag.get(NODE).get(PARENT_NODE).contains(e.drop.get(NODE))) {
144
160
Y.DD.DDM.swapNode(e.drag, e.drop);
146
162
if (this.get('moveType') == 'copy') {
180
this.fire(moveType, { same: same, drag: e.drag, drop: e.drop });
181
this.fire('moved', { same: same, drag: e.drag, drop: e.drop });
196
215
plug: function(cls, config) {
197
this.delegate.dd.plug(cls, config);
216
//I don't like this.. Not at all, need to discuss with the team
217
if (cls && cls.NAME.substring(0, 4).toLowerCase() === 'sort') {
218
this.constructor.superclass.plug.call(this, cls, config);
220
this.delegate.dd.plug(cls, config);
215
* @param Sortable sel The sortable list to join with
239
* @param Sortable sel The Sortable list to join with
216
240
* @param String type The type of join to do: full, inner, outer, none. Default: full
217
241
* @description Join this Sortable with another Sortable instance.
265
289
* @method _join_outer
266
* @param Sortable sel The sortable list to join with
290
* @param Sortable sel The Sortable list to join with
267
291
* @description Allows this Sortable to accept items from the passed Sortable.
269
293
_join_outer: function(sel) {
274
298
* @method _join_inner
275
* @param Sortable sel The sortable list to join with
299
* @param Sortable sel The Sortable list to join with
276
300
* @description Allows this Sortable to give items to the passed Sortable.
278
302
_join_inner: function(sel) {
279
303
sel.delegate.dd.addToGroup(this.get(ID));
306
* A custom callback to allow a user to extract some sort of id or any other data from the node to use in the "ordering list" and then that data should be returned from the callback.
307
* @method getOrdering
308
* @param Function callback
311
getOrdering: function(callback) {
314
if (!Y.Lang.isFunction(callback)) {
315
callback = function (node) {
320
Y.one(this.get(CONT)).all(this.get(NODES)).each(function(node) {
321
ordering.push(callback(node));
282
326
NAME: 'sortable',
404
* @param {Node} node The node instance to test.
405
* @param {String|Node} test The node instance or selector string to test against.
406
* @description Test a Node or a selector for the container
408
_test: function(node, test) {
409
if (test instanceof Y.Node) {
410
return (test === node);
412
return node.test(test);
359
417
* @method getSortable
360
418
* @param {String|Node} node The node instance or selector string to use to find a Sortable instance.
361
* @description Get a sortable instance back from a node reference or a selector string.
419
* @description Get a Sortable instance back from a node reference or a selector string.
363
421
getSortable: function(node) {
365
423
node = Y.one(node);
366
Y.each(Sortable._sortables, function(v) {
367
if (node.test(v.get(CONT))) {
424
Y.each(Y.Sortable._sortables, function(v) {
425
if (Y.Sortable._test(node, v.get(CONT))) {
386
444
* @description Unregister a Sortable instance with the singleton.
388
446
unreg: function(s) {
389
Y.each(Sortable._sortables, function(v, k) {
447
Y.each(Y.Sortable._sortables, function(v, k) {
391
Sortable._sortables[k] = null;
449
Y.Sortable._sortables[k] = null;
392
450
delete Sortable._sortables[k];
398
456
Y.Sortable = Sortable;
402
}, '3.1.2' ,{requires:['dd-delegate', 'dd-drop-plugin', 'dd-proxy']});
460
* @description A Sortable node was moved.
461
* @param {Event.Facade} event An Event Facade object with the following specific property added:
463
* <dt>same</dt><dd>Moved to the same list.</dd>
464
* <dt>drag</dt><dd>The Drag Object</dd>
465
* <dt>drop</dt><dd>The Drop Object</dd>
467
* @type {Event.Custom}
471
* @description A Sortable node was moved.
472
* @param {Event.Facade} event An Event Facade object with the following specific property added:
474
* <dt>same</dt><dd>Moved to the same list.</dd>
475
* <dt>drag</dt><dd>The Drag Object</dd>
476
* <dt>drop</dt><dd>The Drop Object</dd>
478
* @type {Event.Custom}
482
* @description A Sortable node was moved.
483
* @param {Event.Facade} event An Event Facade object with the following specific property added:
485
* <dt>same</dt><dd>Moved to the same list.</dd>
486
* <dt>drag</dt><dd>The Drag Object</dd>
487
* <dt>drop</dt><dd>The Drop Object</dd>
489
* @type {Event.Custom}
493
* @description A Sortable node was moved.
494
* @param {Event.Facade} event An Event Facade object with the following specific property added:
496
* <dt>same</dt><dd>Moved to the same list.</dd>
497
* <dt>drag</dt><dd>The Drag Object</dd>
498
* <dt>drop</dt><dd>The Drop Object</dd>
500
* @type {Event.Custom}
504
* @description A Sortable node was moved.
505
* @param {Event.Facade} event An Event Facade object with the following specific property added:
507
* <dt>same</dt><dd>Moved to the same list.</dd>
508
* <dt>drag</dt><dd>The Drag Object</dd>
509
* <dt>drop</dt><dd>The Drop Object</dd>
511
* @type {Event.Custom}
516
}, '3.2.0' ,{requires:['dd-delegate', 'dd-drop-plugin', 'dd-proxy']});