-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
189 lines (165 loc) · 6.28 KB
/
index.html
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Wikipedia Explorer</title>
<!-- Favicon import -->
<link rel="shortcut icon" type="image/png" href="./images/logo.png"/>
<!-- MDL (Material Design Lite) imports -->
<link rel="stylesheet" href="./mdl/material.min.css">
<script src="./mdl/material.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<!-- jQuery import -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
body {
font-family: 'Roboto';
text-decoration: none;
}
#logo {
width: 30px;
margin-right: 25px;
margin-left: -40px;
}
#title {
margin-right: 20px;
text-decoration: none;
}
#title>a {
text-decoration: none;
color: #F5F5F5;
}
#searchBox {
width: 300px;
vertical-align: middle;
white-space: nowrap;
position: relative;
background: #F5F5F5;
color: #3F51B5;
font-family: 'Roboto';
border: none;
padding-left: 10px;
height: 30px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#searchLabel {
padding-left: 20px;
}
#searchButton {
margin-left: 10px;
margin-bottom: 4px;
margin-right: 10px;
height: 38px;
}
.resultLink {
text-decoration: none;
color: #000000
}
.mdl-mini-footer {
padding-top: 5px;
padding-bottom: 5px;
}
</style>
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<!-- HEADER -->
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<img src="./images/logo-transparent.png" alt="" id="logo">
<!-- Title -->
<span class="mdl-layout-title mdl-layout--large-screen-only" id="title">
<a href="#">Wikipedia Explorer</a>
</span>
<!-- Add spacer, to align navigation to the right -->
<div class="mdl-layout-spacer"></div>
<!-- Search area-->
<form id="search" method="get" onsubmit="search()">
<!-- Search box -->
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" name="query" type="text" id="searchBox" placeholder="Article title" autofocus>
<label class="mdl-textfield__label" id="searchLabel"></label>
</div>
<!-- Seach button: Accent-colored raised button -->
<button id="searchButton" class="mdl-button mdl-js-button mdl-button--raised mdl-button--accent mdl-layout--large-screen-only">
Search
</button>
</form>
</div>
</header>
<!-- CONTENT -->
<main class="mdl-layout__content">
<div class="page-content">
<ul id="resultsList" class="demo-list-three mdl-list">
<!-- Results of search will go here, added with Javascript -->
</ul>
</div>
</main>
<!-- FOOTER -->
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<div class="mdl-logo">Wikipedia Explorer</div>
<ul class="mdl-mini-footer__link-list">
<li>
<a href="https://github.com/AkashBhave/wikipedia-explorer">GitHub</a>
</li>
<li>
<a href="https://github.com/AkashBhave/wikipedia-explorer/blob/master/LICENSE">LICENSE</a>
</li>
</ul>
</div>
<div class="mdl-mini-footer__right-section">
<ul class="mdl-mini-footer__link-list">
<li>Created by <a href="https://github.com/AkashBhave">Akash Bhave</a></li>
</ul>
</div>
</footer>
</div>
<script>
var endpoint = "https://en.wikipedia.org"
var api = "/w/api.php?action=opensearch&format=json&search="
// Prevents the page from refreshing
$("#search").submit(function (e) {
e.preventDefault();
});
function search() {
var query = document.getElementById("searchBox").value;
var requestURL = endpoint + api + query + "&callback=?";
// Reset the content of the previous result
document.getElementById('resultsList').innerHTML = "";
// Uses API to retrieve JSON results
$.ajax({
url: requestURL,
dataType: 'json',
contentType: "text/plain",
type: 'GET',
headers: { 'Api-User-Agent': 'wikipedia-explorer/1.0' },
success: function (data) {
displayData(data)
}
});
}
// Loops through each result, appending it to the CONTENT seciton of page
function displayData(data) {
for (var i = 0; i < data[1].length; i++) {
var title = data[1][i];
var description = data[2][i];
var link = data[3][i];
document.getElementById('resultsList').innerHTML +=
`<li class=\"mdl-list__item mdl-list__item--three-line\">
<span class=\"mdl-list__item-primary-content\">
<span>` + `<a class=\"resultLink\" href=\"` + link + `">` + title + `</a>` + `</span>
<span class=\"mdl-list__item-text-body\">`
+ description +
`</span>
</span>
</li>`;
}
}
</script>
</body>
</html>