55 * Copyright 2012, Ali Farhadi
66 * Released under the MIT license.
77 */
8- jQuery . fn . sortable = function ( ) {
8+ ( function ( $ ) {
9+ var dragging , placeholders = $ ( ) ;
10+ $ . fn . sortable = function ( options ) {
911 return this . each ( function ( ) {
10- var $ = jQuery , index , dragging , items = $ ( this ) . children ( ) ;
12+ var index , items = $ ( this ) . children ( ) , connectWith = false ;
1113 var placeholder = $ ( '<' + items [ 0 ] . tagName + '>' ) . addClass ( 'sortable-placeholder' ) ;
12-
14+ placeholders = placeholders . add ( placeholder ) ;
15+ if ( options && options . connectWith ) {
16+ $ ( connectWith = options . connectWith ) . add ( this ) . data ( 'connectWith' , connectWith ) ;
17+ }
1318 items . attr ( 'draggable' , 'true' ) . bind ( 'dragstart' , function ( e ) {
1419 var dt = e . originalEvent . dataTransfer ;
1520 dt . effectAllowed = 'move' ;
@@ -18,7 +23,7 @@ jQuery.fn.sortable = function() {
1823 index = dragging . index ( ) ;
1924 } ) . bind ( 'dragend' , function ( ) {
2025 dragging . removeClass ( 'sortable-dragging' ) . fadeIn ( ) ;
21- placeholder . detach ( ) ;
26+ placeholders . detach ( ) ;
2227 if ( index != dragging . index ( ) ) {
2328 items . parent ( ) . trigger ( 'sortupdate' ) ;
2429 }
@@ -27,19 +32,25 @@ jQuery.fn.sortable = function() {
2732 this . dragDrop && this . dragDrop ( ) ;
2833 return false ;
2934 } ) . end ( ) . add ( [ this , placeholder ] ) . bind ( 'dragover dragenter' , function ( e ) {
30- if ( ! dragging ) return true ;
35+ if ( ! items . is ( dragging ) && connectWith !== $ ( dragging ) . parent ( ) . data ( 'connectWith' ) ) {
36+ return true ;
37+ }
3138 e . preventDefault ( ) ;
3239 e . originalEvent . dataTransfer . dropEffect = 'move' ;
3340 if ( items . is ( this ) ) {
3441 dragging . hide ( ) ;
3542 $ ( this ) [ placeholder . index ( ) < $ ( this ) . index ( ) ? 'after' : 'before' ] ( placeholder ) ;
3643 }
44+ placeholders . not ( placeholder ) . detach ( ) ;
3745 return false ;
3846 } ) . bind ( 'drop' , function ( e ) {
39- if ( ! dragging ) return true ;
47+ if ( ! items . is ( dragging ) && connectWith !== $ ( dragging ) . parent ( ) . data ( 'connectWith' ) ) {
48+ return true ;
49+ }
4050 e . stopPropagation ( ) ;
4151 placeholder . after ( dragging ) ;
4252 return false ;
4353 } ) ;
4454 } ) ;
4555} ;
56+ } ) ( jQuery ) ;
0 commit comments