~ted/lazr-js/annoying-debug-message

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/sortable/sortable.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-09-09 14:20:30 UTC
  • mfrom: (182.1.3 yui-3.2)
  • Revision ID: launchpad@pqm.canonical.com-20100909142030-13w6vo0ixfysxc15
[r=beuno] Update lazr-js to yui-3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
 
version: 3.1.2
6
 
build: 56
 
5
version: 3.2.0
 
6
build: 2676
7
7
*/
8
8
YUI.add('sortable', function(Y) {
9
9
 
119
119
            if (e.drag.get(NODE) == e.drop.get(NODE)) {
120
120
                return;
121
121
            }
 
122
            // is drop a child of drag?
 
123
            if (e.drag.get(NODE).contains(e.drop.get(NODE))) {
 
124
                return;
 
125
            }
 
126
            var same = false, dir, oldNode, newNode, dropsort, dropNode,
 
127
                moveType = this.get('moveType').toLowerCase();
122
128
 
123
 
            switch (this.get('moveType').toLowerCase()) {
 
129
            if (e.drag.get(NODE).get(PARENT_NODE).contains(e.drop.get(NODE))) {
 
130
                same = true;
 
131
            }
 
132
            if (same && moveType == 'move') {
 
133
                moveType = 'insert';
 
134
            }
 
135
            switch (moveType) {
124
136
                case 'insert':
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));
 
141
                    } else {
 
142
                        dropNode.insert(e.drag.get(NODE), dir);
 
143
                    }
127
144
                    break;
128
145
                case 'swap':
129
146
                    Y.DD.DDM.swapNode(e.drag, e.drop);
130
147
                    break;
131
148
                case 'move':
132
149
                case 'copy':
133
 
                    var dropsort = Y.Sortable.getSortable(e.drop.get(NODE).get(PARENT_NODE)),
134
 
                        oldNode, newNode;
 
150
                    dropsort = Y.Sortable.getSortable(e.drop.get(NODE).get(PARENT_NODE));
135
151
 
136
152
                    if (!dropsort) {
137
153
                        return;
140
156
                    Y.DD.DDM.getDrop(e.drag.get(NODE)).addToGroup(dropsort.get(ID));
141
157
 
142
158
                    //Same List
143
 
                    if (e.drag.get(NODE).get(PARENT_NODE).contains(e.drop.get(NODE))) {
 
159
                    if (same) {
144
160
                        Y.DD.DDM.swapNode(e.drag, e.drop);
145
161
                    } else {
146
162
                        if (this.get('moveType') == 'copy') {
160
176
                    }
161
177
                    break;
162
178
            }
 
179
 
 
180
            this.fire(moveType, { same: same, drag: e.drag, drop: e.drop });
 
181
            this.fire('moved', { same: same, drag: e.drag, drop: e.drop });
163
182
        },
164
183
        /**
165
184
        * @private
194
213
        * @chainable
195
214
        */
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);
 
219
            } else {
 
220
                this.delegate.dd.plug(cls, config);
 
221
            }
198
222
            return this;
199
223
        },
200
224
        /**
212
236
        },
213
237
        /**
214
238
        * @method join
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.
218
242
        * <ul>
253
277
        /**
254
278
        * @private
255
279
        * @method _join_full
256
 
        * @param Sortable sel The sortable list to join with
 
280
        * @param Sortable sel The Sortable list to join with
257
281
        * @description Joins both of the Sortables together.
258
282
        */
