This repository was archived by the owner on Sep 8, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-21
lines changed
Expand file tree Collapse file tree 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', [])
230230 return ;
231231 }
232232
233- function init ( ) {
233+ function wireUp ( ) {
234234 // When we add or remove elements, we need the sortable to 'refresh'
235235 // so it can find the new/removed elements.
236236 scope . $watchCollection ( 'ngModel' , function ( ) {
@@ -444,31 +444,30 @@ angular.module('ui.sortable', [])
444444 patchUISortableOptions ( opts ) ;
445445 }
446446
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+ }
448453
449- var startIfEnabled = function ( ) {
454+ function lazyInit ( ) {
450455 if ( scope . uiSortable && scope . uiSortable . disabled ) {
451- return false ;
452- }
453-
454- if ( ngModel ) {
455- init ( ) ;
456+ watchOnce ( 'uiSortable.disabled' , lazyInit ) ;
456457 } 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 ( ) ;
465458
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+ }
471468 }
469+
470+ lazyInit ( ) ;
472471 }
473472 } ;
474473 }
You can’t perform that action at this time.
0 commit comments