@@ -98,13 +98,11 @@ describe('uiSortable', function() {
98
98
li . simulate ( 'drag' , { dy : dy } ) ;
99
99
expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqual ( [ "One" , "Three" , "Four" , "Two" ] ) ;
100
100
101
- // fails on angular 1.2
102
101
li = element . find ( ':eq(2)' ) ;
103
102
dy = - ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
104
103
li . simulate ( 'drag' , { dy : dy } ) ;
105
104
expect ( $rootScope . items . map ( function ( x ) { return x . text ; } ) ) . toEqual ( [ "Four" , "One" , "Three" , "Two" ] ) ;
106
105
107
- // fails on angular 1.2
108
106
li = element . find ( ':eq(3)' ) ;
109
107
dy = - ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
110
108
li . simulate ( 'drag' , { dy : dy } ) ;
@@ -129,15 +127,13 @@ describe('uiSortable', function() {
129
127
130
128
host . append ( elementTop ) . append ( elementBottom ) ;
131
129
132
- // fails on angular 1.2
133
130
var li1 = elementTop . find ( ':eq(0)' ) ;
134
131
var li2 = elementBottom . find ( ':eq(0)' ) ;
135
132
var dy = EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) + ( li2 . position ( ) . top - li1 . position ( ) . top ) ;
136
133
li1 . simulate ( 'drag' , { dy : dy } ) ;
137
134
expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top Three" ] ) ;
138
135
expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Top One" , "Bottom Two" , "Bottom Three" ] ) ;
139
136
140
- // fails on angular 1.2
141
137
li1 = elementBottom . find ( ':eq(1)' ) ;
142
138
li2 = elementTop . find ( ':eq(1)' ) ;
143
139
dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
@@ -194,10 +190,70 @@ describe('uiSortable', function() {
194
190
li . simulate ( 'drag' , { dy : dy } ) ;
195
191
expect ( $rootScope . items ) . toEqual ( [ "Two" , "Three" , "One" ] ) ;
196
192
193
+ li = element . find ( ':eq(2)' ) ;
194
+ dy = - ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
195
+ li . simulate ( 'drag' , { dy : dy } ) ;
196
+ expect ( $rootScope . items ) . toEqual ( [ "One" , "Two" , "Three" ] ) ;
197
+
197
198
$ ( element ) . remove ( ) ;
198
199
} ) ;
199
200
} ) ;
200
201
202
+ it ( 'should cancel sorting of nodes that contain "Two"' , function ( ) {
203
+ inject ( function ( $compile , $rootScope ) {
204
+ var elementTop , elementBottom ;
205
+ elementTop = $compile ( '<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
206
+ elementBottom = $compile ( '<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
207
+ $rootScope . $apply ( function ( ) {
208
+ $rootScope . itemsTop = [ "Top One" , "Top Two" , "Top Three" ] ;
209
+ $rootScope . itemsBottom = [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ;
210
+ $rootScope . opts = {
211
+ connectWith : ".cross-sortable" ,
212
+ update : function ( e , ui ) {
213
+ if ( ui . item . scope ( ) &&
214
+ ( typeof ui . item . scope ( ) . item === 'string' ) &&
215
+ ui . item . scope ( ) . item . indexOf ( "Two" ) >= 0 ) {
216
+ ui . item . sortable . cancel ( ) ;
217
+ }
218
+ }
219
+ } ;
220
+ } ) ;
221
+
222
+ host . append ( elementTop ) . append ( elementBottom ) ;
223
+
224
+ var li1 = elementTop . find ( ':eq(1)' ) ;
225
+ var li2 = elementBottom . find ( ':eq(0)' ) ;
226
+ var dy = EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) + ( li2 . position ( ) . top - li1 . position ( ) . top ) ;
227
+ li1 . simulate ( 'drag' , { dy : dy } ) ;
228
+ expect ( $rootScope . itemsTop ) . toEqual ( [ "Top One" , "Top Two" , "Top Three" ] ) ;
229
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
230
+
231
+ li1 = elementBottom . find ( ':eq(1)' ) ;
232
+ li2 = elementTop . find ( ':eq(1)' ) ;
233
+ dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
234
+ li1 . simulate ( 'drag' , { dy : dy } ) ;
235
+ expect ( $rootScope . itemsTop ) . toEqual ( [ "Top One" , "Top Two" , "Top Three" ] ) ;
236
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
237
+
238
+ li1 = elementTop . find ( ':eq(0)' ) ;
239
+ li2 = elementBottom . find ( ':eq(0)' ) ;
240
+ dy = EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) + ( li2 . position ( ) . top - li1 . position ( ) . top ) ;
241
+ li1 . simulate ( 'drag' , { dy : dy } ) ;
242
+ expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top Three" ] ) ;
243
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Top One" , "Bottom Two" , "Bottom Three" ] ) ;
244
+
245
+ li1 = elementBottom . find ( ':eq(1)' ) ;
246
+ li2 = elementTop . find ( ':eq(1)' ) ;
247
+ dy = - EXTRA_DY_PERCENTAGE * li1 . outerHeight ( ) - ( li1 . position ( ) . top - li2 . position ( ) . top ) ;
248
+ li1 . simulate ( 'drag' , { dy : dy } ) ;
249
+ expect ( $rootScope . itemsTop ) . toEqual ( [ "Top Two" , "Top One" , "Top Three" ] ) ;
250
+ expect ( $rootScope . itemsBottom ) . toEqual ( [ "Bottom One" , "Bottom Two" , "Bottom Three" ] ) ;
251
+
252
+ $ ( elementTop ) . remove ( ) ;
253
+ $ ( elementBottom ) . remove ( ) ;
254
+ } ) ;
255
+ } ) ;
256
+
201
257
it ( 'should update model from update() callback' , function ( ) {
202
258
inject ( function ( $compile , $rootScope ) {
203
259
var element , logsElement ;
0 commit comments