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