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