|
1 | 1 | /*!
|
2 | 2 | * ui-select
|
3 | 3 | * http://github.com/angular-ui/ui-select
|
4 |
| - * Version: 0.13.3 - 2016-01-25T22:55:58.249Z |
| 4 | + * Version: 0.13.3 - 2016-01-25T23:01:33.462Z |
5 | 5 | * License: MIT
|
6 | 6 | */
|
7 | 7 |
|
@@ -254,8 +254,8 @@ uis.directive('uiSelectChoices',
|
254 | 254 | * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested.
|
255 | 255 | */
|
256 | 256 | uis.controller('uiSelectCtrl',
|
257 |
| - ['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', '$parse', |
258 |
| - function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig, $parse) { |
| 257 | + ['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', '$parse', '$injector', |
| 258 | + function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig, $parse, $injector) { |
259 | 259 |
|
260 | 260 | var ctrl = this;
|
261 | 261 |
|
@@ -290,11 +290,21 @@ uis.controller('uiSelectCtrl',
|
290 | 290 | ctrl.clickTriggeredSelect = false;
|
291 | 291 | ctrl.$filter = $filter;
|
292 | 292 |
|
| 293 | + // Use $injector to check for $animate and store a reference to it |
| 294 | + ctrl.$animate = (function () { |
| 295 | + try { |
| 296 | + return $injector.get('$animate'); |
| 297 | + } catch (err) { |
| 298 | + // $animate does not exist |
| 299 | + return null; |
| 300 | + } |
| 301 | + })(); |
| 302 | + |
293 | 303 | ctrl.searchInput = $element.querySelectorAll('input.ui-select-search');
|
294 | 304 | if (ctrl.searchInput.length !== 1) {
|
295 | 305 | throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length);
|
296 | 306 | }
|
297 |
| - |
| 307 | + |
298 | 308 | ctrl.isEmpty = function() {
|
299 | 309 | return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
|
300 | 310 | };
|
@@ -339,14 +349,29 @@ uis.controller('uiSelectCtrl',
|
339 | 349 | ctrl.activeIndex = 0;
|
340 | 350 | }
|
341 | 351 |
|
342 |
| - // Give it time to appear before focus |
343 |
| - $timeout(function() { |
344 |
| - ctrl.search = initSearchValue || ctrl.search; |
345 |
| - ctrl.searchInput[0].focus(); |
346 |
| - if(!ctrl.tagging.isActivated && ctrl.items.length > 1) { |
347 |
| - _ensureHighlightVisible(); |
348 |
| - } |
349 |
| - }); |
| 352 | + var container = $element.querySelectorAll('.ui-select-choices-content'); |
| 353 | + if (ctrl.$animate && ctrl.$animate.enabled(container[0])) { |
| 354 | + ctrl.$animate.on('enter', container[0], function (elem, phase) { |
| 355 | + if (phase === 'close') { |
| 356 | + // Only focus input after the animation has finished |
| 357 | + $timeout(function () { |
| 358 | + ctrl.focusSearchInput(initSearchValue); |
| 359 | + }); |
| 360 | + } |
| 361 | + }); |
| 362 | + } else { |
| 363 | + $timeout(function () { |
| 364 | + ctrl.focusSearchInput(initSearchValue); |
| 365 | + }); |
| 366 | + } |
| 367 | + } |
| 368 | + }; |
| 369 | + |
| 370 | + ctrl.focusSearchInput = function (initSearchValue) { |
| 371 | + ctrl.search = initSearchValue || ctrl.search; |
| 372 | + ctrl.searchInput[0].focus(); |
| 373 | + if(!ctrl.tagging.isActivated && ctrl.items.length > 1) { |
| 374 | + _ensureHighlightVisible(); |
350 | 375 | }
|
351 | 376 | };
|
352 | 377 |
|
@@ -398,7 +423,7 @@ uis.controller('uiSelectCtrl',
|
398 | 423 | //If collection is an Object, convert it to Array
|
399 | 424 |
|
400 | 425 | var originalSource = ctrl.parserResult.source;
|
401 |
| - |
| 426 | + |
402 | 427 | //When an object is used as source, we better create an array and use it as 'source'
|
403 | 428 | var createArrayFromObject = function(){
|
404 | 429 | var origSrc = originalSource($scope);
|
@@ -444,7 +469,7 @@ uis.controller('uiSelectCtrl',
|
444 | 469 | ctrl.items = [];
|
445 | 470 | } else {
|
446 | 471 | if (!angular.isArray(items)) {
|
447 |
| - throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); |
| 472 | + throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items); |
448 | 473 | } else {
|
449 | 474 | //Remove already selected items (ex: while searching)
|
450 | 475 | //TODO Should add a test
|
|
0 commit comments