Reduce search field focusing, improving performance
Signed-off-by: Igor Vaynberg <igor.vaynberg@gmail.com>
This commit is contained in:
parent
9497693b64
commit
64b69425b0
16
select2.js
16
select2.js
@ -161,10 +161,10 @@
|
|||||||
* the elements under the pointer are scrolled.
|
* the elements under the pointer are scrolled.
|
||||||
*/
|
*/
|
||||||
function installFilteredMouseMove(element) {
|
function installFilteredMouseMove(element) {
|
||||||
var context = $(element[0].document);
|
var context = $(element[0].document);
|
||||||
context.on("mousemove", function (e) {
|
context.on("mousemove", function (e) {
|
||||||
context.data("select2-lastpos", {x: e.pageX, y: e.pageY});
|
context.data("select2-lastpos", {x: e.pageX, y: e.pageY});
|
||||||
});
|
});
|
||||||
element.bind("mousemove", function (e) {
|
element.bind("mousemove", function (e) {
|
||||||
var lastpos = context.data("select2-lastpos");
|
var lastpos = context.data("select2-lastpos");
|
||||||
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
|
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
|
||||||
@ -422,8 +422,8 @@
|
|||||||
// initialize the container
|
// initialize the container
|
||||||
this.initContainer();
|
this.initContainer();
|
||||||
|
|
||||||
installFilteredMouseMove(this.results);
|
//installFilteredMouseMove(this.results);
|
||||||
this.dropdown.delegate(resultsSelector, "mousemove-filtered", this.bind(this.highlightUnderEvent));
|
this.dropdown.delegate(resultsSelector, "mouseover", this.bind(this.highlightUnderEvent));
|
||||||
|
|
||||||
installDebouncedScroll(80, this.results);
|
installDebouncedScroll(80, this.results);
|
||||||
this.dropdown.delegate(resultsSelector, "scroll-debounced", this.bind(this.loadMoreIfNeeded));
|
this.dropdown.delegate(resultsSelector, "scroll-debounced", this.bind(this.loadMoreIfNeeded));
|
||||||
@ -773,13 +773,13 @@
|
|||||||
$(choices[index]).addClass("select2-highlighted");
|
$(choices[index]).addClass("select2-highlighted");
|
||||||
this.ensureHighlightVisible();
|
this.ensureHighlightVisible();
|
||||||
|
|
||||||
if (this.opened()) this.focusSearch();
|
//if (this.opened()) this.focusSearch();
|
||||||
},
|
},
|
||||||
|
|
||||||
highlightUnderEvent: function (event) {
|
highlightUnderEvent: function (event) {
|
||||||
var el = $(event.target).closest(".select2-result");
|
var el = $(event.target).closest(".select2-result");
|
||||||
if (el.length > 0) {
|
if (el.length > 0) {
|
||||||
var choices = this.results.find('.select2-result');
|
var choices = this.results.find('.select2-result');
|
||||||
this.highlight(choices.index(el));
|
this.highlight(choices.index(el));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user