]> git.wh0rd.org - tt-rss.git/blame - functions.js
updater: render login form on access level violation (closes #123)
[tt-rss.git] / functions.js
CommitLineData
760966c1 1var hotkeys_enabled = true;
d96d11f4 2var debug_mode_enabled = false;
a7565293
AD
3var xmlhttp_rpc = Ajax.getTransport();
4
292a8a12 5function browser_has_opacity() {
605f7d46
AD
6 return navigator.userAgent.match("Gecko") != null ||
7 navigator.userAgent.match("Opera") != null;
292a8a12
AD
8}
9
7c620da8
AD
10function is_opera() {
11 return navigator.userAgent.match("Opera");
12}
13
583c58b8
AD
14function is_khtml() {
15 return navigator.userAgent.match("KHTML");
16}
17
18function is_safari() {
19 return navigator.userAgent.match("Safari");
20}
21
55160955 22function exception_error(location, e, silent) {
83f043bb
AD
23 var msg;
24
25 if (e.fileName) {
26 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
27
28 msg = "Exception: " + e.name + ", " + e.message +
29 "\nFunction: " + location + "()" +
30 "\nLocation: " + base_fname + ":" + e.lineNumber;
ee1f45f4 31
83f043bb
AD
32 } else {
33 msg = "Exception: " + e + "\nFunction: " + location + "()";
34 }
35
ee1f45f4
AD
36 debug("<b>EXCEPTION: " + msg + "</b>");
37
55160955
AD
38 if (!silent) {
39 alert(msg);
40 }
7719618b
AD
41}
42
760966c1
AD
43function disableHotkeys() {
44 hotkeys_enabled = false;
45}
46
47function enableHotkeys() {
48 hotkeys_enabled = true;
49}
50
c0e5a40e
AD
51function xmlhttp_ready(obj) {
52 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
53}
54
01a87dff
AD
55function logout_callback() {
56 var container = document.getElementById('notify');
57 if (xmlhttp.readyState == 4) {
58 try {
8e849206
AD
59 var date = new Date();
60 var timestamp = Math.round(date.getTime() / 1000);
d620cfe7 61 window.location.href = "tt-rss.php";
01a87dff
AD
62 } catch (e) {
63 exception_error("logout_callback", e);
64 }
65 }
66}
67
9cfc649a
AD
68function notify_callback() {
69 var container = document.getElementById('notify');
70 if (xmlhttp.readyState == 4) {
71 container.innerHTML=xmlhttp.responseText;
72 }
73}
74
75function rpc_notify_callback() {
76 var container = document.getElementById('notify');
77 if (xmlhttp_rpc.readyState == 4) {
78 container.innerHTML=xmlhttp_rpc.responseText;
79 }
80}
81
7726fa02
AD
82function param_escape(arg) {
83 if (typeof encodeURIComponent != 'undefined')
84 return encodeURIComponent(arg);
85 else
86 return escape(arg);
87}
88
89function param_unescape(arg) {
90 if (typeof decodeURIComponent != 'undefined')
91 return decodeURIComponent(arg);
92 else
93 return unescape(arg);
94}
95
508a81e1
AD
96function delay(gap) {
97 var then,now;
98 then=new Date().getTime();
99 now=then;
100 while((now-then)<gap) {
101 now=new Date().getTime();
102 }
103}
7726fa02 104
ce3bf408 105var notify_hide_timerid = false;
59a543f0 106
ce3bf408 107function hide_notify() {
42c32916
AD
108 var n = document.getElementById("notify");
109 if (n) {
d05514a4 110 n.style.display = "none";
8dcfffd0 111 }
d05514a4 112}
c05608c2 113
42c32916 114function notify_real(msg, no_hide, n_type) {
7726fa02 115
42c32916
AD
116 var n = document.getElementById("notify");
117 var nb = document.getElementById("notify_body");
7726fa02 118
c05608c2 119 if (!n || !nb) return;
f0601b87 120
0655a1d5
AD
121 if (notify_hide_timerid) {
122 window.clearTimeout(notify_hide_timerid);
123 }
124
8dcfffd0 125 if (msg == "") {
0655a1d5
AD
126 if (n.style.display == "block") {
127 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
128 }
129 return;
7726fa02 130 } else {
0ceded7a 131 n.style.display = "block";
8dcfffd0 132 }
7726fa02 133
42c32916
AD
134 /* types:
135
136 1 - generic
137 2 - progress
138 3 - error
139 4 - info
140
141 */
142
f3977cf5
AD
143 if (typeof __ != 'undefined') {
144 msg = __(msg);
145 }
146
42c32916
AD
147 if (n_type == 1) {
148 n.className = "notify";
149 } else if (n_type == 2) {
150 n.className = "notifyProgress";
151 msg = "<img src='images/indicator_white.gif'> " + msg;
152 } else if (n_type == 3) {
f407c086 153 n.className = "notifyError";
0d32b41e 154 msg = "<img src='images/sign_excl.png'> " + msg;
42c32916
AD
155 } else if (n_type == 4) {
156 n.className = "notifyInfo";
0d32b41e 157 msg = "<img src='images/sign_info.png'> " + msg;
0530ddd8
AD
158 }
159
106689b0
AD
160// msg = "<img src='images/live_com_loading.gif'> " + msg;
161
0ceded7a
AD
162 nb.innerHTML = msg;
163
4d4200a8 164 if (!no_hide) {
292a8a12 165 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 166 }
ce3bf408
AD
167}
168
42c32916
AD
169function notify(msg, no_hide) {
170 notify_real(msg, no_hide, 1);
ce3bf408
AD
171}
172
42c32916
AD
173function notify_progress(msg, no_hide) {
174 notify_real(msg, no_hide, 2);
175}
176
177function notify_error(msg, no_hide) {
178 notify_real(msg, no_hide, 3);
179
180}
181
182function notify_info(msg, no_hide) {
183 notify_real(msg, no_hide, 4);
7726fa02
AD
184}
185
508a81e1 186function printLockingError() {
42c32916
AD
187 notify_info("Please wait until operation finishes.");
188}
508a81e1 189
13ad9102 190function hotkey_handler(e) {
760966c1 191
ee1f45f4 192 try {
2e02b896 193
ee1f45f4 194 var keycode;
d96d11f4
AD
195 var shift_key = false;
196
197 try {
198 shift_key = e.shiftKey;
199 } catch (e) {
200
201 }
ee1f45f4
AD
202
203 if (!hotkeys_enabled) return;
204
205 if (window.event) {
206 keycode = window.event.keyCode;
207 } else if (e) {
208 keycode = e.which;
209 }
d437c8cf 210
ee1f45f4 211 if (keycode == 82) { // r
0feab655 212 return scheduleFeedUpdate(true);
ee1f45f4 213 }
0a383013 214
e3612080 215 if (keycode == 83) { // s
0feab655 216 return displayDlg("search", getActiveFeedId());
0a383013
AD
217 }
218
ee1f45f4
AD
219 if (keycode == 85) { // u
220 if (getActiveFeedId()) {
0feab655 221 return viewfeed(getActiveFeedId(), "ForceUpdate");
ee1f45f4
AD
222 }
223 }
224
225 if (keycode == 65) { // a
0feab655 226 return toggleDispRead();
ee1f45f4
AD
227 }
228
0feab655 229 var feedlist = document.getElementById('feedList');
ee1f45f4
AD
230
231 if (keycode == 74) { // j
232 var feed = getActiveFeedId();
233 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
767e2486 234 if (new_feed) viewfeed(new_feed, '');
ee1f45f4
AD
235 }
236
237 if (keycode == 75) { // k
238 var feed = getActiveFeedId();
239 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
767e2486 240 if (new_feed) viewfeed(new_feed, '');
7b433d8c 241 }
9cfc649a 242
583c58b8 243 if (!is_safari() && (keycode == 78 || keycode == 40)) { // n, down
0feab655
AD
244 if (typeof moveToPost != 'undefined') {
245 return moveToPost('next');
e59a2f12 246 }
ee1f45f4
AD
247 }
248
583c58b8 249 if (!is_safari() && (keycode == 80 || keycode == 38)) { // p, up
0feab655
AD
250 if (typeof moveToPost != 'undefined') {
251 return moveToPost('prev');
e59a2f12 252 }
ee1f45f4
AD
253 }
254
d96d11f4
AD
255 if (keycode == 68 && shift_key) { // d
256 if (!debug_mode_enabled) {
257 document.getElementById('debug_output').style.display = 'block';
258 debug('debug mode activated');
259 } else {
260 document.getElementById('debug_output').style.display = 'none';
261 }
262
263 debug_mode_enabled = !debug_mode_enabled;
264 }
265
50a2595d
AD
266 if (keycode == 190 && shift_key) { // >
267 viewFeedGoPage(1);
268 }
269
270 if (keycode == 188 && shift_key) { // <
271 viewFeedGoPage(-1);
272 }
273
274 if (keycode == 191 && shift_key) { // ?
275 viewFeedGoPage(0);
276 }
277
57c9393e 278 if (keycode == 69 && shift_key) { // e
e46cdbb0
AD
279 return editFeedDlg(getActiveFeedId());
280 }
281
57c9393e 282 if (keycode == 70 && shift_key) { // f
e30a61d4
AD
283 if (getActiveFeedId()) {
284 return catchupCurrentFeed();
285 }
286 }
287
57c9393e 288 if (keycode == 80 && shift_key) { // p
e30a61d4
AD
289 if (getActiveFeedId()) {
290 return catchupPage();
291 }
292 }
293
1dc8dba0
AD
294 if (typeof localHotkeyHandler != 'undefined') {
295 try {
296 return localHotkeyHandler(e);
297 } catch (e) {
298 exception_error("hotkey_handler, local:", e);
299 }
300 }
301
d96d11f4 302 debug("KP=" + keycode);
ee1f45f4
AD
303 } catch (e) {
304 exception_error("hotkey_handler", e);
305 }
13ad9102
AD
306}
307
e828e31e 308function cleanSelectedList(element) {
f0601b87
AD
309 var content = document.getElementById(element);
310
703b632e
AD
311 if (!document.getElementById("feedCatHolder")) {
312 for (i = 0; i < content.childNodes.length; i++) {
313 var child = content.childNodes[i];
d0bb308e
AD
314 try {
315 child.className = child.className.replace("Selected", "");
316 } catch (e) {
317 //
318 }
703b632e
AD
319 }
320 } else {
321 for (i = 0; i < content.childNodes.length; i++) {
322 var child = content.childNodes[i];
703b632e 323 if (child.id == "feedCatHolder") {
9cb99906 324 debug(child.id);
c3f348c2 325 var fcat = child.lastChild;
703b632e 326 for (j = 0; j < fcat.childNodes.length; j++) {
befc807f 327 var feed = fcat.childNodes[j];
703b632e
AD
328 feed.className = feed.className.replace("Selected", "");
329 }
330 }
befc807f 331 }
703b632e 332 }
e828e31e
AD
333}
334
335
336function cleanSelected(element) {
337 var content = document.getElementById(element);
f0601b87
AD
338
339 for (i = 0; i < content.rows.length; i++) {
340 content.rows[i].className = content.rows[i].className.replace("Selected", "");
341 }
f0601b87
AD
342}
343
344function getVisibleUnreadHeadlines() {
345 var content = document.getElementById("headlinesList");
346
347 var rows = new Array();
348
349 for (i = 0; i < content.rows.length; i++) {
350 var row_id = content.rows[i].id.replace("RROW-", "");
351 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
352 rows.push(row_id);
353 }
354 }
355 return rows;
356}
357
358function getVisibleHeadlineIds() {
359
360 var content = document.getElementById("headlinesList");
361
362 var rows = new Array();
363
364 for (i = 0; i < content.rows.length; i++) {
365 var row_id = content.rows[i].id.replace("RROW-", "");
366 if (row_id.length > 0) {
367 rows.push(row_id);
368 }
369 }
370 return rows;
371}
372
373function getFirstVisibleHeadlineId() {
374 var rows = getVisibleHeadlineIds();
375 return rows[0];
376}
377
378function getLastVisibleHeadlineId() {
379 var rows = getVisibleHeadlineIds();
380 return rows[rows.length-1];
381}
382
383function markHeadline(id) {
384 var row = document.getElementById("RROW-" + id);
385 if (row) {
35f3c923
AD
386 var is_active = false;
387
388 if (row.className.match("Active")) {
389 is_active = true;
390 }
391 row.className = row.className.replace("Selected", "");
392 row.className = row.className.replace("Active", "");
393 row.className = row.className.replace("Insensitive", "");
394
395 if (is_active) {
396 row.className = row.className = "Active";
397 }
398
72020095
AD
399 var check = document.getElementById("RCHK-" + id);
400
401 if (check) {
402 check.checked = true;
403 }
404
35f3c923
AD
405 row.className = row.className + "Selected";
406
f0601b87
AD
407 }
408}
409
410function getFeedIds() {
411 var content = document.getElementById("feedsList");
412
413 var rows = new Array();
414
415 for (i = 0; i < content.rows.length; i++) {
416 var id = content.rows[i].id.replace("FEEDR-", "");
417 if (id.length > 0) {
418 rows.push(id);
419 }
420 }
421
422 return rows;
423}
13ad9102 424
76b4eae1
AD
425function setCookie(name, value, lifetime, path, domain, secure) {
426
427 var d = false;
428
429 if (lifetime) {
430 d = new Date();
be0801a1 431 d.setTime(d.getTime() + (lifetime * 1000));
76b4eae1
AD
432 }
433
434 int_setCookie(name, value, d, path, domain, secure);
435
436}
437
438function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
439 document.cookie= name + "=" + escape(value) +
440 ((expires) ? "; expires=" + expires.toGMTString() : "") +
441 ((path) ? "; path=" + path : "") +
442 ((domain) ? "; domain=" + domain : "") +
443 ((secure) ? "; secure" : "");
444}
445
76b4eae1
AD
446function delCookie(name, path, domain) {
447 if (getCookie(name)) {
448 document.cookie = name + "=" +
449 ((path) ? ";path=" + path : "") +
450 ((domain) ? ";domain=" + domain : "" ) +
451 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
452 }
453}
454
455
ac43eba1
AD
456function getCookie(name) {
457
458 var dc = document.cookie;
459 var prefix = name + "=";
460 var begin = dc.indexOf("; " + prefix);
461 if (begin == -1) {
462 begin = dc.indexOf(prefix);
463 if (begin != 0) return null;
464 }
465 else {
466 begin += 2;
467 }
468 var end = document.cookie.indexOf(";", begin);
469 if (end == -1) {
470 end = dc.length;
471 }
472 return unescape(dc.substring(begin + prefix.length, end));
473}
474
1a66d16e
AD
475function disableContainerChildren(id, disable, doc) {
476
477 if (!doc) doc = document;
478
479 var container = doc.getElementById(id);
ac43eba1 480
4220b0bd
AD
481 if (!container) {
482 //alert("disableContainerChildren: element " + id + " not found");
483 return;
484 }
485
ac43eba1
AD
486 for (var i = 0; i < container.childNodes.length; i++) {
487 var child = container.childNodes[i];
488
d5224f0d
AD
489 try {
490 child.disabled = disable;
491 } catch (E) {
492
493 }
ac43eba1
AD
494
495 if (disable) {
496 if (child.className && child.className.match("button")) {
497 child.className = "disabledButton";
498 }
499 } else {
500 if (child.className && child.className.match("disabledButton")) {
501 child.className = "button";
502 }
d5224f0d 503 }
ac43eba1
AD
504 }
505
506}
7726fa02 507
e828e31e
AD
508function gotoPreferences() {
509 document.location.href = "prefs.php";
510}
511
512function gotoMain() {
513 document.location.href = "tt-rss.php";
514}
515
8158c57a
AD
516function gotoExportOpml() {
517 document.location.href = "opml.php?op=Export";
518}
86741347
AD
519
520function getActiveFeedId() {
33d13e72
AD
521// return getCookie("ttrss_vf_actfeed");
522 try {
0feab655
AD
523 debug("gAFID: " + active_feed_id);
524 return active_feed_id;
33d13e72
AD
525 } catch (e) {
526 exception_error("getActiveFeedId", e);
527 }
86741347
AD
528}
529
0a6c4846 530function activeFeedIsCat() {
0feab655 531 return active_feed_is_cat;
0a6c4846
AD
532}
533
86741347 534function setActiveFeedId(id) {
33d13e72
AD
535// return setCookie("ttrss_vf_actfeed", id);
536 try {
5c365f60 537 debug("sAFID(" + id + ")");
0feab655 538 active_feed_id = id;
33d13e72
AD
539 } catch (e) {
540 exception_error("setActiveFeedId", e);
541 }
86741347 542}
090e250b 543
ac378ad4 544function parse_counters(reply, scheduled_call) {
1a6a9555 545 try {
ac378ad4 546
9e397d0f
AD
547 var feeds_found = 0;
548
f54f515f
AD
549 if (reply.firstChild && reply.firstChild.firstChild) {
550 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
551 reply = reply.firstChild;
552 }
553
1a6a9555 554 for (var l = 0; l < reply.childNodes.length; l++) {
9cbca41f
AD
555 if (!reply.childNodes[l] ||
556 typeof(reply.childNodes[l].getAttribute) == "undefined") {
6043fb7e
AD
557 // where did this come from?
558 continue;
559 }
560
1a6a9555
AD
561 var id = reply.childNodes[l].getAttribute("id");
562 var t = reply.childNodes[l].getAttribute("type");
563 var ctr = reply.childNodes[l].getAttribute("counter");
023fe037
AD
564 var error = reply.childNodes[l].getAttribute("error");
565 var has_img = reply.childNodes[l].getAttribute("hi");
fb1fb4ab 566 var updated = reply.childNodes[l].getAttribute("updated");
1a6a9555
AD
567
568 if (id == "global-unread") {
0feab655
AD
569 global_unread = ctr;
570 updateTitle();
1a6a9555
AD
571 continue;
572 }
7bf7e4d3
AD
573
574 if (id == "subscribed-feeds") {
575 feeds_found = ctr;
576 continue;
577 }
1a6a9555
AD
578
579 if (t == "category") {
0feab655 580 var catctr = document.getElementById("FCATCTR-" + id);
1a6a9555 581 if (catctr) {
67dabe1a
AD
582 catctr.innerHTML = "(" + ctr + ")";
583 if (ctr > 0) {
584 catctr.className = "catCtrHasUnread";
585 } else {
586 catctr.className = "catCtrNoUnread";
587 }
1a6a9555
AD
588 }
589 continue;
590 }
591
0feab655
AD
592 var feedctr = document.getElementById("FEEDCTR-" + id);
593 var feedu = document.getElementById("FEEDU-" + id);
594 var feedr = document.getElementById("FEEDR-" + id);
595 var feed_img = document.getElementById("FIMG-" + id);
596 var feedlink = document.getElementById("FEEDL-" + id);
597 var feedupd = document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
598
599 if (updated && feedlink) {
600 if (error) {
601 feedlink.title = "Error: " + error + " (" + updated + ")";
602 } else {
603 feedlink.title = "Updated: " + updated;
604 }
605 }
023fe037 606
78d5212c
AD
607 if (updated && feedupd) {
608 if (error) {
609 feedupd.innerHTML = updated + " (Error)";
610 } else {
611 feedupd.innerHTML = updated;
612 }
613 }
614
1a6a9555 615 if (feedctr && feedu && feedr) {
e8ef3b97
AD
616
617 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
5b064721 618 viewCurrentFeed();
e8ef3b97 619 }
1a6a9555
AD
620
621 feedu.innerHTML = ctr;
023fe037 622
426d3c57
AD
623 if (error) {
624 feedr.className = feedr.className.replace("feed", "error");
625 } else if (id > 0) {
626 feedr.className = feedr.className.replace("error", "feed");
023fe037 627 }
1a6a9555
AD
628
629 if (ctr > 0) {
630 feedctr.className = "odd";
631 if (!feedr.className.match("Unread")) {
632 var is_selected = feedr.className.match("Selected");
633
634 feedr.className = feedr.className.replace("Selected", "");
635 feedr.className = feedr.className.replace("Unread", "");
636
637 feedr.className = feedr.className + "Unread";
638
639 if (is_selected) {
640 feedr.className = feedr.className + "Selected";
641 }
642
643 }
644 } else {
645 feedctr.className = "invisible";
646 feedr.className = feedr.className.replace("Unread", "");
647 }
648 }
649 }
9e397d0f 650
0feab655 651 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
7553dd8b 652
0feab655 653 var feeds_stored = number_of_feeds;
9e397d0f
AD
654
655 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
656
657 if (feeds_stored != feeds_found) {
0feab655 658 number_of_feeds = feeds_found;
7bf7e4d3
AD
659
660 if (feeds_stored != 0) {
9e397d0f 661 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 662 setTimeout('updateFeedList(false, false)', 50);
9e397d0f
AD
663 }
664 }
665
1a6a9555 666 } catch (e) {
83f043bb 667 exception_error("parse_counters", e);
1a6a9555
AD
668 }
669}
670
3ac2f3c7 671function parse_counters_reply(xmlhttp, scheduled_call) {
5854573a
AD
672
673 if (!xmlhttp.responseXML) {
42c32916 674 notify_error("Backend did not return valid XML", true);
5854573a
AD
675 return;
676 }
677
678 var reply = xmlhttp.responseXML.firstChild;
679
680 if (!reply) {
42c32916 681 notify_error("Backend did not return expected XML object", true);
5854573a
AD
682 updateTitle("");
683 return;
684 }
685
686 var error_code = false;
687 var error_msg = false;
688
689 if (reply.firstChild) {
690 error_code = reply.firstChild.getAttribute("error-code");
691 error_msg = reply.firstChild.getAttribute("error-msg");
692 }
693
694 if (!error_code) {
695 error_code = reply.getAttribute("error-code");
696 error_msg = reply.getAttribute("error-msg");
697 }
698
699 if (error_code && error_code != 0) {
700 debug("refetch_callback: got error code " + error_code);
701 return fatalError(error_code, error_msg);
702 }
703
704 var counters = reply.firstChild;
705
3ac2f3c7 706 parse_counters(counters, scheduled_call);
5854573a
AD
707
708 var runtime_info = counters.nextSibling;
709
710 parse_runtime_info(runtime_info);
711
712 if (getInitParam("feeds_sort_by_unread") == 1) {
713 resort_feedlist();
714 }
715
716 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
717
718}
719
4f3a84f4 720function all_counters_callback() {
090e250b 721 if (xmlhttp_rpc.readyState == 4) {
7719618b 722 try {
5854573a 723/* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
b00ed196 724 debug("[all_counters_callback] backend did not return valid XML");
7719618b
AD
725 return;
726 }
894ebcf5 727
6b4163cb 728 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
1cb7492d 729
7719618b 730 var reply = xmlhttp_rpc.responseXML.firstChild;
280ee9a3 731
f54f515f
AD
732 var counters = reply.firstChild;
733
734 parse_counters(counters);
1cb7492d
AD
735
736 var runtime = counters.nextSibling;
737
738 if (runtime) {
0feab655 739 parse_runtime_info(runtime);
1cb7492d 740 }
c9268ed5 741
cea51014 742 if (getInitParam("feeds_sort_by_unread") == 1) {
c9268ed5
AD
743 resort_feedlist();
744 }
293fa942 745
5854573a
AD
746 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
747
748 debug("in all_counters_callback");
749
750 parse_counters_reply(xmlhttp_rpc);
293fa942 751
7719618b
AD
752 } catch (e) {
753 exception_error("all_counters_callback", e);
090e250b
AD
754 }
755 }
756}
757
c9268ed5
AD
758function get_feed_entry_unread(doc, elem) {
759
760 var id = elem.id.replace("FEEDR-", "");
761
762 if (id <= 0) {
763 return -1;
764 }
765
766 try {
767 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
768 } catch (e) {
769 return -1;
770 }
771}
772
773function resort_category(doc, node) {
774 debug("resort_category: " + node);
775
776 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
777 for (i = 0; i < node.childNodes.length; i++) {
778 if (node.childNodes[i].nodeName != "LI") { continue; }
779
780 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
781 continue;
782 }
783
784 for (j = i+1; j < node.childNodes.length; j++) {
785 if (node.childNodes[j].nodeName != "LI") { continue; }
786
787 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
788 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
789
790 if (cur_val > tmp_val) {
791 tempnode_i = node.childNodes[i].cloneNode(true);
792 tempnode_j = node.childNodes[j].cloneNode(true);
793 node.replaceChild(tempnode_i, node.childNodes[j]);
794 node.replaceChild(tempnode_j, node.childNodes[i]);
795 }
796 }
797
798 }
799 }
800
801}
802
803function resort_feedlist() {
804 debug("resort_feedlist");
805
0feab655 806 var fd = document;
c9268ed5
AD
807
808 if (fd.getElementById("feedCatHolder")) {
809
810 var feeds = fd.getElementById("feedList");
811 var child = feeds.firstChild;
812
813 while (child) {
814
815 if (child.id == "feedCatHolder") {
816 resort_category(fd, child.firstChild);
817 }
818
819 child = child.nextSibling;
820 }
821
822 } else {
823 resort_category(fd, fd.getElementById("feedList"));
824 }
825}
826
4f3a84f4 827function update_all_counters(feed) {
090e250b 828 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 829 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
830
831 if (feed > 0) {
832 query = query + "&aid=" + feed;
833 }
834
cf4d339c
AD
835 if (tagsAreDisplayed()) {
836 query = query + "&omode=lt";
3fd7138f
AD
837 } else {
838 query = query + "&omode=flc";
cf4d339c
AD
839 }
840
841 debug("update_all_counters QUERY: " + query);
842
86173d9a
AD
843 var date = new Date();
844 var timestamp = Math.round(date.getTime() / 1000);
845 query = query + "&ts=" + timestamp
846
090e250b 847 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 848 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
849 xmlhttp_rpc.send(null);
850 }
851}
7dc66a61
AD
852
853function popupHelp(tid) {
854 var w = window.open("backend.php?op=help&tid=" + tid,
855 "Popup Help",
856 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
857}
b6644d29
AD
858
859/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
860 * * @author Sundar Dorai-Raj
861 * * Email: sdoraira@vt.edu
862 * * This program is free software; you can redistribute it and/or
863 * * modify it under the terms of the GNU General Public License
864 * * as published by the Free Software Foundation; either version 2
865 * * of the License, or (at your option) any later version,
866 * * provided that any use properly credits the author.
867 * * This program is distributed in the hope that it will be useful,
868 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
869 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
870 * * GNU General Public License for more details at http://www.gnu.org * * */
871
872 var numbers=".0123456789";
873 function isNumeric(x) {
874 // is x a String or a character?
875 if(x.length>1) {
876 // remove negative sign
877 x=Math.abs(x)+"";
878 for(j=0;j<x.length;j++) {
879 // call isNumeric recursively for each character
880 number=isNumeric(x.substring(j,j+1));
881 if(!number) return number;
882 }
883 return number;
884 }
885 else {
886 // if x is number return true
887 if(numbers.indexOf(x)>=0) return true;
888 return false;
889 }
890 }
891
3745788e
AD
892
893function hideOrShowFeeds(doc, hide) {
894
7553dd8b
AD
895 debug("hideOrShowFeeds: " + doc + ", " + hide);
896
0feab655 897 var fd = document;
293fa942
AD
898
899 var list = fd.getElementById("feedList");
900
901 if (fd.getElementById("feedCatHolder")) {
902
903 var feeds = fd.getElementById("feedList");
904 var child = feeds.firstChild;
905
906 while (child) {
907
908 if (child.id == "feedCatHolder") {
909 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
910 }
911
912 child = child.nextSibling;
913 }
914
915 } else {
916 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
917 }
918}
919
920function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
921
922// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 923
293fa942 924 var cat_unread = 0;
3745788e 925
4724a093
AD
926 if (!node) {
927 debug("hideOrShowFeeds: passed node is null, aborting");
928 return;
929 }
930
293fa942
AD
931 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
932 for (i = 0; i < node.childNodes.length; i++) {
933 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 934
b31c2311 935 if (node.childNodes[i].style != undefined) {
293fa942 936
b31c2311
AD
937 var has_unread = (node.childNodes[i].className != "feed");
938
939 // debug(node.childNodes[i].id + " --> " + has_unread);
940
941 if (hide && !has_unread) {
942 node.childNodes[i].style.display = "none";
943 }
944
945 if (!hide) {
946 node.childNodes[i].style.display = "list-item";
947 }
948
949 if (has_unread) {
7553dd8b 950 node.childNodes[i].style.display = "list-item";
b31c2311
AD
951 cat_unread++;
952 }
293fa942 953 }
3745788e 954 }
b31c2311 955 }
3745788e 956
293fa942 957 if (cat_unread == 0) {
b31c2311
AD
958 if (cat_node.style == undefined) {
959 debug("ERROR: supplied cat_node " + cat_node +
960 " has no styles. WTF?");
961 return;
962 }
293fa942
AD
963 if (hide) {
964 cat_node.style.display = "none";
965 } else {
966 cat_node.style.display = "list-item";
967 }
7553dd8b 968 } else {
0ac2faea
AD
969 try {
970 cat_node.style.display = "list-item";
971 } catch (e) {
972 debug(e);
973 }
293fa942 974 }
3745788e 975
293fa942 976// debug("unread for category: " + cat_unread);
3745788e
AD
977}
978
35f3c923
AD
979function selectTableRow(r, do_select) {
980 r.className = r.className.replace("Selected", "");
981
982 if (do_select) {
983 r.className = r.className + "Selected";
984 }
985}
986
6c12c809
AD
987function selectTableRowById(elem_id, check_id, do_select) {
988
989 try {
990
991 var row = document.getElementById(elem_id);
992
993 if (row) {
994 selectTableRow(row, do_select);
995 }
996
997 var check = document.getElementById(check_id);
998
999 if (check) {
1000 check.checked = do_select;
1001 }
1002 } catch (e) {
1003 exception_error("selectTableRowById", e);
1004 }
1005}
1006
1572afe5 1007function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 1008 classcheck, reset_others) {
3745788e 1009
35f3c923
AD
1010 var content = document.getElementById(content_id);
1011
1012 if (!content) {
1013 alert("[selectTableRows] Element " + content_id + " not found.");
1014 return;
1015 }
1016
1017 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
1018 if (!classcheck || content.rows[i].className.match(classcheck)) {
1019
1020 if (content.rows[i].id.match(prefix)) {
1021 selectTableRow(content.rows[i], do_select);
649e0af9
AD
1022
1023 var row_id = content.rows[i].id.replace(prefix, "");
1024 var check = document.getElementById(check_prefix + row_id);
3055bc41 1025
649e0af9
AD
1026 if (check) {
1027 check.checked = do_select;
1028 }
1029 } else if (reset_others) {
1030 selectTableRow(content.rows[i], false);
7d8d10c6
AD
1031
1032 var row_id = content.rows[i].id.replace(prefix, "");
1033 var check = document.getElementById(check_prefix + row_id);
1034
1035 if (check) {
1036 check.checked = false;
1037 }
1038
1572afe5 1039 }
649e0af9
AD
1040 } else if (reset_others) {
1041 selectTableRow(content.rows[i], false);
7d8d10c6
AD
1042
1043 var row_id = content.rows[i].id.replace(prefix, "");
1044 var check = document.getElementById(check_prefix + row_id);
1045
1046 if (check) {
1047 check.checked = false;
1048 }
1049
3055bc41 1050 }
35f3c923 1051 }
295f9b42 1052}
91ff844a
AD
1053
1054function getSelectedTableRowIds(content_id, prefix) {
1055
1056 var content = document.getElementById(content_id);
1057
1058 if (!content) {
1059 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
1060 return;
1061 }
1062
1063 var sel_rows = new Array();
1064
1065 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
1066 if (content.rows[i].id.match(prefix) &&
1067 content.rows[i].className.match("Selected")) {
1068
91ff844a
AD
1069 var row_id = content.rows[i].id.replace(prefix + "-", "");
1070 sel_rows.push(row_id);
1071 }
1072 }
1073
1074 return sel_rows;
1075
1076}
1077
386cbf27
AD
1078function toggleSelectRowById(sender, id) {
1079 var row = document.getElementById(id);
1080
1081 if (sender.checked) {
1082 if (!row.className.match("Selected")) {
1083 row.className = row.className + "Selected";
1084 }
1085 } else {
1086 if (row.className.match("Selected")) {
1087 row.className = row.className.replace("Selected", "");
1088 }
1089 }
1090}
1091
b92e6209
AD
1092function toggleSelectListRow(sender) {
1093 var parent_row = sender.parentNode;
1094
1095 if (sender.checked) {
1096 if (!parent_row.className.match("Selected")) {
1097 parent_row.className = parent_row.className + "Selected";
1098 }
1099 } else {
1100 if (parent_row.className.match("Selected")) {
1101 parent_row.className = parent_row.className.replace("Selected", "");
1102 }
1103 }
1104}
1105
386cbf27 1106
1572afe5
AD
1107function toggleSelectRow(sender) {
1108 var parent_row = sender.parentNode.parentNode;
1109
1110 if (sender.checked) {
1111 if (!parent_row.className.match("Selected")) {
1112 parent_row.className = parent_row.className + "Selected";
1113 }
1114 } else {
1115 if (parent_row.className.match("Selected")) {
1116 parent_row.className = parent_row.className.replace("Selected", "");
1117 }
1118 }
1119}
1120
3866b046
AD
1121function openExternalUrl(url) {
1122 var w = window.open(url);
1123}
1572afe5 1124
1da76274 1125function getRelativeFeedId(list, id, direction, unread_only) {
7b433d8c
AD
1126 if (!id) {
1127 if (direction == "next") {
1128 for (i = 0; i < list.childNodes.length; i++) {
1129 var child = list.childNodes[i];
1da76274 1130 if (child.id && child.id == "feedCatHolder") {
c3f348c2 1131 if (child.lastChild) {
d05514a4 1132 var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only);
7b433d8c
AD
1133 if (cr) return cr;
1134 }
1da76274 1135 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
1136 return child.id.replace('FEEDR-', '');
1137 }
1138 }
1139 }
1140
1141 // FIXME select last feed doesn't work when only unread feeds are visible
1142
1143 if (direction == "prev") {
1144 for (i = list.childNodes.length-1; i >= 0; i--) {
1145 var child = list.childNodes[i];
1146 if (child.id == "feedCatHolder") {
1147 if (child.firstChild) {
1148 var cr = getRelativeFeedId(child.firstChild, id, direction);
1149 if (cr) return cr;
1150 }
1151 } else if (child.id.match("FEEDR-")) {
1152
e8bd0da9 1153 if (getInitParam("hide_read_feeds") == 1) {
7b433d8c
AD
1154 if (child.className != "feed") {
1155 alert(child.className);
1156 return child.id.replace('FEEDR-', '');
1157 }
1158 } else {
1159 return child.id.replace('FEEDR-', '');
1160 }
1161 }
1162 }
1163 }
1164 } else {
1165
d05514a4 1166 var feed = list.ownerDocument.getElementById("FEEDR-" + id);
7b433d8c 1167
e8bd0da9 1168 if (getInitParam("hide_read_feeds") == 1) {
1da76274
AD
1169 unread_only = true;
1170 }
1171
7b433d8c
AD
1172 if (direction == "next") {
1173
1da76274 1174 var e = feed;
7b433d8c 1175
1da76274 1176 while (e) {
7b433d8c 1177
1da76274
AD
1178 if (e.nextSibling) {
1179
1180 e = e.nextSibling;
1181
1182 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 1183
1da76274 1184 var this_cat = e.parentNode.parentNode;
7b433d8c 1185
1da76274 1186 e = false;
7b433d8c 1187
1da76274
AD
1188 if (this_cat && this_cat.nextSibling) {
1189 while (!e && this_cat.nextSibling) {
1190 this_cat = this_cat.nextSibling;
1191 if (this_cat.id == "feedCatHolder") {
1192 e = this_cat.firstChild.firstChild;
7b433d8c
AD
1193 }
1194 }
7b433d8c 1195 }
1da76274
AD
1196
1197 } else {
1198 e = false;
1199 }
1200
1201 if (e) {
d05514a4 1202 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1203 e.className.match("feed"))) {
1da76274
AD
1204 return e.id.replace("FEEDR-", "");
1205 }
1206 }
7b433d8c 1207 }
1da76274 1208
7b433d8c
AD
1209 } else if (direction == "prev") {
1210
1da76274 1211 var e = feed;
7b433d8c 1212
1da76274 1213 while (e) {
7b433d8c 1214
1da76274
AD
1215 if (e.previousSibling) {
1216
1217 e = e.previousSibling;
1218
1219 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 1220
1da76274 1221 var this_cat = e.parentNode.parentNode;
7b433d8c 1222
1da76274
AD
1223 e = false;
1224
1225 if (this_cat && this_cat.previousSibling) {
1226 while (!e && this_cat.previousSibling) {
1227 this_cat = this_cat.previousSibling;
1228 if (this_cat.id == "feedCatHolder") {
1229 e = this_cat.firstChild.lastChild;
7b433d8c
AD
1230 }
1231 }
7b433d8c 1232 }
1da76274
AD
1233
1234 } else {
1235 e = false;
1236 }
1237
1238 if (e) {
e686782e 1239 if (!unread_only || (unread_only && e.className != "feed" &&
cabffe9d 1240 e.className.match("feed"))) {
1da76274
AD
1241 return e.id.replace("FEEDR-", "");
1242 }
1243 }
1244 }
7b433d8c
AD
1245 }
1246 }
1247}
36aab70f
AD
1248
1249function showBlockElement(id) {
1250 var elem = document.getElementById(id);
1251
1252 if (elem) {
1253 elem.style.display = "block";
1254 } else {
1255 alert("[showBlockElement] can't find element with id " + id);
1256 }
1257}
1258
a9b0bfd5
AD
1259function hideParentElement(e) {
1260 e.parentNode.style.display = "none";
1261}
1b0809ae
AD
1262
1263function dropboxSelect(e, v) {
1264 for (i = 0; i < e.length; i++) {
1265 if (e[i].value == v) {
1266 e.selectedIndex = i;
1267 break;
1268 }
1269 }
1270}
0ee1d1a0
AD
1271
1272// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1273// bugfixed just a little bit :-)
1274function getURLParam(strParamName){
1275 var strReturn = "";
1276 var strHref = window.location.href;
1277
1278 if (strHref.indexOf("#") == strHref.length-1) {
1279 strHref = strHref.substring(0, strHref.length-1);
1280 }
1281
1282 if ( strHref.indexOf("?") > -1 ){
1283 var strQueryString = strHref.substr(strHref.indexOf("?"));
1284 var aQueryString = strQueryString.split("&");
1285 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1286 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1287 var aParam = aQueryString[iParam].split("=");
1288 strReturn = aParam[1];
1289 break;
1290 }
1291 }
1292 }
1293 return strReturn;
1294}
1295
cf1bc085
AD
1296function leading_zero(p) {
1297 var s = String(p);
1298 if (s.length == 1) s = "0" + s;
1299 return s;
1300}
c38c2b69 1301
86b682ce 1302function closeInfoBox(cleanup) {
e5d758e3
AD
1303 var box = document.getElementById('infoBox');
1304 var shadow = document.getElementById('infoBoxShadow');
1305
1306 if (shadow) {
1307 shadow.style.display = "none";
1308 } else if (box) {
1309 box.style.display = "none";
1310 }
1311
86b682ce
AD
1312 if (cleanup) box.innerHTML = "&nbsp;";
1313
e5d758e3 1314 enableHotkeys();
c14b5566 1315
90ac84df 1316 return false;
e5d758e3
AD
1317}
1318
1319
7b5c6012
AD
1320function displayDlg(id, param) {
1321
1322 if (!xmlhttp_ready(xmlhttp)) {
1323 printLockingError();
1324 return
1325 }
1326
9e31e1b9 1327 notify_progress("Loading, please wait...");
7b5c6012
AD
1328
1329 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1330 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 1331 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
1332 xmlhttp.send(null);
1333
1334 disableHotkeys();
2371c520 1335
90ac84df 1336 return false;
7b5c6012
AD
1337}
1338
e5d758e3 1339function infobox_submit_callback() {
7b5c6012 1340 if (xmlhttp.readyState == 4) {
e5d758e3 1341 closeInfoBox();
7b5c6012 1342
6e6504bc
AD
1343 try {
1344 // called from prefs, reload tab
1345 if (active_tab) {
1346 selectTab(active_tab, false);
1347 }
1348 } catch (e) { }
79f3553b 1349
5e6f933a
AD
1350 if (xmlhttp.responseText) {
1351 notify_info(xmlhttp.responseText);
1352 }
79f3553b 1353
7b5c6012
AD
1354 }
1355}
1356
e5d758e3 1357function infobox_callback() {
7b5c6012 1358 if (xmlhttp.readyState == 4) {
e5d758e3
AD
1359 var box = document.getElementById('infoBox');
1360 var shadow = document.getElementById('infoBoxShadow');
1361 if (box) {
1362 box.innerHTML=xmlhttp.responseText;
1363 if (shadow) {
1364 shadow.style.display = "block";
1365 } else {
1366 box.style.display = "block";
1367 }
1368 }
9c483746 1369 notify("");
e5d758e3 1370 }
7b5c6012
AD
1371}
1372
5e6f933a 1373function addFilter() {
7b5c6012
AD
1374
1375 if (!xmlhttp_ready(xmlhttp)) {
1376 printLockingError();
1377 return
1378 }
1379
c91c2249
AD
1380 var form = document.forms['filter_add_form'];
1381 var reg_exp = form.reg_exp.value;
1382
1383 if (reg_exp == "") {
1384 alert("Can't add filter: nothing to match on.");
1385 return false;
1386 }
1387
79f3553b 1388 var query = Form.serialize("filter_add_form");
7b5c6012 1389
79f3553b
AD
1390 xmlhttp.open("GET", "backend.php?" + query, true);
1391 xmlhttp.onreadystatechange=infobox_submit_callback;
1392 xmlhttp.send(null);
7b5c6012 1393
c14b5566 1394 return true;
7b5c6012
AD
1395}
1396
2371c520
AD
1397function toggleSubmitNotEmpty(e, submit_id) {
1398 try {
1399 document.getElementById(submit_id).disabled = (e.value == "")
1400 } catch (e) {
1401 exception_error("toggleSubmitNotEmpty", e);
1402 }
1403}
1d7bf5a0 1404
605f7d46 1405function isValidURL(s) {
0d32b41e 1406 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
605f7d46 1407}
07eb9178 1408
5e6f933a 1409function qaddFeed() {
07eb9178
AD
1410
1411 if (!xmlhttp_ready(xmlhttp)) {
1412 printLockingError();
1413 return
1414 }
1415
c91c2249
AD
1416 var form = document.forms['feed_add_form'];
1417 var feed_url = form.feed_url.value;
1418
1419 if (feed_url == "") {
1420 alert("Can't subscribe: no feed URL given.");
1421 return false;
1422 }
1423
42c32916 1424 notify_progress("Adding feed...");
07eb9178
AD
1425
1426 closeInfoBox();
1427
0feab655 1428 var feeds_doc = document;
07eb9178 1429
80e4dc34 1430// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1431
1432 var query = Form.serialize("feed_add_form");
1433
1434 xmlhttp.open("GET", "backend.php?" + query, true);
1435 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1436 xmlhttp.send(null);
7bc4f251
AD
1437
1438 return false;
07eb9178
AD
1439}
1440
6e6504bc 1441function filterCR(e, f)
86b682ce
AD
1442{
1443 var key;
1444
1445 if(window.event)
1446 key = window.event.keyCode; //IE
1447 else
1448 key = e.which; //firefox
1449
6e6504bc
AD
1450 if (key == 13) {
1451 if (typeof f != 'undefined') {
1452 f();
1453 return false;
1454 } else {
1455 return false;
1456 }
1457 } else {
1458 return true;
1459 }
86b682ce
AD
1460}
1461
ac378ad4 1462function getMainContext() {
6b4163cb 1463 return this.window;
ac378ad4
AD
1464}
1465
33d13e72 1466function getFeedsContext() {
6b4163cb 1467 return this.window;
33d13e72
AD
1468}
1469
0bd411db 1470function getContentContext() {
6b4163cb 1471 return this.window;
0bd411db
AD
1472}
1473
ee1f45f4 1474function getHeadlinesContext() {
6b4163cb 1475 return this.window;
ee1f45f4
AD
1476}
1477
e8614131
AD
1478var debug_last_class = "even";
1479
ac378ad4 1480function debug(msg) {
ac378ad4 1481
0feab655
AD
1482 if (debug_last_class == "even") {
1483 debug_last_class = "odd";
e8614131 1484 } else {
0feab655 1485 debug_last_class = "even";
e8614131
AD
1486 }
1487
0feab655 1488 var c = document.getElementById('debug_output');
ac378ad4 1489 if (c && c.style.display == "block") {
c9268ed5 1490 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1491 c.removeChild(c.lastChild);
1492 }
1493
1494 var d = new Date();
1495 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1496 ":" + leading_zero(d.getSeconds());
0feab655 1497 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1498 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1499 }
1500}
1501
33d13e72 1502function getInitParam(key) {
be0801a1
AD
1503 var c = getCookie("TTIP:" + key);
1504 if (c) {
1505 return c;
1506 } else {
1507 return getMainContext().init_params[key];
1508 }
33d13e72 1509}
3ac2b520 1510
be0801a1
AD
1511function storeInitParam(key, value) {
1512 try {
1513 init_params[key] = value;
1514 debug("storeInitParam: " + key + " => " + value +
1515 " (" + getInitParam("cookie_lifetime") + ")");
1516 if (getInitParam("cookie_lifetime") > 0) {
1517 setCookie("TTIP:" + key, value, getInitParam("cookie_lifetime"));
1518 } else {
1519 setCookie("TTIP:" + key, value);
1520 }
1521 } catch (e) {
1522 exception_error("storeInitParam", e);
1523 }
1524}
1525
1526
1527/*
e8bd0da9 1528function storeInitParam(key, value, is_client) {
33d13e72 1529 try {
e8bd0da9 1530 if (!is_client) {
1035fcec
AD
1531 if (getMainContext().init_params[key] != value) {
1532 debug("storeInitParam: " + key + " => " + value);
0b7cb301
AD
1533 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1534 // param_escape(key) + "&value=" + param_escape(value));
1535 var f = getMainContext().document.getElementById("backReqBox");
1536 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1537 param_escape(key) + "&value=" + param_escape(value);
1035fcec 1538 }
e8bd0da9 1539 }
1035fcec 1540 getMainContext().init_params[key] = value;
33d13e72
AD
1541 } catch (e) {
1542 exception_error("storeInitParam", e);
1543 }
be0801a1 1544} */
a7565293 1545
1035fcec
AD
1546/*
1547function storeInitParams(params, is_client) {
1548 try {
1549 var s = "";
1550
1551 for (k in params) {
1552 if (getMainContext().init_params[k] != params[k]) {
1553 s += k + "=" + params[k] + ";";
1554 getMainContext().init_params[k] = params[k];
1555 }
1556 }
1557
1558 debug("storeInitParams: " + s);
1559
1560 if (!is_client) {
1561 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1562 }
1563 } catch (e) {
1564 exception_error("storeInitParams", e);
1565 }
1566}*/
1567
a7565293
AD
1568function fatalError(code, message) {
1569 try {
a7565293 1570
b4c27af7 1571 if (code == 6) {
8e849206 1572 window.location.href = "tt-rss.php";
b4c27af7
AD
1573 } else if (code == 5) {
1574 window.location.href = "update.php";
1575 } else {
4724a093
AD
1576 var fe = document.getElementById("fatal_error");
1577 var fc = document.getElementById("fatal_error_msg");
1578
42c32916
AD
1579 if (message == "") message = "Unknown error";
1580
1581 fc.innerHTML = "<img src='images/sign_excl.png'> " + message + " (Code " + code + ")";
4724a093
AD
1582
1583 fe.style.display = "block";
4724a093 1584 }
a7565293
AD
1585
1586 } catch (e) {
1587 exception_error("fatalError", e);
1588 }
1589}
1590
234e467c 1591function getFeedName(id, is_cat) {
64a2875d 1592 var d = getFeedsContext().document;
234e467c
AD
1593
1594 var e;
1595
1596 if (is_cat) {
1597 e = d.getElementById("FCATN-" + id);
1598 } else {
1599 e = d.getElementById("FEEDN-" + id);
1600 }
64a2875d
AD
1601 if (e) {
1602 return e.innerHTML.stripTags();
1603 } else {
1604 return null;
1605 }
1606}
0bd411db
AD
1607
1608function viewContentUrl(url) {
1609 getContentContext().location = url;
1610}
350f0ad1
AD
1611
1612function filterDlgCheckAction(sender) {
1613
1614 try {
1615
1616 var action = sender[sender.selectedIndex].value;
1617
1618 var form = document.forms["filter_add_form"];
1619
1620 if (!form) {
1621 form = document.forms["filter_edit_form"];
1622 }
1623
1624 if (!form) {
1625 debug("filterDlgCheckAction: can't find form!");
1626 return;
1627 }
1628
1629 var action_param = form.action_param;
1630
1631 if (!action_param) {
1632 debug("filterDlgCheckAction: can't find action param!");
1633 return;
1634 }
1635
1636 // if selected action supports parameters, enable params field
1637 if (action == 4) {
1638 action_param.disabled = false;
1639 } else {
1640 action_param.disabled = true;
1641 }
1642
1643 } catch (e) {
1644 exception_error(e, "filterDlgCheckAction");
1645 }
1646
1647}
ef16ae37
AD
1648
1649function explainError(code) {
1650 return displayDlg("explainError", code);
1651}
01a87dff
AD
1652
1653function logoutUser() {
1654 try {
1655 if (xmlhttp_ready(xmlhttp_rpc)) {
64f6db90 1656
42c32916 1657 notify_progress("Logging out, please wait...", true);
64f6db90 1658
01a87dff
AD
1659 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=logout", true);
1660 xmlhttp_rpc.onreadystatechange=logout_callback;
1661 xmlhttp_rpc.send(null);
1662 } else {
1663 printLockingError();
1664 }
1665 } catch (e) {
1666 exception_error("logoutUser", e);
1667 }
1668}