Skip to content

Commit 3387853

Browse files
committed
Keep a cached reference to jQueryfied document
1 parent 720bdb8 commit 3387853

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

select2.js

Lines changed: 9 additions & 6 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, lastMousePosition;
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,7 +165,7 @@
162165
});
163166
}
164167

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

@@ -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.delegate("body", "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)