Skip to content

Commit e2cd841

Browse files
committed
Handling mousemove more delicately
Mousemove fires very frequently and is a sure way of killing any app's FPS. This tweak makes sure it is only bound when it is in fact needed.
1 parent 52425f9 commit e2cd841

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

select2.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ the specific language governing permissions and limitations under the Apache Lic
193193
});
194194
}
195195

196-
$document.on("mousemove", function (e) {
197-
lastMousePosition.x = e.pageX;
198-
lastMousePosition.y = e.pageY;
199-
});
200196

201197
/**
202198
* filters mouse events so an event is fired only if the mouse moved.
@@ -1343,6 +1339,12 @@ the specific language governing permissions and limitations under the Apache Lic
13431339

13441340
this.opening();
13451341

1342+
// Only bind the document mousemove when the dropdown is visible
1343+
$document.on("mousemove.select2Event", function (e) {
1344+
lastMousePosition.x = e.pageX;
1345+
lastMousePosition.y = e.pageY;
1346+
});
1347+
13461348
return true;
13471349
},
13481350

@@ -1439,6 +1441,8 @@ the specific language governing permissions and limitations under the Apache Lic
14391441
this.container.removeClass("select2-dropdown-open").removeClass("select2-container-active");
14401442
this.results.empty();
14411443

1444+
// Now that the dropdown is closed, unbind the global document mousemove event
1445+
$document.off("mousemove.select2Event");
14421446

14431447
this.clearSearch();
14441448
this.search.removeClass("select2-active");

0 commit comments

Comments
 (0)