]> git.wh0rd.org - tt-rss.git/blame - functions.js
opera compatibility fixes
[tt-rss.git] / functions.js
CommitLineData
760966c1
AD
1var hotkeys_enabled = true;
2
a7565293
AD
3var xmlhttp_rpc = Ajax.getTransport();
4
292a8a12 5function browser_has_opacity() {
605f7d46
AD
6 return navigator.userAgent.match("Gecko") != null ||
7 navigator.userAgent.match("Opera") != null;
292a8a12
AD
8}
9
7c620da8
AD
10function is_opera() {
11 return navigator.userAgent.match("Opera");
12}
13
55160955 14function exception_error(location, e, silent) {
83f043bb
AD
15 var msg;
16
17 if (e.fileName) {
18 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
19
20 msg = "Exception: " + e.name + ", " + e.message +
21 "\nFunction: " + location + "()" +
22 "\nLocation: " + base_fname + ":" + e.lineNumber;
ee1f45f4 23
83f043bb
AD
24 } else {
25 msg = "Exception: " + e + "\nFunction: " + location + "()";
26 }
27
ee1f45f4
AD
28 debug("<b>EXCEPTION: " + msg + "</b>");
29
55160955
AD
30 if (!silent) {
31 alert(msg);
32 }
7719618b
AD
33}
34
760966c1
AD
35function disableHotkeys() {
36 hotkeys_enabled = false;
37}
38
39function enableHotkeys() {
40 hotkeys_enabled = true;
41}
42
c0e5a40e
AD
43function xmlhttp_ready(obj) {
44 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
45}
46
9cfc649a
AD
47function notify_callback() {
48 var container = document.getElementById('notify');
49 if (xmlhttp.readyState == 4) {
50 container.innerHTML=xmlhttp.responseText;
51 }
52}
53
54function rpc_notify_callback() {
55 var container = document.getElementById('notify');
56 if (xmlhttp_rpc.readyState == 4) {
57 container.innerHTML=xmlhttp_rpc.responseText;
58 }
59}
60
7726fa02
AD
61function param_escape(arg) {
62 if (typeof encodeURIComponent != 'undefined')
63 return encodeURIComponent(arg);
64 else
65 return escape(arg);
66}
67
68function param_unescape(arg) {
69 if (typeof decodeURIComponent != 'undefined')
70 return decodeURIComponent(arg);
71 else
72 return unescape(arg);
73}
74
508a81e1
AD
75function delay(gap) {
76 var then,now;
77 then=new Date().getTime();
78 now=then;
79 while((now-then)<gap) {
80 now=new Date().getTime();
81 }
82}
7726fa02 83
ce3bf408
AD
84var notify_hide_timerid = false;
85var notify_last_doc = false;
86
59a543f0
AD
87var notify_effect = false;
88
ce3bf408
AD
89function hide_notify() {
90 if (notify_last_doc) {
91 var n = notify_last_doc.getElementById("notify");
292a8a12 92 if (browser_has_opacity()) {
ce3bf408 93 if (notify_opacity >= 0) {
0655a1d5 94 notify_opacity = notify_opacity - 0.1;
ce3bf408 95 n.style.opacity = notify_opacity;
292a8a12 96 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
ce3bf408
AD
97 } else {
98 n.style.display = "none";
292a8a12 99 n.style.opacity = 1;
ce3bf408
AD
100 }
101 } else {
102 n.style.display = "none";
103 }
8dcfffd0 104 }
c05608c2
AD
105}
106
0530ddd8 107function notify_real(msg, doc, no_hide, is_err) {
7726fa02 108
ce3bf408
AD
109 var n = doc.getElementById("notify");
110 var nb = doc.getElementById("notify_body");
7726fa02 111
c05608c2 112 if (!n || !nb) return;
f0601b87 113
0655a1d5
AD
114 if (notify_hide_timerid) {
115 window.clearTimeout(notify_hide_timerid);
116 }
117
118 notify_last_doc = doc;
119 notify_opacity = 1;
120
8dcfffd0 121 if (msg == "") {
0655a1d5
AD
122 if (n.style.display == "block") {
123 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
124 }
125 return;
7726fa02 126 } else {
0ceded7a 127 n.style.display = "block";
8dcfffd0 128 }
7726fa02 129
0530ddd8 130 if (is_err) {
caa53a7c
AD
131 n.style.backgroundColor = "#ffcccc";
132 n.style.color = "black";
0530ddd8
AD
133 n.style.borderColor = "#ff0000";
134 } else {
135 n.style.backgroundColor = "#fff7d5";
136 n.style.borderColor = "#d7c47a";
137 n.style.color = "black";
138 }
139
0ceded7a
AD
140 nb.innerHTML = msg;
141
4d4200a8 142 if (!no_hide) {
292a8a12 143 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 144 }
ce3bf408
AD
145}
146
0530ddd8 147function p_notify(msg, no_hide, is_err) {
9cb99906 148 notify_real(msg, document, no_hide, is_err);
ce3bf408
AD
149}
150
0530ddd8
AD
151function notify(msg, no_hide, is_err) {
152 notify_real(msg, document, no_hide, is_err);
7726fa02
AD
153}
154
508a81e1 155function printLockingError() {
f0601b87 156 notify("Please wait until operation finishes");}
508a81e1 157
13ad9102 158function hotkey_handler(e) {
760966c1 159
ee1f45f4 160 try {
2e02b896 161
ee1f45f4
AD
162 var keycode;
163
164 if (!hotkeys_enabled) return;
165
166 if (window.event) {
167 keycode = window.event.keyCode;
168 } else if (e) {
169 keycode = e.which;
170 }
d437c8cf 171
ee1f45f4
AD
172 var m_ctx = getMainContext();
173 var f_ctx = getFeedsContext();
174 var h_ctx = getHeadlinesContext();
d437c8cf 175
ee1f45f4
AD
176 if (keycode == 82) { // r
177 return m_ctx.scheduleFeedUpdate(true);
178 }
0a383013
AD
179
180 if (keycode == 83) { // r
181 return m_ctx.displayDlg("search", getActiveFeedId());
182 }
183
ee1f45f4
AD
184 if (keycode == 85) { // u
185 if (getActiveFeedId()) {
767e2486 186 return f_ctx.viewfeed(getActiveFeedId(), "ForceUpdate");
ee1f45f4
AD
187 }
188 }
189
190 if (keycode == 65) { // a
191 return m_ctx.toggleDispRead();
192 }
193
9251df44 194 var f_doc = document;
ee1f45f4
AD
195 var feedlist = f_doc.getElementById('feedList');
196
197 if (keycode == 74) { // j
198 var feed = getActiveFeedId();
199 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
767e2486 200 if (new_feed) viewfeed(new_feed, '');
ee1f45f4
AD
201 }
202
203 if (keycode == 75) { // k
204 var feed = getActiveFeedId();
205 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
767e2486 206 if (new_feed) viewfeed(new_feed, '');
7b433d8c 207 }
9cfc649a 208
ee1f45f4 209 if (keycode == 78 || keycode == 40) { // n, down
746a0d5e 210 if (typeof h_ctx.moveToPost != 'undefined') {
e59a2f12
AD
211 return h_ctx.moveToPost('next');
212 }
ee1f45f4
AD
213 }
214
215 if (keycode == 80 || keycode == 38) { // p, up
746a0d5e 216 if (typeof h_ctx.moveToPost != 'undefined') {
e59a2f12
AD
217 return h_ctx.moveToPost('prev');
218 }
ee1f45f4
AD
219 }
220
221 if (typeof localHotkeyHandler != 'undefined') {
222 try {
223 localHotkeyHandler(keycode);
224 } catch (e) {
225 exception_error("hotkey_handler, local:", e);
226 }
227 }
228 } catch (e) {
229 exception_error("hotkey_handler", e);
230 }
13ad9102
AD
231}
232
e828e31e 233function cleanSelectedList(element) {
f0601b87
AD
234 var content = document.getElementById(element);
235
703b632e
AD
236 if (!document.getElementById("feedCatHolder")) {
237 for (i = 0; i < content.childNodes.length; i++) {
238 var child = content.childNodes[i];
d0bb308e
AD
239 try {
240 child.className = child.className.replace("Selected", "");
241 } catch (e) {
242 //
243 }
703b632e
AD
244 }
245 } else {
246 for (i = 0; i < content.childNodes.length; i++) {
247 var child = content.childNodes[i];
703b632e 248 if (child.id == "feedCatHolder") {
9cb99906 249 debug(child.id);
c3f348c2 250 var fcat = child.lastChild;
703b632e 251 for (j = 0; j < fcat.childNodes.length; j++) {
befc807f 252 var feed = fcat.childNodes[j];
703b632e
AD
253 feed.className = feed.className.replace("Selected", "");
254 }
255 }
befc807f 256 }
703b632e 257 }
e828e31e
AD
258}
259
260
261function cleanSelected(element) {
262 var content = document.getElementById(element);
f0601b87
AD
263
264 for (i = 0; i < content.rows.length; i++) {
265 content.rows[i].className = content.rows[i].className.replace("Selected", "");
266 }
f0601b87
AD
267}
268
269function getVisibleUnreadHeadlines() {
270 var content = document.getElementById("headlinesList");
271
272 var rows = new Array();
273
274 for (i = 0; i < content.rows.length; i++) {
275 var row_id = content.rows[i].id.replace("RROW-", "");
276 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
277 rows.push(row_id);
278 }
279 }
280 return rows;
281}
282
283function getVisibleHeadlineIds() {
284
285 var content = document.getElementById("headlinesList");
286
287 var rows = new Array();
288
289 for (i = 0; i < content.rows.length; i++) {
290 var row_id = content.rows[i].id.replace("RROW-", "");
291 if (row_id.length > 0) {
292 rows.push(row_id);
293 }
294 }
295 return rows;
296}
297
298function getFirstVisibleHeadlineId() {
299 var rows = getVisibleHeadlineIds();
300 return rows[0];
301}
302
303function getLastVisibleHeadlineId() {
304 var rows = getVisibleHeadlineIds();
305 return rows[rows.length-1];
306}
307
308function markHeadline(id) {
309 var row = document.getElementById("RROW-" + id);
310 if (row) {
35f3c923
AD
311 var is_active = false;
312
313 if (row.className.match("Active")) {
314 is_active = true;
315 }
316 row.className = row.className.replace("Selected", "");
317 row.className = row.className.replace("Active", "");
318 row.className = row.className.replace("Insensitive", "");
319
320 if (is_active) {
321 row.className = row.className = "Active";
322 }
323
72020095
AD
324 var check = document.getElementById("RCHK-" + id);
325
326 if (check) {
327 check.checked = true;
328 }
329
35f3c923
AD
330 row.className = row.className + "Selected";
331
f0601b87
AD
332 }
333}
334
335function getFeedIds() {
336 var content = document.getElementById("feedsList");
337
338 var rows = new Array();
339
340 for (i = 0; i < content.rows.length; i++) {
341 var id = content.rows[i].id.replace("FEEDR-", "");
342 if (id.length > 0) {
343 rows.push(id);
344 }
345 }
346
347 return rows;
348}
13ad9102 349
76b4eae1
AD
350function setCookie(name, value, lifetime, path, domain, secure) {
351
352 var d = false;
353
354 if (lifetime) {
355 d = new Date();
356 d.setTime(lifetime * 1000);
357 }
358
359 int_setCookie(name, value, d, path, domain, secure);
360
361}
362
363function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
364 document.cookie= name + "=" + escape(value) +
365 ((expires) ? "; expires=" + expires.toGMTString() : "") +
366 ((path) ? "; path=" + path : "") +
367 ((domain) ? "; domain=" + domain : "") +
368 ((secure) ? "; secure" : "");
369}
370
76b4eae1
AD
371function delCookie(name, path, domain) {
372 if (getCookie(name)) {
373 document.cookie = name + "=" +
374 ((path) ? ";path=" + path : "") +
375 ((domain) ? ";domain=" + domain : "" ) +
376 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
377 }
378}
379
380
ac43eba1
AD
381function getCookie(name) {
382
383 var dc = document.cookie;
384 var prefix = name + "=";
385 var begin = dc.indexOf("; " + prefix);
386 if (begin == -1) {
387 begin = dc.indexOf(prefix);
388 if (begin != 0) return null;
389 }
390 else {
391 begin += 2;
392 }
393 var end = document.cookie.indexOf(";", begin);
394 if (end == -1) {
395 end = dc.length;
396 }
397 return unescape(dc.substring(begin + prefix.length, end));
398}
399
1a66d16e
AD
400function disableContainerChildren(id, disable, doc) {
401
402 if (!doc) doc = document;
403
404 var container = doc.getElementById(id);
ac43eba1 405
4220b0bd
AD
406 if (!container) {
407 //alert("disableContainerChildren: element " + id + " not found");
408 return;
409 }
410
ac43eba1
AD
411 for (var i = 0; i < container.childNodes.length; i++) {
412 var child = container.childNodes[i];
413
d5224f0d
AD
414 try {
415 child.disabled = disable;
416 } catch (E) {
417
418 }
ac43eba1
AD
419
420 if (disable) {
421 if (child.className && child.className.match("button")) {
422 child.className = "disabledButton";
423 }
424 } else {
425 if (child.className && child.className.match("disabledButton")) {
426 child.className = "button";
427 }
d5224f0d 428 }
ac43eba1
AD
429 }
430
431}
7726fa02 432
e828e31e
AD
433function gotoPreferences() {
434 document.location.href = "prefs.php";
435}
436
437function gotoMain() {
438 document.location.href = "tt-rss.php";
439}
440
8158c57a
AD
441function gotoExportOpml() {
442 document.location.href = "opml.php?op=Export";
443}
86741347
AD
444
445function getActiveFeedId() {
33d13e72
AD
446// return getCookie("ttrss_vf_actfeed");
447 try {
448 debug("gAFID: " + getMainContext().active_feed_id);
449 return getMainContext().active_feed_id;
450 } catch (e) {
451 exception_error("getActiveFeedId", e);
452 }
86741347
AD
453}
454
0a6c4846
AD
455function activeFeedIsCat() {
456 return getMainContext().active_feed_is_cat;
457}
458
86741347 459function setActiveFeedId(id) {
33d13e72
AD
460// return setCookie("ttrss_vf_actfeed", id);
461 try {
5c365f60 462 debug("sAFID(" + id + ")");
33d13e72
AD
463 getMainContext().active_feed_id = id;
464 } catch (e) {
465 exception_error("setActiveFeedId", e);
466 }
86741347 467}
090e250b 468
ac378ad4 469function parse_counters(reply, scheduled_call) {
1a6a9555 470 try {
6b4163cb
AD
471 var f_document = document;
472 var title_obj = this.window;
ac378ad4 473
9e397d0f
AD
474 var feeds_found = 0;
475
f54f515f
AD
476 if (reply.firstChild && reply.firstChild.firstChild) {
477 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
478 reply = reply.firstChild;
479 }
480
ac378ad4
AD
481 debug("F_DOC: " + f_document + ", T_OBJ: " + title_obj);
482
1a6a9555 483 for (var l = 0; l < reply.childNodes.length; l++) {
9cbca41f
AD
484 if (!reply.childNodes[l] ||
485 typeof(reply.childNodes[l].getAttribute) == "undefined") {
6043fb7e
AD
486 // where did this come from?
487 continue;
488 }
489
1a6a9555
AD
490 var id = reply.childNodes[l].getAttribute("id");
491 var t = reply.childNodes[l].getAttribute("type");
492 var ctr = reply.childNodes[l].getAttribute("counter");
023fe037
AD
493 var error = reply.childNodes[l].getAttribute("error");
494 var has_img = reply.childNodes[l].getAttribute("hi");
fb1fb4ab 495 var updated = reply.childNodes[l].getAttribute("updated");
1a6a9555
AD
496
497 if (id == "global-unread") {
3bdb368b
AD
498 title_obj.global_unread = ctr;
499 title_obj.updateTitle();
1a6a9555
AD
500 continue;
501 }
7bf7e4d3
AD
502
503 if (id == "subscribed-feeds") {
504 feeds_found = ctr;
505 continue;
506 }
1a6a9555
AD
507
508 if (t == "category") {
509 var catctr = f_document.getElementById("FCATCTR-" + id);
510 if (catctr) {
511 catctr.innerHTML = "(" + ctr + " unread)";
512 }
513 continue;
514 }
515
516 var feedctr = f_document.getElementById("FEEDCTR-" + id);
517 var feedu = f_document.getElementById("FEEDU-" + id);
518 var feedr = f_document.getElementById("FEEDR-" + id);
023fe037 519 var feed_img = f_document.getElementById("FIMG-" + id);
fb1fb4ab 520 var feedlink = f_document.getElementById("FEEDL-" + id);
78d5212c 521 var feedupd = f_document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
522
523 if (updated && feedlink) {
524 if (error) {
525 feedlink.title = "Error: " + error + " (" + updated + ")";
526 } else {
527 feedlink.title = "Updated: " + updated;
528 }
529 }
023fe037 530
78d5212c
AD
531 if (updated && feedupd) {
532 if (error) {
533 feedupd.innerHTML = updated + " (Error)";
534 } else {
535 feedupd.innerHTML = updated;
536 }
537 }
538
1a6a9555 539 if (feedctr && feedu && feedr) {
e8ef3b97
AD
540
541 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
5b064721 542 viewCurrentFeed();
e8ef3b97 543 }
1a6a9555
AD
544
545 feedu.innerHTML = ctr;
023fe037 546
426d3c57
AD
547 if (error) {
548 feedr.className = feedr.className.replace("feed", "error");
549 } else if (id > 0) {
550 feedr.className = feedr.className.replace("error", "feed");
023fe037 551 }
1a6a9555
AD
552
553 if (ctr > 0) {
554 feedctr.className = "odd";
555 if (!feedr.className.match("Unread")) {
556 var is_selected = feedr.className.match("Selected");
557
558 feedr.className = feedr.className.replace("Selected", "");
559 feedr.className = feedr.className.replace("Unread", "");
560
561 feedr.className = feedr.className + "Unread";
562
563 if (is_selected) {
564 feedr.className = feedr.className + "Selected";
565 }
566
567 }
568 } else {
569 feedctr.className = "invisible";
570 feedr.className = feedr.className.replace("Unread", "");
571 }
572 }
573 }
9e397d0f 574
7553dd8b
AD
575 hideOrShowFeeds(getFeedsContext().document,
576 getInitParam("hide_read_feeds") == 1);
577
9e397d0f
AD
578 var feeds_stored = getMainContext().number_of_feeds;
579
580 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
581
582 if (feeds_stored != feeds_found) {
7bf7e4d3
AD
583 getMainContext().number_of_feeds = feeds_found;
584
585 if (feeds_stored != 0) {
9e397d0f 586 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 587 setTimeout('updateFeedList(false, false)', 50);
9e397d0f
AD
588 }
589 }
590
1a6a9555 591 } catch (e) {
83f043bb 592 exception_error("parse_counters", e);
1a6a9555
AD
593 }
594}
595
4f3a84f4 596function all_counters_callback() {
090e250b 597 if (xmlhttp_rpc.readyState == 4) {
7719618b 598 try {
3866b046 599 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
b00ed196 600 debug("[all_counters_callback] backend did not return valid XML");
7719618b
AD
601 return;
602 }
894ebcf5 603
6b4163cb 604 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
1cb7492d 605
7719618b 606 var reply = xmlhttp_rpc.responseXML.firstChild;
280ee9a3 607
f54f515f
AD
608 var counters = reply.firstChild;
609
610 parse_counters(counters);
1cb7492d
AD
611
612 var runtime = counters.nextSibling;
613
614 if (runtime) {
615 getMainContext().parse_runtime_info(runtime);
616 }
c9268ed5 617
cea51014 618 if (getInitParam("feeds_sort_by_unread") == 1) {
c9268ed5
AD
619 resort_feedlist();
620 }
293fa942
AD
621
622 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
623
7719618b
AD
624 } catch (e) {
625 exception_error("all_counters_callback", e);
090e250b
AD
626 }
627 }
628}
629
c9268ed5
AD
630function get_feed_entry_unread(doc, elem) {
631
632 var id = elem.id.replace("FEEDR-", "");
633
634 if (id <= 0) {
635 return -1;
636 }
637
638 try {
639 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
640 } catch (e) {
641 return -1;
642 }
643}
644
645function resort_category(doc, node) {
646 debug("resort_category: " + node);
647
648 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
649 for (i = 0; i < node.childNodes.length; i++) {
650 if (node.childNodes[i].nodeName != "LI") { continue; }
651
652 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
653 continue;
654 }
655
656 for (j = i+1; j < node.childNodes.length; j++) {
657 if (node.childNodes[j].nodeName != "LI") { continue; }
658
659 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
660 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
661
662 if (cur_val > tmp_val) {
663 tempnode_i = node.childNodes[i].cloneNode(true);
664 tempnode_j = node.childNodes[j].cloneNode(true);
665 node.replaceChild(tempnode_i, node.childNodes[j]);
666 node.replaceChild(tempnode_j, node.childNodes[i]);
667 }
668 }
669
670 }
671 }
672
673}
674
675function resort_feedlist() {
676 debug("resort_feedlist");
677
678 var fd = getFeedsContext().document;
679
680 if (fd.getElementById("feedCatHolder")) {
681
682 var feeds = fd.getElementById("feedList");
683 var child = feeds.firstChild;
684
685 while (child) {
686
687 if (child.id == "feedCatHolder") {
688 resort_category(fd, child.firstChild);
689 }
690
691 child = child.nextSibling;
692 }
693
694 } else {
695 resort_category(fd, fd.getElementById("feedList"));
696 }
697}
698
4f3a84f4 699function update_all_counters(feed) {
090e250b 700 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 701 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
702
703 if (feed > 0) {
704 query = query + "&aid=" + feed;
705 }
706
090e250b 707 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 708 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
709 xmlhttp_rpc.send(null);
710 }
711}
7dc66a61
AD
712
713function popupHelp(tid) {
714 var w = window.open("backend.php?op=help&tid=" + tid,
715 "Popup Help",
716 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
717}
b6644d29
AD
718
719/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
720 * * @author Sundar Dorai-Raj
721 * * Email: sdoraira@vt.edu
722 * * This program is free software; you can redistribute it and/or
723 * * modify it under the terms of the GNU General Public License
724 * * as published by the Free Software Foundation; either version 2
725 * * of the License, or (at your option) any later version,
726 * * provided that any use properly credits the author.
727 * * This program is distributed in the hope that it will be useful,
728 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
729 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
730 * * GNU General Public License for more details at http://www.gnu.org * * */
731
732 var numbers=".0123456789";
733 function isNumeric(x) {
734 // is x a String or a character?
735 if(x.length>1) {
736 // remove negative sign
737 x=Math.abs(x)+"";
738 for(j=0;j<x.length;j++) {
739 // call isNumeric recursively for each character
740 number=isNumeric(x.substring(j,j+1));
741 if(!number) return number;
742 }
743 return number;
744 }
745 else {
746 // if x is number return true
747 if(numbers.indexOf(x)>=0) return true;
748 return false;
749 }
750 }
751
3745788e
AD
752
753function hideOrShowFeeds(doc, hide) {
754
7553dd8b
AD
755 debug("hideOrShowFeeds: " + doc + ", " + hide);
756
293fa942
AD
757 var fd = getFeedsContext().document;
758
759 var list = fd.getElementById("feedList");
760
761 if (fd.getElementById("feedCatHolder")) {
762
763 var feeds = fd.getElementById("feedList");
764 var child = feeds.firstChild;
765
766 while (child) {
767
768 if (child.id == "feedCatHolder") {
769 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
770 }
771
772 child = child.nextSibling;
773 }
774
775 } else {
776 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
777 }
778}
779
780function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
781
782// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 783
293fa942 784 var cat_unread = 0;
3745788e 785
293fa942
AD
786 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
787 for (i = 0; i < node.childNodes.length; i++) {
788 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 789
b31c2311 790 if (node.childNodes[i].style != undefined) {
293fa942 791
b31c2311
AD
792 var has_unread = (node.childNodes[i].className != "feed");
793
794 // debug(node.childNodes[i].id + " --> " + has_unread);
795
796 if (hide && !has_unread) {
797 node.childNodes[i].style.display = "none";
798 }
799
800 if (!hide) {
801 node.childNodes[i].style.display = "list-item";
802 }
803
804 if (has_unread) {
7553dd8b 805 node.childNodes[i].style.display = "list-item";
b31c2311
AD
806 cat_unread++;
807 }
293fa942 808 }
3745788e 809 }
b31c2311 810 }
3745788e 811
293fa942 812 if (cat_unread == 0) {
b31c2311
AD
813 if (cat_node.style == undefined) {
814 debug("ERROR: supplied cat_node " + cat_node +
815 " has no styles. WTF?");
816 return;
817 }
293fa942
AD
818 if (hide) {
819 cat_node.style.display = "none";
820 } else {
821 cat_node.style.display = "list-item";
822 }
7553dd8b 823 } else {
0ac2faea
AD
824 try {
825 cat_node.style.display = "list-item";
826 } catch (e) {
827 debug(e);
828 }
293fa942 829 }
3745788e 830
293fa942 831// debug("unread for category: " + cat_unread);
3745788e
AD
832}
833
35f3c923
AD
834function selectTableRow(r, do_select) {
835 r.className = r.className.replace("Selected", "");
836
837 if (do_select) {
838 r.className = r.className + "Selected";
839 }
840}
841
6c12c809
AD
842function selectTableRowById(elem_id, check_id, do_select) {
843
844 try {
845
846 var row = document.getElementById(elem_id);
847
848 if (row) {
849 selectTableRow(row, do_select);
850 }
851
852 var check = document.getElementById(check_id);
853
854 if (check) {
855 check.checked = do_select;
856 }
857 } catch (e) {
858 exception_error("selectTableRowById", e);
859 }
860}
861
1572afe5 862function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 863 classcheck, reset_others) {
3745788e 864
35f3c923
AD
865 var content = document.getElementById(content_id);
866
867 if (!content) {
868 alert("[selectTableRows] Element " + content_id + " not found.");
869 return;
870 }
871
872 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
873 if (!classcheck || content.rows[i].className.match(classcheck)) {
874
875 if (content.rows[i].id.match(prefix)) {
876 selectTableRow(content.rows[i], do_select);
649e0af9
AD
877
878 var row_id = content.rows[i].id.replace(prefix, "");
879 var check = document.getElementById(check_prefix + row_id);
3055bc41 880
649e0af9
AD
881 if (check) {
882 check.checked = do_select;
883 }
884 } else if (reset_others) {
885 selectTableRow(content.rows[i], false);
7d8d10c6
AD
886
887 var row_id = content.rows[i].id.replace(prefix, "");
888 var check = document.getElementById(check_prefix + row_id);
889
890 if (check) {
891 check.checked = false;
892 }
893
1572afe5 894 }
649e0af9
AD
895 } else if (reset_others) {
896 selectTableRow(content.rows[i], false);
7d8d10c6
AD
897
898 var row_id = content.rows[i].id.replace(prefix, "");
899 var check = document.getElementById(check_prefix + row_id);
900
901 if (check) {
902 check.checked = false;
903 }
904
3055bc41 905 }
35f3c923 906 }
295f9b42 907}
91ff844a
AD
908
909function getSelectedTableRowIds(content_id, prefix) {
910
911 var content = document.getElementById(content_id);
912
913 if (!content) {
914 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
915 return;
916 }
917
918 var sel_rows = new Array();
919
920 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
921 if (content.rows[i].id.match(prefix) &&
922 content.rows[i].className.match("Selected")) {
923
91ff844a
AD
924 var row_id = content.rows[i].id.replace(prefix + "-", "");
925 sel_rows.push(row_id);
926 }
927 }
928
929 return sel_rows;
930
931}
932
386cbf27
AD
933function toggleSelectRowById(sender, id) {
934 var row = document.getElementById(id);
935
936 if (sender.checked) {
937 if (!row.className.match("Selected")) {
938 row.className = row.className + "Selected";
939 }
940 } else {
941 if (row.className.match("Selected")) {
942 row.className = row.className.replace("Selected", "");
943 }
944 }
945}
946
b92e6209
AD
947function toggleSelectListRow(sender) {
948 var parent_row = sender.parentNode;
949
950 if (sender.checked) {
951 if (!parent_row.className.match("Selected")) {
952 parent_row.className = parent_row.className + "Selected";
953 }
954 } else {
955 if (parent_row.className.match("Selected")) {
956 parent_row.className = parent_row.className.replace("Selected", "");
957 }
958 }
959}
960
386cbf27 961
1572afe5
AD
962function toggleSelectRow(sender) {
963 var parent_row = sender.parentNode.parentNode;
964
965 if (sender.checked) {
966 if (!parent_row.className.match("Selected")) {
967 parent_row.className = parent_row.className + "Selected";
968 }
969 } else {
970 if (parent_row.className.match("Selected")) {
971 parent_row.className = parent_row.className.replace("Selected", "");
972 }
973 }
974}
975
3866b046
AD
976function openExternalUrl(url) {
977 var w = window.open(url);
978}
1572afe5 979
1da76274 980function getRelativeFeedId(list, id, direction, unread_only) {
7b433d8c
AD
981 if (!id) {
982 if (direction == "next") {
983 for (i = 0; i < list.childNodes.length; i++) {
984 var child = list.childNodes[i];
1da76274 985 if (child.id && child.id == "feedCatHolder") {
c3f348c2 986 if (child.lastChild) {
7b433d8c
AD
987 var cr = getRelativeFeedId(child.firstChild, id, direction);
988 if (cr) return cr;
989 }
1da76274 990 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
991 return child.id.replace('FEEDR-', '');
992 }
993 }
994 }
995
996 // FIXME select last feed doesn't work when only unread feeds are visible
997
998 if (direction == "prev") {
999 for (i = list.childNodes.length-1; i >= 0; i--) {
1000 var child = list.childNodes[i];
1001 if (child.id == "feedCatHolder") {
1002 if (child.firstChild) {
1003 var cr = getRelativeFeedId(child.firstChild, id, direction);
1004 if (cr) return cr;
1005 }
1006 } else if (child.id.match("FEEDR-")) {
1007
e8bd0da9 1008 if (getInitParam("hide_read_feeds") == 1) {
7b433d8c
AD
1009 if (child.className != "feed") {
1010 alert(child.className);
1011 return child.id.replace('FEEDR-', '');
1012 }
1013 } else {
1014 return child.id.replace('FEEDR-', '');
1015 }
1016 }
1017 }
1018 }
1019 } else {
1020
1021 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
1022
e8bd0da9 1023 if (getInitParam("hide_read_feeds") == 1) {
1da76274
AD
1024 unread_only = true;
1025 }
1026
7b433d8c
AD
1027 if (direction == "next") {
1028
1da76274 1029 var e = feed;
7b433d8c 1030
1da76274 1031 while (e) {
7b433d8c 1032
1da76274
AD
1033 if (e.nextSibling) {
1034
1035 e = e.nextSibling;
1036
1037 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 1038
1da76274 1039 var this_cat = e.parentNode.parentNode;
7b433d8c 1040
1da76274 1041 e = false;
7b433d8c 1042
1da76274
AD
1043 if (this_cat && this_cat.nextSibling) {
1044 while (!e && this_cat.nextSibling) {
1045 this_cat = this_cat.nextSibling;
1046 if (this_cat.id == "feedCatHolder") {
1047 e = this_cat.firstChild.firstChild;
7b433d8c
AD
1048 }
1049 }
7b433d8c 1050 }
1da76274
AD
1051
1052 } else {
1053 e = false;
1054 }
1055
1056 if (e) {
e686782e
AD
1057 if (!unread_only || (unread_only && e.className != "feed" &&
1058 e.className != "error")) {
1da76274
AD
1059 return e.id.replace("FEEDR-", "");
1060 }
1061 }
7b433d8c 1062 }
1da76274 1063
7b433d8c
AD
1064 } else if (direction == "prev") {
1065
1da76274 1066 var e = feed;
7b433d8c 1067
1da76274 1068 while (e) {
7b433d8c 1069
1da76274
AD
1070 if (e.previousSibling) {
1071
1072 e = e.previousSibling;
1073
1074 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 1075
1da76274 1076 var this_cat = e.parentNode.parentNode;
7b433d8c 1077
1da76274
AD
1078 e = false;
1079
1080 if (this_cat && this_cat.previousSibling) {
1081 while (!e && this_cat.previousSibling) {
1082 this_cat = this_cat.previousSibling;
1083 if (this_cat.id == "feedCatHolder") {
1084 e = this_cat.firstChild.lastChild;
7b433d8c
AD
1085 }
1086 }
7b433d8c 1087 }
1da76274
AD
1088
1089 } else {
1090 e = false;
1091 }
1092
1093 if (e) {
e686782e
AD
1094 if (!unread_only || (unread_only && e.className != "feed" &&
1095 e.className != "error")) {
1da76274
AD
1096 return e.id.replace("FEEDR-", "");
1097 }
1098 }
1099 }
7b433d8c
AD
1100 }
1101 }
1102}
36aab70f
AD
1103
1104function showBlockElement(id) {
1105 var elem = document.getElementById(id);
1106
1107 if (elem) {
1108 elem.style.display = "block";
1109 } else {
1110 alert("[showBlockElement] can't find element with id " + id);
1111 }
1112}
1113
a9b0bfd5
AD
1114function hideParentElement(e) {
1115 e.parentNode.style.display = "none";
1116}
1b0809ae
AD
1117
1118function dropboxSelect(e, v) {
1119 for (i = 0; i < e.length; i++) {
1120 if (e[i].value == v) {
1121 e.selectedIndex = i;
1122 break;
1123 }
1124 }
1125}
0ee1d1a0
AD
1126
1127// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1128// bugfixed just a little bit :-)
1129function getURLParam(strParamName){
1130 var strReturn = "";
1131 var strHref = window.location.href;
1132
1133 if (strHref.indexOf("#") == strHref.length-1) {
1134 strHref = strHref.substring(0, strHref.length-1);
1135 }
1136
1137 if ( strHref.indexOf("?") > -1 ){
1138 var strQueryString = strHref.substr(strHref.indexOf("?"));
1139 var aQueryString = strQueryString.split("&");
1140 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1141 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1142 var aParam = aQueryString[iParam].split("=");
1143 strReturn = aParam[1];
1144 break;
1145 }
1146 }
1147 }
1148 return strReturn;
1149}
1150
cf1bc085
AD
1151function leading_zero(p) {
1152 var s = String(p);
1153 if (s.length == 1) s = "0" + s;
1154 return s;
1155}
c38c2b69 1156
86b682ce 1157function closeInfoBox(cleanup) {
e5d758e3
AD
1158 var box = document.getElementById('infoBox');
1159 var shadow = document.getElementById('infoBoxShadow');
1160
1161 if (shadow) {
1162 shadow.style.display = "none";
1163 } else if (box) {
1164 box.style.display = "none";
1165 }
1166
86b682ce
AD
1167 if (cleanup) box.innerHTML = "&nbsp;";
1168
e5d758e3 1169 enableHotkeys();
c14b5566 1170
90ac84df 1171 return false;
e5d758e3
AD
1172}
1173
1174
7b5c6012
AD
1175function displayDlg(id, param) {
1176
1177 if (!xmlhttp_ready(xmlhttp)) {
1178 printLockingError();
1179 return
1180 }
1181
1182 notify("");
1183
1184 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1185 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 1186 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
1187 xmlhttp.send(null);
1188
1189 disableHotkeys();
2371c520 1190
90ac84df 1191 return false;
7b5c6012
AD
1192}
1193
e5d758e3 1194function infobox_submit_callback() {
7b5c6012 1195 if (xmlhttp.readyState == 4) {
e5d758e3 1196 closeInfoBox();
7b5c6012
AD
1197
1198 // called from prefs, reload tab
1199 if (active_tab) {
1200 selectTab(active_tab, false);
1201 }
79f3553b
AD
1202
1203 notify(xmlhttp.responseText);
1204
7b5c6012
AD
1205 }
1206}
1207
e5d758e3 1208function infobox_callback() {
7b5c6012 1209 if (xmlhttp.readyState == 4) {
e5d758e3
AD
1210 var box = document.getElementById('infoBox');
1211 var shadow = document.getElementById('infoBoxShadow');
1212 if (box) {
1213 box.innerHTML=xmlhttp.responseText;
1214 if (shadow) {
1215 shadow.style.display = "block";
1216 } else {
1217 box.style.display = "block";
1218 }
1219 }
1220 }
7b5c6012
AD
1221}
1222
1223function qaddFilter() {
1224
1225 if (!xmlhttp_ready(xmlhttp)) {
1226 printLockingError();
1227 return
1228 }
1229
79f3553b 1230 var query = Form.serialize("filter_add_form");
7b5c6012 1231
79f3553b
AD
1232 xmlhttp.open("GET", "backend.php?" + query, true);
1233 xmlhttp.onreadystatechange=infobox_submit_callback;
1234 xmlhttp.send(null);
7b5c6012 1235
c14b5566 1236 return true;
7b5c6012
AD
1237}
1238
2371c520
AD
1239function toggleSubmitNotEmpty(e, submit_id) {
1240 try {
1241 document.getElementById(submit_id).disabled = (e.value == "")
1242 } catch (e) {
1243 exception_error("toggleSubmitNotEmpty", e);
1244 }
1245}
1d7bf5a0 1246
605f7d46
AD
1247function isValidURL(s) {
1248 return s.match("http://") != null || s.match("https://") != null;
1249}
07eb9178
AD
1250
1251function qafAdd() {
1252
1253 if (!xmlhttp_ready(xmlhttp)) {
1254 printLockingError();
1255 return
1256 }
1257
1258 notify("Adding feed...");
1259
1260 closeInfoBox();
1261
33d13e72 1262 var feeds_doc = getFeedsContext().document;
07eb9178 1263
80e4dc34 1264// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1265
1266 var query = Form.serialize("feed_add_form");
1267
1268 xmlhttp.open("GET", "backend.php?" + query, true);
1269 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1270 xmlhttp.send(null);
07eb9178
AD
1271}
1272
86b682ce
AD
1273function filterCR(e)
1274{
1275 var key;
1276
1277 if(window.event)
1278 key = window.event.keyCode; //IE
1279 else
1280 key = e.which; //firefox
1281
1282 if(key == 13)
1283 return false;
1284 else
1285 return true;
1286}
1287
ac378ad4 1288function getMainContext() {
6b4163cb 1289 return this.window;
ac378ad4
AD
1290}
1291
33d13e72 1292function getFeedsContext() {
6b4163cb 1293 return this.window;
33d13e72
AD
1294}
1295
0bd411db 1296function getContentContext() {
6b4163cb 1297 return this.window;
0bd411db
AD
1298}
1299
ee1f45f4
AD
1300
1301function getHeadlinesContext() {
6b4163cb 1302 return this.window;
ee1f45f4
AD
1303}
1304
e8614131
AD
1305var debug_last_class = "even";
1306
ac378ad4
AD
1307function debug(msg) {
1308 var ctx = getMainContext();
1309
e8614131
AD
1310 if (ctx.debug_last_class == "even") {
1311 ctx.debug_last_class = "odd";
1312 } else {
1313 ctx.debug_last_class = "even";
1314 }
1315
ac378ad4
AD
1316 var c = ctx.document.getElementById('debug_output');
1317 if (c && c.style.display == "block") {
c9268ed5 1318 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1319 c.removeChild(c.lastChild);
1320 }
1321
1322 var d = new Date();
1323 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1324 ":" + leading_zero(d.getSeconds());
e8614131
AD
1325 c.innerHTML = "<li class=\"" + ctx.debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1326 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1327 }
1328}
1329
33d13e72
AD
1330function getInitParam(key) {
1331 return getMainContext().init_params[key];
1332}
3ac2b520 1333
e8bd0da9 1334function storeInitParam(key, value, is_client) {
33d13e72 1335 try {
e8bd0da9 1336 if (!is_client) {
1035fcec
AD
1337 if (getMainContext().init_params[key] != value) {
1338 debug("storeInitParam: " + key + " => " + value);
0b7cb301
AD
1339 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1340 // param_escape(key) + "&value=" + param_escape(value));
1341 var f = getMainContext().document.getElementById("backReqBox");
1342 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1343 param_escape(key) + "&value=" + param_escape(value);
1035fcec 1344 }
e8bd0da9 1345 }
1035fcec 1346 getMainContext().init_params[key] = value;
33d13e72
AD
1347 } catch (e) {
1348 exception_error("storeInitParam", e);
1349 }
1350}
a7565293 1351
1035fcec
AD
1352/*
1353function storeInitParams(params, is_client) {
1354 try {
1355 var s = "";
1356
1357 for (k in params) {
1358 if (getMainContext().init_params[k] != params[k]) {
1359 s += k + "=" + params[k] + ";";
1360 getMainContext().init_params[k] = params[k];
1361 }
1362 }
1363
1364 debug("storeInitParams: " + s);
1365
1366 if (!is_client) {
1367 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1368 }
1369 } catch (e) {
1370 exception_error("storeInitParams", e);
1371 }
1372}*/
1373
a7565293
AD
1374function fatalError(code, message) {
1375 try {
1376 var fe = document.getElementById("fatal_error");
1377 var fc = document.getElementById("fatal_error_msg");
1378
1379 fc.innerHTML = "Code " + code + ": " + message;
1380
1381 fe.style.display = "block";
1382
1383 } catch (e) {
1384 exception_error("fatalError", e);
1385 }
1386}
1387
234e467c 1388function getFeedName(id, is_cat) {
64a2875d 1389 var d = getFeedsContext().document;
234e467c
AD
1390
1391 var e;
1392
1393 if (is_cat) {
1394 e = d.getElementById("FCATN-" + id);
1395 } else {
1396 e = d.getElementById("FEEDN-" + id);
1397 }
64a2875d
AD
1398 if (e) {
1399 return e.innerHTML.stripTags();
1400 } else {
1401 return null;
1402 }
1403}
0bd411db
AD
1404
1405function viewContentUrl(url) {
1406 getContentContext().location = url;
1407}