Skip to content

Commit c227b16

Browse files
author
David Baum
committed
refactoring SearchController
1 parent e985536 commit c227b16

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

ui/scripts/Search/SearchController.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
var searchController = (function() {
22

3-
var searchInputId = "searchField";
4-
var jQsearchInputID = "#searchField";
3+
const searchInputId = "searchField";
4+
const jQsearchInputID = "#searchField";
55

6-
var suggestions = null;
6+
let suggestions = null;
77

8-
var rootDivElement;
8+
let rootDivElement;
99

10-
var config = {
11-
active : true
12-
}
13-
14-
//config parameters
15-
var controllerConfig = {
10+
//config parameters
11+
let controllerConfig = {
1612
active : true,
1713
timeout: false,
1814
timeoutTime: 1000
@@ -28,7 +24,7 @@ var searchController = (function() {
2824
rootDivElement = rootDiv;
2925

3026

31-
var cssLink = document.createElement("link");
27+
const cssLink = document.createElement("link");
3228
cssLink.type = "text/css";
3329
cssLink.rel = "stylesheet";
3430
cssLink.href = "scripts/Search/tt.css";
@@ -40,7 +36,7 @@ var searchController = (function() {
4036
rootDiv.setAttribute("ignoreTheme", "true");
4137

4238
//create search input field
43-
var searchInput = document.createElement("INPUT");
39+
const searchInput = document.createElement("INPUT");
4440
searchInput.id = searchInputId;
4541
searchInput.type = "text";
4642

@@ -71,12 +67,12 @@ var searchController = (function() {
7167

7268
suggestions = new Bloodhound({
7369
datumTokenizer: function(entity) {
74-
var tokenizerQN = Bloodhound.tokenizers.whitespace(entity.qualifiedName);
70+
const tokenizerQN = Bloodhound.tokenizers.whitespace(entity.qualifiedName);
7571

7672
tokenizerQN.push(entity.name);
7773

78-
var splits = entity.qualifiedName.split(".").reverse();
79-
var splitString = "";
74+
const splits = entity.qualifiedName.split(".").reverse();
75+
let splitString = "";
8076
splits.forEach(function(elementString){
8177
splitString = elementString + splitString;
8278
tokenizerQN.push(splitString);
@@ -106,13 +102,13 @@ var searchController = (function() {
106102
suggestion: Handlebars.compile('<div class="result"><p class="name">{{name}}</p><p class="qualifiedName">{{qualifiedName}}</p></div>')
107103
}
108104
});
109-
$(jQsearchInputID).on("typeahead:selected", function(event, suggestion, dataset) {
105+
$(jQsearchInputID).on("typeahead:selected", function(event, suggestion) {
110106
selectEntity(suggestion.id);
111107
});
112-
$(jQsearchInputID).on("typeahead:opened", function(event, suggestion, dataset) {
108+
$(jQsearchInputID).on("typeahead:opened", function() {
113109
rootDivElement.parentElement.style.overflow = "visible";
114110
});
115-
$(jQsearchInputID).on("typeahead:closed", function(event, suggestion, dataset) {
111+
$(jQsearchInputID).on("typeahead:closed", function() {
116112
rootDivElement.parentElement.style.overflow = "hidden";
117113
});
118114

@@ -122,17 +118,17 @@ var searchController = (function() {
122118

123119
function selectEntity(id) {
124120

125-
var applicationEvent = {
121+
const applicationEvent = {
126122
sender: searchController,
127123
entities: [model.getEntityById(id)]
128-
}
124+
};
129125

130126
events.selected.on.publish(applicationEvent);
131127
}
132128

133129
function onEntitySelected(applicationEvent) {
134130

135-
var entity = applicationEvent.entities[0];
131+
const entity = applicationEvent.entities[0];
136132
$(jQsearchInputID).val(entity.qualifiedName);
137133
}
138134

0 commit comments

Comments
 (0)