]> git.wh0rd.org - tt-rss.git/blame - functions.js
disable infobox overlay
[tt-rss.git] / functions.js
CommitLineData
760966c1
AD
1var hotkeys_enabled = true;
2
292a8a12 3function browser_has_opacity() {
605f7d46
AD
4 return navigator.userAgent.match("Gecko") != null ||
5 navigator.userAgent.match("Opera") != null;
292a8a12
AD
6}
7
7719618b 8function exception_error(location, e) {
83f043bb
AD
9 var msg;
10
11 if (e.fileName) {
12 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
13
14 msg = "Exception: " + e.name + ", " + e.message +
15 "\nFunction: " + location + "()" +
16 "\nLocation: " + base_fname + ":" + e.lineNumber;
17 } else {
18 msg = "Exception: " + e + "\nFunction: " + location + "()";
19 }
20
21 alert(msg);
7719618b
AD
22}
23
760966c1
AD
24function disableHotkeys() {
25 hotkeys_enabled = false;
26}
27
28function enableHotkeys() {
29 hotkeys_enabled = true;
30}
31
c0e5a40e
AD
32function xmlhttp_ready(obj) {
33 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
34}
35
9cfc649a
AD
36function notify_callback() {
37 var container = document.getElementById('notify');
38 if (xmlhttp.readyState == 4) {
39 container.innerHTML=xmlhttp.responseText;
40 }
41}
42
43function rpc_notify_callback() {
44 var container = document.getElementById('notify');
45 if (xmlhttp_rpc.readyState == 4) {
46 container.innerHTML=xmlhttp_rpc.responseText;
47 }
48}
49
1572afe5
AD
50function rpc_pnotify_callback() {
51 var container = parent.document.getElementById('notify');
52 if (xmlhttp_rpc.readyState == 4) {
53 container.innerHTML=xmlhttp_rpc.responseText;
54 }
55}
56
7726fa02
AD
57function param_escape(arg) {
58 if (typeof encodeURIComponent != 'undefined')
59 return encodeURIComponent(arg);
60 else
61 return escape(arg);
62}
63
64function param_unescape(arg) {
65 if (typeof decodeURIComponent != 'undefined')
66 return decodeURIComponent(arg);
67 else
68 return unescape(arg);
69}
70
508a81e1
AD
71function delay(gap) {
72 var then,now;
73 then=new Date().getTime();
74 now=then;
75 while((now-then)<gap) {
76 now=new Date().getTime();
77 }
78}
7726fa02 79
ce3bf408
AD
80var notify_hide_timerid = false;
81var notify_last_doc = false;
82
83function hide_notify() {
84 if (notify_last_doc) {
85 var n = notify_last_doc.getElementById("notify");
292a8a12 86 if (browser_has_opacity()) {
ce3bf408
AD
87 if (notify_opacity >= 0) {
88 notify_opacity = notify_opacity - 0.2;
89 n.style.opacity = notify_opacity;
292a8a12 90 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
ce3bf408
AD
91 } else {
92 n.style.display = "none";
292a8a12 93 n.style.opacity = 1;
ce3bf408
AD
94 }
95 } else {
96 n.style.display = "none";
97 }
8dcfffd0 98 }
c05608c2
AD
99}
100
0530ddd8 101function notify_real(msg, doc, no_hide, is_err) {
7726fa02 102
ce3bf408
AD
103 var n = doc.getElementById("notify");
104 var nb = doc.getElementById("notify_body");
7726fa02 105
c05608c2 106 if (!n || !nb) return;
f0601b87 107
8dcfffd0 108 if (msg == "") {
0ceded7a 109 n.style.display = "none";
7726fa02 110 } else {
0ceded7a 111 n.style.display = "block";
8dcfffd0 112 }
7726fa02 113
0530ddd8 114 if (is_err) {
caa53a7c
AD
115 n.style.backgroundColor = "#ffcccc";
116 n.style.color = "black";
0530ddd8
AD
117 n.style.borderColor = "#ff0000";
118 } else {
119 n.style.backgroundColor = "#fff7d5";
120 n.style.borderColor = "#d7c47a";
121 n.style.color = "black";
122 }
123
0ceded7a
AD
124 nb.innerHTML = msg;
125
ce3bf408
AD
126 if (notify_hide_timerid) {
127 window.clearTimeout(notify_hide_timerid);
128 }
129
130 notify_last_doc = doc;
131 notify_opacity = 1;
132
4d4200a8 133 if (!no_hide) {
292a8a12 134 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 135 }
ce3bf408
AD
136}
137
0530ddd8
AD
138function p_notify(msg, no_hide, is_err) {
139 notify_real(msg, parent.document, no_hide, is_err);
ce3bf408
AD
140}
141
0530ddd8
AD
142function notify(msg, no_hide, is_err) {
143 notify_real(msg, document, no_hide, is_err);
7726fa02
AD
144}
145
508a81e1 146function printLockingError() {
f0601b87 147 notify("Please wait until operation finishes");}
508a81e1 148
13ad9102
AD
149var seq = "";
150
151function hotkey_handler(e) {
760966c1 152
13ad9102
AD
153 var keycode;
154
760966c1
AD
155 if (!hotkeys_enabled) return;
156
13ad9102
AD
157 if (window.event) {
158 keycode = window.event.keyCode;
159 } else if (e) {
160 keycode = e.which;
161 }
162
163 if (keycode == 13 || keycode == 27) {
164 seq = "";
165 } else {
166 seq = seq + "" + keycode;
167 }
168
2e02b896
AD
169 if (document.getElementById("piggie")) {
170
171 if (seq.match("807371717369")) {
172 seq = "";
173 localPiggieFunction(true);
174 } else {
175 localPiggieFunction(false);
176 }
bb7cface
AD
177 }
178
9cfc649a 179 if (typeof localHotkeyHandler != 'undefined') {
7b433d8c
AD
180 try {
181 localHotkeyHandler(keycode);
182 } catch (e) {
83f043bb 183 exception_error("hotkey_handler", e);
7b433d8c 184 }
9cfc649a
AD
185 }
186
13ad9102
AD
187}
188
e828e31e 189function cleanSelectedList(element) {
f0601b87
AD
190 var content = document.getElementById(element);
191
703b632e
AD
192 if (!document.getElementById("feedCatHolder")) {
193 for (i = 0; i < content.childNodes.length; i++) {
194 var child = content.childNodes[i];
d0bb308e
AD
195 try {
196 child.className = child.className.replace("Selected", "");
197 } catch (e) {
198 //
199 }
703b632e
AD
200 }
201 } else {
202 for (i = 0; i < content.childNodes.length; i++) {
203 var child = content.childNodes[i];
703b632e 204 if (child.id == "feedCatHolder") {
befc807f 205 parent.debug(child.id);
c3f348c2 206 var fcat = child.lastChild;
703b632e 207 for (j = 0; j < fcat.childNodes.length; j++) {
befc807f 208 var feed = fcat.childNodes[j];
703b632e
AD
209 feed.className = feed.className.replace("Selected", "");
210 }
211 }
befc807f 212 }
703b632e 213 }
e828e31e
AD
214}
215
216
217function cleanSelected(element) {
218 var content = document.getElementById(element);
f0601b87
AD
219
220 for (i = 0; i < content.rows.length; i++) {
221 content.rows[i].className = content.rows[i].className.replace("Selected", "");
222 }
f0601b87
AD
223}
224
225function getVisibleUnreadHeadlines() {
226 var content = document.getElementById("headlinesList");
227
228 var rows = new Array();
229
230 for (i = 0; i < content.rows.length; i++) {
231 var row_id = content.rows[i].id.replace("RROW-", "");
232 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
233 rows.push(row_id);
234 }
235 }
236 return rows;
237}
238
239function getVisibleHeadlineIds() {
240
241 var content = document.getElementById("headlinesList");
242
243 var rows = new Array();
244
245 for (i = 0; i < content.rows.length; i++) {
246 var row_id = content.rows[i].id.replace("RROW-", "");
247 if (row_id.length > 0) {
248 rows.push(row_id);
249 }
250 }
251 return rows;
252}
253
254function getFirstVisibleHeadlineId() {
255 var rows = getVisibleHeadlineIds();
256 return rows[0];
257}
258
259function getLastVisibleHeadlineId() {
260 var rows = getVisibleHeadlineIds();
261 return rows[rows.length-1];
262}
263
264function markHeadline(id) {
265 var row = document.getElementById("RROW-" + id);
266 if (row) {
35f3c923
AD
267 var is_active = false;
268
269 if (row.className.match("Active")) {
270 is_active = true;
271 }
272 row.className = row.className.replace("Selected", "");
273 row.className = row.className.replace("Active", "");
274 row.className = row.className.replace("Insensitive", "");
275
276 if (is_active) {
277 row.className = row.className = "Active";
278 }
279
72020095
AD
280 var check = document.getElementById("RCHK-" + id);
281
282 if (check) {
283 check.checked = true;
284 }
285
35f3c923
AD
286 row.className = row.className + "Selected";
287
f0601b87
AD
288 }
289}
290
291function getFeedIds() {
292 var content = document.getElementById("feedsList");
293
294 var rows = new Array();
295
296 for (i = 0; i < content.rows.length; i++) {
297 var id = content.rows[i].id.replace("FEEDR-", "");
298 if (id.length > 0) {
299 rows.push(id);
300 }
301 }
302
303 return rows;
304}
13ad9102 305
76b4eae1
AD
306function setCookie(name, value, lifetime, path, domain, secure) {
307
308 var d = false;
309
310 if (lifetime) {
311 d = new Date();
312 d.setTime(lifetime * 1000);
313 }
314
315 int_setCookie(name, value, d, path, domain, secure);
316
317}
318
319function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
320 document.cookie= name + "=" + escape(value) +
321 ((expires) ? "; expires=" + expires.toGMTString() : "") +
322 ((path) ? "; path=" + path : "") +
323 ((domain) ? "; domain=" + domain : "") +
324 ((secure) ? "; secure" : "");
325}
326
76b4eae1
AD
327function delCookie(name, path, domain) {
328 if (getCookie(name)) {
329 document.cookie = name + "=" +
330 ((path) ? ";path=" + path : "") +
331 ((domain) ? ";domain=" + domain : "" ) +
332 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
333 }
334}
335
336
ac43eba1
AD
337function getCookie(name) {
338
339 var dc = document.cookie;
340 var prefix = name + "=";
341 var begin = dc.indexOf("; " + prefix);
342 if (begin == -1) {
343 begin = dc.indexOf(prefix);
344 if (begin != 0) return null;
345 }
346 else {
347 begin += 2;
348 }
349 var end = document.cookie.indexOf(";", begin);
350 if (end == -1) {
351 end = dc.length;
352 }
353 return unescape(dc.substring(begin + prefix.length, end));
354}
355
1a66d16e
AD
356function disableContainerChildren(id, disable, doc) {
357
358 if (!doc) doc = document;
359
360 var container = doc.getElementById(id);
ac43eba1
AD
361
362 for (var i = 0; i < container.childNodes.length; i++) {
363 var child = container.childNodes[i];
364
d5224f0d
AD
365 try {
366 child.disabled = disable;
367 } catch (E) {
368
369 }
ac43eba1
AD
370
371 if (disable) {
372 if (child.className && child.className.match("button")) {
373 child.className = "disabledButton";
374 }
375 } else {
376 if (child.className && child.className.match("disabledButton")) {
377 child.className = "button";
378 }
d5224f0d 379 }
ac43eba1
AD
380 }
381
382}
7726fa02 383
e828e31e
AD
384function gotoPreferences() {
385 document.location.href = "prefs.php";
386}
387
388function gotoMain() {
389 document.location.href = "tt-rss.php";
390}
391
8158c57a
AD
392function gotoExportOpml() {
393 document.location.href = "opml.php?op=Export";
394}
86741347
AD
395
396function getActiveFeedId() {
397 return getCookie("ttrss_vf_actfeed");
398}
399
400function setActiveFeedId(id) {
401 return setCookie("ttrss_vf_actfeed", id);
402}
090e250b
AD
403
404var xmlhttp_rpc = false;
405
406/*@cc_on @*/
407/*@if (@_jscript_version >= 5)
408// JScript gives us Conditional compilation, we can cope with old IE versions.
409// and security blocked creation of the objects.
410try {
411 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
412} catch (e) {
413 try {
414 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
415 } catch (E) {
416 xmlhttp_rpc = false;
417 }
418}
419@end @*/
420
421if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
422 xmlhttp_rpc = new XMLHttpRequest();
423}
424
e8ef3b97 425function parse_counters(reply, f_document, title_obj, scheduled_call) {
1a6a9555
AD
426 try {
427 for (var l = 0; l < reply.childNodes.length; l++) {
9cbca41f
AD
428 if (!reply.childNodes[l] ||
429 typeof(reply.childNodes[l].getAttribute) == "undefined") {
6043fb7e
AD
430 // where did this come from?
431 continue;
432 }
433
1a6a9555
AD
434 var id = reply.childNodes[l].getAttribute("id");
435 var t = reply.childNodes[l].getAttribute("type");
436 var ctr = reply.childNodes[l].getAttribute("counter");
023fe037
AD
437 var error = reply.childNodes[l].getAttribute("error");
438 var has_img = reply.childNodes[l].getAttribute("hi");
fb1fb4ab 439 var updated = reply.childNodes[l].getAttribute("updated");
1a6a9555
AD
440
441 if (id == "global-unread") {
3bdb368b
AD
442 title_obj.global_unread = ctr;
443 title_obj.updateTitle();
1a6a9555
AD
444 continue;
445 }
446
447 if (t == "category") {
448 var catctr = f_document.getElementById("FCATCTR-" + id);
449 if (catctr) {
450 catctr.innerHTML = "(" + ctr + " unread)";
451 }
452 continue;
453 }
454
455 var feedctr = f_document.getElementById("FEEDCTR-" + id);
456 var feedu = f_document.getElementById("FEEDU-" + id);
457 var feedr = f_document.getElementById("FEEDR-" + id);
023fe037 458 var feed_img = f_document.getElementById("FIMG-" + id);
fb1fb4ab
AD
459 var feedlink = f_document.getElementById("FEEDL-" + id);
460
461 if (updated && feedlink) {
462 if (error) {
463 feedlink.title = "Error: " + error + " (" + updated + ")";
464 } else {
465 feedlink.title = "Updated: " + updated;
466 }
467 }
023fe037 468
1a6a9555 469 if (feedctr && feedu && feedr) {
e8ef3b97
AD
470
471 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
472 var hf = title_obj.parent.frames["headlines-frame"];
473 hf.location.reload(true);
474 }
1a6a9555
AD
475
476 feedu.innerHTML = ctr;
023fe037 477
426d3c57
AD
478 if (error) {
479 feedr.className = feedr.className.replace("feed", "error");
480 } else if (id > 0) {
481 feedr.className = feedr.className.replace("error", "feed");
023fe037 482 }
1a6a9555
AD
483
484 if (ctr > 0) {
485 feedctr.className = "odd";
486 if (!feedr.className.match("Unread")) {
487 var is_selected = feedr.className.match("Selected");
488
489 feedr.className = feedr.className.replace("Selected", "");
490 feedr.className = feedr.className.replace("Unread", "");
491
492 feedr.className = feedr.className + "Unread";
493
494 if (is_selected) {
495 feedr.className = feedr.className + "Selected";
496 }
497
498 }
499 } else {
500 feedctr.className = "invisible";
501 feedr.className = feedr.className.replace("Unread", "");
502 }
503 }
504 }
505 } catch (e) {
83f043bb 506 exception_error("parse_counters", e);
1a6a9555
AD
507 }
508}
509
3bdb368b
AD
510// this one is called from feedlist context
511// thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
512
4f3a84f4 513function all_counters_callback() {
090e250b 514 if (xmlhttp_rpc.readyState == 4) {
7719618b 515 try {
3866b046 516 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
7719618b
AD
517 notify("[all_counters_callback] backend did not return valid XML");
518 return;
519 }
894ebcf5
AD
520
521 if (!parent.frames["feeds-frame"]) {
522 notify("[all_counters_callback] no parent feeds-frame");
523 return;
524 }
525
7719618b 526 var reply = xmlhttp_rpc.responseXML.firstChild;
7719618b 527 var f_document = parent.frames["feeds-frame"].document;
280ee9a3 528
3bdb368b 529 parse_counters(reply, f_document, parent);
7719618b 530
7719618b
AD
531 } catch (e) {
532 exception_error("all_counters_callback", e);
090e250b
AD
533 }
534 }
535}
536
4f3a84f4 537function update_all_counters(feed) {
090e250b 538 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 539 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
540
541 if (feed > 0) {
542 query = query + "&aid=" + feed;
543 }
544
090e250b 545 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 546 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
547 xmlhttp_rpc.send(null);
548 }
549}
7dc66a61
AD
550
551function popupHelp(tid) {
552 var w = window.open("backend.php?op=help&tid=" + tid,
553 "Popup Help",
554 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
555}
b6644d29
AD
556
557/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
558 * * @author Sundar Dorai-Raj
559 * * Email: sdoraira@vt.edu
560 * * This program is free software; you can redistribute it and/or
561 * * modify it under the terms of the GNU General Public License
562 * * as published by the Free Software Foundation; either version 2
563 * * of the License, or (at your option) any later version,
564 * * provided that any use properly credits the author.
565 * * This program is distributed in the hope that it will be useful,
566 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
567 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
568 * * GNU General Public License for more details at http://www.gnu.org * * */
569
570 var numbers=".0123456789";
571 function isNumeric(x) {
572 // is x a String or a character?
573 if(x.length>1) {
574 // remove negative sign
575 x=Math.abs(x)+"";
576 for(j=0;j<x.length;j++) {
577 // call isNumeric recursively for each character
578 number=isNumeric(x.substring(j,j+1));
579 if(!number) return number;
580 }
581 return number;
582 }
583 else {
584 // if x is number return true
585 if(numbers.indexOf(x)>=0) return true;
586 return false;
587 }
588 }
589
3745788e
AD
590
591function hideOrShowFeeds(doc, hide) {
592
3ed751d4
AD
593 if (!doc.styleSheets) return;
594
3745788e
AD
595 var css_rules = doc.styleSheets[0].cssRules;
596
bbf4d0b2
AD
597 if (!css_rules || !css_rules.length) return;
598
3745788e
AD
599 for (i = 0; i < css_rules.length; i++) {
600 var rule = css_rules[i];
601
602 if (rule.selectorText == "ul.feedList li.feed") {
603 if (!hide) {
604 rule.style.display = "block";
605 } else {
606 rule.style.display = "none";
607 }
608 }
609
610 }
611
612}
613
35f3c923
AD
614function selectTableRow(r, do_select) {
615 r.className = r.className.replace("Selected", "");
616
617 if (do_select) {
618 r.className = r.className + "Selected";
619 }
620}
621
6c12c809
AD
622function selectTableRowById(elem_id, check_id, do_select) {
623
624 try {
625
626 var row = document.getElementById(elem_id);
627
628 if (row) {
629 selectTableRow(row, do_select);
630 }
631
632 var check = document.getElementById(check_id);
633
634 if (check) {
635 check.checked = do_select;
636 }
637 } catch (e) {
638 exception_error("selectTableRowById", e);
639 }
640}
641
1572afe5 642function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 643 classcheck, reset_others) {
3745788e 644
35f3c923
AD
645 var content = document.getElementById(content_id);
646
647 if (!content) {
648 alert("[selectTableRows] Element " + content_id + " not found.");
649 return;
650 }
651
652 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
653 if (!classcheck || content.rows[i].className.match(classcheck)) {
654
655 if (content.rows[i].id.match(prefix)) {
656 selectTableRow(content.rows[i], do_select);
649e0af9
AD
657
658 var row_id = content.rows[i].id.replace(prefix, "");
659 var check = document.getElementById(check_prefix + row_id);
3055bc41 660
649e0af9
AD
661 if (check) {
662 check.checked = do_select;
663 }
664 } else if (reset_others) {
665 selectTableRow(content.rows[i], false);
7d8d10c6
AD
666
667 var row_id = content.rows[i].id.replace(prefix, "");
668 var check = document.getElementById(check_prefix + row_id);
669
670 if (check) {
671 check.checked = false;
672 }
673
1572afe5 674 }
649e0af9
AD
675 } else if (reset_others) {
676 selectTableRow(content.rows[i], false);
7d8d10c6
AD
677
678 var row_id = content.rows[i].id.replace(prefix, "");
679 var check = document.getElementById(check_prefix + row_id);
680
681 if (check) {
682 check.checked = false;
683 }
684
3055bc41 685 }
35f3c923 686 }
295f9b42 687}
91ff844a
AD
688
689function getSelectedTableRowIds(content_id, prefix) {
690
691 var content = document.getElementById(content_id);
692
693 if (!content) {
694 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
695 return;
696 }
697
698 var sel_rows = new Array();
699
700 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
701 if (content.rows[i].id.match(prefix) &&
702 content.rows[i].className.match("Selected")) {
703
91ff844a
AD
704 var row_id = content.rows[i].id.replace(prefix + "-", "");
705 sel_rows.push(row_id);
706 }
707 }
708
709 return sel_rows;
710
711}
712
386cbf27
AD
713function toggleSelectRowById(sender, id) {
714 var row = document.getElementById(id);
715
716 if (sender.checked) {
717 if (!row.className.match("Selected")) {
718 row.className = row.className + "Selected";
719 }
720 } else {
721 if (row.className.match("Selected")) {
722 row.className = row.className.replace("Selected", "");
723 }
724 }
725}
726
b92e6209
AD
727function toggleSelectListRow(sender) {
728 var parent_row = sender.parentNode;
729
730 if (sender.checked) {
731 if (!parent_row.className.match("Selected")) {
732 parent_row.className = parent_row.className + "Selected";
733 }
734 } else {
735 if (parent_row.className.match("Selected")) {
736 parent_row.className = parent_row.className.replace("Selected", "");
737 }
738 }
739}
740
386cbf27 741
1572afe5
AD
742function toggleSelectRow(sender) {
743 var parent_row = sender.parentNode.parentNode;
744
745 if (sender.checked) {
746 if (!parent_row.className.match("Selected")) {
747 parent_row.className = parent_row.className + "Selected";
748 }
749 } else {
750 if (parent_row.className.match("Selected")) {
751 parent_row.className = parent_row.className.replace("Selected", "");
752 }
753 }
754}
755
3866b046
AD
756function openExternalUrl(url) {
757 var w = window.open(url);
758}
1572afe5 759
1da76274 760function getRelativeFeedId(list, id, direction, unread_only) {
7b433d8c
AD
761 if (!id) {
762 if (direction == "next") {
763 for (i = 0; i < list.childNodes.length; i++) {
764 var child = list.childNodes[i];
1da76274 765 if (child.id && child.id == "feedCatHolder") {
c3f348c2 766 if (child.lastChild) {
7b433d8c
AD
767 var cr = getRelativeFeedId(child.firstChild, id, direction);
768 if (cr) return cr;
769 }
1da76274 770 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
771 return child.id.replace('FEEDR-', '');
772 }
773 }
774 }
775
776 // FIXME select last feed doesn't work when only unread feeds are visible
777
778 if (direction == "prev") {
779 for (i = list.childNodes.length-1; i >= 0; i--) {
780 var child = list.childNodes[i];
781 if (child.id == "feedCatHolder") {
782 if (child.firstChild) {
783 var cr = getRelativeFeedId(child.firstChild, id, direction);
784 if (cr) return cr;
785 }
786 } else if (child.id.match("FEEDR-")) {
787
788 if (getCookie("ttrss_vf_hreadf") == 1) {
789 if (child.className != "feed") {
790 alert(child.className);
791 return child.id.replace('FEEDR-', '');
792 }
793 } else {
794 return child.id.replace('FEEDR-', '');
795 }
796 }
797 }
798 }
799 } else {
800
801 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
802
1da76274
AD
803 if (getCookie("ttrss_vf_hreadf") == 1) {
804 unread_only = true;
805 }
806
7b433d8c
AD
807 if (direction == "next") {
808
1da76274 809 var e = feed;
7b433d8c 810
1da76274 811 while (e) {
7b433d8c 812
1da76274
AD
813 if (e.nextSibling) {
814
815 e = e.nextSibling;
816
817 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 818
1da76274 819 var this_cat = e.parentNode.parentNode;
7b433d8c 820
1da76274 821 e = false;
7b433d8c 822
1da76274
AD
823 if (this_cat && this_cat.nextSibling) {
824 while (!e && this_cat.nextSibling) {
825 this_cat = this_cat.nextSibling;
826 if (this_cat.id == "feedCatHolder") {
827 e = this_cat.firstChild.firstChild;
7b433d8c
AD
828 }
829 }
7b433d8c 830 }
1da76274
AD
831
832 } else {
833 e = false;
834 }
835
836 if (e) {
e686782e
AD
837 if (!unread_only || (unread_only && e.className != "feed" &&
838 e.className != "error")) {
1da76274
AD
839 return e.id.replace("FEEDR-", "");
840 }
841 }
7b433d8c 842 }
1da76274 843
7b433d8c
AD
844 } else if (direction == "prev") {
845
1da76274 846 var e = feed;
7b433d8c 847
1da76274 848 while (e) {
7b433d8c 849
1da76274
AD
850 if (e.previousSibling) {
851
852 e = e.previousSibling;
853
854 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 855
1da76274 856 var this_cat = e.parentNode.parentNode;
7b433d8c 857
1da76274
AD
858 e = false;
859
860 if (this_cat && this_cat.previousSibling) {
861 while (!e && this_cat.previousSibling) {
862 this_cat = this_cat.previousSibling;
863 if (this_cat.id == "feedCatHolder") {
864 e = this_cat.firstChild.lastChild;
7b433d8c
AD
865 }
866 }
7b433d8c 867 }
1da76274
AD
868
869 } else {
870 e = false;
871 }
872
873 if (e) {
e686782e
AD
874 if (!unread_only || (unread_only && e.className != "feed" &&
875 e.className != "error")) {
1da76274
AD
876 return e.id.replace("FEEDR-", "");
877 }
878 }
879 }
7b433d8c
AD
880 }
881 }
882}
36aab70f
AD
883
884function showBlockElement(id) {
885 var elem = document.getElementById(id);
886
887 if (elem) {
888 elem.style.display = "block";
889 } else {
890 alert("[showBlockElement] can't find element with id " + id);
891 }
892}
893
a9b0bfd5
AD
894function hideParentElement(e) {
895 e.parentNode.style.display = "none";
896}
1b0809ae
AD
897
898function dropboxSelect(e, v) {
899 for (i = 0; i < e.length; i++) {
900 if (e[i].value == v) {
901 e.selectedIndex = i;
902 break;
903 }
904 }
905}
0ee1d1a0
AD
906
907// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
908// bugfixed just a little bit :-)
909function getURLParam(strParamName){
910 var strReturn = "";
911 var strHref = window.location.href;
912
913 if (strHref.indexOf("#") == strHref.length-1) {
914 strHref = strHref.substring(0, strHref.length-1);
915 }
916
917 if ( strHref.indexOf("?") > -1 ){
918 var strQueryString = strHref.substr(strHref.indexOf("?"));
919 var aQueryString = strQueryString.split("&");
920 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
921 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
922 var aParam = aQueryString[iParam].split("=");
923 strReturn = aParam[1];
924 break;
925 }
926 }
927 }
928 return strReturn;
929}
930
cf1bc085
AD
931function leading_zero(p) {
932 var s = String(p);
933 if (s.length == 1) s = "0" + s;
934 return s;
935}
c38c2b69
AD
936
937function center_element(e) {
c38c2b69 938
5917a8e4
AD
939 try {
940 var c_width = document.body.clientWidth;
941 var c_height = document.body.clientHeight;
942
943 var c_scroll = document.body.scrollTop;
c38c2b69 944
5917a8e4
AD
945 var e_width = e.clientWidth;
946 var e_height = e.clientHeight;
947
948 var set_y = (c_height / 2) + c_scroll - (e_height / 2);
949 var set_x = (c_width / 2) - (e_width / 2);
950
951 e.style.top = set_y + "px";
952 e.style.left = set_x + "px";
953 } catch (e) {
954 exception_error("center_element", e);
955 }
c38c2b69 956}
7b5c6012 957
e5d758e3
AD
958function closeInfoBox() {
959 var box = document.getElementById('infoBox');
960 var shadow = document.getElementById('infoBoxShadow');
961
962 if (shadow) {
963 shadow.style.display = "none";
964 } else if (box) {
965 box.style.display = "none";
966 }
967
968 enableHotkeys();
969}
970
971
7b5c6012
AD
972function displayDlg(id, param) {
973
974 if (!xmlhttp_ready(xmlhttp)) {
975 printLockingError();
976 return
977 }
978
979 notify("");
980
981 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
982 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 983 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
984 xmlhttp.send(null);
985
986 disableHotkeys();
2371c520 987
7b5c6012
AD
988}
989
e5d758e3 990function infobox_submit_callback() {
7b5c6012
AD
991 if (xmlhttp.readyState == 4) {
992 notify(xmlhttp.responseText);
e5d758e3 993 closeInfoBox();
7b5c6012
AD
994
995 // called from prefs, reload tab
996 if (active_tab) {
997 selectTab(active_tab, false);
998 }
999 }
1000}
1001
e5d758e3 1002function infobox_callback() {
7b5c6012 1003 if (xmlhttp.readyState == 4) {
e5d758e3
AD
1004 var box = document.getElementById('infoBox');
1005 var shadow = document.getElementById('infoBoxShadow');
1006 if (box) {
1007 box.innerHTML=xmlhttp.responseText;
1008 if (shadow) {
1009 shadow.style.display = "block";
1010 } else {
1011 box.style.display = "block";
1012 }
1013 }
1014 }
7b5c6012
AD
1015}
1016
1017function qaddFilter() {
1018
1019 if (!xmlhttp_ready(xmlhttp)) {
1020 printLockingError();
1021 return
1022 }
1023
1024 var regexp = document.getElementById("fadd_regexp");
1025 var match = document.getElementById("fadd_match");
1026 var feed = document.getElementById("fadd_feed");
1027 var action = document.getElementById("fadd_action");
1028
1029 if (regexp.value.length == 0) {
e5d758e3 1030 alert("Missing filter expression.");
7b5c6012
AD
1031 } else {
1032 notify("Adding filter...");
1033
1034 var v_match = match[match.selectedIndex].text;
1035 var feed_id = feed[feed.selectedIndex].id;
1036 var action_id = action[action.selectedIndex].id;
1037
1038 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add&regexp=" +
1039 param_escape(regexp.value) + "&match=" + v_match +
1040 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
1041
e5d758e3 1042 xmlhttp.onreadystatechange=infobox_submit_callback;
7b5c6012
AD
1043 xmlhttp.send(null);
1044
1045 regexp.value = "";
1046 }
1047
1048}
1049
2371c520
AD
1050function toggleSubmitNotEmpty(e, submit_id) {
1051 try {
1052 document.getElementById(submit_id).disabled = (e.value == "")
1053 } catch (e) {
1054 exception_error("toggleSubmitNotEmpty", e);
1055 }
1056}
1d7bf5a0 1057
605f7d46
AD
1058function isValidURL(s) {
1059 return s.match("http://") != null || s.match("https://") != null;
1060}