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