Skip to content

Commit

Permalink
Keep a cached reference to jQueryfied document
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Sep 12, 2012
1 parent 720bdb8 commit 3387853
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions select2.js
Expand Up @@ -40,7 +40,8 @@
return;
}

var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer, lastMousePosition;
var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer,
lastMousePosition, $document;

KEY = {
TAB: 9,
Expand Down Expand Up @@ -90,6 +91,8 @@
}
};

$document = $(document);

nextUid=(function() { var counter=1; return function() { return counter++; }; }());

function indexOf(value, array) {
Expand Down Expand Up @@ -162,7 +165,7 @@
});
}

$(document).delegate("body", "mousemove", function (e) {
$document.delegate("body", "mousemove", function (e) {
lastMousePosition = {x: e.pageX, y: e.pageY};
});

Expand Down Expand Up @@ -493,16 +496,16 @@
*
* also takes care of clicks on label tags that point to the source element
*/
$(document).ready(function () {
$(document).delegate("body", "mousedown touchend", function (e) {
$document.ready(function () {
$document.delegate("body", "mousedown touchend", function (e) {
var target = $(e.target).closest("div.select2-container").get(0), attr;
if (target) {
$(document).find("div.select2-container-active").each(function () {
$document.find("div.select2-container-active").each(function () {
if (this !== target) $(this).data("select2").blur();
});
} else {
target = $(e.target).closest("div.select2-drop").get(0);
$(document).find("div.select2-drop-active").each(function () {
$document.find("div.select2-drop-active").each(function () {
if (this !== target) $(this).data("select2").blur();
});
}
Expand Down

0 comments on commit 3387853

Please sign in to comment.