This repository was archived by the owner on Sep 8, 2020. It is now read-only.
File tree 1 file changed +20
-21
lines changed
1 file changed +20
-21
lines changed Original file line number Diff line number Diff line change @@ -230,7 +230,7 @@ angular.module('ui.sortable', [])
230
230
return ;
231
231
}
232
232
233
- function init ( ) {
233
+ function wireUp ( ) {
234
234
// When we add or remove elements, we need the sortable to 'refresh'
235
235
// so it can find the new/removed elements.
236
236
scope . $watchCollection ( 'ngModel' , function ( ) {
@@ -444,31 +444,30 @@ angular.module('ui.sortable', [])
444
444
patchUISortableOptions ( opts ) ;
445
445
}
446
446
447
- var stopDisabledWatcher = angular . noop ;
447
+ function watchOnce ( watchExpr , fn ) {
448
+ var cancelWatcher = scope . $watch ( watchExpr , function ( ) {
449
+ fn . apply ( this , arguments ) ;
450
+ cancelWatcher ( ) ;
451
+ } ) ;
452
+ }
448
453
449
- var startIfEnabled = function ( ) {
454
+ function lazyInit ( ) {
450
455
if ( scope . uiSortable && scope . uiSortable . disabled ) {
451
- return false ;
452
- }
453
-
454
- if ( ngModel ) {
455
- init ( ) ;
456
+ watchOnce ( 'uiSortable.disabled' , lazyInit ) ;
456
457
} else {
457
- $log . info ( 'ui.sortable: ngModel not provided!' , element ) ;
458
- }
459
-
460
- // Create sortable
461
- element . sortable ( opts ) ;
462
-
463
- // Stop Watcher
464
- stopDisabledWatcher ( ) ;
465
458
466
- return true ;
467
- } ;
468
-
469
- if ( ! startIfEnabled ( ) ) {
470
- stopDisabledWatcher = scope . $watch ( 'uiSortable.disabled' , startIfEnabled ) ;
459
+ if ( ngModel ) {
460
+ wireUp ( ) ;
461
+ } else {
462
+ $log . info ( 'ui.sortable: ngModel not provided!' , element ) ;
463
+ }
464
+
465
+ // Create sortable
466
+ element . sortable ( opts ) ;
467
+ }
471
468
}
469
+
470
+ lazyInit ( ) ;
472
471
}
473
472
} ;
474
473
}
You can’t perform that action at this time.
0 commit comments