]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
MIN_UPDATE_TIME, 600 -> 1800 sec
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
1/*
2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
4*/
5
6var xmlhttp = false;
7
76798ff3
AD
8var total_unread = 0;
9
1cd17194
AD
10/*@cc_on @*/
11/*@if (@_jscript_version >= 5)
12// JScript gives us Conditional compilation, we can cope with old IE versions.
13// and security blocked creation of the objects.
14try {
15 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
16} catch (e) {
17 try {
18 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
19 } catch (E) {
20 xmlhttp = false;
21 }
22}
23@end @*/
24
25if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
26 xmlhttp = new XMLHttpRequest();
27}
28
a234aee5
AD
29function printLockingError() {
30 notify("Please wait until operation finishes");
31}
32
175847de
AD
33function notify_callback() {
34 var container = document.getElementById('notify');
35 if (xmlhttp.readyState == 4) {
36 container.innerHTML=xmlhttp.responseText;
37 }
38}
39
1cd17194 40function feedlist_callback() {
d76a3b03 41 var container = document.getElementById('feeds');
1cd17194 42 if (xmlhttp.readyState == 4) {
d76a3b03 43 container.innerHTML=xmlhttp.responseText;
76798ff3
AD
44
45 var feedtu = document.getElementById("FEEDTU");
46
47 if (feedtu) {
48 total_unread = feedtu.innerHTML;
49 update_title();
50 }
476cac42
AD
51
52 notify("");
1cd17194
AD
53 }
54}
55
56function viewfeed_callback() {
d76a3b03 57 var container = document.getElementById('headlines');
1cd17194 58 if (xmlhttp.readyState == 4) {
d76a3b03 59 container.innerHTML = xmlhttp.responseText;
a1a8a2be
AD
60
61 var factive = document.getElementById("FACTIVE");
62 var funread = document.getElementById("FUNREAD");
63 var ftotal = document.getElementById("FTOTAL");
64
65 if (ftotal && factive && funread) {
66 var feed_id = factive.innerHTML;
67
68 var feedr = document.getElementById("FEEDR-" + feed_id);
69 var feedt = document.getElementById("FEEDT-" + feed_id);
70 var feedu = document.getElementById("FEEDU-" + feed_id);
71
72 feedt.innerHTML = ftotal.innerHTML;
73 feedu.innerHTML = funread.innerHTML;
74
75 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
76 feedr.className = feedr.className + "Unread";
77 } else if (feedu.innerHTML <= 0) {
78 feedr.className = feedr.className.replace("Unread", "");
79 }
80
81 }
1c37c607
AD
82
83 notify("");
84
85 }
1cd17194
AD
86}
87
88function view_callback() {
d76a3b03 89 var container = document.getElementById('content');
1cd17194 90 if (xmlhttp.readyState == 4) {
d76a3b03 91 container.innerHTML=xmlhttp.responseText;
1cd17194
AD
92 }
93}
94
95
476cac42 96function updateFeedList(called_from_timer, fetch) {
076682aa 97
40d13c28 98 if (called_from_timer != true) {
476cac42
AD
99 //document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
100 notify("Updating feeds...");
40d13c28 101 }
82baad4a 102
331900c6
AD
103 var query_str = "backend.php?op=feeds";
104
105 if (fetch) query_str = query_str + "&fetch=yes";
106
076682aa
AD
107 if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
108 xmlhttp.open("GET", query_str, true);
109 xmlhttp.onreadystatechange=feedlist_callback;
110 xmlhttp.send(null);
111 } else {
a234aee5 112 printLockingError();
076682aa 113 }
1cd17194
AD
114}
115
175847de
AD
116function catchupPage(feed) {
117
076682aa 118 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 119 printLockingError();
076682aa
AD
120 return
121 }
122
175847de
AD
123 var content = document.getElementById("headlinesList");
124
125 var rows = new Array();
126
127 for (i = 0; i < content.rows.length; i++) {
128 var row_id = content.rows[i].id.replace("RROW-", "");
129 if (row_id.length > 0) {
130 rows.push(row_id);
131 content.rows[i].className = content.rows[i].className.replace("Unread", "");
132 }
133 }
134
135 var feedr = document.getElementById("FEEDR-" + feed);
136 var feedu = document.getElementById("FEEDU-" + feed);
137
138 feedu.innerHTML = feedu.innerHTML - rows.length;
139
140 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
141 feedr.className = feedr.className + "Unread";
142 } else if (feedu.innerHTML <= 0) {
143 feedr.className = feedr.className.replace("Unread", "");
144 }
145
146 var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" +
147 param_escape(rows.toString());
148
149 notify("Marking this page as read...");
150
151 xmlhttp.open("GET", query_str, true);
152 xmlhttp.onreadystatechange=notify_callback;
153 xmlhttp.send(null);
154
155}
156
476cac42 157function catchupAllFeeds() {
076682aa
AD
158
159 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 160 printLockingError();
076682aa
AD
161 return
162 }
476cac42
AD
163 var query_str = "backend.php?op=feeds&subop=catchupAll";
164
165 notify("Marking all feeds as read...");
166
167 xmlhttp.open("GET", query_str, true);
168 xmlhttp.onreadystatechange=feedlist_callback;
169 xmlhttp.send(null);
170
171}
1cd17194 172
476cac42 173function viewfeed(feed, skip, subop) {
1cd17194 174
1c37c607
AD
175// document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
176// document.getElementById('content').innerHTML='&nbsp;';
d76a3b03 177
076682aa 178 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 179 printLockingError();
076682aa
AD
180 return
181 }
182
d76a3b03 183 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
476cac42 184 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
1cd17194
AD
185 xmlhttp.onreadystatechange=viewfeed_callback;
186 xmlhttp.send(null);
187
1c37c607
AD
188 notify("Loading headlines...");
189
1cd17194
AD
190}
191
a1a8a2be 192function view(id,feed_id) {
d76a3b03 193
076682aa 194 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 195 printLockingError();
076682aa
AD
196 return
197 }
198
d76a3b03
AD
199 var crow = document.getElementById("RROW-" + id);
200
a1a8a2be
AD
201 if (crow.className.match("Unread")) {
202 var umark = document.getElementById("FEEDU-" + feed_id);
203 umark.innerHTML = umark.innerHTML - 1;
d76a3b03 204 crow.className = crow.className.replace("Unread", "");
d76a3b03 205
a1a8a2be
AD
206 if (umark.innerHTML == "0") {
207 var feedr = document.getElementById("FEEDR-" + feed_id);
208 feedr.className = feedr.className.replace("Unread", "");
209 }
b197f117 210
76798ff3
AD
211 total_unread--;
212
b197f117 213 update_title();
76798ff3 214 }
1cd17194 215
b197f117
AD
216 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
217
218 if (upd_img_pic) {
219 upd_img_pic.innerHTML = "";
220 }
221
d76a3b03 222 document.getElementById('content').innerHTML='Loading, please wait...';
1cd17194 223
d76a3b03 224 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
1cd17194
AD
225 xmlhttp.onreadystatechange=view_callback;
226 xmlhttp.send(null);
227
228}
229
40d13c28
AD
230function timeout() {
231
5d348fee 232 updateFeedList(true, true);
40d13c28 233
ac53063a
AD
234 setTimeout("timeout()", 1800*1000);
235
236}
237
238function search(feed, sender) {
239
076682aa 240 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 241 printLockingError();
076682aa
AD
242 return
243 }
244
ac53063a
AD
245 notify("Search: " + feed + ", " + sender.value)
246
247 document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
248 document.getElementById('content').innerHTML='&nbsp;';
249
250 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
251 "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
252 xmlhttp.onreadystatechange=viewfeed_callback;
253 xmlhttp.send(null);
40d13c28
AD
254
255}
256
76798ff3
AD
257function update_title() {
258 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
259}
1cd17194 260
76798ff3 261function init() {
476cac42 262 updateFeedList(false, false);
ac53063a 263 setTimeout("timeout()", 1800*1000);
1cd17194 264}