Store last mouse position in a variable instead of document datastore
It's hundred times faster. See http://jsperf.com/data-vs-variable
This commit is contained in:
parent
96657a16aa
commit
720bdb8c4f
@ -40,7 +40,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer;
|
var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer, lastMousePosition;
|
||||||
|
|
||||||
KEY = {
|
KEY = {
|
||||||
TAB: 9,
|
TAB: 9,
|
||||||
@ -163,7 +163,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(document).delegate("body", "mousemove", function (e) {
|
$(document).delegate("body", "mousemove", function (e) {
|
||||||
$.data(document, "select2-lastpos", {x: e.pageX, y: e.pageY});
|
lastMousePosition = {x: e.pageX, y: e.pageY};
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -174,7 +174,7 @@
|
|||||||
*/
|
*/
|
||||||
function installFilteredMouseMove(element) {
|
function installFilteredMouseMove(element) {
|
||||||
element.bind("mousemove", function (e) {
|
element.bind("mousemove", function (e) {
|
||||||
var lastpos = $.data(document, "select2-lastpos");
|
var lastpos = lastMousePosition;
|
||||||
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
|
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
|
||||||
$(e.target).trigger("mousemove-filtered", e);
|
$(e.target).trigger("mousemove-filtered", e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user