qiniu_form 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2251 @@
1
+ (function( $, undefined ) {
2
+
3
+ var uuid = 0,
4
+ runiqueId = /^ui-id-\d+$/;
5
+
6
+ // $.ui might exist from components with no dependencies, e.g., $.ui.position
7
+ $.ui = $.ui || {};
8
+
9
+ $.extend( $.ui, {
10
+ version: "1.10.4",
11
+
12
+ keyCode: {
13
+ BACKSPACE: 8,
14
+ COMMA: 188,
15
+ DELETE: 46,
16
+ DOWN: 40,
17
+ END: 35,
18
+ ENTER: 13,
19
+ ESCAPE: 27,
20
+ HOME: 36,
21
+ LEFT: 37,
22
+ NUMPAD_ADD: 107,
23
+ NUMPAD_DECIMAL: 110,
24
+ NUMPAD_DIVIDE: 111,
25
+ NUMPAD_ENTER: 108,
26
+ NUMPAD_MULTIPLY: 106,
27
+ NUMPAD_SUBTRACT: 109,
28
+ PAGE_DOWN: 34,
29
+ PAGE_UP: 33,
30
+ PERIOD: 190,
31
+ RIGHT: 39,
32
+ SPACE: 32,
33
+ TAB: 9,
34
+ UP: 38
35
+ }
36
+ });
37
+
38
+ // plugins
39
+ $.fn.extend({
40
+ focus: (function( orig ) {
41
+ return function( delay, fn ) {
42
+ return typeof delay === "number" ?
43
+ this.each(function() {
44
+ var elem = this;
45
+ setTimeout(function() {
46
+ $( elem ).focus();
47
+ if ( fn ) {
48
+ fn.call( elem );
49
+ }
50
+ }, delay );
51
+ }) :
52
+ orig.apply( this, arguments );
53
+ };
54
+ })( $.fn.focus ),
55
+
56
+ scrollParent: function() {
57
+ var scrollParent;
58
+ if (($.ui.ie && (/(static|relative)/).test(this.css("position"))) || (/absolute/).test(this.css("position"))) {
59
+ scrollParent = this.parents().filter(function() {
60
+ return (/(relative|absolute|fixed)/).test($.css(this,"position")) && (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
61
+ }).eq(0);
62
+ } else {
63
+ scrollParent = this.parents().filter(function() {
64
+ return (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
65
+ }).eq(0);
66
+ }
67
+
68
+ return (/fixed/).test(this.css("position")) || !scrollParent.length ? $(document) : scrollParent;
69
+ },
70
+
71
+ zIndex: function( zIndex ) {
72
+ if ( zIndex !== undefined ) {
73
+ return this.css( "zIndex", zIndex );
74
+ }
75
+
76
+ if ( this.length ) {
77
+ var elem = $( this[ 0 ] ), position, value;
78
+ while ( elem.length && elem[ 0 ] !== document ) {
79
+ // Ignore z-index if position is set to a value where z-index is ignored by the browser
80
+ // This makes behavior of this function consistent across browsers
81
+ // WebKit always returns auto if the element is positioned
82
+ position = elem.css( "position" );
83
+ if ( position === "absolute" || position === "relative" || position === "fixed" ) {
84
+ // IE returns 0 when zIndex is not specified
85
+ // other browsers return a string
86
+ // we ignore the case of nested elements with an explicit value of 0
87
+ // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
88
+ value = parseInt( elem.css( "zIndex" ), 10 );
89
+ if ( !isNaN( value ) && value !== 0 ) {
90
+ return value;
91
+ }
92
+ }
93
+ elem = elem.parent();
94
+ }
95
+ }
96
+
97
+ return 0;
98
+ },
99
+
100
+ uniqueId: function() {
101
+ return this.each(function() {
102
+ if ( !this.id ) {
103
+ this.id = "ui-id-" + (++uuid);
104
+ }
105
+ });
106
+ },
107
+
108
+ removeUniqueId: function() {
109
+ return this.each(function() {
110
+ if ( runiqueId.test( this.id ) ) {
111
+ $( this ).removeAttr( "id" );
112
+ }
113
+ });
114
+ }
115
+ });
116
+
117
+ // selectors
118
+ function focusable( element, isTabIndexNotNaN ) {
119
+ var map, mapName, img,
120
+ nodeName = element.nodeName.toLowerCase();
121
+ if ( "area" === nodeName ) {
122
+ map = element.parentNode;
123
+ mapName = map.name;
124
+ if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
125
+ return false;
126
+ }
127
+ img = $( "img[usemap=#" + mapName + "]" )[0];
128
+ return !!img && visible( img );
129
+ }
130
+ return ( /input|select|textarea|button|object/.test( nodeName ) ?
131
+ !element.disabled :
132
+ "a" === nodeName ?
133
+ element.href || isTabIndexNotNaN :
134
+ isTabIndexNotNaN) &&
135
+ // the element and all of its ancestors must be visible
136
+ visible( element );
137
+ }
138
+
139
+ function visible( element ) {
140
+ return $.expr.filters.visible( element ) &&
141
+ !$( element ).parents().addBack().filter(function() {
142
+ return $.css( this, "visibility" ) === "hidden";
143
+ }).length;
144
+ }
145
+
146
+ $.extend( $.expr[ ":" ], {
147
+ data: $.expr.createPseudo ?
148
+ $.expr.createPseudo(function( dataName ) {
149
+ return function( elem ) {
150
+ return !!$.data( elem, dataName );
151
+ };
152
+ }) :
153
+ // support: jQuery <1.8
154
+ function( elem, i, match ) {
155
+ return !!$.data( elem, match[ 3 ] );
156
+ },
157
+
158
+ focusable: function( element ) {
159
+ return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
160
+ },
161
+
162
+ tabbable: function( element ) {
163
+ var tabIndex = $.attr( element, "tabindex" ),
164
+ isTabIndexNaN = isNaN( tabIndex );
165
+ return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
166
+ }
167
+ });
168
+
169
+ // support: jQuery <1.8
170
+ if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
171
+ $.each( [ "Width", "Height" ], function( i, name ) {
172
+ var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
173
+ type = name.toLowerCase(),
174
+ orig = {
175
+ innerWidth: $.fn.innerWidth,
176
+ innerHeight: $.fn.innerHeight,
177
+ outerWidth: $.fn.outerWidth,
178
+ outerHeight: $.fn.outerHeight
179
+ };
180
+
181
+ function reduce( elem, size, border, margin ) {
182
+ $.each( side, function() {
183
+ size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
184
+ if ( border ) {
185
+ size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
186
+ }
187
+ if ( margin ) {
188
+ size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
189
+ }
190
+ });
191
+ return size;
192
+ }
193
+
194
+ $.fn[ "inner" + name ] = function( size ) {
195
+ if ( size === undefined ) {
196
+ return orig[ "inner" + name ].call( this );
197
+ }
198
+
199
+ return this.each(function() {
200
+ $( this ).css( type, reduce( this, size ) + "px" );
201
+ });
202
+ };
203
+
204
+ $.fn[ "outer" + name] = function( size, margin ) {
205
+ if ( typeof size !== "number" ) {
206
+ return orig[ "outer" + name ].call( this, size );
207
+ }
208
+
209
+ return this.each(function() {
210
+ $( this).css( type, reduce( this, size, true, margin ) + "px" );
211
+ });
212
+ };
213
+ });
214
+ }
215
+
216
+ // support: jQuery <1.8
217
+ if ( !$.fn.addBack ) {
218
+ $.fn.addBack = function( selector ) {
219
+ return this.add( selector == null ?
220
+ this.prevObject : this.prevObject.filter( selector )
221
+ );
222
+ };
223
+ }
224
+
225
+ // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
226
+ if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
227
+ $.fn.removeData = (function( removeData ) {
228
+ return function( key ) {
229
+ if ( arguments.length ) {
230
+ return removeData.call( this, $.camelCase( key ) );
231
+ } else {
232
+ return removeData.call( this );
233
+ }
234
+ };
235
+ })( $.fn.removeData );
236
+ }
237
+
238
+
239
+
240
+
241
+
242
+ // deprecated
243
+ $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
244
+
245
+ $.support.selectstart = "onselectstart" in document.createElement( "div" );
246
+ $.fn.extend({
247
+ disableSelection: function() {
248
+ return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
249
+ ".ui-disableSelection", function( event ) {
250
+ event.preventDefault();
251
+ });
252
+ },
253
+
254
+ enableSelection: function() {
255
+ return this.unbind( ".ui-disableSelection" );
256
+ }
257
+ });
258
+
259
+ $.extend( $.ui, {
260
+ // $.ui.plugin is deprecated. Use $.widget() extensions instead.
261
+ plugin: {
262
+ add: function( module, option, set ) {
263
+ var i,
264
+ proto = $.ui[ module ].prototype;
265
+ for ( i in set ) {
266
+ proto.plugins[ i ] = proto.plugins[ i ] || [];
267
+ proto.plugins[ i ].push( [ option, set[ i ] ] );
268
+ }
269
+ },
270
+ call: function( instance, name, args ) {
271
+ var i,
272
+ set = instance.plugins[ name ];
273
+ if ( !set || !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) {
274
+ return;
275
+ }
276
+
277
+ for ( i = 0; i < set.length; i++ ) {
278
+ if ( instance.options[ set[ i ][ 0 ] ] ) {
279
+ set[ i ][ 1 ].apply( instance.element, args );
280
+ }
281
+ }
282
+ }
283
+ },
284
+
285
+ // only used by resizable
286
+ hasScroll: function( el, a ) {
287
+
288
+ //If overflow is hidden, the element might have extra content, but the user wants to hide it
289
+ if ( $( el ).css( "overflow" ) === "hidden") {
290
+ return false;
291
+ }
292
+
293
+ var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
294
+ has = false;
295
+
296
+ if ( el[ scroll ] > 0 ) {
297
+ return true;
298
+ }
299
+
300
+ // TODO: determine which cases actually cause this to happen
301
+ // if the element doesn't have the scroll set, see if it's possible to
302
+ // set the scroll
303
+ el[ scroll ] = 1;
304
+ has = ( el[ scroll ] > 0 );
305
+ el[ scroll ] = 0;
306
+ return has;
307
+ }
308
+ });
309
+
310
+ })( jQuery );
311
+ (function( $, undefined ) {
312
+
313
+ var uuid = 0,
314
+ slice = Array.prototype.slice,
315
+ _cleanData = $.cleanData;
316
+ $.cleanData = function( elems ) {
317
+ for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
318
+ try {
319
+ $( elem ).triggerHandler( "remove" );
320
+ // http://bugs.jquery.com/ticket/8235
321
+ } catch( e ) {}
322
+ }
323
+ _cleanData( elems );
324
+ };
325
+
326
+ $.widget = function( name, base, prototype ) {
327
+ var fullName, existingConstructor, constructor, basePrototype,
328
+ // proxiedPrototype allows the provided prototype to remain unmodified
329
+ // so that it can be used as a mixin for multiple widgets (#8876)
330
+ proxiedPrototype = {},
331
+ namespace = name.split( "." )[ 0 ];
332
+
333
+ name = name.split( "." )[ 1 ];
334
+ fullName = namespace + "-" + name;
335
+
336
+ if ( !prototype ) {
337
+ prototype = base;
338
+ base = $.Widget;
339
+ }
340
+
341
+ // create selector for plugin
342
+ $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
343
+ return !!$.data( elem, fullName );
344
+ };
345
+
346
+ $[ namespace ] = $[ namespace ] || {};
347
+ existingConstructor = $[ namespace ][ name ];
348
+ constructor = $[ namespace ][ name ] = function( options, element ) {
349
+ // allow instantiation without "new" keyword
350
+ if ( !this._createWidget ) {
351
+ return new constructor( options, element );
352
+ }
353
+
354
+ // allow instantiation without initializing for simple inheritance
355
+ // must use "new" keyword (the code above always passes args)
356
+ if ( arguments.length ) {
357
+ this._createWidget( options, element );
358
+ }
359
+ };
360
+ // extend with the existing constructor to carry over any static properties
361
+ $.extend( constructor, existingConstructor, {
362
+ version: prototype.version,
363
+ // copy the object used to create the prototype in case we need to
364
+ // redefine the widget later
365
+ _proto: $.extend( {}, prototype ),
366
+ // track widgets that inherit from this widget in case this widget is
367
+ // redefined after a widget inherits from it
368
+ _childConstructors: []
369
+ });
370
+
371
+ basePrototype = new base();
372
+ // we need to make the options hash a property directly on the new instance
373
+ // otherwise we'll modify the options hash on the prototype that we're
374
+ // inheriting from
375
+ basePrototype.options = $.widget.extend( {}, basePrototype.options );
376
+ $.each( prototype, function( prop, value ) {
377
+ if ( !$.isFunction( value ) ) {
378
+ proxiedPrototype[ prop ] = value;
379
+ return;
380
+ }
381
+ proxiedPrototype[ prop ] = (function() {
382
+ var _super = function() {
383
+ return base.prototype[ prop ].apply( this, arguments );
384
+ },
385
+ _superApply = function( args ) {
386
+ return base.prototype[ prop ].apply( this, args );
387
+ };
388
+ return function() {
389
+ var __super = this._super,
390
+ __superApply = this._superApply,
391
+ returnValue;
392
+
393
+ this._super = _super;
394
+ this._superApply = _superApply;
395
+
396
+ returnValue = value.apply( this, arguments );
397
+
398
+ this._super = __super;
399
+ this._superApply = __superApply;
400
+
401
+ return returnValue;
402
+ };
403
+ })();
404
+ });
405
+ constructor.prototype = $.widget.extend( basePrototype, {
406
+ // TODO: remove support for widgetEventPrefix
407
+ // always use the name + a colon as the prefix, e.g., draggable:start
408
+ // don't prefix for widgets that aren't DOM-based
409
+ widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name
410
+ }, proxiedPrototype, {
411
+ constructor: constructor,
412
+ namespace: namespace,
413
+ widgetName: name,
414
+ widgetFullName: fullName
415
+ });
416
+
417
+ // If this widget is being redefined then we need to find all widgets that
418
+ // are inheriting from it and redefine all of them so that they inherit from
419
+ // the new version of this widget. We're essentially trying to replace one
420
+ // level in the prototype chain.
421
+ if ( existingConstructor ) {
422
+ $.each( existingConstructor._childConstructors, function( i, child ) {
423
+ var childPrototype = child.prototype;
424
+
425
+ // redefine the child widget using the same prototype that was
426
+ // originally used, but inherit from the new version of the base
427
+ $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
428
+ });
429
+ // remove the list of existing child constructors from the old constructor
430
+ // so the old child constructors can be garbage collected
431
+ delete existingConstructor._childConstructors;
432
+ } else {
433
+ base._childConstructors.push( constructor );
434
+ }
435
+
436
+ $.widget.bridge( name, constructor );
437
+ };
438
+
439
+ $.widget.extend = function( target ) {
440
+ var input = slice.call( arguments, 1 ),
441
+ inputIndex = 0,
442
+ inputLength = input.length,
443
+ key,
444
+ value;
445
+ for ( ; inputIndex < inputLength; inputIndex++ ) {
446
+ for ( key in input[ inputIndex ] ) {
447
+ value = input[ inputIndex ][ key ];
448
+ if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
449
+ // Clone objects
450
+ if ( $.isPlainObject( value ) ) {
451
+ target[ key ] = $.isPlainObject( target[ key ] ) ?
452
+ $.widget.extend( {}, target[ key ], value ) :
453
+ // Don't extend strings, arrays, etc. with objects
454
+ $.widget.extend( {}, value );
455
+ // Copy everything else by reference
456
+ } else {
457
+ target[ key ] = value;
458
+ }
459
+ }
460
+ }
461
+ }
462
+ return target;
463
+ };
464
+
465
+ $.widget.bridge = function( name, object ) {
466
+ var fullName = object.prototype.widgetFullName || name;
467
+ $.fn[ name ] = function( options ) {
468
+ var isMethodCall = typeof options === "string",
469
+ args = slice.call( arguments, 1 ),
470
+ returnValue = this;
471
+
472
+ // allow multiple hashes to be passed on init
473
+ options = !isMethodCall && args.length ?
474
+ $.widget.extend.apply( null, [ options ].concat(args) ) :
475
+ options;
476
+
477
+ if ( isMethodCall ) {
478
+ this.each(function() {
479
+ var methodValue,
480
+ instance = $.data( this, fullName );
481
+ if ( !instance ) {
482
+ return $.error( "cannot call methods on " + name + " prior to initialization; " +
483
+ "attempted to call method '" + options + "'" );
484
+ }
485
+ if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
486
+ return $.error( "no such method '" + options + "' for " + name + " widget instance" );
487
+ }
488
+ methodValue = instance[ options ].apply( instance, args );
489
+ if ( methodValue !== instance && methodValue !== undefined ) {
490
+ returnValue = methodValue && methodValue.jquery ?
491
+ returnValue.pushStack( methodValue.get() ) :
492
+ methodValue;
493
+ return false;
494
+ }
495
+ });
496
+ } else {
497
+ this.each(function() {
498
+ var instance = $.data( this, fullName );
499
+ if ( instance ) {
500
+ instance.option( options || {} )._init();
501
+ } else {
502
+ $.data( this, fullName, new object( options, this ) );
503
+ }
504
+ });
505
+ }
506
+
507
+ return returnValue;
508
+ };
509
+ };
510
+
511
+ $.Widget = function( /* options, element */ ) {};
512
+ $.Widget._childConstructors = [];
513
+
514
+ $.Widget.prototype = {
515
+ widgetName: "widget",
516
+ widgetEventPrefix: "",
517
+ defaultElement: "<div>",
518
+ options: {
519
+ disabled: false,
520
+
521
+ // callbacks
522
+ create: null
523
+ },
524
+ _createWidget: function( options, element ) {
525
+ element = $( element || this.defaultElement || this )[ 0 ];
526
+ this.element = $( element );
527
+ this.uuid = uuid++;
528
+ this.eventNamespace = "." + this.widgetName + this.uuid;
529
+ this.options = $.widget.extend( {},
530
+ this.options,
531
+ this._getCreateOptions(),
532
+ options );
533
+
534
+ this.bindings = $();
535
+ this.hoverable = $();
536
+ this.focusable = $();
537
+
538
+ if ( element !== this ) {
539
+ $.data( element, this.widgetFullName, this );
540
+ this._on( true, this.element, {
541
+ remove: function( event ) {
542
+ if ( event.target === element ) {
543
+ this.destroy();
544
+ }
545
+ }
546
+ });
547
+ this.document = $( element.style ?
548
+ // element within the document
549
+ element.ownerDocument :
550
+ // element is window or document
551
+ element.document || element );
552
+ this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
553
+ }
554
+
555
+ this._create();
556
+ this._trigger( "create", null, this._getCreateEventData() );
557
+ this._init();
558
+ },
559
+ _getCreateOptions: $.noop,
560
+ _getCreateEventData: $.noop,
561
+ _create: $.noop,
562
+ _init: $.noop,
563
+
564
+ destroy: function() {
565
+ this._destroy();
566
+ // we can probably remove the unbind calls in 2.0
567
+ // all event bindings should go through this._on()
568
+ this.element
569
+ .unbind( this.eventNamespace )
570
+ // 1.9 BC for #7810
571
+ // TODO remove dual storage
572
+ .removeData( this.widgetName )
573
+ .removeData( this.widgetFullName )
574
+ // support: jquery <1.6.3
575
+ // http://bugs.jquery.com/ticket/9413
576
+ .removeData( $.camelCase( this.widgetFullName ) );
577
+ this.widget()
578
+ .unbind( this.eventNamespace )
579
+ .removeAttr( "aria-disabled" )
580
+ .removeClass(
581
+ this.widgetFullName + "-disabled " +
582
+ "ui-state-disabled" );
583
+
584
+ // clean up events and states
585
+ this.bindings.unbind( this.eventNamespace );
586
+ this.hoverable.removeClass( "ui-state-hover" );
587
+ this.focusable.removeClass( "ui-state-focus" );
588
+ },
589
+ _destroy: $.noop,
590
+
591
+ widget: function() {
592
+ return this.element;
593
+ },
594
+
595
+ option: function( key, value ) {
596
+ var options = key,
597
+ parts,
598
+ curOption,
599
+ i;
600
+
601
+ if ( arguments.length === 0 ) {
602
+ // don't return a reference to the internal hash
603
+ return $.widget.extend( {}, this.options );
604
+ }
605
+
606
+ if ( typeof key === "string" ) {
607
+ // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
608
+ options = {};
609
+ parts = key.split( "." );
610
+ key = parts.shift();
611
+ if ( parts.length ) {
612
+ curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
613
+ for ( i = 0; i < parts.length - 1; i++ ) {
614
+ curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
615
+ curOption = curOption[ parts[ i ] ];
616
+ }
617
+ key = parts.pop();
618
+ if ( arguments.length === 1 ) {
619
+ return curOption[ key ] === undefined ? null : curOption[ key ];
620
+ }
621
+ curOption[ key ] = value;
622
+ } else {
623
+ if ( arguments.length === 1 ) {
624
+ return this.options[ key ] === undefined ? null : this.options[ key ];
625
+ }
626
+ options[ key ] = value;
627
+ }
628
+ }
629
+
630
+ this._setOptions( options );
631
+
632
+ return this;
633
+ },
634
+ _setOptions: function( options ) {
635
+ var key;
636
+
637
+ for ( key in options ) {
638
+ this._setOption( key, options[ key ] );
639
+ }
640
+
641
+ return this;
642
+ },
643
+ _setOption: function( key, value ) {
644
+ this.options[ key ] = value;
645
+
646
+ if ( key === "disabled" ) {
647
+ this.widget()
648
+ .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
649
+ .attr( "aria-disabled", value );
650
+ this.hoverable.removeClass( "ui-state-hover" );
651
+ this.focusable.removeClass( "ui-state-focus" );
652
+ }
653
+
654
+ return this;
655
+ },
656
+
657
+ enable: function() {
658
+ return this._setOption( "disabled", false );
659
+ },
660
+ disable: function() {
661
+ return this._setOption( "disabled", true );
662
+ },
663
+
664
+ _on: function( suppressDisabledCheck, element, handlers ) {
665
+ var delegateElement,
666
+ instance = this;
667
+
668
+ // no suppressDisabledCheck flag, shuffle arguments
669
+ if ( typeof suppressDisabledCheck !== "boolean" ) {
670
+ handlers = element;
671
+ element = suppressDisabledCheck;
672
+ suppressDisabledCheck = false;
673
+ }
674
+
675
+ // no element argument, shuffle and use this.element
676
+ if ( !handlers ) {
677
+ handlers = element;
678
+ element = this.element;
679
+ delegateElement = this.widget();
680
+ } else {
681
+ // accept selectors, DOM elements
682
+ element = delegateElement = $( element );
683
+ this.bindings = this.bindings.add( element );
684
+ }
685
+
686
+ $.each( handlers, function( event, handler ) {
687
+ function handlerProxy() {
688
+ // allow widgets to customize the disabled handling
689
+ // - disabled as an array instead of boolean
690
+ // - disabled class as method for disabling individual parts
691
+ if ( !suppressDisabledCheck &&
692
+ ( instance.options.disabled === true ||
693
+ $( this ).hasClass( "ui-state-disabled" ) ) ) {
694
+ return;
695
+ }
696
+ return ( typeof handler === "string" ? instance[ handler ] : handler )
697
+ .apply( instance, arguments );
698
+ }
699
+
700
+ // copy the guid so direct unbinding works
701
+ if ( typeof handler !== "string" ) {
702
+ handlerProxy.guid = handler.guid =
703
+ handler.guid || handlerProxy.guid || $.guid++;
704
+ }
705
+
706
+ var match = event.match( /^(\w+)\s*(.*)$/ ),
707
+ eventName = match[1] + instance.eventNamespace,
708
+ selector = match[2];
709
+ if ( selector ) {
710
+ delegateElement.delegate( selector, eventName, handlerProxy );
711
+ } else {
712
+ element.bind( eventName, handlerProxy );
713
+ }
714
+ });
715
+ },
716
+
717
+ _off: function( element, eventName ) {
718
+ eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
719
+ element.unbind( eventName ).undelegate( eventName );
720
+ },
721
+
722
+ _delay: function( handler, delay ) {
723
+ function handlerProxy() {
724
+ return ( typeof handler === "string" ? instance[ handler ] : handler )
725
+ .apply( instance, arguments );
726
+ }
727
+ var instance = this;
728
+ return setTimeout( handlerProxy, delay || 0 );
729
+ },
730
+
731
+ _hoverable: function( element ) {
732
+ this.hoverable = this.hoverable.add( element );
733
+ this._on( element, {
734
+ mouseenter: function( event ) {
735
+ $( event.currentTarget ).addClass( "ui-state-hover" );
736
+ },
737
+ mouseleave: function( event ) {
738
+ $( event.currentTarget ).removeClass( "ui-state-hover" );
739
+ }
740
+ });
741
+ },
742
+
743
+ _focusable: function( element ) {
744
+ this.focusable = this.focusable.add( element );
745
+ this._on( element, {
746
+ focusin: function( event ) {
747
+ $( event.currentTarget ).addClass( "ui-state-focus" );
748
+ },
749
+ focusout: function( event ) {
750
+ $( event.currentTarget ).removeClass( "ui-state-focus" );
751
+ }
752
+ });
753
+ },
754
+
755
+ _trigger: function( type, event, data ) {
756
+ var prop, orig,
757
+ callback = this.options[ type ];
758
+
759
+ data = data || {};
760
+ event = $.Event( event );
761
+ event.type = ( type === this.widgetEventPrefix ?
762
+ type :
763
+ this.widgetEventPrefix + type ).toLowerCase();
764
+ // the original event may come from any element
765
+ // so we need to reset the target on the new event
766
+ event.target = this.element[ 0 ];
767
+
768
+ // copy original event properties over to the new event
769
+ orig = event.originalEvent;
770
+ if ( orig ) {
771
+ for ( prop in orig ) {
772
+ if ( !( prop in event ) ) {
773
+ event[ prop ] = orig[ prop ];
774
+ }
775
+ }
776
+ }
777
+
778
+ this.element.trigger( event, data );
779
+ return !( $.isFunction( callback ) &&
780
+ callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
781
+ event.isDefaultPrevented() );
782
+ }
783
+ };
784
+
785
+ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
786
+ $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
787
+ if ( typeof options === "string" ) {
788
+ options = { effect: options };
789
+ }
790
+ var hasOptions,
791
+ effectName = !options ?
792
+ method :
793
+ options === true || typeof options === "number" ?
794
+ defaultEffect :
795
+ options.effect || defaultEffect;
796
+ options = options || {};
797
+ if ( typeof options === "number" ) {
798
+ options = { duration: options };
799
+ }
800
+ hasOptions = !$.isEmptyObject( options );
801
+ options.complete = callback;
802
+ if ( options.delay ) {
803
+ element.delay( options.delay );
804
+ }
805
+ if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
806
+ element[ method ]( options );
807
+ } else if ( effectName !== method && element[ effectName ] ) {
808
+ element[ effectName ]( options.duration, options.easing, callback );
809
+ } else {
810
+ element.queue(function( next ) {
811
+ $( this )[ method ]();
812
+ if ( callback ) {
813
+ callback.call( element[ 0 ] );
814
+ }
815
+ next();
816
+ });
817
+ }
818
+ };
819
+ });
820
+
821
+ })( jQuery );
822
+ (function( $, undefined ) {
823
+
824
+ var mouseHandled = false;
825
+ $( document ).mouseup( function() {
826
+ mouseHandled = false;
827
+ });
828
+
829
+ $.widget("ui.mouse", {
830
+ version: "1.10.4",
831
+ options: {
832
+ cancel: "input,textarea,button,select,option",
833
+ distance: 1,
834
+ delay: 0
835
+ },
836
+ _mouseInit: function() {
837
+ var that = this;
838
+
839
+ this.element
840
+ .bind("mousedown."+this.widgetName, function(event) {
841
+ return that._mouseDown(event);
842
+ })
843
+ .bind("click."+this.widgetName, function(event) {
844
+ if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
845
+ $.removeData(event.target, that.widgetName + ".preventClickEvent");
846
+ event.stopImmediatePropagation();
847
+ return false;
848
+ }
849
+ });
850
+
851
+ this.started = false;
852
+ },
853
+
854
+ // TODO: make sure destroying one instance of mouse doesn't mess with
855
+ // other instances of mouse
856
+ _mouseDestroy: function() {
857
+ this.element.unbind("."+this.widgetName);
858
+ if ( this._mouseMoveDelegate ) {
859
+ $(document)
860
+ .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
861
+ .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
862
+ }
863
+ },
864
+
865
+ _mouseDown: function(event) {
866
+ // don't let more than one widget handle mouseStart
867
+ if( mouseHandled ) { return; }
868
+
869
+ // we may have missed mouseup (out of window)
870
+ (this._mouseStarted && this._mouseUp(event));
871
+
872
+ this._mouseDownEvent = event;
873
+
874
+ var that = this,
875
+ btnIsLeft = (event.which === 1),
876
+ // event.target.nodeName works around a bug in IE 8 with
877
+ // disabled inputs (#7620)
878
+ elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
879
+ if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
880
+ return true;
881
+ }
882
+
883
+ this.mouseDelayMet = !this.options.delay;
884
+ if (!this.mouseDelayMet) {
885
+ this._mouseDelayTimer = setTimeout(function() {
886
+ that.mouseDelayMet = true;
887
+ }, this.options.delay);
888
+ }
889
+
890
+ if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
891
+ this._mouseStarted = (this._mouseStart(event) !== false);
892
+ if (!this._mouseStarted) {
893
+ event.preventDefault();
894
+ return true;
895
+ }
896
+ }
897
+
898
+ // Click event may never have fired (Gecko & Opera)
899
+ if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
900
+ $.removeData(event.target, this.widgetName + ".preventClickEvent");
901
+ }
902
+
903
+ // these delegates are required to keep context
904
+ this._mouseMoveDelegate = function(event) {
905
+ return that._mouseMove(event);
906
+ };
907
+ this._mouseUpDelegate = function(event) {
908
+ return that._mouseUp(event);
909
+ };
910
+ $(document)
911
+ .bind("mousemove."+this.widgetName, this._mouseMoveDelegate)
912
+ .bind("mouseup."+this.widgetName, this._mouseUpDelegate);
913
+
914
+ event.preventDefault();
915
+
916
+ mouseHandled = true;
917
+ return true;
918
+ },
919
+
920
+ _mouseMove: function(event) {
921
+ // IE mouseup check - mouseup happened when mouse was out of window
922
+ if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
923
+ return this._mouseUp(event);
924
+ }
925
+
926
+ if (this._mouseStarted) {
927
+ this._mouseDrag(event);
928
+ return event.preventDefault();
929
+ }
930
+
931
+ if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
932
+ this._mouseStarted =
933
+ (this._mouseStart(this._mouseDownEvent, event) !== false);
934
+ (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
935
+ }
936
+
937
+ return !this._mouseStarted;
938
+ },
939
+
940
+ _mouseUp: function(event) {
941
+ $(document)
942
+ .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
943
+ .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
944
+
945
+ if (this._mouseStarted) {
946
+ this._mouseStarted = false;
947
+
948
+ if (event.target === this._mouseDownEvent.target) {
949
+ $.data(event.target, this.widgetName + ".preventClickEvent", true);
950
+ }
951
+
952
+ this._mouseStop(event);
953
+ }
954
+
955
+ return false;
956
+ },
957
+
958
+ _mouseDistanceMet: function(event) {
959
+ return (Math.max(
960
+ Math.abs(this._mouseDownEvent.pageX - event.pageX),
961
+ Math.abs(this._mouseDownEvent.pageY - event.pageY)
962
+ ) >= this.options.distance
963
+ );
964
+ },
965
+
966
+ _mouseDelayMet: function(/* event */) {
967
+ return this.mouseDelayMet;
968
+ },
969
+
970
+ // These are placeholder methods, to be overriden by extending plugin
971
+ _mouseStart: function(/* event */) {},
972
+ _mouseDrag: function(/* event */) {},
973
+ _mouseStop: function(/* event */) {},
974
+ _mouseCapture: function(/* event */) { return true; }
975
+ });
976
+
977
+ })(jQuery);
978
+ (function( $, undefined ) {
979
+
980
+ function isOverAxis( x, reference, size ) {
981
+ return ( x > reference ) && ( x < ( reference + size ) );
982
+ }
983
+
984
+ function isFloating(item) {
985
+ return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
986
+ }
987
+
988
+ $.widget("ui.sortable", $.ui.mouse, {
989
+ version: "1.10.4",
990
+ widgetEventPrefix: "sort",
991
+ ready: false,
992
+ options: {
993
+ appendTo: "parent",
994
+ axis: false,
995
+ connectWith: false,
996
+ containment: false,
997
+ cursor: "auto",
998
+ cursorAt: false,
999
+ dropOnEmpty: true,
1000
+ forcePlaceholderSize: false,
1001
+ forceHelperSize: false,
1002
+ grid: false,
1003
+ handle: false,
1004
+ helper: "original",
1005
+ items: "> *",
1006
+ opacity: false,
1007
+ placeholder: false,
1008
+ revert: false,
1009
+ scroll: true,
1010
+ scrollSensitivity: 20,
1011
+ scrollSpeed: 20,
1012
+ scope: "default",
1013
+ tolerance: "intersect",
1014
+ zIndex: 1000,
1015
+
1016
+ // callbacks
1017
+ activate: null,
1018
+ beforeStop: null,
1019
+ change: null,
1020
+ deactivate: null,
1021
+ out: null,
1022
+ over: null,
1023
+ receive: null,
1024
+ remove: null,
1025
+ sort: null,
1026
+ start: null,
1027
+ stop: null,
1028
+ update: null
1029
+ },
1030
+ _create: function() {
1031
+
1032
+ var o = this.options;
1033
+ this.containerCache = {};
1034
+ this.element.addClass("ui-sortable");
1035
+
1036
+ //Get the items
1037
+ this.refresh();
1038
+
1039
+ //Let's determine if the items are being displayed horizontally
1040
+ this.floating = this.items.length ? o.axis === "x" || isFloating(this.items[0].item) : false;
1041
+
1042
+ //Let's determine the parent's offset
1043
+ this.offset = this.element.offset();
1044
+
1045
+ //Initialize mouse events for interaction
1046
+ this._mouseInit();
1047
+
1048
+ //We're ready to go
1049
+ this.ready = true;
1050
+
1051
+ },
1052
+
1053
+ _destroy: function() {
1054
+ this.element
1055
+ .removeClass("ui-sortable ui-sortable-disabled");
1056
+ this._mouseDestroy();
1057
+
1058
+ for ( var i = this.items.length - 1; i >= 0; i-- ) {
1059
+ this.items[i].item.removeData(this.widgetName + "-item");
1060
+ }
1061
+
1062
+ return this;
1063
+ },
1064
+
1065
+ _setOption: function(key, value){
1066
+ if ( key === "disabled" ) {
1067
+ this.options[ key ] = value;
1068
+
1069
+ this.widget().toggleClass( "ui-sortable-disabled", !!value );
1070
+ } else {
1071
+ // Don't call widget base _setOption for disable as it adds ui-state-disabled class
1072
+ $.Widget.prototype._setOption.apply(this, arguments);
1073
+ }
1074
+ },
1075
+
1076
+ _mouseCapture: function(event, overrideHandle) {
1077
+ var currentItem = null,
1078
+ validHandle = false,
1079
+ that = this;
1080
+
1081
+ if (this.reverting) {
1082
+ return false;
1083
+ }
1084
+
1085
+ if(this.options.disabled || this.options.type === "static") {
1086
+ return false;
1087
+ }
1088
+
1089
+ //We have to refresh the items data once first
1090
+ this._refreshItems(event);
1091
+
1092
+ //Find out if the clicked node (or one of its parents) is a actual item in this.items
1093
+ $(event.target).parents().each(function() {
1094
+ if($.data(this, that.widgetName + "-item") === that) {
1095
+ currentItem = $(this);
1096
+ return false;
1097
+ }
1098
+ });
1099
+ if($.data(event.target, that.widgetName + "-item") === that) {
1100
+ currentItem = $(event.target);
1101
+ }
1102
+
1103
+ if(!currentItem) {
1104
+ return false;
1105
+ }
1106
+ if(this.options.handle && !overrideHandle) {
1107
+ $(this.options.handle, currentItem).find("*").addBack().each(function() {
1108
+ if(this === event.target) {
1109
+ validHandle = true;
1110
+ }
1111
+ });
1112
+ if(!validHandle) {
1113
+ return false;
1114
+ }
1115
+ }
1116
+
1117
+ this.currentItem = currentItem;
1118
+ this._removeCurrentsFromItems();
1119
+ return true;
1120
+
1121
+ },
1122
+
1123
+ _mouseStart: function(event, overrideHandle, noActivation) {
1124
+
1125
+ var i, body,
1126
+ o = this.options;
1127
+
1128
+ this.currentContainer = this;
1129
+
1130
+ //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
1131
+ this.refreshPositions();
1132
+
1133
+ //Create and append the visible helper
1134
+ this.helper = this._createHelper(event);
1135
+
1136
+ //Cache the helper size
1137
+ this._cacheHelperProportions();
1138
+
1139
+ /*
1140
+ * - Position generation -
1141
+ * This block generates everything position related - it's the core of draggables.
1142
+ */
1143
+
1144
+ //Cache the margins of the original element
1145
+ this._cacheMargins();
1146
+
1147
+ //Get the next scrolling parent
1148
+ this.scrollParent = this.helper.scrollParent();
1149
+
1150
+ //The element's absolute position on the page minus margins
1151
+ this.offset = this.currentItem.offset();
1152
+ this.offset = {
1153
+ top: this.offset.top - this.margins.top,
1154
+ left: this.offset.left - this.margins.left
1155
+ };
1156
+
1157
+ $.extend(this.offset, {
1158
+ click: { //Where the click happened, relative to the element
1159
+ left: event.pageX - this.offset.left,
1160
+ top: event.pageY - this.offset.top
1161
+ },
1162
+ parent: this._getParentOffset(),
1163
+ relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
1164
+ });
1165
+
1166
+ // Only after we got the offset, we can change the helper's position to absolute
1167
+ // TODO: Still need to figure out a way to make relative sorting possible
1168
+ this.helper.css("position", "absolute");
1169
+ this.cssPosition = this.helper.css("position");
1170
+
1171
+ //Generate the original position
1172
+ this.originalPosition = this._generatePosition(event);
1173
+ this.originalPageX = event.pageX;
1174
+ this.originalPageY = event.pageY;
1175
+
1176
+ //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
1177
+ (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
1178
+
1179
+ //Cache the former DOM position
1180
+ this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
1181
+
1182
+ //If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way
1183
+ if(this.helper[0] !== this.currentItem[0]) {
1184
+ this.currentItem.hide();
1185
+ }
1186
+
1187
+ //Create the placeholder
1188
+ this._createPlaceholder();
1189
+
1190
+ //Set a containment if given in the options
1191
+ if(o.containment) {
1192
+ this._setContainment();
1193
+ }
1194
+
1195
+ if( o.cursor && o.cursor !== "auto" ) { // cursor option
1196
+ body = this.document.find( "body" );
1197
+
1198
+ // support: IE
1199
+ this.storedCursor = body.css( "cursor" );
1200
+ body.css( "cursor", o.cursor );
1201
+
1202
+ this.storedStylesheet = $( "<style>*{ cursor: "+o.cursor+" !important; }</style>" ).appendTo( body );
1203
+ }
1204
+
1205
+ if(o.opacity) { // opacity option
1206
+ if (this.helper.css("opacity")) {
1207
+ this._storedOpacity = this.helper.css("opacity");
1208
+ }
1209
+ this.helper.css("opacity", o.opacity);
1210
+ }
1211
+
1212
+ if(o.zIndex) { // zIndex option
1213
+ if (this.helper.css("zIndex")) {
1214
+ this._storedZIndex = this.helper.css("zIndex");
1215
+ }
1216
+ this.helper.css("zIndex", o.zIndex);
1217
+ }
1218
+
1219
+ //Prepare scrolling
1220
+ if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
1221
+ this.overflowOffset = this.scrollParent.offset();
1222
+ }
1223
+
1224
+ //Call callbacks
1225
+ this._trigger("start", event, this._uiHash());
1226
+
1227
+ //Recache the helper size
1228
+ if(!this._preserveHelperProportions) {
1229
+ this._cacheHelperProportions();
1230
+ }
1231
+
1232
+
1233
+ //Post "activate" events to possible containers
1234
+ if( !noActivation ) {
1235
+ for ( i = this.containers.length - 1; i >= 0; i-- ) {
1236
+ this.containers[ i ]._trigger( "activate", event, this._uiHash( this ) );
1237
+ }
1238
+ }
1239
+
1240
+ //Prepare possible droppables
1241
+ if($.ui.ddmanager) {
1242
+ $.ui.ddmanager.current = this;
1243
+ }
1244
+
1245
+ if ($.ui.ddmanager && !o.dropBehaviour) {
1246
+ $.ui.ddmanager.prepareOffsets(this, event);
1247
+ }
1248
+
1249
+ this.dragging = true;
1250
+
1251
+ this.helper.addClass("ui-sortable-helper");
1252
+ this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
1253
+ return true;
1254
+
1255
+ },
1256
+
1257
+ _mouseDrag: function(event) {
1258
+ var i, item, itemElement, intersection,
1259
+ o = this.options,
1260
+ scrolled = false;
1261
+
1262
+ //Compute the helpers position
1263
+ this.position = this._generatePosition(event);
1264
+ this.positionAbs = this._convertPositionTo("absolute");
1265
+
1266
+ if (!this.lastPositionAbs) {
1267
+ this.lastPositionAbs = this.positionAbs;
1268
+ }
1269
+
1270
+ //Do scrolling
1271
+ if(this.options.scroll) {
1272
+ if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
1273
+
1274
+ if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
1275
+ this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
1276
+ } else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) {
1277
+ this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
1278
+ }
1279
+
1280
+ if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
1281
+ this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
1282
+ } else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
1283
+ this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
1284
+ }
1285
+
1286
+ } else {
1287
+
1288
+ if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
1289
+ scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
1290
+ } else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
1291
+ scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
1292
+ }
1293
+
1294
+ if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
1295
+ scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
1296
+ } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
1297
+ scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
1298
+ }
1299
+
1300
+ }
1301
+
1302
+ if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
1303
+ $.ui.ddmanager.prepareOffsets(this, event);
1304
+ }
1305
+ }
1306
+
1307
+ //Regenerate the absolute position used for position checks
1308
+ this.positionAbs = this._convertPositionTo("absolute");
1309
+
1310
+ //Set the helper position
1311
+ if(!this.options.axis || this.options.axis !== "y") {
1312
+ this.helper[0].style.left = this.position.left+"px";
1313
+ }
1314
+ if(!this.options.axis || this.options.axis !== "x") {
1315
+ this.helper[0].style.top = this.position.top+"px";
1316
+ }
1317
+
1318
+ //Rearrange
1319
+ for (i = this.items.length - 1; i >= 0; i--) {
1320
+
1321
+ //Cache variables and intersection, continue if no intersection
1322
+ item = this.items[i];
1323
+ itemElement = item.item[0];
1324
+ intersection = this._intersectsWithPointer(item);
1325
+ if (!intersection) {
1326
+ continue;
1327
+ }
1328
+
1329
+ // Only put the placeholder inside the current Container, skip all
1330
+ // items from other containers. This works because when moving
1331
+ // an item from one container to another the
1332
+ // currentContainer is switched before the placeholder is moved.
1333
+ //
1334
+ // Without this, moving items in "sub-sortables" can cause
1335
+ // the placeholder to jitter beetween the outer and inner container.
1336
+ if (item.instance !== this.currentContainer) {
1337
+ continue;
1338
+ }
1339
+
1340
+ // cannot intersect with itself
1341
+ // no useless actions that have been done before
1342
+ // no action if the item moved is the parent of the item checked
1343
+ if (itemElement !== this.currentItem[0] &&
1344
+ this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement &&
1345
+ !$.contains(this.placeholder[0], itemElement) &&
1346
+ (this.options.type === "semi-dynamic" ? !$.contains(this.element[0], itemElement) : true)
1347
+ ) {
1348
+
1349
+ this.direction = intersection === 1 ? "down" : "up";
1350
+
1351
+ if (this.options.tolerance === "pointer" || this._intersectsWithSides(item)) {
1352
+ this._rearrange(event, item);
1353
+ } else {
1354
+ break;
1355
+ }
1356
+
1357
+ this._trigger("change", event, this._uiHash());
1358
+ break;
1359
+ }
1360
+ }
1361
+
1362
+ //Post events to containers
1363
+ this._contactContainers(event);
1364
+
1365
+ //Interconnect with droppables
1366
+ if($.ui.ddmanager) {
1367
+ $.ui.ddmanager.drag(this, event);
1368
+ }
1369
+
1370
+ //Call callbacks
1371
+ this._trigger("sort", event, this._uiHash());
1372
+
1373
+ this.lastPositionAbs = this.positionAbs;
1374
+ return false;
1375
+
1376
+ },
1377
+
1378
+ _mouseStop: function(event, noPropagation) {
1379
+
1380
+ if(!event) {
1381
+ return;
1382
+ }
1383
+
1384
+ //If we are using droppables, inform the manager about the drop
1385
+ if ($.ui.ddmanager && !this.options.dropBehaviour) {
1386
+ $.ui.ddmanager.drop(this, event);
1387
+ }
1388
+
1389
+ if(this.options.revert) {
1390
+ var that = this,
1391
+ cur = this.placeholder.offset(),
1392
+ axis = this.options.axis,
1393
+ animation = {};
1394
+
1395
+ if ( !axis || axis === "x" ) {
1396
+ animation.left = cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollLeft);
1397
+ }
1398
+ if ( !axis || axis === "y" ) {
1399
+ animation.top = cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollTop);
1400
+ }
1401
+ this.reverting = true;
1402
+ $(this.helper).animate( animation, parseInt(this.options.revert, 10) || 500, function() {
1403
+ that._clear(event);
1404
+ });
1405
+ } else {
1406
+ this._clear(event, noPropagation);
1407
+ }
1408
+
1409
+ return false;
1410
+
1411
+ },
1412
+
1413
+ cancel: function() {
1414
+
1415
+ if(this.dragging) {
1416
+
1417
+ this._mouseUp({ target: null });
1418
+
1419
+ if(this.options.helper === "original") {
1420
+ this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
1421
+ } else {
1422
+ this.currentItem.show();
1423
+ }
1424
+
1425
+ //Post deactivating events to containers
1426
+ for (var i = this.containers.length - 1; i >= 0; i--){
1427
+ this.containers[i]._trigger("deactivate", null, this._uiHash(this));
1428
+ if(this.containers[i].containerCache.over) {
1429
+ this.containers[i]._trigger("out", null, this._uiHash(this));
1430
+ this.containers[i].containerCache.over = 0;
1431
+ }
1432
+ }
1433
+
1434
+ }
1435
+
1436
+ if (this.placeholder) {
1437
+ //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
1438
+ if(this.placeholder[0].parentNode) {
1439
+ this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
1440
+ }
1441
+ if(this.options.helper !== "original" && this.helper && this.helper[0].parentNode) {
1442
+ this.helper.remove();
1443
+ }
1444
+
1445
+ $.extend(this, {
1446
+ helper: null,
1447
+ dragging: false,
1448
+ reverting: false,
1449
+ _noFinalSort: null
1450
+ });
1451
+
1452
+ if(this.domPosition.prev) {
1453
+ $(this.domPosition.prev).after(this.currentItem);
1454
+ } else {
1455
+ $(this.domPosition.parent).prepend(this.currentItem);
1456
+ }
1457
+ }
1458
+
1459
+ return this;
1460
+
1461
+ },
1462
+
1463
+ serialize: function(o) {
1464
+
1465
+ var items = this._getItemsAsjQuery(o && o.connected),
1466
+ str = [];
1467
+ o = o || {};
1468
+
1469
+ $(items).each(function() {
1470
+ var res = ($(o.item || this).attr(o.attribute || "id") || "").match(o.expression || (/(.+)[\-=_](.+)/));
1471
+ if (res) {
1472
+ str.push((o.key || res[1]+"[]")+"="+(o.key && o.expression ? res[1] : res[2]));
1473
+ }
1474
+ });
1475
+
1476
+ if(!str.length && o.key) {
1477
+ str.push(o.key + "=");
1478
+ }
1479
+
1480
+ return str.join("&");
1481
+
1482
+ },
1483
+
1484
+ toArray: function(o) {
1485
+
1486
+ var items = this._getItemsAsjQuery(o && o.connected),
1487
+ ret = [];
1488
+
1489
+ o = o || {};
1490
+
1491
+ items.each(function() { ret.push($(o.item || this).attr(o.attribute || "id") || ""); });
1492
+ return ret;
1493
+
1494
+ },
1495
+
1496
+ /* Be careful with the following core functions */
1497
+ _intersectsWith: function(item) {
1498
+
1499
+ var x1 = this.positionAbs.left,
1500
+ x2 = x1 + this.helperProportions.width,
1501
+ y1 = this.positionAbs.top,
1502
+ y2 = y1 + this.helperProportions.height,
1503
+ l = item.left,
1504
+ r = l + item.width,
1505
+ t = item.top,
1506
+ b = t + item.height,
1507
+ dyClick = this.offset.click.top,
1508
+ dxClick = this.offset.click.left,
1509
+ isOverElementHeight = ( this.options.axis === "x" ) || ( ( y1 + dyClick ) > t && ( y1 + dyClick ) < b ),
1510
+ isOverElementWidth = ( this.options.axis === "y" ) || ( ( x1 + dxClick ) > l && ( x1 + dxClick ) < r ),
1511
+ isOverElement = isOverElementHeight && isOverElementWidth;
1512
+
1513
+ if ( this.options.tolerance === "pointer" ||
1514
+ this.options.forcePointerForContainers ||
1515
+ (this.options.tolerance !== "pointer" && this.helperProportions[this.floating ? "width" : "height"] > item[this.floating ? "width" : "height"])
1516
+ ) {
1517
+ return isOverElement;
1518
+ } else {
1519
+
1520
+ return (l < x1 + (this.helperProportions.width / 2) && // Right Half
1521
+ x2 - (this.helperProportions.width / 2) < r && // Left Half
1522
+ t < y1 + (this.helperProportions.height / 2) && // Bottom Half
1523
+ y2 - (this.helperProportions.height / 2) < b ); // Top Half
1524
+
1525
+ }
1526
+ },
1527
+
1528
+ _intersectsWithPointer: function(item) {
1529
+
1530
+ var isOverElementHeight = (this.options.axis === "x") || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
1531
+ isOverElementWidth = (this.options.axis === "y") || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
1532
+ isOverElement = isOverElementHeight && isOverElementWidth,
1533
+ verticalDirection = this._getDragVerticalDirection(),
1534
+ horizontalDirection = this._getDragHorizontalDirection();
1535
+
1536
+ if (!isOverElement) {
1537
+ return false;
1538
+ }
1539
+
1540
+ return this.floating ?
1541
+ ( ((horizontalDirection && horizontalDirection === "right") || verticalDirection === "down") ? 2 : 1 )
1542
+ : ( verticalDirection && (verticalDirection === "down" ? 2 : 1) );
1543
+
1544
+ },
1545
+
1546
+ _intersectsWithSides: function(item) {
1547
+
1548
+ var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
1549
+ isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
1550
+ verticalDirection = this._getDragVerticalDirection(),
1551
+ horizontalDirection = this._getDragHorizontalDirection();
1552
+
1553
+ if (this.floating && horizontalDirection) {
1554
+ return ((horizontalDirection === "right" && isOverRightHalf) || (horizontalDirection === "left" && !isOverRightHalf));
1555
+ } else {
1556
+ return verticalDirection && ((verticalDirection === "down" && isOverBottomHalf) || (verticalDirection === "up" && !isOverBottomHalf));
1557
+ }
1558
+
1559
+ },
1560
+
1561
+ _getDragVerticalDirection: function() {
1562
+ var delta = this.positionAbs.top - this.lastPositionAbs.top;
1563
+ return delta !== 0 && (delta > 0 ? "down" : "up");
1564
+ },
1565
+
1566
+ _getDragHorizontalDirection: function() {
1567
+ var delta = this.positionAbs.left - this.lastPositionAbs.left;
1568
+ return delta !== 0 && (delta > 0 ? "right" : "left");
1569
+ },
1570
+
1571
+ refresh: function(event) {
1572
+ this._refreshItems(event);
1573
+ this.refreshPositions();
1574
+ return this;
1575
+ },
1576
+
1577
+ _connectWith: function() {
1578
+ var options = this.options;
1579
+ return options.connectWith.constructor === String ? [options.connectWith] : options.connectWith;
1580
+ },
1581
+
1582
+ _getItemsAsjQuery: function(connected) {
1583
+
1584
+ var i, j, cur, inst,
1585
+ items = [],
1586
+ queries = [],
1587
+ connectWith = this._connectWith();
1588
+
1589
+ if(connectWith && connected) {
1590
+ for (i = connectWith.length - 1; i >= 0; i--){
1591
+ cur = $(connectWith[i]);
1592
+ for ( j = cur.length - 1; j >= 0; j--){
1593
+ inst = $.data(cur[j], this.widgetFullName);
1594
+ if(inst && inst !== this && !inst.options.disabled) {
1595
+ queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), inst]);
1596
+ }
1597
+ }
1598
+ }
1599
+ }
1600
+
1601
+ queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), this]);
1602
+
1603
+ function addItems() {
1604
+ items.push( this );
1605
+ }
1606
+ for (i = queries.length - 1; i >= 0; i--){
1607
+ queries[i][0].each( addItems );
1608
+ }
1609
+
1610
+ return $(items);
1611
+
1612
+ },
1613
+
1614
+ _removeCurrentsFromItems: function() {
1615
+
1616
+ var list = this.currentItem.find(":data(" + this.widgetName + "-item)");
1617
+
1618
+ this.items = $.grep(this.items, function (item) {
1619
+ for (var j=0; j < list.length; j++) {
1620
+ if(list[j] === item.item[0]) {
1621
+ return false;
1622
+ }
1623
+ }
1624
+ return true;
1625
+ });
1626
+
1627
+ },
1628
+
1629
+ _refreshItems: function(event) {
1630
+
1631
+ this.items = [];
1632
+ this.containers = [this];
1633
+
1634
+ var i, j, cur, inst, targetData, _queries, item, queriesLength,
1635
+ items = this.items,
1636
+ queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]],
1637
+ connectWith = this._connectWith();
1638
+
1639
+ if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
1640
+ for (i = connectWith.length - 1; i >= 0; i--){
1641
+ cur = $(connectWith[i]);
1642
+ for (j = cur.length - 1; j >= 0; j--){
1643
+ inst = $.data(cur[j], this.widgetFullName);
1644
+ if(inst && inst !== this && !inst.options.disabled) {
1645
+ queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
1646
+ this.containers.push(inst);
1647
+ }
1648
+ }
1649
+ }
1650
+ }
1651
+
1652
+ for (i = queries.length - 1; i >= 0; i--) {
1653
+ targetData = queries[i][1];
1654
+ _queries = queries[i][0];
1655
+
1656
+ for (j=0, queriesLength = _queries.length; j < queriesLength; j++) {
1657
+ item = $(_queries[j]);
1658
+
1659
+ item.data(this.widgetName + "-item", targetData); // Data for target checking (mouse manager)
1660
+
1661
+ items.push({
1662
+ item: item,
1663
+ instance: targetData,
1664
+ width: 0, height: 0,
1665
+ left: 0, top: 0
1666
+ });
1667
+ }
1668
+ }
1669
+
1670
+ },
1671
+
1672
+ refreshPositions: function(fast) {
1673
+
1674
+ //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
1675
+ if(this.offsetParent && this.helper) {
1676
+ this.offset.parent = this._getParentOffset();
1677
+ }
1678
+
1679
+ var i, item, t, p;
1680
+
1681
+ for (i = this.items.length - 1; i >= 0; i--){
1682
+ item = this.items[i];
1683
+
1684
+ //We ignore calculating positions of all connected containers when we're not over them
1685
+ if(item.instance !== this.currentContainer && this.currentContainer && item.item[0] !== this.currentItem[0]) {
1686
+ continue;
1687
+ }
1688
+
1689
+ t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
1690
+
1691
+ if (!fast) {
1692
+ item.width = t.outerWidth();
1693
+ item.height = t.outerHeight();
1694
+ }
1695
+
1696
+ p = t.offset();
1697
+ item.left = p.left;
1698
+ item.top = p.top;
1699
+ }
1700
+
1701
+ if(this.options.custom && this.options.custom.refreshContainers) {
1702
+ this.options.custom.refreshContainers.call(this);
1703
+ } else {
1704
+ for (i = this.containers.length - 1; i >= 0; i--){
1705
+ p = this.containers[i].element.offset();
1706
+ this.containers[i].containerCache.left = p.left;
1707
+ this.containers[i].containerCache.top = p.top;
1708
+ this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
1709
+ this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
1710
+ }
1711
+ }
1712
+
1713
+ return this;
1714
+ },
1715
+
1716
+ _createPlaceholder: function(that) {
1717
+ that = that || this;
1718
+ var className,
1719
+ o = that.options;
1720
+
1721
+ if(!o.placeholder || o.placeholder.constructor === String) {
1722
+ className = o.placeholder;
1723
+ o.placeholder = {
1724
+ element: function() {
1725
+
1726
+ var nodeName = that.currentItem[0].nodeName.toLowerCase(),
1727
+ element = $( "<" + nodeName + ">", that.document[0] )
1728
+ .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
1729
+ .removeClass("ui-sortable-helper");
1730
+
1731
+ if ( nodeName === "tr" ) {
1732
+ that.currentItem.children().each(function() {
1733
+ $( "<td>&#160;</td>", that.document[0] )
1734
+ .attr( "colspan", $( this ).attr( "colspan" ) || 1 )
1735
+ .appendTo( element );
1736
+ });
1737
+ } else if ( nodeName === "img" ) {
1738
+ element.attr( "src", that.currentItem.attr( "src" ) );
1739
+ }
1740
+
1741
+ if ( !className ) {
1742
+ element.css( "visibility", "hidden" );
1743
+ }
1744
+
1745
+ return element;
1746
+ },
1747
+ update: function(container, p) {
1748
+
1749
+ // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that
1750
+ // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified
1751
+ if(className && !o.forcePlaceholderSize) {
1752
+ return;
1753
+ }
1754
+
1755
+ //If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item
1756
+ if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css("paddingTop")||0, 10) - parseInt(that.currentItem.css("paddingBottom")||0, 10)); }
1757
+ if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css("paddingLeft")||0, 10) - parseInt(that.currentItem.css("paddingRight")||0, 10)); }
1758
+ }
1759
+ };
1760
+ }
1761
+
1762
+ //Create the placeholder
1763
+ that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));
1764
+
1765
+ //Append it after the actual current item
1766
+ that.currentItem.after(that.placeholder);
1767
+
1768
+ //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
1769
+ o.placeholder.update(that, that.placeholder);
1770
+
1771
+ },
1772
+
1773
+ _contactContainers: function(event) {
1774
+ var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom, floating,
1775
+ innermostContainer = null,
1776
+ innermostIndex = null;
1777
+
1778
+ // get innermost container that intersects with item
1779
+ for (i = this.containers.length - 1; i >= 0; i--) {
1780
+
1781
+ // never consider a container that's located within the item itself
1782
+ if($.contains(this.currentItem[0], this.containers[i].element[0])) {
1783
+ continue;
1784
+ }
1785
+
1786
+ if(this._intersectsWith(this.containers[i].containerCache)) {
1787
+
1788
+ // if we've already found a container and it's more "inner" than this, then continue
1789
+ if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0])) {
1790
+ continue;
1791
+ }
1792
+
1793
+ innermostContainer = this.containers[i];
1794
+ innermostIndex = i;
1795
+
1796
+ } else {
1797
+ // container doesn't intersect. trigger "out" event if necessary
1798
+ if(this.containers[i].containerCache.over) {
1799
+ this.containers[i]._trigger("out", event, this._uiHash(this));
1800
+ this.containers[i].containerCache.over = 0;
1801
+ }
1802
+ }
1803
+
1804
+ }
1805
+
1806
+ // if no intersecting containers found, return
1807
+ if(!innermostContainer) {
1808
+ return;
1809
+ }
1810
+
1811
+ // move the item into the container if it's not there already
1812
+ if(this.containers.length === 1) {
1813
+ if (!this.containers[innermostIndex].containerCache.over) {
1814
+ this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
1815
+ this.containers[innermostIndex].containerCache.over = 1;
1816
+ }
1817
+ } else {
1818
+
1819
+ //When entering a new container, we will find the item with the least distance and append our item near it
1820
+ dist = 10000;
1821
+ itemWithLeastDistance = null;
1822
+ floating = innermostContainer.floating || isFloating(this.currentItem);
1823
+ posProperty = floating ? "left" : "top";
1824
+ sizeProperty = floating ? "width" : "height";
1825
+ base = this.positionAbs[posProperty] + this.offset.click[posProperty];
1826
+ for (j = this.items.length - 1; j >= 0; j--) {
1827
+ if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) {
1828
+ continue;
1829
+ }
1830
+ if(this.items[j].item[0] === this.currentItem[0]) {
1831
+ continue;
1832
+ }
1833
+ if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
1834
+ continue;
1835
+ }
1836
+ cur = this.items[j].item.offset()[posProperty];
1837
+ nearBottom = false;
1838
+ if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
1839
+ nearBottom = true;
1840
+ cur += this.items[j][sizeProperty];
1841
+ }
1842
+
1843
+ if(Math.abs(cur - base) < dist) {
1844
+ dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
1845
+ this.direction = nearBottom ? "up": "down";
1846
+ }
1847
+ }
1848
+
1849
+ //Check if dropOnEmpty is enabled
1850
+ if(!itemWithLeastDistance && !this.options.dropOnEmpty) {
1851
+ return;
1852
+ }
1853
+
1854
+ if(this.currentContainer === this.containers[innermostIndex]) {
1855
+ return;
1856
+ }
1857
+
1858
+ itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
1859
+ this._trigger("change", event, this._uiHash());
1860
+ this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
1861
+ this.currentContainer = this.containers[innermostIndex];
1862
+
1863
+ //Update the placeholder
1864
+ this.options.placeholder.update(this.currentContainer, this.placeholder);
1865
+
1866
+ this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
1867
+ this.containers[innermostIndex].containerCache.over = 1;
1868
+ }
1869
+
1870
+
1871
+ },
1872
+
1873
+ _createHelper: function(event) {
1874
+
1875
+ var o = this.options,
1876
+ helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper === "clone" ? this.currentItem.clone() : this.currentItem);
1877
+
1878
+ //Add the helper to the DOM if that didn't happen already
1879
+ if(!helper.parents("body").length) {
1880
+ $(o.appendTo !== "parent" ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
1881
+ }
1882
+
1883
+ if(helper[0] === this.currentItem[0]) {
1884
+ this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") };
1885
+ }
1886
+
1887
+ if(!helper[0].style.width || o.forceHelperSize) {
1888
+ helper.width(this.currentItem.width());
1889
+ }
1890
+ if(!helper[0].style.height || o.forceHelperSize) {
1891
+ helper.height(this.currentItem.height());
1892
+ }
1893
+
1894
+ return helper;
1895
+
1896
+ },
1897
+
1898
+ _adjustOffsetFromHelper: function(obj) {
1899
+ if (typeof obj === "string") {
1900
+ obj = obj.split(" ");
1901
+ }
1902
+ if ($.isArray(obj)) {
1903
+ obj = {left: +obj[0], top: +obj[1] || 0};
1904
+ }
1905
+ if ("left" in obj) {
1906
+ this.offset.click.left = obj.left + this.margins.left;
1907
+ }
1908
+ if ("right" in obj) {
1909
+ this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
1910
+ }
1911
+ if ("top" in obj) {
1912
+ this.offset.click.top = obj.top + this.margins.top;
1913
+ }
1914
+ if ("bottom" in obj) {
1915
+ this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
1916
+ }
1917
+ },
1918
+
1919
+ _getParentOffset: function() {
1920
+
1921
+
1922
+ //Get the offsetParent and cache its position
1923
+ this.offsetParent = this.helper.offsetParent();
1924
+ var po = this.offsetParent.offset();
1925
+
1926
+ // This is a special case where we need to modify a offset calculated on start, since the following happened:
1927
+ // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
1928
+ // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
1929
+ // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
1930
+ if(this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
1931
+ po.left += this.scrollParent.scrollLeft();
1932
+ po.top += this.scrollParent.scrollTop();
1933
+ }
1934
+
1935
+ // This needs to be actually done for all browsers, since pageX/pageY includes this information
1936
+ // with an ugly IE fix
1937
+ if( this.offsetParent[0] === document.body || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
1938
+ po = { top: 0, left: 0 };
1939
+ }
1940
+
1941
+ return {
1942
+ top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
1943
+ left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
1944
+ };
1945
+
1946
+ },
1947
+
1948
+ _getRelativeOffset: function() {
1949
+
1950
+ if(this.cssPosition === "relative") {
1951
+ var p = this.currentItem.position();
1952
+ return {
1953
+ top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
1954
+ left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
1955
+ };
1956
+ } else {
1957
+ return { top: 0, left: 0 };
1958
+ }
1959
+
1960
+ },
1961
+
1962
+ _cacheMargins: function() {
1963
+ this.margins = {
1964
+ left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
1965
+ top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
1966
+ };
1967
+ },
1968
+
1969
+ _cacheHelperProportions: function() {
1970
+ this.helperProportions = {
1971
+ width: this.helper.outerWidth(),
1972
+ height: this.helper.outerHeight()
1973
+ };
1974
+ },
1975
+
1976
+ _setContainment: function() {
1977
+
1978
+ var ce, co, over,
1979
+ o = this.options;
1980
+ if(o.containment === "parent") {
1981
+ o.containment = this.helper[0].parentNode;
1982
+ }
1983
+ if(o.containment === "document" || o.containment === "window") {
1984
+ this.containment = [
1985
+ 0 - this.offset.relative.left - this.offset.parent.left,
1986
+ 0 - this.offset.relative.top - this.offset.parent.top,
1987
+ $(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,
1988
+ ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
1989
+ ];
1990
+ }
1991
+
1992
+ if(!(/^(document|window|parent)$/).test(o.containment)) {
1993
+ ce = $(o.containment)[0];
1994
+ co = $(o.containment).offset();
1995
+ over = ($(ce).css("overflow") !== "hidden");
1996
+
1997
+ this.containment = [
1998
+ co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left,
1999
+ co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top,
2000
+ co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left,
2001
+ co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top
2002
+ ];
2003
+ }
2004
+
2005
+ },
2006
+
2007
+ _convertPositionTo: function(d, pos) {
2008
+
2009
+ if(!pos) {
2010
+ pos = this.position;
2011
+ }
2012
+ var mod = d === "absolute" ? 1 : -1,
2013
+ scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
2014
+ scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
2015
+
2016
+ return {
2017
+ top: (
2018
+ pos.top + // The absolute mouse position
2019
+ this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
2020
+ this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
2021
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
2022
+ ),
2023
+ left: (
2024
+ pos.left + // The absolute mouse position
2025
+ this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
2026
+ this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
2027
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
2028
+ )
2029
+ };
2030
+
2031
+ },
2032
+
2033
+ _generatePosition: function(event) {
2034
+
2035
+ var top, left,
2036
+ o = this.options,
2037
+ pageX = event.pageX,
2038
+ pageY = event.pageY,
2039
+ scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
2040
+
2041
+ // This is another very weird special case that only happens for relative elements:
2042
+ // 1. If the css position is relative
2043
+ // 2. and the scroll parent is the document or similar to the offset parent
2044
+ // we have to refresh the relative offset during the scroll so there are no jumps
2045
+ if(this.cssPosition === "relative" && !(this.scrollParent[0] !== document && this.scrollParent[0] !== this.offsetParent[0])) {
2046
+ this.offset.relative = this._getRelativeOffset();
2047
+ }
2048
+
2049
+ /*
2050
+ * - Position constraining -
2051
+ * Constrain the position to a mix of grid, containment.
2052
+ */
2053
+
2054
+ if(this.originalPosition) { //If we are not dragging yet, we won't check for options
2055
+
2056
+ if(this.containment) {
2057
+ if(event.pageX - this.offset.click.left < this.containment[0]) {
2058
+ pageX = this.containment[0] + this.offset.click.left;
2059
+ }
2060
+ if(event.pageY - this.offset.click.top < this.containment[1]) {
2061
+ pageY = this.containment[1] + this.offset.click.top;
2062
+ }
2063
+ if(event.pageX - this.offset.click.left > this.containment[2]) {
2064
+ pageX = this.containment[2] + this.offset.click.left;
2065
+ }
2066
+ if(event.pageY - this.offset.click.top > this.containment[3]) {
2067
+ pageY = this.containment[3] + this.offset.click.top;
2068
+ }
2069
+ }
2070
+
2071
+ if(o.grid) {
2072
+ top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
2073
+ pageY = this.containment ? ( (top - this.offset.click.top >= this.containment[1] && top - this.offset.click.top <= this.containment[3]) ? top : ((top - this.offset.click.top >= this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
2074
+
2075
+ left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
2076
+ pageX = this.containment ? ( (left - this.offset.click.left >= this.containment[0] && left - this.offset.click.left <= this.containment[2]) ? left : ((left - this.offset.click.left >= this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
2077
+ }
2078
+
2079
+ }
2080
+
2081
+ return {
2082
+ top: (
2083
+ pageY - // The absolute mouse position
2084
+ this.offset.click.top - // Click offset (relative to the element)
2085
+ this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
2086
+ this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
2087
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
2088
+ ),
2089
+ left: (
2090
+ pageX - // The absolute mouse position
2091
+ this.offset.click.left - // Click offset (relative to the element)
2092
+ this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
2093
+ this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
2094
+ ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
2095
+ )
2096
+ };
2097
+
2098
+ },
2099
+
2100
+ _rearrange: function(event, i, a, hardRefresh) {
2101
+
2102
+ a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction === "down" ? i.item[0] : i.item[0].nextSibling));
2103
+
2104
+ //Various things done here to improve the performance:
2105
+ // 1. we create a setTimeout, that calls refreshPositions
2106
+ // 2. on the instance, we have a counter variable, that get's higher after every append
2107
+ // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
2108
+ // 4. this lets only the last addition to the timeout stack through
2109
+ this.counter = this.counter ? ++this.counter : 1;
2110
+ var counter = this.counter;
2111
+
2112
+ this._delay(function() {
2113
+ if(counter === this.counter) {
2114
+ this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
2115
+ }
2116
+ });
2117
+
2118
+ },
2119
+
2120
+ _clear: function(event, noPropagation) {
2121
+
2122
+ this.reverting = false;
2123
+ // We delay all events that have to be triggered to after the point where the placeholder has been removed and
2124
+ // everything else normalized again
2125
+ var i,
2126
+ delayedTriggers = [];
2127
+
2128
+ // We first have to update the dom position of the actual currentItem
2129
+ // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
2130
+ if(!this._noFinalSort && this.currentItem.parent().length) {
2131
+ this.placeholder.before(this.currentItem);
2132
+ }
2133
+ this._noFinalSort = null;
2134
+
2135
+ if(this.helper[0] === this.currentItem[0]) {
2136
+ for(i in this._storedCSS) {
2137
+ if(this._storedCSS[i] === "auto" || this._storedCSS[i] === "static") {
2138
+ this._storedCSS[i] = "";
2139
+ }
2140
+ }
2141
+ this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
2142
+ } else {
2143
+ this.currentItem.show();
2144
+ }
2145
+
2146
+ if(this.fromOutside && !noPropagation) {
2147
+ delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
2148
+ }
2149
+ if((this.fromOutside || this.domPosition.prev !== this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent !== this.currentItem.parent()[0]) && !noPropagation) {
2150
+ delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
2151
+ }
2152
+
2153
+ // Check if the items Container has Changed and trigger appropriate
2154
+ // events.
2155
+ if (this !== this.currentContainer) {
2156
+ if(!noPropagation) {
2157
+ delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); });
2158
+ delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
2159
+ delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
2160
+ }
2161
+ }
2162
+
2163
+
2164
+ //Post events to containers
2165
+ function delayEvent( type, instance, container ) {
2166
+ return function( event ) {
2167
+ container._trigger( type, event, instance._uiHash( instance ) );
2168
+ };
2169
+ }
2170
+ for (i = this.containers.length - 1; i >= 0; i--){
2171
+ if (!noPropagation) {
2172
+ delayedTriggers.push( delayEvent( "deactivate", this, this.containers[ i ] ) );
2173
+ }
2174
+ if(this.containers[i].containerCache.over) {
2175
+ delayedTriggers.push( delayEvent( "out", this, this.containers[ i ] ) );
2176
+ this.containers[i].containerCache.over = 0;
2177
+ }
2178
+ }
2179
+
2180
+ //Do what was originally in plugins
2181
+ if ( this.storedCursor ) {
2182
+ this.document.find( "body" ).css( "cursor", this.storedCursor );
2183
+ this.storedStylesheet.remove();
2184
+ }
2185
+ if(this._storedOpacity) {
2186
+ this.helper.css("opacity", this._storedOpacity);
2187
+ }
2188
+ if(this._storedZIndex) {
2189
+ this.helper.css("zIndex", this._storedZIndex === "auto" ? "" : this._storedZIndex);
2190
+ }
2191
+
2192
+ this.dragging = false;
2193
+ if(this.cancelHelperRemoval) {
2194
+ if(!noPropagation) {
2195
+ this._trigger("beforeStop", event, this._uiHash());
2196
+ for (i=0; i < delayedTriggers.length; i++) {
2197
+ delayedTriggers[i].call(this, event);
2198
+ } //Trigger all delayed events
2199
+ this._trigger("stop", event, this._uiHash());
2200
+ }
2201
+
2202
+ this.fromOutside = false;
2203
+ return false;
2204
+ }
2205
+
2206
+ if(!noPropagation) {
2207
+ this._trigger("beforeStop", event, this._uiHash());
2208
+ }
2209
+
2210
+ //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
2211
+ this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
2212
+
2213
+ if(this.helper[0] !== this.currentItem[0]) {
2214
+ this.helper.remove();
2215
+ }
2216
+ this.helper = null;
2217
+
2218
+ if(!noPropagation) {
2219
+ for (i=0; i < delayedTriggers.length; i++) {
2220
+ delayedTriggers[i].call(this, event);
2221
+ } //Trigger all delayed events
2222
+ this._trigger("stop", event, this._uiHash());
2223
+ }
2224
+
2225
+ this.fromOutside = false;
2226
+ return true;
2227
+
2228
+ },
2229
+
2230
+ _trigger: function() {
2231
+ if ($.Widget.prototype._trigger.apply(this, arguments) === false) {
2232
+ this.cancel();
2233
+ }
2234
+ },
2235
+
2236
+ _uiHash: function(_inst) {
2237
+ var inst = _inst || this;
2238
+ return {
2239
+ helper: inst.helper,
2240
+ placeholder: inst.placeholder || $([]),
2241
+ position: inst.position,
2242
+ originalPosition: inst.originalPosition,
2243
+ offset: inst.positionAbs,
2244
+ item: inst.currentItem,
2245
+ sender: _inst ? _inst.element : null
2246
+ };
2247
+ }
2248
+
2249
+ });
2250
+
2251
+ })(jQuery);