2016-11-02 20:16:31 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** inject search widget */
|
|
|
|
function inject_search(elem) {
|
2016-12-26 21:46:27 +05:00
|
|
|
var inner = document.createElement("div");
|
2016-12-26 22:03:47 +05:00
|
|
|
inner.setAttribute("class", "navbar");
|
2016-12-26 21:46:27 +05:00
|
|
|
var button = document.createElement("button");
|
|
|
|
var input = document.createElement("input");
|
|
|
|
var newsgroup = document.createElement("input");
|
|
|
|
var status = document.createElement("span");
|
|
|
|
var output = document.createElement("div");
|
2016-11-02 20:16:31 +05:00
|
|
|
|
2016-12-26 21:46:27 +05:00
|
|
|
button.innerHTML = "search";
|
|
|
|
|
|
|
|
function inject_search_result(r) {
|
2016-12-26 21:48:00 +05:00
|
|
|
if(!r)return;
|
2016-12-26 21:46:27 +05:00
|
|
|
var e = document.createElement("div");
|
|
|
|
var a = document.createElement("a");
|
|
|
|
a.href = r.URL;
|
|
|
|
a.target = "_blank";
|
|
|
|
e.appendChild(a);
|
|
|
|
var txt = document.createTextNode(r.Message_id);
|
|
|
|
a.appendChild(txt);
|
|
|
|
output.appendChild(document.createElement("hr"));
|
|
|
|
output.appendChild(e);
|
|
|
|
}
|
2016-11-02 20:16:31 +05:00
|
|
|
|
2016-12-26 21:46:27 +05:00
|
|
|
var search = function() {
|
|
|
|
var text = input.value;
|
|
|
|
input.value = "";
|
|
|
|
var group = newsgroup.value;
|
|
|
|
while(output.children.length > 0)
|
|
|
|
output.children[0].remove();
|
|
|
|
var ajax = new XMLHttpRequest();
|
|
|
|
ajax.onreadystatechange = function() {
|
|
|
|
if (ajax.readyState == XMLHttpRequest.DONE) {
|
|
|
|
// done
|
|
|
|
if(ajax.status == 200) {
|
|
|
|
// good
|
|
|
|
var result = JSON.parse(ajax.responseText);
|
|
|
|
var num = result.length - 1;
|
|
|
|
if (num <= 0) {
|
|
|
|
status.innerHTML = "no results";
|
|
|
|
} else {
|
|
|
|
status.innerHTML = "found "+num+" results";
|
|
|
|
for (var idx = 0 ; idx < result.length; idx++ ) {
|
|
|
|
inject_search_result(result[idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
status.innerHTML = "HTTP "+ajax.status;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
status.innerHTML = "searching... ";
|
2016-11-02 20:16:31 +05:00
|
|
|
}
|
2016-12-26 21:46:27 +05:00
|
|
|
};
|
|
|
|
ajax.open("GET", "/api/find?text="+text+"&group="+group);
|
|
|
|
ajax.send();
|
|
|
|
};
|
|
|
|
|
|
|
|
button.onclick = function(ev) {
|
|
|
|
search();
|
|
|
|
};
|
|
|
|
|
2016-12-26 21:48:45 +05:00
|
|
|
input.onkeydown = function(ev) {
|
2016-12-26 21:48:00 +05:00
|
|
|
if (ev.keyCode == 13)
|
|
|
|
search();
|
2016-12-26 21:46:27 +05:00
|
|
|
};
|
|
|
|
|
2016-12-26 21:48:00 +05:00
|
|
|
newsgroup.onkeydown = function(ev) {
|
|
|
|
if (ev.keyCode == 13)
|
|
|
|
search();
|
2016-12-26 21:46:27 +05:00
|
|
|
};
|
2016-11-02 20:16:31 +05:00
|
|
|
|
2016-12-26 21:46:27 +05:00
|
|
|
inner.appendChild(document.createTextNode("text: "));
|
|
|
|
inner.appendChild(input);
|
|
|
|
inner.appendChild(document.createTextNode("board: "));
|
|
|
|
inner.appendChild(newsgroup);
|
|
|
|
inner.appendChild(button);
|
|
|
|
inner.appendChild(status);
|
|
|
|
|
|
|
|
elem.appendChild(inner);
|
|
|
|
elem.appendChild(output);
|
2016-11-02 20:16:31 +05:00
|
|
|
}
|