Skip to content

Commit 5646046

Browse files
rcosnitalukeapage
authored andcommitted
I added missing fulltext search scripts.
1 parent 070afab commit 5646046

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
window.SearcherDisplay = (function($) {
2+
/**
3+
* This class provides support for displaying quick search text results to users.
4+
*/
5+
function SearcherDisplay() { }
6+
7+
SearcherDisplay.prototype.init = function() {
8+
this._displayQuickSearch();
9+
};
10+
11+
/**
12+
* This method creates the quick text search entry in navigation menu and wires all required events.
13+
*/
14+
SearcherDisplay.prototype._displayQuickSearch = function() {
15+
var quickSearch = $(document.createElement("iframe")),
16+
topNavigation = $("#topNavigation"),
17+
self = this;
18+
19+
quickSearch.attr("src", "quicksearch.html");
20+
quickSearch.css("width", "300px");
21+
quickSearch.css("height", "50px");
22+
quickSearch.css("float", "right");
23+
quickSearch.css("border", "none");
24+
25+
topNavigation.append(quickSearch);
26+
27+
window.top.addEventListener("message", function(msg) {
28+
var msgData = msg.data;
29+
30+
if (msgData.msgid != "docstrap.quicksearch.done") {
31+
return;
32+
}
33+
34+
var results = msg.data.results || [];
35+
36+
self._displaySearchResults(results);
37+
});
38+
};
39+
40+
/**
41+
* This method displays the quick text search results in a modal dialog.
42+
*/
43+
SearcherDisplay.prototype._displaySearchResults = function(results) {
44+
var resultsHolder = $($("#searchResults").find(".modal-body")),
45+
fragment = document.createDocumentFragment(),
46+
resultsList = document.createElement("ul");
47+
48+
resultsHolder.empty();
49+
50+
for (var idx = 0; idx < results.length; idx++) {
51+
var result = results[idx],
52+
item = document.createElement("li"),
53+
link = document.createElement("a");
54+
55+
link.href = result.id;
56+
link.innerHTML = result.title;
57+
58+
item.appendChild(link)
59+
resultsList.appendChild(item);
60+
}
61+
62+
fragment.appendChild(resultsList);
63+
resultsHolder.append(fragment);
64+
65+
$("#searchResults").modal({"show": true});
66+
};
67+
68+
return new SearcherDisplay();
69+
})($);

0 commit comments

Comments
 (0)