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

Commit

Permalink
feat(ngAnimate): add support for ngAnimate
Browse files Browse the repository at this point in the history
Merge branch 'patrickhousley-issue-859'
  • Loading branch information
aaronroberson committed Jan 25, 2016
2 parents e7b4c52 + fa61cae commit 8da8a6d
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* put as much logic in the controller (instead of the link functions) as possible so it can be easily tested.
*/
uis.controller('uiSelectCtrl',
['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', '$parse',
function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig, $parse) {
['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', '$parse', '$injector',
function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig, $parse, $injector) {

var ctrl = this;

Expand Down Expand Up @@ -41,11 +41,21 @@ uis.controller('uiSelectCtrl',
ctrl.clickTriggeredSelect = false;
ctrl.$filter = $filter;

// Use $injector to check for $animate and store a reference to it
ctrl.$animate = (function () {
try {
return $injector.get('$animate');
} catch (err) {
// $animate does not exist
return null;
}
})();

ctrl.searchInput = $element.querySelectorAll('input.ui-select-search');
if (ctrl.searchInput.length !== 1) {
throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length);
}

ctrl.isEmpty = function() {
return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
};
Expand Down Expand Up @@ -90,14 +100,29 @@ uis.controller('uiSelectCtrl',
ctrl.activeIndex = 0;
}

// Give it time to appear before focus
$timeout(function() {
ctrl.search = initSearchValue || ctrl.search;
ctrl.searchInput[0].focus();
if(!ctrl.tagging.isActivated && ctrl.items.length > 1) {
_ensureHighlightVisible();
}
});
var container = $element.querySelectorAll('.ui-select-choices-content');
if (ctrl.$animate && ctrl.$animate.enabled(container[0])) {
ctrl.$animate.on('enter', container[0], function (elem, phase) {
if (phase === 'close') {
// Only focus input after the animation has finished
$timeout(function () {
ctrl.focusSearchInput(initSearchValue);
});
}
});
} else {
$timeout(function () {
ctrl.focusSearchInput(initSearchValue);
});
}
}
};

ctrl.focusSearchInput = function (initSearchValue) {
ctrl.search = initSearchValue || ctrl.search;
ctrl.searchInput[0].focus();
if(!ctrl.tagging.isActivated && ctrl.items.length > 1) {
_ensureHighlightVisible();
}
};

Expand Down Expand Up @@ -149,7 +174,7 @@ uis.controller('uiSelectCtrl',
//If collection is an Object, convert it to Array

var originalSource = ctrl.parserResult.source;

//When an object is used as source, we better create an array and use it as 'source'
var createArrayFromObject = function(){
var origSrc = originalSource($scope);
Expand Down Expand Up @@ -195,7 +220,7 @@ uis.controller('uiSelectCtrl',
ctrl.items = [];
} else {
if (!angular.isArray(items)) {
throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items);
throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items);
} else {
//Remove already selected items (ex: while searching)
//TODO Should add a test
Expand Down

0 comments on commit 8da8a6d

Please sign in to comment.