-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
114 lines (94 loc) · 4.48 KB
/
Copy pathscript.js
File metadata and controls
114 lines (94 loc) · 4.48 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
$(".dropdown-menu").click(function() {
$(".navbar-collapse").collapse("hide");
});
$(".homeLink").click(function() {
$(".navbar-collapse").collapse("hide");
});
/*WikipediaViewer*/
$(".searchResult").css("display","none");
document.querySelector("#go").addEventListener("click", function () {
var keyword = document.getElementById("query").value;
if(keyword){
$.ajax( {
type: 'GET',
dataType: 'json',
url: "https://en.wikipedia.org/w/api.php?action=opensearch&search=" + keyword + "&limit=10&format=json&callback=?",
success: function(responseText,statusText,xhr) {
$(".searchResult").css("display","block");
$("h1").addClass("addMargin");
if (typeof responseText[1][0] !== "undefined") {
$("#title1").html(responseText[1][0]);
$("#summary1").html(responseText[2][0]);
$("#link1").attr('href',responseText[3][0]);
} else {
$("#searchResult1").css("display","none");
}
if (typeof responseText[1][1] !== "undefined") {
document.querySelector("#title2").textContent = responseText[1][1];
document.querySelector("#summary2").textContent = responseText[2][1];
$("#link2").attr('href',responseText[3][1]);
} else {
$("#searchResult2").css("display","none");
}
if (typeof responseText[1][2] !== "undefined") {
document.getElementById("title3").textContent = responseText[1][2];
document.getElementById("summary3").textContent = responseText[2][2];
$("#link3").attr('href',responseText[3][2]);
} else {
$("#searchResult3").css("display","none");
}
if (typeof responseText[1][3] !== "undefined") {
$("#title4").html(responseText[1][3]);
$("#summary4").html(responseText[2][3]);
$("#link4").attr('href',responseText[3][3]);
} else {
$("#searchResult4").css("display","none");
}
if (typeof responseText[1][4] !== "undefined") {
document.querySelector("#title5").textContent = responseText[1][4];
document.querySelector("#summary5").textContent = responseText[2][4];
$("#link5").attr('href',responseText[3][4]);
} else {
$("#searchResult5").css("display","none");
}
if (typeof responseText[1][5] !== "undefined") {
document.getElementById("title6").textContent = responseText[1][5];
document.getElementById("summary6").textContent = responseText[2][5];
$("#link6").attr('href',responseText[3][5]);
} else {
$("#searchResult6").css("display","none");
}
if (typeof responseText[1][6] !== "undefined") {
$("#title7").html(responseText[1][6]);
$("#summary7").html(responseText[2][6]);
$("#link7").attr('href',responseText[3][6]);
} else {
$("#searchResult7").css("display","none");
}
if (typeof responseText[1][7] !== "undefined") {
document.querySelector("#title8").textContent = responseText[1][7];
document.querySelector("#summary8").textContent = responseText[2][7];
$("#link8").attr('href',responseText[3][7]);
} else {
$("#searchResult8").css("display","none");
}
if (typeof responseText[1][8] !== "undefined") {
document.getElementById("title9").textContent = responseText[1][8];
document.getElementById("summary9").textContent = responseText[2][8];
$("#link9").attr('href',responseText[3][8]);
} else {
$("#searchResult9").css("display","none");
}
if (typeof responseText[1][9] !== "undefined") {
$("#title10").html(responseText[1][9]);
$("#summary10").html(responseText[2][9]);
$("#link10").attr('href',responseText[3][9]);
} else {
$("#lastResult").css("display","none");
}
}
});
} else {
alert("Please Enter a word to lookup!")
}
});