|
445 | 445 | }
|
446 | 446 |
|
447 | 447 | this.hideMenus();
|
| 448 | + |
| 449 | + // Get top and bottom width of selectBox |
448 | 450 | var borderBottomWidth = parseInt(control.css('borderBottomWidth')) || 0;
|
449 |
| - |
| 451 | + var borderTopWidth = parseInt(control.css('borderTopWidth')) || 0; |
| 452 | + |
| 453 | + // Get top or bottom position for menu |
| 454 | + var top = control.offset().top + control.outerHeight() - borderBottomWidth |
| 455 | + , posTop = top+options.outerHeight()>$(window).outerHeight(); |
| 456 | + top = posTop?control.offset().top - options.outerHeight() + borderTopWidth:top; |
| 457 | + |
| 458 | + // Save if position is top to options data |
| 459 | + options.data('posTop',posTop); |
| 460 | + |
| 461 | + |
450 | 462 | // Menu position
|
451 | 463 | options
|
452 | 464 | .width(control.innerWidth())
|
453 | 465 | .css({
|
454 |
| - top: control.offset().top + control.outerHeight() - borderBottomWidth, |
| 466 | + top: top, |
455 | 467 | left: control.offset().left
|
456 |
| - }); |
| 468 | + }) |
| 469 | + // Add Top and Bottom class based on position |
| 470 | + .addClass('selectBox-options selectBox-options-'+(posTop?'top':'bottom')); |
457 | 471 |
|
458 | 472 |
|
459 | 473 | if (select.triggerHandler('beforeopen')) {
|
|
487 | 501 | var li = options.find('.selectBox-selected:first');
|
488 | 502 | this.keepOptionInView(li, true);
|
489 | 503 | this.addHover(li);
|
490 |
| - control.addClass('selectBox-menuShowing'); |
| 504 | + control.addClass('selectBox-menuShowing selectBox-menuShowing-'+(posTop?'top':'bottom')); |
491 | 505 |
|
492 | 506 | $(document).bind('mousedown.selectBox', function (event) {
|
493 | 507 | if (1 === event.which) {
|
|
512 | 526 | var options = $(this)
|
513 | 527 | , select = options.data('selectBox-select')
|
514 | 528 | , control = select.data('selectBox-control')
|
515 |
| - , settings = select.data('selectBox-settings'); |
| 529 | + , settings = select.data('selectBox-settings') |
| 530 | + , posTop = options.data('posTop'); |
516 | 531 |
|
517 | 532 | if (select.triggerHandler('beforeclose')) {
|
518 | 533 | return false;
|
|
523 | 538 | _selectBox: true
|
524 | 539 | });
|
525 | 540 | };
|
526 |
| - |
527 | 541 | if (settings) {
|
528 | 542 | switch (settings.menuTransition) {
|
529 | 543 | case 'fade':
|
|
539 | 553 | if (!settings.menuSpeed) {
|
540 | 554 | dispatchCloseEvent();
|
541 | 555 | }
|
542 |
| - control.removeClass('selectBox-menuShowing'); |
| 556 | + control.removeClass('selectBox-menuShowing selectBox-menuShowing-'+(posTop?'top':'bottom')); |
543 | 557 | } else {
|
544 | 558 | $(this).hide();
|
545 | 559 | $(this).triggerHandler('close', {
|
546 | 560 | _selectBox: true
|
547 | 561 | });
|
548 |
| - $(this).removeClass('selectBox-menuShowing'); |
| 562 | + $(this).removeClass('selectBox-menuShowing selectBox-menuShowing-'+(posTop?'top':'bottom')); |
549 | 563 | }
|
| 564 | + //Remove Top or Bottom class based on position |
| 565 | + options.removeClass('selectBox-options selectBox-options-'+(posTop?'top':'bottom')); |
| 566 | + options.data('posTop' , false); |
550 | 567 | });
|
551 | 568 | };
|
552 | 569 |
|
|
0 commit comments