forked from neapolitan-a-la-code/guardianProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
78 lines (52 loc) · 1.93 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
74
75
76
77
$(document).ready(function() {
var fillNews = function(sect) {
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "http://content.guardianapis.com/search?api-key=qbgzuh9db2dke2gym45p59wb&show-fields=all&order-by=newest§ion=" + sect,
success: function(data) {
var HTMLtoAppend = "<img src='";
for (var i = 0; i < 5; i++) {
if (i === 0) {
HTMLtoAppend += data.response.results[i].fields.thumbnail + "'> ";
}
HTMLtoAppend += (i+1) + ". " + "<a href='"
+ data.response.results[i].webUrl + "'> "
+ data.response.results[i].webTitle + "</a><br> "
+ data.response.results[i].fields.trailText + "<br><br> ";
}
$("#" + sect).append(HTMLtoAppend);
}
});
};
fillNews ("uk-news");
fillNews ("football");
fillNews ("travel");
function capFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
var topicCount = 0;
var topics = ["culture","politics","world","money"];
$("div #tabs").tabs();
$("#plustab a").click(function() {
var topicToCreate = (topics[topicCount]);
var topicCapTitle = capFirstLetter(topicToCreate);
var num_tabs = $("div#tabs ul li").length + 1;
// alert("hello");
if (topicCount == topics.length ) {
return null;
}
$("#tab-names").append(
"<li id='" + topicToCreate + "tab'><a href='#" + topicToCreate
+ "' style='color:#066EC9 ; font-family: arial,sans-serif;' role='tab' data-toggle='tab'>"
+ topicCapTitle + "</a></li>"
);
$("div .tab-content").append(
"<div class='tab-pane' id=" + topicToCreate +"></div>"
);
fillNews (topicToCreate);
// $("div #tabs").tabs("refresh");
topicCount ++;
});
});