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