Remove custom typeahead mouse events

closes #7096
This commit is contained in:
Steffen van Bergerem 2016-09-13 02:31:06 +02:00 committed by Dennis Schubert
parent 260272cbee
commit ffb442266f
No known key found for this signature in database
GPG key ID: 5A0304BEA7966D7E
2 changed files with 1 additions and 34 deletions

View file

@ -5,8 +5,6 @@ app.views.SearchBase = app.views.Base.extend({
this.setupBloodhound(options); this.setupBloodhound(options);
if(options.customSearch) { this.setupCustomSearch(); } if(options.customSearch) { this.setupCustomSearch(); }
this.setupTypeahead(); this.setupTypeahead();
// TODO: Remove this as soon as corejavascript/typeahead.js has its first release
this.setupMouseSelectionEvents();
if(options.autoselect) { this.setupAutoselect(); } if(options.autoselect) { this.setupAutoselect(); }
}, },
@ -98,19 +96,6 @@ app.views.SearchBase = app.views.Base.extend({
suggestion.addClass("tt-cursor"); suggestion.addClass("tt-cursor");
}, },
// TODO: Remove this as soon as corejavascript/typeahead.js has its first release
setupMouseSelectionEvents: function() {
var self = this,
selectSuggestion = function(e) { self._selectSuggestion($(e.target).closest(".tt-suggestion")); },
deselectAllSuggestions = function() { self._deselectAllSuggestions(); };
this.typeaheadInput.on("typeahead:render", function() {
self.$(".tt-menu .tt-suggestion").off("mouseover").on("mouseover", selectSuggestion);
self.$(".tt-menu .tt-suggestion *").off("mouseover").on("mouseover", selectSuggestion);
self.$(".tt-menu .tt-suggestion").off("mouseleave").on("mouseleave", deselectAllSuggestions);
});
},
// Selects the first result when the result dropdown opens // Selects the first result when the result dropdown opens
setupAutoselect: function() { setupAutoselect: function() {
var self = this; var self = this;

View file

@ -41,12 +41,6 @@ describe("app.views.SearchBase", function() {
expect(app.views.SearchBase.prototype.setupTypeahead).toHaveBeenCalled(); expect(app.views.SearchBase.prototype.setupTypeahead).toHaveBeenCalled();
}); });
it("calls setupMouseSelectionEvents", function() {
spyOn(app.views.SearchBase.prototype, "setupMouseSelectionEvents");
this.view = new app.views.SearchBase({el: "#search_people_form", typeaheadInput: $("#q")});
expect(app.views.SearchBase.prototype.setupMouseSelectionEvents).toHaveBeenCalled();
});
it("initializes the array of diaspora ids that should be excluded from the search results", function() { it("initializes the array of diaspora ids that should be excluded from the search results", function() {
this.view = new app.views.SearchBase({el: "#search_people_form", typeaheadInput: $("#q")}); this.view = new app.views.SearchBase({el: "#search_people_form", typeaheadInput: $("#q")});
expect(this.view.ignoreDiasporaIds.length).toBe(0); expect(this.view.ignoreDiasporaIds.length).toBe(0);
@ -165,24 +159,12 @@ describe("app.views.SearchBase", function() {
}); });
}); });
describe("setupMouseSelectionEvents", function() { describe("typeahead mouse events", function() {
beforeEach(function() { beforeEach(function() {
this.view = new app.views.SearchBase({el: "#search_people_form", typeaheadInput: $("#q")}); this.view = new app.views.SearchBase({el: "#search_people_form", typeaheadInput: $("#q")});
this.view.bloodhound.add(this.bloodhoundData); this.view.bloodhound.add(this.bloodhoundData);
}); });
it("binds mouseover and mouseleave events only once", function() {
this.search(this.view, "user");
$("#q").trigger("focusout");
expect($._data($(".tt-menu .tt-suggestion")[0], "events").mouseover.length).toBe(1);
expect($._data($(".tt-menu .tt-suggestion")[0], "events").mouseout.length).toBe(1);
this.search(this.view, "user");
$("#q").trigger("focusout");
expect($._data($(".tt-menu .tt-suggestion")[0], "events").mouseover.length).toBe(1);
expect($._data($(".tt-menu .tt-suggestion")[0], "events").mouseout.length).toBe(1);
});
it("allows selecting results with the mouse", function() { it("allows selecting results with the mouse", function() {
this.search(this.view, "user"); this.search(this.view, "user");
this.view.$(".tt-menu .tt-suggestion:eq(0)").trigger("mouseover"); this.view.$(".tt-menu .tt-suggestion:eq(0)").trigger("mouseover");