-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
171 lines (145 loc) · 4.42 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test App</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="stylesheet" href="./bootstrap-3.3.2-dist/css/bootstrap.min.css" >
<script src="./js/jquery-1.11.2.min.js"></script>
<script src="./bootstrap-3.3.2-dist/js/bootstrap.min.js"></script>
<script src="./js/underscore-min.js"></script>
<style>
.mygrid-wrapper-div {
border: solid red 3px;
overflow: scroll;
height: 400px;
}
</style>
<script type="text/javascript">
var gCompiled;
var gRefreshEntertaimentFlag = 1;
var gRefreshTechFlag = 1;
$(document).ready(function () {
var template = $("#template").html()
gCompiled = _.template(template);
$("#btnRefreshNews").on("click", function (e) {
load_news();
});
$("#btnRefreshEntertaiment").on("click", function (e) {
load_entertaiment();
});
$("#btnRefreshTechNews").on("click", function (e) {
load_tech_news();
});
$('a[data-toggle="tab"]').on("shown.bs.tab", function (e) {
var currentTab = $(".nav-tabs .active").text();
$("#news").hide();
$("#entertaiment").hide();
$("#tech_news").hide();
if (currentTab == 'News') {
$("#news").show();
}
if (currentTab == "Entertainment") {
if (gRefreshEntertaimentFlag == 1) {
$("#btnRefreshEntertaiment").trigger("click");
gRefreshEntertaimentFlag = 0;
} else {
$("#entertaiment").show();
}
}
if (currentTab =="Tech News") {
if (gRefreshTechFlag == 1) {
$("#btnRefreshTechNews").trigger("click");
gRefreshTechFlag = 0;
} else {
$("#tech_news").show();
}
}
});
load_news();
});
function load_news() {
var strDiv = "news";
showWait(strDiv, true);
$.get( "http://localhost/ludala/rssController.php?rss=news", function (response) {
var data = eval( "(" + response + ")");
refreshNews("news_content", data);
showWait(strDiv, false);
});
}
function load_entertaiment() {
var strDiv = "entertaiment";
showWait(strDiv, true);
$.ajax({
type: "GET",
dataType: "JSON",
url: "http://localhost/ludala/rssController.php?rss=entertaiment",
success: function(response) {
refreshNews("entertaiment_content", response);
showWait(strDiv, false);
}
});
}
function load_tech_news() {
var strDiv = "tech_news";
showWait(strDiv, true);
$.getJSON( "http://localhost/ludala/rssController.php?rss=tech_news", function( data ) {
refreshNews("tech_news_content", data);
showWait(strDiv, false);
});
}
function showWait(strDiv, showFlag) {
var div = "#" + strDiv;
if (showFlag) {
$(div).hide();
$("#pleaseWaitDiv").show();
} else {
$("#pleaseWaitDiv").hide();
$(div).show();
}
}
function refreshNews(strDiv, json) {
var div = "#" + strDiv;
if (json.Result == "OK") {
var info = json.Info;
$(div).html(gCompiled( {items : info}));
} else {
alert(json.Message);
}
}
</script>
</head>
<body>
<div id='content'>
<ul class="nav nav-tabs">
<li class="active"><a href="#news" data-toggle="tab">News</a></li>
<li><a href="#entertaiment" data-toggle="tab">Entertainment</a></li>
<li><a href="#tech_news" data-toggle="tab">Tech News</a></li>
</ul>
<div id="tabContent" class="tab-content">
<div class="tab-pane fade in active" id="news">
<button type="button" class="btn btn-primary btn-lg"
id="btnRefreshNews">Refresh News</button>
<div id="news_content" class="mygrid-wrapper-div"></div>
</div>
<div class="tab-pane fade" id="entertaiment">
<button type="button" class="btn btn-primary btn-lg"
id="btnRefreshEntertaiment">Refresh Entertaiment News</button>
<div id="entertaiment_content" class="mygrid-wrapper-div"></div>
</div>
<div class="tab-pane fade" id="tech_news">
<button type="button" class="btn btn-primary btn-lg"
id="btnRefreshTechNews">Refresh Tech News</button>
<div id="tech_news_content" class="mygrid-wrapper-div"'></div>
</div>
<script type="text/template" id="template">
<div class="list-group">
<% _.each(items, function(item,key,arr) { %>
<a href="<%=item.link%>" class="list-group-item"><%=item.title%></a>
<% }); %>
</div>
</script>
<div id='pleaseWaitDiv'>
Loading, please wait...
</div>
</body>
</html>