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

container receives width style when hidden input has one or via opt

Signed-off-by: Igor Vaynberg <igor.vaynberg@gmail.com>
This commit is contained in:
Kevin Miller 2012-07-18 10:25:32 -05:00 committed by Igor Vaynberg
parent 6c330eb53b
commit 17ffe5772e

View File

@ -1114,7 +1114,7 @@
var style, attrs, matches, i, l; var style, attrs, matches, i, l;
// see if there is width specified in opts // see if there is width specified in opts
if (this.opts.width !== undefined) if (this.opts.width !== undefined && this.opts.width !== 'copy')
return this.opts.width; return this.opts.width;
// next check if there is inline style on the element that contains width // next check if there is inline style on the element that contains width
@ -1129,6 +1129,7 @@
} }
} }
if (this.opts.width !== 'copy') {
// next check if css('width') can resolve a width that is percent based, this is sometimes possible // 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 // when attached to input type=hidden or elements hidden via css
style = this.opts.element.css('width'); style = this.opts.element.css('width');
@ -1137,15 +1138,29 @@
// finally, fallback on the calculated width of the element // finally, fallback on the calculated width of the element
return (this.opts.element.width() === 0 ? 'auto' : this.opts.element.outerWidth() + 'px'); return (this.opts.element.width() === 0 ? 'auto' : this.opts.element.outerWidth() + 'px');
} }
return null;
},
/**
* Set the width for the container element.
**/
setContainerWidth : function(container) {
var width = this.getContainerWidth();
if (!width) return;
container.attr('style', "width: " + width);
}
}); });
SingleSelect2 = clazz(AbstractSelect2, { SingleSelect2 = clazz(AbstractSelect2, {
// single // single
createContainer: function () { createContainer: function () {
return $("<div></div>", { var container = $("<div></div>", {
"class": "select2-container", "class": "select2-container"
"style": "width: " + this.getContainerWidth()
}).html([ }).html([
" <a href='javascript:void(0)' class='select2-choice'>", " <a href='javascript:void(0)' class='select2-choice'>",
" <span></span><abbr class='select2-search-choice-close' style='display:none;'></abbr>", " <span></span><abbr class='select2-search-choice-close' style='display:none;'></abbr>",
@ -1158,6 +1173,8 @@
" <ul class='select2-results'>" , " <ul class='select2-results'>" ,
" </ul>" , " </ul>" ,
"</div>"].join("")); "</div>"].join(""));
this.setContainerWidth(container);
}, },
// single // single
@ -1456,9 +1473,8 @@
// multi // multi
createContainer: function () { createContainer: function () {
return $("<div></div>", { var container = $("<div></div>", {
"class": "select2-container select2-container-multi", "class": "select2-container select2-container-multi"
"style": "width: " + this.getContainerWidth()
}).html([ }).html([
" <ul class='select2-choices'>", " <ul class='select2-choices'>",
//"<li class='select2-search-choice'><span>California</span><a href="javascript:void(0)" class="select2-search-choice-close"></a></li>" , //"<li class='select2-search-choice'><span>California</span><a href="javascript:void(0)" class="select2-search-choice-close"></a></li>" ,
@ -1470,6 +1486,10 @@
" <ul class='select2-results'>" , " <ul class='select2-results'>" ,
" </ul>" , " </ul>" ,
"</div>"].join("")); "</div>"].join(""));
this.setContainerWidth(container);
return container;
}, },
// multi // multi