From 15a72117d1a4cf7d4e04d3732452755b3de4d9cb Mon Sep 17 00:00:00 2001 From: mkfsn Date: Mon, 20 Feb 2017 12:10:39 +0800 Subject: [PATCH 1/3] Dropping unused variable countLimit --- src/angularjs-dropdown-multiselect.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/angularjs-dropdown-multiselect.js b/src/angularjs-dropdown-multiselect.js index 1594e442..69c46f8b 100644 --- a/src/angularjs-dropdown-multiselect.js +++ b/src/angularjs-dropdown-multiselect.js @@ -283,7 +283,6 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co var result = itemsText.join(', '); var index = result.length - 4; - var countLimit = 100; while (textWidth(result) > widthLimit) { if (itemsText[itemsText.length - 1] !== "...") { itemsText.push('...'); From b3fa8ba90cce40035f33ecb86bc4478343ff927a Mon Sep 17 00:00:00 2001 From: mkfsn Date: Mon, 20 Feb 2017 17:00:19 +0800 Subject: [PATCH 2/3] Prevent infinite loop --- src/angularjs-dropdown-multiselect.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/angularjs-dropdown-multiselect.js b/src/angularjs-dropdown-multiselect.js index 69c46f8b..084efdd3 100644 --- a/src/angularjs-dropdown-multiselect.js +++ b/src/angularjs-dropdown-multiselect.js @@ -260,9 +260,8 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co if ($scope.settings.smartButtonMaxItems > 0) { var paddingWidth = 12 * 2, - borderWidth = 1 * 2, - dropdownIconWidth = 8; - var ellipsisWidth = textWidth("..."); + borderWidth = 1 * 2, + dropdownIconWidth = 8; var widthLimit = $element[0].offsetWidth - paddingWidth - borderWidth - dropdownIconWidth; var itemsText = []; @@ -283,8 +282,12 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co var result = itemsText.join(', '); var index = result.length - 4; + + if ($element[0].offsetWidth === 0) + return result; + while (textWidth(result) > widthLimit) { - if (itemsText[itemsText.length - 1] !== "...") { + if (itemsText[itemsText.length - 1] !== '...') { itemsText.push('...'); result = result + "..."; } From 9063275fc28e6ef0cb90bc4559f9f10c9d1aca50 Mon Sep 17 00:00:00 2001 From: mkfsn Date: Mon, 20 Feb 2017 17:01:07 +0800 Subject: [PATCH 3/3] Add a event if no result is found when searching --- src/angularjs-dropdown-multiselect.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/angularjs-dropdown-multiselect.js b/src/angularjs-dropdown-multiselect.js index 084efdd3..a87a1d28 100644 --- a/src/angularjs-dropdown-multiselect.js +++ b/src/angularjs-dropdown-multiselect.js @@ -100,6 +100,7 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co onDeselectAll: angular.noop, onInitDone: angular.noop, onMaxSelectionReached: angular.noop, + onSearchNotFound: angular.noop, onSelectionChanged: angular.noop, onClose: angular.noop }; @@ -507,6 +508,7 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co } else if ($scope.settings.enableSearch) { $scope.selectAll(); } + $scope.externalEvents.onSearchNotFound($scope.input.searchFilter, $scope); } };