]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
new view mode: unread or updated
[tt-rss.git] / tt-rss.js
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
6 var xmlhttp = false;
7
8 var total_unread = 0;
9 var first_run = true;
10
11 var search_query = "";
12 var search_mode = "";
13
14 var display_tags = false;
15
16 /*@cc_on @*/
17 /*@if (@_jscript_version >= 5)
18 // JScript gives us Conditional compilation, we can cope with old IE versions.
19 // and security blocked creation of the objects.
20 try {
21 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
22 } catch (e) {
23 try {
24 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
25 } catch (E) {
26 xmlhttp = false;
27 }
28 }
29 @end @*/
30
31 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
32 xmlhttp = new XMLHttpRequest();
33 }
34
35 function toggleTags() {
36 display_tags = !display_tags;
37
38 var p = document.getElementById("dispSwitchPrompt");
39
40 if (display_tags) {
41 p.innerHTML = "display feeds";
42 } else {
43 p.innerHTML = "display tags";
44 }
45
46 updateFeedList();
47 }
48
49 /*
50 function feedlist_callback() {
51 var container = document.getElementById('feeds');
52 if (xmlhttp.readyState == 4) {
53 container.innerHTML=xmlhttp.responseText;
54
55 if (first_run) {
56 scheduleFeedUpdate(false);
57 if (getCookie("ttrss_vf_actfeed")) {
58 viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
59 }
60 first_run = false;
61 } else {
62 notify("");
63 }
64 }
65 }
66 */
67
68 function refetch_callback() {
69 if (xmlhttp.readyState == 4) {
70
71 document.title = "Tiny Tiny RSS";
72 notify("All feeds updated.");
73
74 if (!xmlhttp.responseXML) {
75 notify("refetch_callback: backend did not return valid XML");
76 return;
77 }
78
79 var reply = xmlhttp.responseXML.firstChild;
80
81 if (!reply) {
82 notify("refetch_callback: backend did not return expected XML object");
83 return;
84 }
85
86 var f_document = window.frames["feeds-frame"].document;
87
88 for (var l = 0; l < reply.childNodes.length; l++) {
89 var id = reply.childNodes[l].getAttribute("id");
90 var ctr = reply.childNodes[l].getAttribute("counter");
91
92 var feedctr = f_document.getElementById("FEEDCTR-" + id);
93 var feedu = f_document.getElementById("FEEDU-" + id);
94 var feedr = f_document.getElementById("FEEDR-" + id);
95
96 if (feedctr && feedu && feedr) {
97
98 feedu.innerHTML = ctr;
99
100 if (ctr > 0) {
101 feedctr.className = "odd";
102 if (!feedr.className.match("Unread")) {
103 feedr.className = feedr.className + "Unread";
104 }
105 } else {
106 feedctr.className = "invisible";
107 feedr.className = feedr.className.replace("Unread", "");
108 }
109 }
110 }
111 }
112 }
113
114 function updateFeed(feed_id) {
115
116 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
117
118 if (xmlhttp_ready(xmlhttp)) {
119 xmlhttp.open("GET", query_str, true);
120 xmlhttp.onreadystatechange=feed_update_callback;
121 xmlhttp.send(null);
122 } else {
123 printLockingError();
124 }
125
126 }
127
128 function scheduleFeedUpdate(force) {
129
130 notify("Updating feeds in background...");
131
132 document.title = "Tiny Tiny RSS - Updating...";
133
134 var query_str = "backend.php?op=rpc&subop=";
135
136 if (force) {
137 query_str = query_str + "forceUpdateAllFeeds";
138 } else {
139 query_str = query_str + "updateAllFeeds";
140 }
141
142 if (xmlhttp_ready(xmlhttp)) {
143 xmlhttp.open("GET", query_str, true);
144 xmlhttp.onreadystatechange=refetch_callback;
145 xmlhttp.send(null);
146 } else {
147 printLockingError();
148 }
149 }
150
151 function updateFeedList(silent, fetch) {
152
153 // if (silent != true) {
154 // notify("Loading feed list...");
155 // }
156
157 var query_str = "backend.php?op=feeds";
158
159 if (display_tags) {
160 query_str = query_str + "&tags=1";
161 }
162
163 if (getActiveFeedId()) {
164 query_str = query_str + "&actid=" + getActiveFeedId();
165 }
166
167 if (fetch) query_str = query_str + "&fetch=yes";
168
169 var feeds_frame = document.getElementById("feeds-frame");
170
171 feeds_frame.src = query_str;
172 }
173
174 function catchupAllFeeds() {
175
176 var query_str = "backend.php?op=feeds&subop=catchupAll";
177
178 notify("Marking all feeds as read...");
179
180 var feeds_frame = document.getElementById("feeds-frame");
181
182 feeds_frame.src = query_str;
183
184 }
185
186 function viewCurrentFeed(skip, subop) {
187
188 if (getActiveFeedId()) {
189 viewfeed(getActiveFeedId(), skip, subop);
190 }
191 }
192
193 function viewfeed(feed, skip, subop) {
194
195 // notify("Loading headlines...");
196
197 enableHotkeys();
198
199 var searchbox = document.getElementById("searchbox");
200
201 if (searchbox) {
202 search_query = searchbox.value;
203 } else {
204 search_query = "";
205 }
206
207 var searchmodebox = document.getElementById("searchmodebox");
208
209 if (searchmodebox) {
210 search_mode = searchmodebox.value;
211 } else {
212 search_mode = "";
213 }
214
215 setCookie("ttrss_vf_smode", search_mode);
216
217 var viewbox = document.getElementById("viewbox");
218
219 var view_mode;
220
221 if (viewbox) {
222 view_mode = viewbox[viewbox.selectedIndex].text;
223 } else {
224 view_mode = "All Posts";
225 }
226
227 setCookie("ttrss_vf_vmode", view_mode);
228
229 var limitbox = document.getElementById("limitbox");
230
231 var limit;
232
233 if (limitbox) {
234 limit = limitbox[limitbox.selectedIndex].text;
235 setCookie("ttrss_vf_limit", limit);
236 } else {
237 limit = "All";
238 }
239
240 setActiveFeedId(feed);
241
242 var f_doc = frames["feeds-frame"].document;
243
244 // f_doc.getElementById("ACTFEEDID").innerHTML = feed;
245
246 if (subop == "MarkAllRead") {
247
248 var feedr = f_doc.getElementById("FEEDR-" + feed);
249 var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
250
251 feedctr.className = "invisible";
252
253 if (feedr.className.match("Unread")) {
254 feedr.className = feedr.className.replace("Unread", "");
255 }
256 }
257
258 var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
259 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
260 "&view=" + param_escape(view_mode) + "&limit=" + limit +
261 "&smode=" + param_escape(search_mode);
262
263 if (search_query != "") {
264 query = query + "&search=" + param_escape(search_query);
265 }
266
267 var headlines_frame = parent.frames["headlines-frame"];
268
269 headlines_frame.location.href = query + "&addheader=true";
270
271 cleanSelected("feedsList");
272 var feedr = document.getElementById("FEEDR-" + feed);
273 if (feedr) {
274 feedr.className = feedr.className + "Selected";
275 }
276
277 disableContainerChildren("headlinesToolbar", false, doc);
278
279 var btnMarkAsRead = document.getElementById("btnMarkFeedAsRead");
280
281 if (btnMarkAsRead && (feed < 0 || !isNumeric(feed))) {
282 btnMarkAsRead.disabled = true;
283 btnMarkAsRead.className = "disabledButton";
284 }
285
286 // notify("");
287
288 }
289
290
291 function timeout() {
292 scheduleFeedUpdate(true);
293 setTimeout("timeout()", 1800*1000);
294 }
295
296 function resetSearch() {
297 var searchbox = document.getElementById("searchbox")
298
299 if (searchbox.value != "" && getActiveFeedId()) {
300 searchbox.value = "";
301 viewfeed(getActiveFeedId(), 0, "");
302 }
303 }
304
305 function search() {
306 viewCurrentFeed(0, "");
307 }
308
309 function localPiggieFunction(enable) {
310 if (enable) {
311 var query_str = "backend.php?op=feeds&subop=piggie";
312
313 if (xmlhttp_ready(xmlhttp)) {
314
315 xmlhttp.open("GET", query_str, true);
316 xmlhttp.onreadystatechange=feedlist_callback;
317 xmlhttp.send(null);
318 }
319 }
320 }
321
322 function localHotkeyHandler(keycode) {
323
324 /* if (keycode == 78) {
325 return moveToPost('next');
326 }
327
328 if (keycode == 80) {
329 return moveToPost('prev');
330 } */
331
332 if (keycode == 82) {
333 return scheduleFeedUpdate(true);
334 }
335
336 if (keycode == 85) {
337 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
338 }
339
340 // notify("KC: " + keycode);
341
342 }
343
344 function genericSanityCheck() {
345
346 if (!xmlhttp) {
347 document.getElementById("headlines").innerHTML =
348 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
349 "to function properly. Your browser doesn't seem to support it.";
350 return false;
351 }
352
353 setCookie("ttrss_vf_test", "TEST");
354 if (getCookie("ttrss_vf_test") != "TEST") {
355
356 document.getElementById("headlines").innerHTML =
357 "<b>Fatal error:</b> This program requires cookies " +
358 "to function properly. Your browser doesn't seem to support them.";
359
360 return false;
361 }
362
363 return true;
364 }
365
366 function init() {
367
368 disableContainerChildren("headlinesToolbar", true);
369
370 if (!genericSanityCheck())
371 return;
372
373 setCookie("ttrss_vf_actfeed", "");
374
375 updateFeedList(false, false);
376 document.onkeydown = hotkey_handler;
377
378 setTimeout("timeout()", 1800*1000);
379 scheduleFeedUpdate(true);
380
381 var content = document.getElementById("content");
382
383 if (getCookie("ttrss_vf_vmode")) {
384 var viewbox = document.getElementById("viewbox");
385 viewbox.value = getCookie("ttrss_vf_vmode");
386 }
387
388 if (getCookie("ttrss_vf_limit")) {
389 var limitbox = document.getElementById("limitbox");
390 limitbox.value = getCookie("ttrss_vf_limit");
391 }
392
393 // if (getCookie("ttrss_vf_actfeed")) {
394 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
395 // }
396
397 }
398
399