]> git.wh0rd.org - tt-rss.git/blame - functions.js
css-based layout + required 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
AD
147function p_notify(msg, no_hide, is_err) {
148 notify_real(msg, parent.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;
6b4163cb
AD
165
166 return; //fixme disables for now
ee1f45f4
AD
167
168 if (window.event) {
169 keycode = window.event.keyCode;
170 } else if (e) {
171 keycode = e.which;
172 }
d437c8cf 173
ee1f45f4
AD
174 var m_ctx = getMainContext();
175 var f_ctx = getFeedsContext();
176 var h_ctx = getHeadlinesContext();
d437c8cf 177
ee1f45f4
AD
178 if (keycode == 82) { // r
179 return m_ctx.scheduleFeedUpdate(true);
180 }
0a383013
AD
181
182 if (keycode == 83) { // r
183 return m_ctx.displayDlg("search", getActiveFeedId());
184 }
185
ee1f45f4
AD
186 if (keycode == 85) { // u
187 if (getActiveFeedId()) {
767e2486 188 return f_ctx.viewfeed(getActiveFeedId(), "ForceUpdate");
ee1f45f4
AD
189 }
190 }
191
192 if (keycode == 65) { // a
193 return m_ctx.toggleDispRead();
194 }
195
196 var f_doc = m_ctx.frames["feeds-frame"].document;
197 var feedlist = f_doc.getElementById('feedList');
198
199 if (keycode == 74) { // j
200 var feed = getActiveFeedId();
201 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
767e2486 202 if (new_feed) viewfeed(new_feed, '');
ee1f45f4
AD
203 }
204
205 if (keycode == 75) { // k
206 var feed = getActiveFeedId();
207 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
767e2486 208 if (new_feed) viewfeed(new_feed, '');
7b433d8c 209 }
9cfc649a 210
ee1f45f4 211 if (keycode == 78 || keycode == 40) { // n, down
746a0d5e 212 if (typeof h_ctx.moveToPost != 'undefined') {
e59a2f12
AD
213 return h_ctx.moveToPost('next');
214 }
ee1f45f4
AD
215 }
216
217 if (keycode == 80 || keycode == 38) { // p, up
746a0d5e 218 if (typeof h_ctx.moveToPost != 'undefined') {
e59a2f12
AD
219 return h_ctx.moveToPost('prev');
220 }
ee1f45f4
AD
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
0a6c4846
AD
457function activeFeedIsCat() {
458 return getMainContext().active_feed_is_cat;
459}
460
86741347 461function setActiveFeedId(id) {
33d13e72
AD
462// return setCookie("ttrss_vf_actfeed", id);
463 try {
5c365f60 464 debug("sAFID(" + id + ")");
33d13e72
AD
465 getMainContext().active_feed_id = id;
466 } catch (e) {
467 exception_error("setActiveFeedId", e);
468 }
86741347 469}
090e250b 470
ac378ad4 471function parse_counters(reply, scheduled_call) {
1a6a9555 472 try {
6b4163cb
AD
473 var f_document = document;
474 var title_obj = this.window;
ac378ad4 475
9e397d0f
AD
476 var feeds_found = 0;
477
f54f515f
AD
478 if (reply.firstChild && reply.firstChild.firstChild) {
479 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
480 reply = reply.firstChild;
481 }
482
ac378ad4
AD
483 debug("F_DOC: " + f_document + ", T_OBJ: " + title_obj);
484
1a6a9555 485 for (var l = 0; l < reply.childNodes.length; l++) {
9cbca41f
AD
486 if (!reply.childNodes[l] ||
487 typeof(reply.childNodes[l].getAttribute) == "undefined") {
6043fb7e
AD
488 // where did this come from?
489 continue;
490 }
491
1a6a9555
AD
492 var id = reply.childNodes[l].getAttribute("id");
493 var t = reply.childNodes[l].getAttribute("type");
494 var ctr = reply.childNodes[l].getAttribute("counter");
023fe037
AD
495 var error = reply.childNodes[l].getAttribute("error");
496 var has_img = reply.childNodes[l].getAttribute("hi");
fb1fb4ab 497 var updated = reply.childNodes[l].getAttribute("updated");
1a6a9555
AD
498
499 if (id == "global-unread") {
3bdb368b
AD
500 title_obj.global_unread = ctr;
501 title_obj.updateTitle();
1a6a9555
AD
502 continue;
503 }
7bf7e4d3
AD
504
505 if (id == "subscribed-feeds") {
506 feeds_found = ctr;
507 continue;
508 }
1a6a9555
AD
509
510 if (t == "category") {
511 var catctr = f_document.getElementById("FCATCTR-" + id);
512 if (catctr) {
513 catctr.innerHTML = "(" + ctr + " unread)";
514 }
515 continue;
516 }
517
518 var feedctr = f_document.getElementById("FEEDCTR-" + id);
519 var feedu = f_document.getElementById("FEEDU-" + id);
520 var feedr = f_document.getElementById("FEEDR-" + id);
023fe037 521 var feed_img = f_document.getElementById("FIMG-" + id);
fb1fb4ab 522 var feedlink = f_document.getElementById("FEEDL-" + id);
78d5212c 523 var feedupd = f_document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
524
525 if (updated && feedlink) {
526 if (error) {
527 feedlink.title = "Error: " + error + " (" + updated + ")";
528 } else {
529 feedlink.title = "Updated: " + updated;
530 }
531 }
023fe037 532
78d5212c
AD
533 if (updated && feedupd) {
534 if (error) {
535 feedupd.innerHTML = updated + " (Error)";
536 } else {
537 feedupd.innerHTML = updated;
538 }
539 }
540
1a6a9555 541 if (feedctr && feedu && feedr) {
e8ef3b97
AD
542
543 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
544 var hf = title_obj.parent.frames["headlines-frame"];
545 hf.location.reload(true);
546 }
1a6a9555
AD
547
548 feedu.innerHTML = ctr;
023fe037 549
426d3c57
AD
550 if (error) {
551 feedr.className = feedr.className.replace("feed", "error");
552 } else if (id > 0) {
553 feedr.className = feedr.className.replace("error", "feed");
023fe037 554 }
1a6a9555
AD
555
556 if (ctr > 0) {
557 feedctr.className = "odd";
558 if (!feedr.className.match("Unread")) {
559 var is_selected = feedr.className.match("Selected");
560
561 feedr.className = feedr.className.replace("Selected", "");
562 feedr.className = feedr.className.replace("Unread", "");
563
564 feedr.className = feedr.className + "Unread";
565
566 if (is_selected) {
567 feedr.className = feedr.className + "Selected";
568 }
569
570 }
571 } else {
572 feedctr.className = "invisible";
573 feedr.className = feedr.className.replace("Unread", "");
574 }
575 }
576 }
9e397d0f 577
7553dd8b
AD
578 hideOrShowFeeds(getFeedsContext().document,
579 getInitParam("hide_read_feeds") == 1);
580
9e397d0f
AD
581 var feeds_stored = getMainContext().number_of_feeds;
582
583 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
584
585 if (feeds_stored != feeds_found) {
7bf7e4d3
AD
586 getMainContext().number_of_feeds = feeds_found;
587
588 if (feeds_stored != 0) {
9e397d0f
AD
589 debug("Subscribed feed number changed, refreshing feedlist");
590 updateFeedList();
591 }
592 }
593
1a6a9555 594 } catch (e) {
83f043bb 595 exception_error("parse_counters", e);
1a6a9555
AD
596 }
597}
598
4f3a84f4 599function all_counters_callback() {
090e250b 600 if (xmlhttp_rpc.readyState == 4) {
7719618b 601 try {
3866b046 602 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
b00ed196 603 debug("[all_counters_callback] backend did not return valid XML");
7719618b
AD
604 return;
605 }
894ebcf5 606
6b4163cb 607 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
1cb7492d 608
7719618b 609 var reply = xmlhttp_rpc.responseXML.firstChild;
280ee9a3 610
f54f515f
AD
611 var counters = reply.firstChild;
612
613 parse_counters(counters);
1cb7492d
AD
614
615 var runtime = counters.nextSibling;
616
617 if (runtime) {
618 getMainContext().parse_runtime_info(runtime);
619 }
c9268ed5 620
cea51014 621 if (getInitParam("feeds_sort_by_unread") == 1) {
c9268ed5
AD
622 resort_feedlist();
623 }
293fa942
AD
624
625 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
626
7719618b
AD
627 } catch (e) {
628 exception_error("all_counters_callback", e);
090e250b
AD
629 }
630 }
631}
632
c9268ed5
AD
633function get_feed_entry_unread(doc, elem) {
634
635 var id = elem.id.replace("FEEDR-", "");
636
637 if (id <= 0) {
638 return -1;
639 }
640
641 try {
642 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
643 } catch (e) {
644 return -1;
645 }
646}
647
648function resort_category(doc, node) {
649 debug("resort_category: " + node);
650
651 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
652 for (i = 0; i < node.childNodes.length; i++) {
653 if (node.childNodes[i].nodeName != "LI") { continue; }
654
655 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
656 continue;
657 }
658
659 for (j = i+1; j < node.childNodes.length; j++) {
660 if (node.childNodes[j].nodeName != "LI") { continue; }
661
662 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
663 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
664
665 if (cur_val > tmp_val) {
666 tempnode_i = node.childNodes[i].cloneNode(true);
667 tempnode_j = node.childNodes[j].cloneNode(true);
668 node.replaceChild(tempnode_i, node.childNodes[j]);
669 node.replaceChild(tempnode_j, node.childNodes[i]);
670 }
671 }
672
673 }
674 }
675
676}
677
678function resort_feedlist() {
679 debug("resort_feedlist");
680
681 var fd = getFeedsContext().document;
682
683 if (fd.getElementById("feedCatHolder")) {
684
685 var feeds = fd.getElementById("feedList");
686 var child = feeds.firstChild;
687
688 while (child) {
689
690 if (child.id == "feedCatHolder") {
691 resort_category(fd, child.firstChild);
692 }
693
694 child = child.nextSibling;
695 }
696
697 } else {
698 resort_category(fd, fd.getElementById("feedList"));
699 }
700}
701
4f3a84f4 702function update_all_counters(feed) {
090e250b 703 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 704 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
705
706 if (feed > 0) {
707 query = query + "&aid=" + feed;
708 }
709
090e250b 710 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 711 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
712 xmlhttp_rpc.send(null);
713 }
714}
7dc66a61
AD
715
716function popupHelp(tid) {
717 var w = window.open("backend.php?op=help&tid=" + tid,
718 "Popup Help",
719 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
720}
b6644d29
AD
721
722/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
723 * * @author Sundar Dorai-Raj
724 * * Email: sdoraira@vt.edu
725 * * This program is free software; you can redistribute it and/or
726 * * modify it under the terms of the GNU General Public License
727 * * as published by the Free Software Foundation; either version 2
728 * * of the License, or (at your option) any later version,
729 * * provided that any use properly credits the author.
730 * * This program is distributed in the hope that it will be useful,
731 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
732 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
733 * * GNU General Public License for more details at http://www.gnu.org * * */
734
735 var numbers=".0123456789";
736 function isNumeric(x) {
737 // is x a String or a character?
738 if(x.length>1) {
739 // remove negative sign
740 x=Math.abs(x)+"";
741 for(j=0;j<x.length;j++) {
742 // call isNumeric recursively for each character
743 number=isNumeric(x.substring(j,j+1));
744 if(!number) return number;
745 }
746 return number;
747 }
748 else {
749 // if x is number return true
750 if(numbers.indexOf(x)>=0) return true;
751 return false;
752 }
753 }
754
3745788e
AD
755
756function hideOrShowFeeds(doc, hide) {
757
7553dd8b
AD
758 debug("hideOrShowFeeds: " + doc + ", " + hide);
759
293fa942
AD
760 var fd = getFeedsContext().document;
761
762 var list = fd.getElementById("feedList");
763
764 if (fd.getElementById("feedCatHolder")) {
765
766 var feeds = fd.getElementById("feedList");
767 var child = feeds.firstChild;
768
769 while (child) {
770
771 if (child.id == "feedCatHolder") {
772 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
773 }
774
775 child = child.nextSibling;
776 }
777
778 } else {
779 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
780 }
781}
782
783function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
784
785// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 786
293fa942 787 var cat_unread = 0;
3745788e 788
293fa942
AD
789 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
790 for (i = 0; i < node.childNodes.length; i++) {
791 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 792
b31c2311 793 if (node.childNodes[i].style != undefined) {
293fa942 794
b31c2311
AD
795 var has_unread = (node.childNodes[i].className != "feed");
796
797 // debug(node.childNodes[i].id + " --> " + has_unread);
798
799 if (hide && !has_unread) {
800 node.childNodes[i].style.display = "none";
801 }
802
803 if (!hide) {
804 node.childNodes[i].style.display = "list-item";
805 }
806
807 if (has_unread) {
7553dd8b 808 node.childNodes[i].style.display = "list-item";
b31c2311
AD
809 cat_unread++;
810 }
293fa942 811 }
3745788e 812 }
b31c2311 813 }
3745788e 814
293fa942 815 if (cat_unread == 0) {
b31c2311
AD
816 if (cat_node.style == undefined) {
817 debug("ERROR: supplied cat_node " + cat_node +
818 " has no styles. WTF?");
819 return;
820 }
293fa942
AD
821 if (hide) {
822 cat_node.style.display = "none";
823 } else {
824 cat_node.style.display = "list-item";
825 }
7553dd8b 826 } else {
0ac2faea
AD
827 try {
828 cat_node.style.display = "list-item";
829 } catch (e) {
830 debug(e);
831 }
293fa942 832 }
3745788e 833
293fa942 834// debug("unread for category: " + cat_unread);
3745788e
AD
835}
836
35f3c923
AD
837function selectTableRow(r, do_select) {
838 r.className = r.className.replace("Selected", "");
839
840 if (do_select) {
841 r.className = r.className + "Selected";
842 }
843}
844
6c12c809
AD
845function selectTableRowById(elem_id, check_id, do_select) {
846
847 try {
848
849 var row = document.getElementById(elem_id);
850
851 if (row) {
852 selectTableRow(row, do_select);
853 }
854
855 var check = document.getElementById(check_id);
856
857 if (check) {
858 check.checked = do_select;
859 }
860 } catch (e) {
861 exception_error("selectTableRowById", e);
862 }
863}
864
1572afe5 865function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 866 classcheck, reset_others) {
3745788e 867
35f3c923
AD
868 var content = document.getElementById(content_id);
869
870 if (!content) {
871 alert("[selectTableRows] Element " + content_id + " not found.");
872 return;
873 }
874
875 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
876 if (!classcheck || content.rows[i].className.match(classcheck)) {
877
878 if (content.rows[i].id.match(prefix)) {
879 selectTableRow(content.rows[i], do_select);
649e0af9
AD
880
881 var row_id = content.rows[i].id.replace(prefix, "");
882 var check = document.getElementById(check_prefix + row_id);
3055bc41 883
649e0af9
AD
884 if (check) {
885 check.checked = do_select;
886 }
887 } else if (reset_others) {
888 selectTableRow(content.rows[i], false);
7d8d10c6
AD
889
890 var row_id = content.rows[i].id.replace(prefix, "");
891 var check = document.getElementById(check_prefix + row_id);
892
893 if (check) {
894 check.checked = false;
895 }
896
1572afe5 897 }
649e0af9
AD
898 } else if (reset_others) {
899 selectTableRow(content.rows[i], false);
7d8d10c6
AD
900
901 var row_id = content.rows[i].id.replace(prefix, "");
902 var check = document.getElementById(check_prefix + row_id);
903
904 if (check) {
905 check.checked = false;
906 }
907
3055bc41 908 }
35f3c923 909 }
295f9b42 910}
91ff844a
AD
911
912function getSelectedTableRowIds(content_id, prefix) {
913
914 var content = document.getElementById(content_id);
915
916 if (!content) {
917 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
918 return;
919 }
920
921 var sel_rows = new Array();
922
923 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
924 if (content.rows[i].id.match(prefix) &&
925 content.rows[i].className.match("Selected")) {
926
91ff844a
AD
927 var row_id = content.rows[i].id.replace(prefix + "-", "");
928 sel_rows.push(row_id);
929 }
930 }
931
932 return sel_rows;
933
934}
935
386cbf27
AD
936function toggleSelectRowById(sender, id) {
937 var row = document.getElementById(id);
938
939 if (sender.checked) {
940 if (!row.className.match("Selected")) {
941 row.className = row.className + "Selected";
942 }
943 } else {
944 if (row.className.match("Selected")) {
945 row.className = row.className.replace("Selected", "");
946 }
947 }
948}
949
b92e6209
AD
950function toggleSelectListRow(sender) {
951 var parent_row = sender.parentNode;
952
953 if (sender.checked) {
954 if (!parent_row.className.match("Selected")) {
955 parent_row.className = parent_row.className + "Selected";
956 }
957 } else {
958 if (parent_row.className.match("Selected")) {
959 parent_row.className = parent_row.className.replace("Selected", "");
960 }
961 }
962}
963
386cbf27 964
1572afe5
AD
965function toggleSelectRow(sender) {
966 var parent_row = sender.parentNode.parentNode;
967
968 if (sender.checked) {
969 if (!parent_row.className.match("Selected")) {
970 parent_row.className = parent_row.className + "Selected";
971 }
972 } else {
973 if (parent_row.className.match("Selected")) {
974 parent_row.className = parent_row.className.replace("Selected", "");
975 }
976 }
977}
978
3866b046
AD
979function openExternalUrl(url) {
980 var w = window.open(url);
981}
1572afe5 982
1da76274 983function getRelativeFeedId(list, id, direction, unread_only) {
7b433d8c
AD
984 if (!id) {
985 if (direction == "next") {
986 for (i = 0; i < list.childNodes.length; i++) {
987 var child = list.childNodes[i];
1da76274 988 if (child.id && child.id == "feedCatHolder") {
c3f348c2 989 if (child.lastChild) {
7b433d8c
AD
990 var cr = getRelativeFeedId(child.firstChild, id, direction);
991 if (cr) return cr;
992 }
1da76274 993 } else if (child.id && child.id.match("FEEDR-")) {
7b433d8c
AD
994 return child.id.replace('FEEDR-', '');
995 }
996 }
997 }
998
999 // FIXME select last feed doesn't work when only unread feeds are visible
1000
1001 if (direction == "prev") {
1002 for (i = list.childNodes.length-1; i >= 0; i--) {
1003 var child = list.childNodes[i];
1004 if (child.id == "feedCatHolder") {
1005 if (child.firstChild) {
1006 var cr = getRelativeFeedId(child.firstChild, id, direction);
1007 if (cr) return cr;
1008 }
1009 } else if (child.id.match("FEEDR-")) {
1010
e8bd0da9 1011 if (getInitParam("hide_read_feeds") == 1) {
7b433d8c
AD
1012 if (child.className != "feed") {
1013 alert(child.className);
1014 return child.id.replace('FEEDR-', '');
1015 }
1016 } else {
1017 return child.id.replace('FEEDR-', '');
1018 }
1019 }
1020 }
1021 }
1022 } else {
1023
1024 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
1025
e8bd0da9 1026 if (getInitParam("hide_read_feeds") == 1) {
1da76274
AD
1027 unread_only = true;
1028 }
1029
7b433d8c
AD
1030 if (direction == "next") {
1031
1da76274 1032 var e = feed;
7b433d8c 1033
1da76274 1034 while (e) {
7b433d8c 1035
1da76274
AD
1036 if (e.nextSibling) {
1037
1038 e = e.nextSibling;
1039
1040 } else if (e.parentNode.parentNode.nextSibling) {
7b433d8c 1041
1da76274 1042 var this_cat = e.parentNode.parentNode;
7b433d8c 1043
1da76274 1044 e = false;
7b433d8c 1045
1da76274
AD
1046 if (this_cat && this_cat.nextSibling) {
1047 while (!e && this_cat.nextSibling) {
1048 this_cat = this_cat.nextSibling;
1049 if (this_cat.id == "feedCatHolder") {
1050 e = this_cat.firstChild.firstChild;
7b433d8c
AD
1051 }
1052 }
7b433d8c 1053 }
1da76274
AD
1054
1055 } else {
1056 e = false;
1057 }
1058
1059 if (e) {
e686782e
AD
1060 if (!unread_only || (unread_only && e.className != "feed" &&
1061 e.className != "error")) {
1da76274
AD
1062 return e.id.replace("FEEDR-", "");
1063 }
1064 }
7b433d8c 1065 }
1da76274 1066
7b433d8c
AD
1067 } else if (direction == "prev") {
1068
1da76274 1069 var e = feed;
7b433d8c 1070
1da76274 1071 while (e) {
7b433d8c 1072
1da76274
AD
1073 if (e.previousSibling) {
1074
1075 e = e.previousSibling;
1076
1077 } else if (e.parentNode.parentNode.previousSibling) {
7b433d8c 1078
1da76274 1079 var this_cat = e.parentNode.parentNode;
7b433d8c 1080
1da76274
AD
1081 e = false;
1082
1083 if (this_cat && this_cat.previousSibling) {
1084 while (!e && this_cat.previousSibling) {
1085 this_cat = this_cat.previousSibling;
1086 if (this_cat.id == "feedCatHolder") {
1087 e = this_cat.firstChild.lastChild;
7b433d8c
AD
1088 }
1089 }
7b433d8c 1090 }
1da76274
AD
1091
1092 } else {
1093 e = false;
1094 }
1095
1096 if (e) {
e686782e
AD
1097 if (!unread_only || (unread_only && e.className != "feed" &&
1098 e.className != "error")) {
1da76274
AD
1099 return e.id.replace("FEEDR-", "");
1100 }
1101 }
1102 }
7b433d8c
AD
1103 }
1104 }
1105}
36aab70f
AD
1106
1107function showBlockElement(id) {
1108 var elem = document.getElementById(id);
1109
1110 if (elem) {
1111 elem.style.display = "block";
1112 } else {
1113 alert("[showBlockElement] can't find element with id " + id);
1114 }
1115}
1116
a9b0bfd5
AD
1117function hideParentElement(e) {
1118 e.parentNode.style.display = "none";
1119}
1b0809ae
AD
1120
1121function dropboxSelect(e, v) {
1122 for (i = 0; i < e.length; i++) {
1123 if (e[i].value == v) {
1124 e.selectedIndex = i;
1125 break;
1126 }
1127 }
1128}
0ee1d1a0
AD
1129
1130// originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1131// bugfixed just a little bit :-)
1132function getURLParam(strParamName){
1133 var strReturn = "";
1134 var strHref = window.location.href;
1135
1136 if (strHref.indexOf("#") == strHref.length-1) {
1137 strHref = strHref.substring(0, strHref.length-1);
1138 }
1139
1140 if ( strHref.indexOf("?") > -1 ){
1141 var strQueryString = strHref.substr(strHref.indexOf("?"));
1142 var aQueryString = strQueryString.split("&");
1143 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1144 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1145 var aParam = aQueryString[iParam].split("=");
1146 strReturn = aParam[1];
1147 break;
1148 }
1149 }
1150 }
1151 return strReturn;
1152}
1153
cf1bc085
AD
1154function leading_zero(p) {
1155 var s = String(p);
1156 if (s.length == 1) s = "0" + s;
1157 return s;
1158}
c38c2b69 1159
86b682ce 1160function closeInfoBox(cleanup) {
e5d758e3
AD
1161 var box = document.getElementById('infoBox');
1162 var shadow = document.getElementById('infoBoxShadow');
1163
1164 if (shadow) {
1165 shadow.style.display = "none";
1166 } else if (box) {
1167 box.style.display = "none";
1168 }
1169
86b682ce
AD
1170 if (cleanup) box.innerHTML = "&nbsp;";
1171
e5d758e3 1172 enableHotkeys();
c14b5566 1173
90ac84df 1174 return false;
e5d758e3
AD
1175}
1176
1177
7b5c6012
AD
1178function displayDlg(id, param) {
1179
1180 if (!xmlhttp_ready(xmlhttp)) {
1181 printLockingError();
1182 return
1183 }
1184
1185 notify("");
1186
1187 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1188 param_escape(id) + "&param=" + param_escape(param), true);
e5d758e3 1189 xmlhttp.onreadystatechange=infobox_callback;
7b5c6012
AD
1190 xmlhttp.send(null);
1191
1192 disableHotkeys();
2371c520 1193
90ac84df 1194 return false;
7b5c6012
AD
1195}
1196
e5d758e3 1197function infobox_submit_callback() {
7b5c6012 1198 if (xmlhttp.readyState == 4) {
e5d758e3 1199 closeInfoBox();
7b5c6012
AD
1200
1201 // called from prefs, reload tab
1202 if (active_tab) {
1203 selectTab(active_tab, false);
1204 }
79f3553b
AD
1205
1206 notify(xmlhttp.responseText);
1207
7b5c6012
AD
1208 }
1209}
1210
e5d758e3 1211function infobox_callback() {
7b5c6012 1212 if (xmlhttp.readyState == 4) {
e5d758e3
AD
1213 var box = document.getElementById('infoBox');
1214 var shadow = document.getElementById('infoBoxShadow');
1215 if (box) {
1216 box.innerHTML=xmlhttp.responseText;
1217 if (shadow) {
1218 shadow.style.display = "block";
1219 } else {
1220 box.style.display = "block";
1221 }
1222 }
1223 }
7b5c6012
AD
1224}
1225
1226function qaddFilter() {
1227
1228 if (!xmlhttp_ready(xmlhttp)) {
1229 printLockingError();
1230 return
1231 }
1232
79f3553b 1233 var query = Form.serialize("filter_add_form");
7b5c6012 1234
79f3553b
AD
1235 xmlhttp.open("GET", "backend.php?" + query, true);
1236 xmlhttp.onreadystatechange=infobox_submit_callback;
1237 xmlhttp.send(null);
7b5c6012 1238
c14b5566 1239 return true;
7b5c6012
AD
1240}
1241
2371c520
AD
1242function toggleSubmitNotEmpty(e, submit_id) {
1243 try {
1244 document.getElementById(submit_id).disabled = (e.value == "")
1245 } catch (e) {
1246 exception_error("toggleSubmitNotEmpty", e);
1247 }
1248}
1d7bf5a0 1249
605f7d46
AD
1250function isValidURL(s) {
1251 return s.match("http://") != null || s.match("https://") != null;
1252}
07eb9178
AD
1253
1254function qafAdd() {
1255
1256 if (!xmlhttp_ready(xmlhttp)) {
1257 printLockingError();
1258 return
1259 }
1260
1261 notify("Adding feed...");
1262
1263 closeInfoBox();
1264
33d13e72 1265 var feeds_doc = getFeedsContext().document;
07eb9178
AD
1266
1267 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1268
1269 var query = Form.serialize("feed_add_form");
1270
1271 xmlhttp.open("GET", "backend.php?" + query, true);
1272 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1273 xmlhttp.send(null);
07eb9178
AD
1274}
1275
86b682ce
AD
1276function filterCR(e)
1277{
1278 var key;
1279
1280 if(window.event)
1281 key = window.event.keyCode; //IE
1282 else
1283 key = e.which; //firefox
1284
1285 if(key == 13)
1286 return false;
1287 else
1288 return true;
1289}
1290
ac378ad4 1291function getMainContext() {
6b4163cb 1292 return this.window;
ac378ad4
AD
1293}
1294
33d13e72 1295function getFeedsContext() {
6b4163cb 1296 return this.window;
33d13e72
AD
1297}
1298
0bd411db 1299function getContentContext() {
6b4163cb 1300 return this.window;
0bd411db
AD
1301}
1302
ee1f45f4
AD
1303
1304function getHeadlinesContext() {
6b4163cb 1305 return this.window;
ee1f45f4
AD
1306}
1307
e8614131
AD
1308var debug_last_class = "even";
1309
ac378ad4
AD
1310function debug(msg) {
1311 var ctx = getMainContext();
1312
e8614131
AD
1313 if (ctx.debug_last_class == "even") {
1314 ctx.debug_last_class = "odd";
1315 } else {
1316 ctx.debug_last_class = "even";
1317 }
1318
ac378ad4
AD
1319 var c = ctx.document.getElementById('debug_output');
1320 if (c && c.style.display == "block") {
c9268ed5 1321 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1322 c.removeChild(c.lastChild);
1323 }
1324
1325 var d = new Date();
1326 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1327 ":" + leading_zero(d.getSeconds());
e8614131
AD
1328 c.innerHTML = "<li class=\"" + ctx.debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1329 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1330 }
1331}
1332
33d13e72
AD
1333function getInitParam(key) {
1334 return getMainContext().init_params[key];
1335}
3ac2b520 1336
e8bd0da9 1337function storeInitParam(key, value, is_client) {
33d13e72 1338 try {
e8bd0da9 1339 if (!is_client) {
1035fcec
AD
1340 if (getMainContext().init_params[key] != value) {
1341 debug("storeInitParam: " + key + " => " + value);
0b7cb301
AD
1342 //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1343 // param_escape(key) + "&value=" + param_escape(value));
1344 var f = getMainContext().document.getElementById("backReqBox");
1345 f.src = "backend.php?op=rpc&subop=storeParam&key=" +
1346 param_escape(key) + "&value=" + param_escape(value);
1035fcec 1347 }
e8bd0da9 1348 }
1035fcec 1349 getMainContext().init_params[key] = value;
33d13e72
AD
1350 } catch (e) {
1351 exception_error("storeInitParam", e);
1352 }
1353}
a7565293 1354
1035fcec
AD
1355/*
1356function storeInitParams(params, is_client) {
1357 try {
1358 var s = "";
1359
1360 for (k in params) {
1361 if (getMainContext().init_params[k] != params[k]) {
1362 s += k + "=" + params[k] + ";";
1363 getMainContext().init_params[k] = params[k];
1364 }
1365 }
1366
1367 debug("storeInitParams: " + s);
1368
1369 if (!is_client) {
1370 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1371 }
1372 } catch (e) {
1373 exception_error("storeInitParams", e);
1374 }
1375}*/
1376
a7565293
AD
1377function fatalError(code, message) {
1378 try {
1379 var fe = document.getElementById("fatal_error");
1380 var fc = document.getElementById("fatal_error_msg");
1381
1382 fc.innerHTML = "Code " + code + ": " + message;
1383
1384 fe.style.display = "block";
1385
1386 } catch (e) {
1387 exception_error("fatalError", e);
1388 }
1389}
1390
234e467c 1391function getFeedName(id, is_cat) {
64a2875d 1392 var d = getFeedsContext().document;
234e467c
AD
1393
1394 var e;
1395
1396 if (is_cat) {
1397 e = d.getElementById("FCATN-" + id);
1398 } else {
1399 e = d.getElementById("FEEDN-" + id);
1400 }
64a2875d
AD
1401 if (e) {
1402 return e.innerHTML.stripTags();
1403 } else {
1404 return null;
1405 }
1406}
0bd411db
AD
1407
1408function viewContentUrl(url) {
1409 getContentContext().location = url;
1410}