259
283
        _join_full: function(sel) {
263
287
        /**
264
288
        * @private
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.
268
292
        */
269
293
        _join_outer: function(sel) {
272
296
        /**
273
297
        * @private
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.
277
301
        */
278
302
        _join_inner: function(sel) {
279
303
            sel.delegate.dd.addToGroup(this.get(ID));
280
 
        }
 
304
        },
 
305
        /**
 
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 
 
309
        * @returns Array
 
310
        */
 
311
        getOrdering: function(callback) {
 
312
            var ordering = [];
 
313
 
 
314
            if (!Y.Lang.isFunction(callback)) {
 
315
                callback = function (node) {
 
316
                    return node;
 
317
                };
 
318
            }
 
319
 
 
320
            Y.one(this.get(CONT)).all(this.get(NODES)).each(function(node) {
 
321
                ordering.push(callback(node));
 
322
            });
 
323
            return ordering;
 
324
       }
281
325
    }, {
282
326
        NAME: 'sortable',
283
327
        ATTRS: {
307
351
            },
308
352
            /**
309
353
            * @attribute opacity
310
 
            * @description The ocpacity to test the proxy item to when dragging.
 
354
            * @description The opacity to change the proxy item to when dragging.
311
355
            * @type String
312
356
            */        
313
357
            opacity: {
323
367
            },
324
368
            /**
325
369
            * @attribute id
326
 
            * @description The id of this sortable, used to get a reference to this sortable list from another list.
 
370
            * @description The id of this Sortable, used to get a reference to this Sortable list from another list.
327
371
            * @type String
328
372
            */        
329
373
            id: {
356
400
        _sortables: [],
357
401
        /**
358
402
        * @static
 
403
        * @method _test
 
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
 
407
        */
 
408
        _test: function(node, test) {
 
409
            if (test instanceof Y.Node) {
 
410
                return (test === node);
 
411
            } else {
 
412
                return node.test(test);
 
413
            }
 
414
        },
 
415
        /**
 
416
        * @static
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.
362
420
        */
363
421
        getSortable: function(node) {
364
422
            var s = null;
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))) {
368
426
                    s = v;
369
427
                }
370
428
            });
377
435
        * @description Register a Sortable instance with the singleton to allow lookups later.
378
436
        */
379
437
        reg: function(s) {
380
 
            Sortable._sortables.push(s);
 
438
            Y.Sortable._sortables.push(s);
381
439
        },
382
440
        /**
383
441
        * @static
386
444
        * @description Unregister a Sortable instance with the singleton.
387
445
        */
388
446
        unreg: function(s) {
389
 
            Y.each(Sortable._sortables, function(v, k) {
 
447
            Y.each(Y.Sortable._sortables, function(v, k) {
390
448
                if (v === s) {
391
 
                    Sortable._sortables[k] = null;
 
449
                    Y.Sortable._sortables[k] = null;
392
450
                    delete Sortable._sortables[k];
393
451
                }
394
452
            });
397
455
 
398
456
    Y.Sortable = Sortable;
399
457
 
400
 
 
401
 
 
402
 
}, '3.1.2' ,{requires:['dd-delegate', 'dd-drop-plugin', 'dd-proxy']});
 
458
    /**
 
459
    * @event copy
 
460
    * @description A Sortable node was moved.
 
461
    * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
462
    * <dl>
 
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>
 
466
    * </dl>
 
467
    * @type {Event.Custom}
 
468
    *
 
469
    *
 
470
    * @event move
 
471
    * @description A Sortable node was moved.
 
472
    * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
473
    * <dl>
 
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>
 
477
    * </dl>
 
478
    * @type {Event.Custom}
 
479
    *
 
480
    *
 
481
    * @event insert
 
482
    * @description A Sortable node was moved.
 
483
    * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
484
    * <dl>
 
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>
 
488
    * </dl>
 
489
    * @type {Event.Custom}
 
490
    *
 
491
    *
 
492
    * @event swap
 
493
    * @description A Sortable node was moved.
 
494
    * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
495
    * <dl>
 
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>
 
499
    * </dl>
 
500
    * @type {Event.Custom}
 
501
    *
 
502
    *
 
503
    * @event moved
 
504
    * @description A Sortable node was moved.
 
505
    * @param {Event.Facade} event An Event Facade object with the following specific property added:
 
506
    * <dl>
 
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>
 
510
    * </dl>
 
511
    * @type {Event.Custom}
 
512
    */
 
513
 
 
514
 
 
515
 
 
516
}, '3.2.0' ,{requires:['dd-delegate', 'dd-drop-plugin', 'dd-proxy']});