-
Notifications
You must be signed in to change notification settings - Fork 8
/
awesomedata.js
67 lines (55 loc) · 1.79 KB
/
awesomedata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { Ci, Cc, Cu } = require("chrome");
Cu.import("resource://gre/modules/Services.jsm", this);
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
function AutoCompleteInput(aSearches) {
this.searches = aSearches;
}
AutoCompleteInput.prototype = {
timeout: 10,
textValue: "",
searches: null,
searchParam: "",
popupOpen: false,
minResultsForPopup: 0,
invalidate: function() {},
disableAutoComplete: false,
completeDefaultIndex: false,
get popup() { return this; },
onSearchBegin: function() {},
onSearchComplete: function() {},
setSelectedIndex: function() {},
get searchCount() { return this.searches.length; },
getSearchAt: function(aIndex) this.searches[aIndex],
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIAutoCompleteInput,
Ci.nsIAutoCompletePopup,
])
};
exports.search = function search(options) {
let controller = Cc["@mozilla.org/autocomplete/controller;1"].
getService(Ci.nsIAutoCompleteController);
// Make an AutoCompleteInput that uses our searches
// and confirms results on search complete
let input = new AutoCompleteInput(["history"]);
controller.input = input;
input.searchParam = options.search;
input.onSearchBegin = function() {};
input.onSearchComplete = function onSearchComplete() {
let results = [];
for (let i = 0; i < controller.matchCount; i++) {
let result = {
url: controller.getValueAt(i),
title: controller.getCommentAt(i),
//label: controller.getLabelAt(i),
style: controller.getStyleAt(i),
image: controller.getImageAt(i)
};
if (options.onResult)
options.onResult(result);
results.push(result);
}
if (options.onComplete)
options.onComplete(results);
};
controller.startSearch(options.search);
};