Skip to content

Commit 9d69c60

Browse files
committed
Fix #654
minWidth option now supports percentage as well as pixel values.
1 parent 8a3f392 commit 9d69c60

File tree

2 files changed

+104
-77
lines changed

2 files changed

+104
-77
lines changed

src/jquery.multiselect.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,24 +441,41 @@
441441
setTimeout($.proxy(self.refresh, self), 10);
442442
});
443443
},
444-
444+
_getMinWidth: function() {
445+
var minVal = this.options.minWidth;
446+
var width = 0;
447+
switch (typeof minVal) {
448+
case 'number':
449+
width = minVal;
450+
break;
451+
case 'string':
452+
var lastChar = minVal[ minVal.length -1 ];
453+
width = minVal.match(/\d+/);
454+
if(lastChar === '%') {
455+
width = this.element.parent().outerWidth() * (width/100);
456+
} else {
457+
width = parseInt(minVal, 10);
458+
}
459+
break;
460+
}
461+
return width;
462+
},
445463
// set button width
446464
_setButtonWidth: function() {
447465
var width = this.element.outerWidth();
448-
var o = this.options;
466+
var minVal = this._getMinWidth();
449467

450-
if(/\d/.test(o.minWidth) && width < o.minWidth) {
451-
width = o.minWidth;
468+
if(width < minVal) {
469+
width = minVal;
452470
}
453-
454471
// set widths
455472
this.button.outerWidth(width);
456473
},
457474

458475
// set menu width
459476
_setMenuWidth: function() {
460477
var m = this.menu;
461-
var width = (this.button.outerWidth() <= 0) ? this.options.minWidth : this.button.outerWidth();
478+
var width = (this.button.outerWidth() <= 0) ? this._getMinWidth() : this.button.outerWidth();
462479
m.outerWidth(this.options.menuWidth || width);
463480
},
464481

@@ -733,7 +750,7 @@
733750
break;
734751
case 'minWidth':
735752
case 'menuWidth':
736-
this.options[key] = parseInt(value, 10);
753+
this.options[key] = value;
737754
this._setButtonWidth();
738755
this._setMenuWidth();
739756
break;

0 commit comments

Comments
 (0)