Improve performance on text measuring
Signed-off-by: Igor Vaynberg <igor.vaynberg@gmail.com>
This commit is contained in:
parent
0ff41ca512
commit
65eb7c3404
13
select2.js
13
select2.js
@ -40,7 +40,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid;
|
var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer;
|
||||||
|
|
||||||
KEY = {
|
KEY = {
|
||||||
TAB: 9,
|
TAB: 9,
|
||||||
@ -202,8 +202,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function measureTextWidth(e) {
|
function measureTextWidth(e) {
|
||||||
var sizer, width,
|
var style = e.currentStyle || window.getComputedStyle(e, null);
|
||||||
style = e.currentStyle || window.getComputedStyle(e, null);
|
if (!sizer){
|
||||||
sizer = $("<div></div>").css({
|
sizer = $("<div></div>").css({
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
left: "-1000px",
|
left: "-1000px",
|
||||||
@ -217,11 +217,10 @@
|
|||||||
textTransform: style.textTransform,
|
textTransform: style.textTransform,
|
||||||
whiteSpace: "nowrap"
|
whiteSpace: "nowrap"
|
||||||
});
|
});
|
||||||
sizer.text(e.val());
|
|
||||||
$("body").append(sizer);
|
$("body").append(sizer);
|
||||||
width = sizer.width();
|
}
|
||||||
sizer.remove();
|
sizer.text(e.val());
|
||||||
return width;
|
return sizer.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user