2
2
* Contains ui-select "intelligence".
3
3
*
4
4
* The goal is to limit dependency on the DOM whenever possible and
5
- * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested.
5
+ * put as much logic in the controller (instead of the link functions) as possible so it can be
6
+ * easily tested.
6
7
*/
7
8
uis . controller ( 'uiSelectCtrl' ,
8
- [ '$scope' , '$element' , '$timeout' , '$filter' , '$$uisDebounce' , 'uisRepeatParser' , 'uiSelectMinErr' , 'uiSelectConfig' , '$parse' , '$injector' , '$window' ,
9
- function ( $scope , $element , $timeout , $filter , $$uisDebounce , RepeatParser , uiSelectMinErr , uiSelectConfig , $parse , $injector , $window ) {
9
+ [ '$scope' , '$element' , '$timeout' , '$filter' , '$$uisDebounce' , 'uisRepeatParser' , 'uiSelectMinErr' , 'uiSelectConfig' , '$parse' , '$injector' , '$window' , '$q' ,
10
+ function ( $scope , $element , $timeout , $filter , $$uisDebounce , RepeatParser , uiSelectMinErr , uiSelectConfig , $parse , $injector , $window , $q ) {
10
11
11
12
var ctrl = this ;
12
13
@@ -156,7 +157,9 @@ uis.controller('uiSelectCtrl',
156
157
var searchInput = $element . querySelectorAll ( '.ui-select-search' ) ;
157
158
158
159
if ( _canAnimate ( container ) ) {
159
- _animateDropdown ( searchInput , initSearchValue , container ) ;
160
+ // Only focus input after the animation has finished
161
+ _animateDropdown ( searchInput , container )
162
+ . then ( _focusWhenReady . bind ( null , initSearchValue ) ) ;
160
163
} else {
161
164
_focusWhenReady ( initSearchValue ) ;
162
165
}
@@ -167,26 +170,28 @@ uis.controller('uiSelectCtrl',
167
170
return ctrl . $animate && ctrl . $animate . on && ctrl . $animate . enabled ( element [ 0 ] ) ;
168
171
}
169
172
170
- function _animateDropdown ( searchInput , initSearchValue , container ) {
171
- var animateHandler = function ( elem , phase ) {
172
- if ( phase === 'start' && ctrl . items . length === 0 ) {
173
- // Only focus input after the animation has finished
174
- ctrl . $animate . off ( 'removeClass' , searchInput [ 0 ] , animateHandler ) ;
175
- _focusWhenReady ( initSearchValue ) ;
173
+ function _animateDropdown ( searchInput , container ) {
174
+
175
+ return $q ( function ( resolve , reject ) {
176
+
177
+ var animateHandler = function ( elem , phase ) {
178
+ if ( phase === 'start' && ctrl . items . length === 0 ) {
179
+ ctrl . $animate . off ( 'removeClass' , searchInput [ 0 ] , animateHandler ) ;
180
+ resolve ( ) ;
181
+ }
182
+ else if ( phase === 'close' ) {
183
+ ctrl . $animate . off ( 'enter' , container [ 0 ] , animateHandler ) ;
184
+ resolve ( ) ;
185
+ }
186
+ } ;
187
+
188
+ if ( ctrl . items . length > 0 ) {
189
+ ctrl . $animate . on ( 'enter' , container [ 0 ] , animateHandler ) ;
176
190
}
177
- else if ( phase === 'close' ) {
178
- // Only focus input after the animation has finished
179
- ctrl . $animate . off ( 'enter' , container [ 0 ] , animateHandler ) ;
180
- _focusWhenReady ( initSearchValue ) ;
191
+ else {
192
+ ctrl . $animate . on ( 'removeClass' , searchInput [ 0 ] , animateHandler ) ;
181
193
}
182
- } ;
183
-
184
- if ( ctrl . items . length > 0 ) {
185
- ctrl . $animate . on ( 'enter' , container [ 0 ] , animateHandler ) ;
186
- }
187
- else {
188
- ctrl . $animate . on ( 'removeClass' , searchInput [ 0 ] , animateHandler ) ;
189
- }
194
+ } ) ;
190
195
}
191
196
192
197
function _focusWhenReady ( initSearchValue ) {
@@ -326,7 +331,8 @@ uis.controller('uiSelectCtrl',
326
331
/**
327
332
* Typeahead mode: lets the user refresh the collection using his own function.
328
333
*
329
- * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31
334
+ * See Expose $select.search for external / remote filtering
335
+ * https://github.com/angular-ui/ui-select/pull/31
330
336
*/
331
337
ctrl . refresh = function ( refreshAttr ) {
332
338
if ( refreshAttr !== undefined ) {
0 commit comments