Skip to content

Commit b91c082

Browse files
committed
v1.1.0
Removed autoWidth option; control now inherits the size of the original select element
1 parent 5dc01a5 commit b91c082

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

README

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ jQuery selectBox
22

33
A cosmetic, styleable replacement for SELECT elements.
44

5-
Homepage: http://abeautifulsite.net/blog/2011/01/jquery-selectbox-plugin/
6-
Demo: http://labs.abeautifulsite.dev/jquery-selectBox/
5+
Homepage: http://abeautifulsite.net/blog/2011/01/jquery-selectbox-plugin/
6+
Demo: http://labs.abeautifulsite.dev/jquery-selectBox/
77

88
Copyright 2012 Cory LaViska for A Beautiful Site, LLC.
99

@@ -17,7 +17,7 @@ Features:
1717
- Shift + click (or shift + enter) to select a range of options in multi-select controls
1818
- Type to search when the control has focus
1919
- Auto-height based on the size attribute (to use, omit the height property in your CSS!)
20-
- Tested in IE7-IE9, Firefox 3-4, recent webkit browsers, and Opera
20+
- Tested in IE7-IE9, Firefox 3-4, recent WebKit browsers, and Opera
2121

2222

2323
License:
@@ -103,6 +103,7 @@ Change Log:
103103
- Fixed meta/ctrl key issue (#41)
104104
- Expanded iOS/Android check to include Windows 7 Phone and BlackBerry
105105
v1.0.9 (2012-01-04) - Dropdown label class now syncs with selected option's class(es)
106+
v1.1.0 (2012-01-06) - Removed autowidth option; control now inherits the size of the original select element
106107

107108

108109
Known Issues:

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ <h1>$("SELECT").selectBox();</h1>
142142

143143
<p>
144144
<label for="standard-dropdown">Standard Dropdown</label><br />
145-
<select id="standard-dropdown" name="standard-dropdown" class="custom-class1 custom-class2">
145+
<select id="standard-dropdown" name="standard-dropdown" class="custom-class1 custom-class2" style="width: 200px;">
146146
<option value="1" class="test-class-1">Item 1</option>
147147
<option value="2" class="test-class-2" selected="selected">Item 2</option>
148-
<option value="3" class="test-class-3">Item 3 has &lt;a&gt; really long label but it won't affect the control's display at all</option>
148+
<option value="3" class="test-class-3">Item 3 has a really long label that will not interfere with the control’s width</option>
149149
<option value="4" class="test-class-4">Item 4</option>
150150
<option value="5" disabled="disabled">Item 5 (disabled)</option>
151151
<option value="6">Item 6</option>

jquery.selectBox.css

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* Dropdown control */
22
.selectBox-dropdown {
3-
width: 210px; /* width = (desired width) - padding-right */
4-
padding-right: 40px;
3+
min-width: 75px;
54
position: relative;
65
border: solid 1px #BBB;
76
line-height: 1.5;
@@ -38,8 +37,7 @@
3837
}
3938

4039
.selectBox-dropdown .selectBox-label {
41-
width: 100%;
42-
padding: .2em .3em;
40+
padding: 2px 8px;
4341
display: inline-block;
4442
white-space: nowrap;
4543
overflow: hidden;
@@ -72,7 +70,7 @@
7270

7371
/* Inline control */
7472
.selectBox-inline {
75-
width: 250px;
73+
min-width: 75px;
7674
outline: none;
7775
border: solid 1px #BBB;
7876
background: #FFF;

jquery.selectBox.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ if(jQuery) (function($) {
3939
inline = select.attr('multiple') || parseInt(select.attr('size')) > 1;
4040

4141
var settings = data || {};
42-
if( settings.autoWidth === undefined ) settings.autoWidth = true;
43-
44-
// Inherit class names, style, and title attributes
42+
4543
control
44+
.width(select.outerWidth())
4645
.addClass(select.attr('class'))
47-
.attr('style', select.attr('style') || '')
4846
.attr('title', select.attr('title') || '')
4947
.attr('tabindex', parseInt(select.attr('tabindex')))
5048
.css('display', 'inline-block')
@@ -133,7 +131,9 @@ if(jQuery) (function($) {
133131
arrow = $('<span class="selectBox-arrow" />');
134132

135133
// Update label
136-
label.attr('class', getLabelClass(select)).text(getLabelText(select));
134+
label
135+
.attr('class', getLabelClass(select))
136+
.text(getLabelText(select));
137137

138138
options = getOptions(select, 'dropdown');
139139
options.appendTo('BODY');
@@ -160,9 +160,13 @@ if(jQuery) (function($) {
160160
handleKeyPress(select, event);
161161
})
162162
.insertAfter(select);
163-
163+
164+
// Set label width
165+
var labelWidth = control.width() - arrow.outerWidth() - parseInt(label.css('paddingLeft')) - parseInt(label.css('paddingLeft'));
166+
label.width(labelWidth);
167+
164168
disableSelection(control);
165-
169+
166170
}
167171

168172
// Store data for later use and show the control
@@ -343,18 +347,15 @@ if(jQuery) (function($) {
343347

344348
hideMenus();
345349

346-
// Auto-width
347-
if( settings.autoWidth ) options.css('width', control.innerWidth());
348-
if(options.innerWidth() < control.innerWidth()) {
349-
options.css('width', control.innerWidth() - parseInt(options.css('padding-left')) - parseInt(options.css('padding-right')));
350-
}
351-
352350
var borderBottomWidth = isNaN(control.css('borderBottomWidth')) ? 0 : parseInt(control.css('borderBottomWidth'));
351+
353352
// Menu position
354-
options.css({
355-
top: control.offset().top + control.outerHeight() - borderBottomWidth,
356-
left: control.offset().left
357-
});
353+
options
354+
.width(control.innerWidth())
355+
.css({
356+
top: control.offset().top + control.outerHeight() - borderBottomWidth,
357+
left: control.offset().left
358+
});
358359

359360
// Show menu
360361
switch( settings.menuTransition ) {

0 commit comments

Comments
 (0)