improve percent width detection. issue #115
This commit is contained in:
parent
9c864f1da0
commit
77de06ecf3
10
select2.js
10
select2.js
@ -1044,9 +1044,12 @@
|
||||
// abstract
|
||||
getContainerWidth: function () {
|
||||
var style, attrs, matches, i, l;
|
||||
|
||||
// see if there is width specified in opts
|
||||
if (this.opts.width !== undefined)
|
||||
return this.opts.width;
|
||||
|
||||
// next check if there is inline style on the element that contains width
|
||||
style = this.opts.element.attr('style');
|
||||
if (style !== undefined) {
|
||||
attrs = style.split(';');
|
||||
@ -1057,6 +1060,13 @@
|
||||
return matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
// next check if css('width') can resolve a width that is percent based, this is sometimes possible
|
||||
// when attached to input type=hidden or elements hidden via css
|
||||
style = this.opts.element.css('width');
|
||||
if (style.indexOf("%") > 0) return style;
|
||||
|
||||
// finally, fallback on the calculated width of the element
|
||||
return (this.opts.element.width() === 0 ? 'auto' : this.opts.element.width() + 'px');
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user