window.onload =
function
() {
document.getElementById(
"search-query"
).focus();
};
$(document).ready(
function
() {
$(
"#search-button"
).on(
'click'
,
function
() {
$(
'#results-indicate'
).css(
'display'
,
'block'
);
var
keyword = document.getElementById(
"search-query"
).value;
document.getElementById(
'search-term'
).innerHTML = keyword;
var
url =
"https://ja.wikipedia.org/w/api.php?action=opensearch&search="
+ keyword +
"&limit=10&format=json&callback=?"
$.ajax({
url: url,
dataType:
'jsonp'
,
success:
function
(info) {
document.getElementById(
"the-results"
).innerHTML =
''
;
var
headlines = info[1];
var
extract = info[2];
var
link = info[3];
for
(i = 0; i < headlines.length; i++) {
document.getElementById(
"the-results"
).innerHTML +=
'<strong>'
+
'<a href="'
+ link[i] +
'" target="_blank">'
+ headlines[i] +
'</a>'
+
'</strong>'
+
'<br>'
+
'<font color="green">'
+ link[i] +
'</font>'
+
'<br>'
+ extract[i] +
'<br><br>'
;
}
}
})
})
$(
'#search-query'
).keyup(
function
(event){
if
(event.keyCode == 13) {
event.preventDefault();
$(
'#search-button'
).click();
}
})
})