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