]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
schema/upgrade-1.0.6-1.0.7.sql: fix
[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 var global_unread = 0;
17
18 /*@cc_on @*/
19 /*@if (@_jscript_version >= 5)
20 // JScript gives us Conditional compilation, we can cope with old IE versions.
21 // and security blocked creation of the objects.
22 try {
23 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
24 } catch (e) {
25 try {
26 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
27 } catch (E) {
28 xmlhttp = false;
29 }
30 }
31 @end @*/
32
33 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
34 xmlhttp = new XMLHttpRequest();
35 }
36
37 function toggleTags() {
38 display_tags = !display_tags;
39
40 var p = document.getElementById("dispSwitchPrompt");
41
42 if (display_tags) {
43 p.innerHTML = "display feeds";
44 } else {
45 p.innerHTML = "display tags";
46 }
47
48 updateFeedList();
49 }
50
51 function dlg_frefresh_callback() {
52 if (xmlhttp.readyState == 4) {
53 updateFeedList(false, false);
54 closeDlg();
55 }
56 }
57
58 function dialog_refresh_callback() {
59 if (xmlhttp.readyState == 4) {
60 var dlg = document.getElementById("userDlg");
61
62 dlg.innerHTML = xmlhttp.responseText;
63 dlg.style.display = "block";
64 }
65 }
66
67 function refetch_callback() {
68 if (xmlhttp.readyState == 4) {
69
70 // document.title = "Tiny Tiny RSS";
71
72 if (!xmlhttp.responseXML) {
73 notify("refetch_callback: backend did not return valid XML");
74 return;
75 }
76
77 var reply = xmlhttp.responseXML.firstChild;
78
79 if (!reply) {
80 notify("refetch_callback: backend did not return expected XML object");
81 return;
82 }
83
84 var f_document = window.frames["feeds-frame"].document;
85
86 for (var l = 0; l < reply.childNodes.length; l++) {
87 var id = reply.childNodes[l].getAttribute("id");
88 var ctr = reply.childNodes[l].getAttribute("counter");
89
90 var feedctr = f_document.getElementById("FEEDCTR-" + id);
91 var feedu = f_document.getElementById("FEEDU-" + id);
92 var feedr = f_document.getElementById("FEEDR-" + id);
93
94 /* TODO figure out how to update this from viewfeed.js->view()
95 disabled for now...
96
97 if (id == "global-unread") {
98 global_unread = ctr;
99 } */
100
101 if (feedctr && feedu && feedr) {
102
103 feedu.innerHTML = ctr;
104
105 if (ctr > 0) {
106 feedctr.className = "odd";
107 if (!feedr.className.match("Unread")) {
108 feedr.className = feedr.className + "Unread";
109 }
110 } else {
111 feedctr.className = "invisible";
112 feedr.className = feedr.className.replace("Unread", "");
113 }
114 }
115 }
116
117 updateTitle("");
118 notify("All feeds updated.");
119
120 }
121 }
122
123 function updateFeed(feed_id) {
124
125 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
126
127 if (xmlhttp_ready(xmlhttp)) {
128 xmlhttp.open("GET", query_str, true);
129 xmlhttp.onreadystatechange=feed_update_callback;
130 xmlhttp.send(null);
131 } else {
132 printLockingError();
133 }
134
135 }
136
137 function scheduleFeedUpdate(force) {
138
139 notify("Updating feeds in background...");
140
141 // document.title = "Tiny Tiny RSS - Updating...";
142
143 updateTitle("Updating...");
144
145 var query_str = "backend.php?op=rpc&subop=";
146
147 if (force) {
148 query_str = query_str + "forceUpdateAllFeeds";
149 } else {
150 query_str = query_str + "updateAllFeeds";
151 }
152
153 if (xmlhttp_ready(xmlhttp)) {
154 xmlhttp.open("GET", query_str, true);
155 xmlhttp.onreadystatechange=refetch_callback;
156 xmlhttp.send(null);
157 } else {
158 printLockingError();
159 }
160 }
161
162 function updateFeedList(silent, fetch) {
163
164 // if (silent != true) {
165 // notify("Loading feed list...");
166 // }
167
168 var query_str = "backend.php?op=feeds";
169
170 if (display_tags) {
171 query_str = query_str + "&tags=1";
172 }
173
174 if (getActiveFeedId()) {
175 query_str = query_str + "&actid=" + getActiveFeedId();
176 }
177
178 if (fetch) query_str = query_str + "&fetch=yes";
179
180 var feeds_frame = document.getElementById("feeds-frame");
181
182 feeds_frame.src = query_str;
183 }
184
185 function catchupAllFeeds() {
186
187 var query_str = "backend.php?op=feeds&subop=catchupAll";
188
189 notify("Marking all feeds as read...");
190
191 var feeds_frame = document.getElementById("feeds-frame");
192
193 feeds_frame.src = query_str;
194
195 global_unread = 0;
196 updateTitle();
197
198 }
199
200 function viewCurrentFeed(skip, subop) {
201
202 if (getActiveFeedId()) {
203 viewfeed(getActiveFeedId(), skip, subop);
204 } else {
205 disableContainerChildren("headlinesToolbar", false, document);
206 viewfeed(-1, skip, subop); // FIXME
207 }
208 }
209
210 function viewfeed(feed, skip, subop) {
211
212 // notify("Loading headlines...");
213
214 enableHotkeys();
215
216 var searchbox = document.getElementById("searchbox");
217
218 if (searchbox) {
219 search_query = searchbox.value;
220 } else {
221 search_query = "";
222 }
223
224 var searchmodebox = document.getElementById("searchmodebox");
225
226 if (searchmodebox) {
227 search_mode = searchmodebox.value;
228 } else {
229 search_mode = "";
230 }
231
232 setCookie("ttrss_vf_smode", search_mode);
233
234 var viewbox = document.getElementById("viewbox");
235
236 var view_mode;
237
238 if (viewbox) {
239 view_mode = viewbox[viewbox.selectedIndex].text;
240 } else {
241 view_mode = "All Posts";
242 }
243
244 setCookie("ttrss_vf_vmode", view_mode);
245
246 var limitbox = document.getElementById("limitbox");
247
248 var limit;
249
250 if (limitbox) {
251 limit = limitbox[limitbox.selectedIndex].text;
252 setCookie("ttrss_vf_limit", limit);
253 } else {
254 limit = "All";
255 }
256
257 setActiveFeedId(feed);
258
259 var f_doc = frames["feeds-frame"].document;
260
261 // f_doc.getElementById("ACTFEEDID").innerHTML = feed;
262
263 if (subop == "MarkAllRead") {
264
265 var feedr = f_doc.getElementById("FEEDR-" + feed);
266 var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
267
268 feedctr.className = "invisible";
269
270 if (feedr.className.match("Unread")) {
271 feedr.className = feedr.className.replace("Unread", "");
272 }
273 }
274
275 var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
276 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
277 "&view=" + param_escape(view_mode) + "&limit=" + limit +
278 "&smode=" + param_escape(search_mode);
279
280 if (search_query != "") {
281 query = query + "&search=" + param_escape(search_query);
282 }
283
284 var headlines_frame = parent.frames["headlines-frame"];
285
286 headlines_frame.location.href = query + "&addheader=true";
287
288 cleanSelected("feedsList");
289 var feedr = document.getElementById("FEEDR-" + feed);
290 if (feedr) {
291 feedr.className = feedr.className + "Selected";
292 }
293
294 disableContainerChildren("headlinesToolbar", false, doc);
295
296 var btnMarkAsRead = document.getElementById("btnMarkFeedAsRead");
297
298 if (btnMarkAsRead && !isNumeric(feed)) {
299 btnMarkAsRead.disabled = true;
300 btnMarkAsRead.className = "disabledButton";
301 }
302
303 // notify("");
304
305 }
306
307
308 function timeout() {
309 scheduleFeedUpdate(true);
310 setTimeout("timeout()", 1800*1000);
311 }
312
313 function resetSearch() {
314 var searchbox = document.getElementById("searchbox")
315
316 if (searchbox.value != "" && getActiveFeedId()) {
317 searchbox.value = "";
318 viewfeed(getActiveFeedId(), 0, "");
319 }
320 }
321
322 function search() {
323 viewCurrentFeed(0, "");
324 }
325
326 function localPiggieFunction(enable) {
327 if (enable) {
328 var query_str = "backend.php?op=feeds&subop=piggie";
329
330 if (xmlhttp_ready(xmlhttp)) {
331
332 xmlhttp.open("GET", query_str, true);
333 xmlhttp.onreadystatechange=feedlist_callback;
334 xmlhttp.send(null);
335 }
336 }
337 }
338
339 function localHotkeyHandler(keycode) {
340
341 /* if (keycode == 78) {
342 return moveToPost('next');
343 }
344
345 if (keycode == 80) {
346 return moveToPost('prev');
347 } */
348
349 if (keycode == 82) {
350 return scheduleFeedUpdate(true);
351 }
352
353 if (keycode == 85) {
354 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
355 }
356
357 // notify("KC: " + keycode);
358
359 }
360
361 function updateTitle(s) {
362 var tmp = "Tiny Tiny RSS";
363
364 if (global_unread > 0) {
365 tmp = tmp + " (" + global_unread + ")";
366 }
367
368 if (s) {
369 tmp = tmp + " - " + s;
370 }
371 document.title = tmp;
372 }
373
374 function genericSanityCheck() {
375
376 if (!xmlhttp) {
377 document.getElementById("headlines").innerHTML =
378 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
379 "to function properly. Your browser doesn't seem to support it.";
380 return false;
381 }
382
383 setCookie("ttrss_vf_test", "TEST");
384 if (getCookie("ttrss_vf_test") != "TEST") {
385
386 document.getElementById("headlines").innerHTML =
387 "<b>Fatal error:</b> This program requires cookies " +
388 "to function properly. Your browser doesn't seem to support them.";
389
390 return false;
391 }
392
393 return true;
394 }
395
396 function init() {
397
398 disableContainerChildren("headlinesToolbar", true);
399
400 if (!genericSanityCheck())
401 return;
402
403 setCookie("ttrss_vf_actfeed", "");
404
405 updateFeedList(false, false);
406 document.onkeydown = hotkey_handler;
407
408 setTimeout("timeout()", 1800*1000);
409 scheduleFeedUpdate(true);
410
411 var content = document.getElementById("content");
412
413 if (getCookie("ttrss_vf_vmode")) {
414 var viewbox = document.getElementById("viewbox");
415 viewbox.value = getCookie("ttrss_vf_vmode");
416 }
417
418 if (getCookie("ttrss_vf_limit")) {
419 var limitbox = document.getElementById("limitbox");
420 limitbox.value = getCookie("ttrss_vf_limit");
421 }
422
423 // if (getCookie("ttrss_vf_actfeed")) {
424 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
425 // }
426
427 }
428
429 function quickMenuGo() {
430 var chooser = document.getElementById("quickMenuChooser");
431
432 var opname = chooser[chooser.selectedIndex].text;
433
434 if (opname == "Preferences") {
435 gotoPreferences();
436 }
437
438 if (opname == "Extended search") {
439 displayDlg("search");
440 return;
441 }
442
443 if (opname.match("Add new feed")) {
444 displayDlg("quickAddFeed");
445 return;
446 }
447
448 if (opname.match("Remove this feed")) {
449 var actid = getActiveFeedId();
450
451 if (!actid) {
452 notify("Please select some feed first.");
453 return;
454 }
455
456 displayDlg("quickDelFeed", actid);
457 return;
458 }
459 }
460
461 function qafAdd() {
462
463 if (!xmlhttp_ready(xmlhttp)) {
464 printLockingError();
465 return
466 }
467
468 var link = document.getElementById("qafInput");
469
470 if (link.value.length == 0) {
471 notify("Missing feed URL.");
472 } else {
473 notify("Adding feed...");
474
475 var feeds_doc = window.frames["feeds-frame"].document;
476
477 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
478
479 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
480 param_escape(link.value), true);
481 xmlhttp.onreadystatechange=dlg_frefresh_callback;
482 xmlhttp.send(null);
483
484 link.value = "";
485
486 }
487 }
488
489 function displayDlg(id, param) {
490
491 notify("");
492
493 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
494 param_escape(id) + "&param=" + param_escape(param), true);
495 xmlhttp.onreadystatechange=dialog_refresh_callback;
496 xmlhttp.send(null);
497
498 }
499
500 function closeDlg() {
501 var dlg = document.getElementById("userDlg");
502 dlg.style.display = "none";
503 }
504
505 function qfdDelete(feed_id) {
506
507 notify("Removing feed...");
508
509 var feeds_doc = window.frames["feeds-frame"].document;
510 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
511
512 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
513 xmlhttp.onreadystatechange=dlg_frefresh_callback;
514 xmlhttp.send(null);
515 }
516
517