Skip to content

Commit c6873d8

Browse files
author
Marc J. Schmidt
committed
Merge pull request marcj#129 from TehCanadian/master
Options out of viewport detection and class customizing
2 parents 3a539ca + fee8d85 commit c6873d8

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

jquery.selectBox.css

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
border-color: #666;
2929
}
3030

31-
.selectBox-dropdown.selectBox-menuShowing {
31+
.selectBox-dropdown.selectBox-menuShowing-bottom {
3232
-moz-border-radius-bottomleft: 0;
3333
-moz-border-radius-bottomright: 0;
3434
-webkit-border-bottom-left-radius: 0;
@@ -37,6 +37,15 @@
3737
border-bottom-right-radius: 0;
3838
}
3939

40+
.selectBox-dropdown.selectBox-menuShowing-top {
41+
-moz-border-radius-topleft: 0;
42+
-moz-border-radius-topright: 0;
43+
-webkit-border-top-left-radius: 0;
44+
-webkit-border-top-right-radius: 0;
45+
border-top-left-radius: 0;
46+
border-top-right-radius: 0;
47+
}
48+
4049
.selectBox-dropdown .selectBox-label {
4150
padding: 2px 8px;
4251
display: inline-block;
@@ -97,6 +106,26 @@
97106
margin: 0;
98107
}
99108

109+
.selectBox-options.selectBox-options-top{
110+
border-bottom:none;
111+
margin-top:1px;
112+
-moz-border-radius-topleft: 5px;
113+
-moz-border-radius-topright: 5px;
114+
-webkit-border-top-left-radius: 5px;
115+
-webkit-border-top-right-radius: 5px;
116+
border-top-left-radius: 5px;
117+
border-top-right-radius: 5px;
118+
}
119+
.selectBox-options.selectBox-options-bottom{
120+
border-top:none;
121+
-moz-border-radius-bottomleft: 5px;
122+
-moz-border-radius-bottomright: 5px;
123+
-webkit-border-bottom-left-radius: 5px;
124+
-webkit-border-bottom-right-radius: 5px;
125+
border-bottom-left-radius: 5px;
126+
border-bottom-right-radius: 5px;
127+
}
128+
100129
.selectBox-options LI A {
101130
line-height: 1.5;
102131
padding: 0 .5em;
@@ -144,4 +173,4 @@
144173

145174
.selectBox-inline.selectBox-disabled .selectBox-options A {
146175
background-color: transparent !important;
147-
}
176+
}

jquery.selectBox.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,29 @@
445445
}
446446

447447
this.hideMenus();
448+
449+
// Get top and bottom width of selectBox
448450
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+
450462
// Menu position
451463
options
452464
.width(control.innerWidth())
453465
.css({
454-
top: control.offset().top + control.outerHeight() - borderBottomWidth,
466+
top: top,
455467
left: control.offset().left
456-
});
468+
})
469+
// Add Top and Bottom class based on position
470+
.addClass('selectBox-options selectBox-options-'+(posTop?'top':'bottom'));
457471

458472

459473
if (select.triggerHandler('beforeopen')) {
@@ -487,7 +501,7 @@
487501
var li = options.find('.selectBox-selected:first');
488502
this.keepOptionInView(li, true);
489503
this.addHover(li);
490-
control.addClass('selectBox-menuShowing');
504+
control.addClass('selectBox-menuShowing selectBox-menuShowing-'+(posTop?'top':'bottom'));
491505

492506
$(document).bind('mousedown.selectBox', function (event) {
493507
if (1 === event.which) {
@@ -512,7 +526,8 @@
512526
var options = $(this)
513527
, select = options.data('selectBox-select')
514528
, control = select.data('selectBox-control')
515-
, settings = select.data('selectBox-settings');
529+
, settings = select.data('selectBox-settings')
530+
, posTop = options.data('posTop');
516531

517532
if (select.triggerHandler('beforeclose')) {
518533
return false;
@@ -523,7 +538,6 @@
523538
_selectBox: true
524539
});
525540
};
526-
527541
if (settings) {
528542
switch (settings.menuTransition) {
529543
case 'fade':
@@ -539,14 +553,17 @@
539553
if (!settings.menuSpeed) {
540554
dispatchCloseEvent();
541555
}
542-
control.removeClass('selectBox-menuShowing');
556+
control.removeClass('selectBox-menuShowing selectBox-menuShowing-'+(posTop?'top':'bottom'));
543557
} else {
544558
$(this).hide();
545559
$(this).triggerHandler('close', {
546560
_selectBox: true
547561
});
548-
$(this).removeClass('selectBox-menuShowing');
562+
$(this).removeClass('selectBox-menuShowing selectBox-menuShowing-'+(posTop?'top':'bottom'));
549563
}
564+
//Remove Top or Bottom class based on position
565+
options.removeClass('selectBox-options selectBox-options-'+(posTop?'top':'bottom'));
566+
options.data('posTop' , false);
550567
});
551568
};
552569

0 commit comments

Comments
 (0)