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