/
script.js
73 lines (51 loc) · 2.2 KB
/
script.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
68
69
70
71
72
73
$(document).ready(function(){
var endpoint = "https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch=";
var bgArray = ["linear-gradient(#353FA0, #fff) no-repeat",
"linear-gradient(#EA0C0C, #fff) no-repeat",
"linear-gradient(#0CEA5B, #fff) no-repeat",
"linear-gradient(#EAE30C, #fff) no-repeat",
"linear-gradient(#895F8E, #fff) no-repeat"];
var bgCounter = 0;
$("#searchForm").submit(function(){
$("body").css("background", bgArray[bgCounter]);
$("body").css("backgroundAttachment", "fixed")
if (bgCounter < bgArray.length - 1) {
bgCounter++;
} else {
bgCounter = 0;
}
$('h1').css({
//for firefox
"-moz-animation-name":"rotatebox",
"-moz-animation-duration":"0.8s",
"-moz-animation-iteration-count":"1",
"-moz-animation-fill-mode":"forwards",
//for safari & chrome
"-webkit-animation-name":"rotatebox",
"-webkit-animation-duration":"0.8s",
"-webkit-animation-iteration-count":"1",
"-webkit-animation-fill-mode" : "forwards",
});
setTimeout(function(){
$("h1").css("animation-name", "");
}, 1000);
if ($("#query").val() != "") {
var queryText = $("#query").val();
$.getJSON(endpoint + queryText + "&callback=?").success(function(data) {
$("#container").html("");
for (var key in data.query.pages) {
$("#container").append("<div class='article'><a target='_blank' href='https://en.wikipedia.org/?curid=" + data.query.pages[key]["pageid"] + "'><h3>" + data.query.pages[key]["title"] + "</h3></a><p><i>" + data.query.pages[key]["extract"] + "</i></p></div>");
}
}).fail(function(){
$("#container").html("<h3>Sorry! Something's not working right now. Please check back later.</h3>");
});
} else {
$("#container").html("<h3>Search to find a list of Wikipedia entries related to your topic</h3>");
}
});
$("#random").click(function(){
var randArt = Math.floor(Math.random()*999999);
var url = "https://en.wikipedia.org/?curid=" + randArt;
window.open(url,'_blank');
});
});