Skip to content

Commit 2adb8d3

Browse files
committed
Merge pull request select2#403 from byroot/fix-perfs-issues
Fix perfs issues
2 parents 96657a1 + 7bc63dd commit 2adb8d3

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

select2.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
return;
4141
}
4242

43-
var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer;
43+
var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer,
44+
lastMousePosition, $document;
4445

4546
KEY = {
4647
TAB: 9,
@@ -90,6 +91,8 @@
9091
}
9192
};
9293

94+
$document = $(document);
95+
9396
nextUid=(function() { var counter=1; return function() { return counter++; }; }());
9497

9598
function indexOf(value, array) {
@@ -162,8 +165,8 @@
162165
});
163166
}
164167

165-
$(document).delegate("body", "mousemove", function (e) {
166-
$.data(document, "select2-lastpos", {x: e.pageX, y: e.pageY});
168+
$document.bind("mousemove", function (e) {
169+
lastMousePosition = {x: e.pageX, y: e.pageY};
167170
});
168171

169172
/**
@@ -174,7 +177,7 @@
174177
*/
175178
function installFilteredMouseMove(element) {
176179
element.bind("mousemove", function (e) {
177-
var lastpos = $.data(document, "select2-lastpos");
180+
var lastpos = lastMousePosition;
178181
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
179182
$(e.target).trigger("mousemove-filtered", e);
180183
}
@@ -493,16 +496,16 @@
493496
*
494497
* also takes care of clicks on label tags that point to the source element
495498
*/
496-
$(document).ready(function () {
497-
$(document).delegate("body", "mousedown touchend", function (e) {
499+
$document.ready(function () {
500+
$document.bind("mousedown touchend", function (e) {
498501
var target = $(e.target).closest("div.select2-container").get(0), attr;
499502
if (target) {
500-
$(document).find("div.select2-container-active").each(function () {
503+
$document.find("div.select2-container-active").each(function () {
501504
if (this !== target) $(this).data("select2").blur();
502505
});
503506
} else {
504507
target = $(e.target).closest("div.select2-drop").get(0);
505-
$(document).find("div.select2-drop-active").each(function () {
508+
$document.find("div.select2-drop-active").each(function () {
506509
if (this !== target) $(this).data("select2").blur();
507510
});
508511
}

0 commit comments

Comments
 (0)