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