From d4d15583b76c63ce304ad9e261422e6583a5d058 Mon Sep 17 00:00:00 2001 From: michaschwab Date: Fri, 11 Mar 2016 07:00:17 -0500 Subject: [PATCH 1/3] now, ui sortable only starts if the disabled option is not set. once the disabled option is removed, ui sortable will launch. --- src/sortable.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/sortable.js b/src/sortable.js index 37ad210..47800d5 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -448,8 +448,17 @@ angular.module('ui.sortable', []) $log.info('ui.sortable: ngModel not provided!', element); } - // Create sortable - element.sortable(opts); + var created = false; + scope.$watch('uiSortable.disabled', function() + { + if(!created && !scope.uiSortable.disabled) + { + created = true; + + // Create sortable + element.sortable(opts); + } + }); } }; } From 6991b9fcbc1734910e6476fa3ddd879e17cbabff Mon Sep 17 00:00:00 2001 From: michaschwab Date: Fri, 11 Mar 2016 11:23:24 -0500 Subject: [PATCH 2/3] moved starting code into a new function, and cancelling watcher if start function is called. --- src/sortable.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/sortable.js b/src/sortable.js index 47800d5..c043fa7 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -448,17 +448,27 @@ angular.module('ui.sortable', []) $log.info('ui.sortable: ngModel not provided!', element); } - var created = false; - scope.$watch('uiSortable.disabled', function() + var listener = function() {}; + + var startIfEnabled = function() { - if(!created && !scope.uiSortable.disabled) + if(!scope.uiSortable.disabled) { - created = true; - // Create sortable element.sortable(opts); + + // Stop Watcher + listener(); + + return true; } - }); + return false; + }; + + if(!startIfEnabled()) + { + listener = scope.$watch('uiSortable.disabled', startIfEnabled); + } } }; } From ec6567f66a6d2fedc85bf2ba0cda8748fc83778f Mon Sep 17 00:00:00 2001 From: michaschwab Date: Fri, 11 Mar 2016 11:51:45 -0500 Subject: [PATCH 3/3] memory efficiency with angular.noop --- src/sortable.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sortable.js b/src/sortable.js index c043fa7..5dbc047 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -448,7 +448,7 @@ angular.module('ui.sortable', []) $log.info('ui.sortable: ngModel not provided!', element); } - var listener = function() {}; + var stopDisabledWatcher = angular.noop; var startIfEnabled = function() { @@ -458,7 +458,7 @@ angular.module('ui.sortable', []) element.sortable(opts); // Stop Watcher - listener(); + stopDisabledWatcher(); return true; } @@ -467,7 +467,7 @@ angular.module('ui.sortable', []) if(!startIfEnabled()) { - listener = scope.$watch('uiSortable.disabled', startIfEnabled); + stopDisabledWatcher = scope.$watch('uiSortable.disabled', startIfEnabled); } } };