1
0
mirror of synced 2024-11-25 14:26:03 +03:00

improve percent width detection. issue #115

This commit is contained in:
Igor Vaynberg 2012-07-06 12:13:12 +03:00
parent 9c864f1da0
commit 77de06ecf3

View File

@ -1044,9 +1044,12 @@
// abstract // abstract
getContainerWidth: function () { getContainerWidth: function () {
var style, attrs, matches, i, l; var style, attrs, matches, i, l;
// see if there is width specified in opts
if (this.opts.width !== undefined) if (this.opts.width !== undefined)
return this.opts.width; return this.opts.width;
// next check if there is inline style on the element that contains width
style = this.opts.element.attr('style'); style = this.opts.element.attr('style');
if (style !== undefined) { if (style !== undefined) {
attrs = style.split(';'); attrs = style.split(';');
@ -1057,6 +1060,13 @@
return matches[1]; 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'); return (this.opts.element.width() === 0 ? 'auto' : this.opts.element.width() + 'px');
} }
}); });