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
@@ -151,7 +152,9 @@ uis.controller('uiSelectCtrl',
151
152
var searchInput = $element . querySelectorAll ( '.ui-select-search' ) ;
152
153
153
154
if ( _canAnimate ( container ) ) {
154
- _animateDropdown ( searchInput , initSearchValue , container ) ;
155
+ // Only focus input after the animation has finished
156
+ _animateDropdown ( searchInput , container )
157
+ . then ( _focusWhenReady . bind ( null , initSearchValue ) ) ;
155
158
} else {
156
159
_focusWhenReady ( initSearchValue ) ;
157
160
}
@@ -162,26 +165,28 @@ uis.controller('uiSelectCtrl',
162
165
return ctrl . $animate && ctrl . $animate . on && ctrl . $animate . enabled ( element [ 0 ] ) ;
163
166
}
164
167
165
- function _animateDropdown ( searchInput , initSearchValue , container ) {
166
- var animateHandler = function ( elem , phase ) {
167
- if ( phase === 'start' && ctrl . items . length === 0 ) {
168
- // Only focus input after the animation has finished
169
- ctrl . $animate . off ( 'removeClass' , searchInput [ 0 ] , animateHandler ) ;
170
- _focusWhenReady ( initSearchValue ) ;
168
+ function _animateDropdown ( searchInput , container ) {
169
+
170
+ return $q ( function ( resolve , reject ) {
171
+
172
+ var animateHandler = function ( elem , phase ) {
173
+ if ( phase === 'start' && ctrl . items . length === 0 ) {
174
+ ctrl . $animate . off ( 'removeClass' , searchInput [ 0 ] , animateHandler ) ;
175
+ resolve ( ) ;
176
+ }
177
+ else if ( phase === 'close' ) {
178
+ ctrl . $animate . off ( 'enter' , container [ 0 ] , animateHandler ) ;
179
+ resolve ( ) ;
180
+ }
181
+ } ;
182
+
183
+ if ( ctrl . items . length > 0 ) {
184
+ ctrl . $animate . on ( 'enter' , container [ 0 ] , animateHandler ) ;
171
185
}
172
- else if ( phase === 'close' ) {
173
- // Only focus input after the animation has finished
174
- ctrl . $animate . off ( 'enter' , container [ 0 ] , animateHandler ) ;
175
- _focusWhenReady ( initSearchValue ) ;
186
+ else {
187
+ ctrl . $animate . on ( 'removeClass' , searchInput [ 0 ] , animateHandler ) ;
176
188
}
177
- } ;
178
-
179
- if ( ctrl . items . length > 0 ) {
180
- ctrl . $animate . on ( 'enter' , container [ 0 ] , animateHandler ) ;
181
- }
182
- else {
183
- ctrl . $animate . on ( 'removeClass' , searchInput [ 0 ] , animateHandler ) ;
184
- }
189
+ } ) ;
185
190
}
186
191
187
192
function _focusWhenReady ( initSearchValue ) {
@@ -318,7 +323,8 @@ uis.controller('uiSelectCtrl',
318
323
/**
319
324
* Typeahead mode: lets the user refresh the collection using his own function.
320
325
*
321
- * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31
326
+ * See Expose $select.search for external / remote filtering
327
+ * https://github.com/angular-ui/ui-select/pull/31
322
328
*/
323
329
ctrl . refresh = function ( refreshAttr ) {
324
330
if ( refreshAttr !== undefined ) {
0 commit comments