Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 530c41a

Browse files
committed
Make the sizeSearchInput compatible with AngularJS 1.2.x by removing the use of the $scope.$watchGroup API.
1 parent b1fefd8 commit 530c41a

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

src/uiSelectController.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -366,32 +366,35 @@ uis.controller('uiSelectCtrl',
366366
return ctrl.placeholder;
367367
};
368368

369-
var containerSizeWatch;
370-
ctrl.sizeSearchInput = function(){
369+
var sizeWatch = null;
370+
ctrl.sizeSearchInput = function() {
371371
var input = _searchInput[0],
372-
container = _searchInput.parent().parent()[0];
373-
_searchInput.css('width','10px');
374-
var calculate = function(){
375-
var newWidth = container.clientWidth - input.offsetLeft - 10;
376-
if(newWidth < 50) newWidth = container.clientWidth;
377-
_searchInput.css('width',newWidth+'px');
378-
};
379-
$timeout(function(){ //Give tags time to render correctly
380-
if ((container.clientWidth === 0 || input.offsetParent === null) && !containerSizeWatch) {
381-
containerSizeWatch = $scope.$watchGroup([
382-
function(){ return container.clientWidth; },
383-
function(){ return input.offsetParent; }
384-
], function(newValues){
385-
if (newValues[0] !== 0 && newValues[1] !== null){
386-
calculate();
387-
containerSizeWatch();
388-
containerSizeWatch = null;
372+
container = _searchInput.parent().parent()[0],
373+
calculateContainerWidth = function() {
374+
// Return the container width only if the search input is visible
375+
return container.clientWidth * !!input.offsetParent;
376+
},
377+
updateIfVisible = function(containerWidth) {
378+
if (containerWidth === 0) {
379+
return false;
380+
}
381+
var inputWidth = containerWidth - input.offsetLeft - 10;
382+
if (inputWidth < 50) inputWidth = containerWidth;
383+
_searchInput.css('width', inputWidth+'px');
384+
return true;
385+
};
386+
387+
_searchInput.css('width', '10px');
388+
$timeout(function() { //Give tags time to render correctly
389+
if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) {
390+
sizeWatch = $scope.$watch(calculateContainerWidth, function(containerWidth) {
391+
if (updateIfVisible(containerWidth)) {
392+
sizeWatch();
393+
sizeWatch = null;
389394
}
390395
});
391-
}else if (!containerSizeWatch) {
392-
calculate();
393396
}
394-
}, 0, false);
397+
});
395398
};
396399

397400
function _handleDropDownSelection(key) {

0 commit comments

Comments
 (0)