apply offscreen class after calculating width because offscreen class resets the width. also use css('width') when copying width if it returns a usable value. fixes #1140. fixes #1079
This commit is contained in:
parent
ec83e76f5e
commit
de07ba2b16
17
select2.js
17
select2.js
@ -637,7 +637,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
// swap container for the element
|
// swap container for the element
|
||||||
this.opts.element
|
this.opts.element
|
||||||
.data("select2", this)
|
.data("select2", this)
|
||||||
.addClass("select2-offscreen")
|
|
||||||
.bind("focus.select2", function() { $(this).select2("focus"); })
|
.bind("focus.select2", function() { $(this).select2("focus"); })
|
||||||
.attr("tabIndex", "-1")
|
.attr("tabIndex", "-1")
|
||||||
.before(this.container);
|
.before(this.container);
|
||||||
@ -1574,12 +1573,12 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.opts.width === "resolve") {
|
// 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');
|
if (style && style.length > 0) return style;
|
||||||
if (style.indexOf("%") > 0) return style;
|
|
||||||
|
|
||||||
|
if (this.opts.width === "resolve") {
|
||||||
// finally, fallback on the calculated width of the element
|
// finally, fallback on the calculated width of the element
|
||||||
return (this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px');
|
return (this.opts.element.outerWidth(false) === 0 ? 'auto' : this.opts.element.outerWidth(false) + 'px');
|
||||||
}
|
}
|
||||||
@ -1593,6 +1592,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
};
|
};
|
||||||
|
|
||||||
var width = resolveContainerWidth.call(this);
|
var width = resolveContainerWidth.call(this);
|
||||||
|
console.log("width: ",width);
|
||||||
if (width !== null) {
|
if (width !== null) {
|
||||||
this.container.css("width", width);
|
this.container.css("width", width);
|
||||||
}
|
}
|
||||||
@ -1811,11 +1811,11 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}));
|
}));
|
||||||
this.search.bind("focus", this.bind(function(){
|
this.search.bind("focus", this.bind(function(){
|
||||||
this.container.addClass("select2-container-active");
|
this.container.addClass("select2-container-active");
|
||||||
}))
|
}));
|
||||||
|
|
||||||
this.initContainerWidth();
|
this.initContainerWidth();
|
||||||
|
this.opts.element.addClass("select2-offscreen");
|
||||||
this.setPlaceholder();
|
this.setPlaceholder();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// single
|
// single
|
||||||
@ -2251,6 +2251,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
this.initContainerWidth();
|
this.initContainerWidth();
|
||||||
|
this.opts.element.addClass("select2-offscreen");
|
||||||
|
|
||||||
// set the placeholder if necessary
|
// set the placeholder if necessary
|
||||||
this.clearSearch();
|
this.clearSearch();
|
||||||
|
Loading…
Reference in New Issue
Block a user