@@ -257,8 +257,12 @@ uis.directive('uiSelect',
257
257
directionUpClassName = 'direction-up' ;
258
258
259
259
// Support changing the direction of the dropdown if there isn't enough space to render it.
260
- scope . $watch ( '$select.open' , function ( isOpen ) {
261
- if ( isOpen ) {
260
+ scope . $watch ( '$select.open' , function ( ) {
261
+ scope . calculateDropdownPos ( ) ;
262
+ } ) ;
263
+
264
+ scope . calculateDropdownPos = function ( ) {
265
+ if ( $select . open ) {
262
266
dropdown = angular . element ( element ) . querySelectorAll ( '.ui-select-dropdown' ) ;
263
267
if ( dropdown . length === 0 ) {
264
268
return ;
@@ -269,14 +273,25 @@ uis.directive('uiSelect',
269
273
270
274
// Delay positioning the dropdown until all choices have been added so its height is correct.
271
275
$timeout ( function ( ) {
276
+
277
+ element . removeClass ( directionUpClassName ) ;
278
+
272
279
var offset = uisOffset ( element ) ;
273
280
var offsetDropdown = uisOffset ( dropdown ) ;
274
281
282
+ //https://code.google.com/p/chromium/issues/detail?id=342307#c4
283
+ var scrollTop = $document [ 0 ] . documentElement . scrollTop || $document [ 0 ] . body . scrollTop ; //To make it cross browser (blink, webkit, IE, Firefox).
284
+
275
285
// Determine if the direction of the dropdown needs to be changed.
276
- if ( offset . top + offset . height + offsetDropdown . height > $document [ 0 ] . documentElement . scrollTop + $document [ 0 ] . documentElement . clientHeight ) {
286
+ if ( offset . top + offset . height + offsetDropdown . height > scrollTop + $document [ 0 ] . documentElement . clientHeight ) {
287
+ //Go UP
277
288
dropdown [ 0 ] . style . position = 'absolute' ;
278
289
dropdown [ 0 ] . style . top = ( offsetDropdown . height * - 1 ) + 'px' ;
279
290
element . addClass ( directionUpClassName ) ;
291
+ } else {
292
+ //Go DOWN
293
+ dropdown [ 0 ] . style . position = '' ;
294
+ dropdown [ 0 ] . style . top = '' ;
280
295
}
281
296
282
297
// Display the dropdown once it has been positioned.
@@ -292,7 +307,7 @@ uis.directive('uiSelect',
292
307
dropdown [ 0 ] . style . top = '' ;
293
308
element . removeClass ( directionUpClassName ) ;
294
309
}
295
- } ) ;
310
+ } ;
296
311
} ;
297
312
}
298
313
} ;
0 commit comments