@@ -328,57 +328,70 @@ uis.directive('uiSelect',
328
328
329
329
} ;
330
330
331
- scope . calculateDropdownPos = function ( ) {
331
+ var calculateDropdownPosAfterAnimation = function ( ) {
332
+ // Delay positioning the dropdown until all choices have been added so its height is correct.
333
+ $timeout ( function ( ) {
334
+ if ( $select . dropdownPosition === 'up' ) {
335
+ //Go UP
336
+ setDropdownPosUp ( ) ;
337
+ } else {
338
+ //AUTO
339
+ element . removeClass ( directionUpClassName ) ;
340
+
341
+ var offset = uisOffset ( element ) ;
342
+ var offsetDropdown = uisOffset ( dropdown ) ;
343
+
344
+ //https://code.google.com/p/chromium/issues/detail?id=342307#c4
345
+ var scrollTop = $document [ 0 ] . documentElement . scrollTop || $document [ 0 ] . body . scrollTop ; //To make it cross browser (blink, webkit, IE, Firefox).
346
+
347
+ // Determine if the direction of the dropdown needs to be changed.
348
+ if ( offset . top + offset . height + offsetDropdown . height > scrollTop + $document [ 0 ] . documentElement . clientHeight ) {
349
+ //Go UP
350
+ setDropdownPosUp ( offset , offsetDropdown ) ;
351
+ } else {
352
+ //Go DOWN
353
+ setDropdownPosDown ( offset , offsetDropdown ) ;
354
+ }
355
+ }
332
356
357
+ // Display the dropdown once it has been positioned.
358
+ dropdown [ 0 ] . style . opacity = 1 ;
359
+ } ) ;
360
+ } ;
361
+
362
+ scope . calculateDropdownPos = function ( ) {
333
363
if ( $select . open ) {
334
364
dropdown = angular . element ( element ) . querySelectorAll ( '.ui-select-dropdown' ) ;
365
+
335
366
if ( dropdown . length === 0 ) {
336
367
return ;
337
368
}
338
369
339
370
// Hide the dropdown so there is no flicker until $timeout is done executing.
340
371
dropdown [ 0 ] . style . opacity = 0 ;
341
372
342
- // Delay positioning the dropdown until all choices have been added so its height is correct.
343
- $timeout ( function ( ) {
344
-
345
- if ( $select . dropdownPosition === 'up' ) {
346
- //Go UP
347
- setDropdownPosUp ( ) ;
348
-
349
- } else { //AUTO
350
-
351
- element . removeClass ( directionUpClassName ) ;
373
+ if ( ! uisOffset ( dropdown ) . height && $select . $animate && $select . $animate . on && $select . $animate . enabled ( dropdown ) ) {
374
+ var needsCalculated = true ;
352
375
353
- var offset = uisOffset ( element ) ;
354
- var offsetDropdown = uisOffset ( dropdown ) ;
355
-
356
- //https://code.google.com/p/chromium/issues/detail?id=342307#c4
357
- var scrollTop = $document [ 0 ] . documentElement . scrollTop || $document [ 0 ] . body . scrollTop ; //To make it cross browser (blink, webkit, IE, Firefox).
358
-
359
- // Determine if the direction of the dropdown needs to be changed.
360
- if ( offset . top + offset . height + offsetDropdown . height > scrollTop + $document [ 0 ] . documentElement . clientHeight ) {
361
- //Go UP
362
- setDropdownPosUp ( offset , offsetDropdown ) ;
363
- } else {
364
- //Go DOWN
365
- setDropdownPosDown ( offset , offsetDropdown ) ;
376
+ $select . $animate . on ( 'enter' , dropdown , function ( elem , phase ) {
377
+ if ( phase === 'close' && needsCalculated ) {
378
+ calculateDropdownPosAfterAnimation ( ) ;
379
+ needsCalculated = false ;
366
380
}
367
-
368
- }
369
-
370
- // Display the dropdown once it has been positioned.
371
- dropdown [ 0 ] . style . opacity = 1 ;
372
- } ) ;
381
+ } ) ;
382
+ } else {
383
+ calculateDropdownPosAfterAnimation ( ) ;
384
+ }
373
385
} else {
374
- if ( dropdown === null || dropdown . length === 0 ) {
375
- return ;
376
- }
386
+ if ( dropdown === null || dropdown . length === 0 ) {
387
+ return ;
388
+ }
377
389
378
- // Reset the position of the dropdown.
379
- dropdown [ 0 ] . style . position = '' ;
380
- dropdown [ 0 ] . style . top = '' ;
381
- element . removeClass ( directionUpClassName ) ;
390
+ // Reset the position of the dropdown.
391
+ dropdown [ 0 ] . style . opacity = 0 ;
392
+ dropdown [ 0 ] . style . position = '' ;
393
+ dropdown [ 0 ] . style . top = '' ;
394
+ element . removeClass ( directionUpClassName ) ;
382
395
}
383
396
} ;
384
397
} ;
0 commit comments