]> git.wh0rd.org - tt-rss.git/blame - functions.js
misc code cleanup
[tt-rss.git] / functions.js
CommitLineData
760966c1 1var hotkeys_enabled = true;
a7565293 2var xmlhttp_rpc = Ajax.getTransport();
730dbf19 3var notify_silent = false;
99509451 4var last_progress_point = 0;
61992f57 5
b07b61da
AD
6/* add method to remove element from array */
7
8Array.prototype.remove = function(s) {
9 for (var i=0; i < this.length; i++) {
10 if (s == this[i]) this.splice(i, 1);
11 }
12}
13
e12a547e
AD
14function is_msie() {
15 return navigator.userAgent.match("MSIE");
16}
17
7c620da8 18function is_opera() {
ee8768db 19 return window.opera;
583c58b8
AD
20}
21
55160955 22function exception_error(location, e, silent) {
83f043bb
AD
23 var msg;
24
25 if (e.fileName) {
26 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
27
28 msg = "Exception: " + e.name + ", " + e.message +
29 "\nFunction: " + location + "()" +
30 "\nLocation: " + base_fname + ":" + e.lineNumber;
ee1f45f4 31
83f043bb
AD
32 } else {
33 msg = "Exception: " + e + "\nFunction: " + location + "()";
34 }
35
ee1f45f4
AD
36 debug("<b>EXCEPTION: " + msg + "</b>");
37
55160955
AD
38 if (!silent) {
39 alert(msg);
40 }
7719618b
AD
41}
42
760966c1
AD
43function disableHotkeys() {
44 hotkeys_enabled = false;
45}
46
47function enableHotkeys() {
48 hotkeys_enabled = true;
49}
50
c0e5a40e
AD
51function xmlhttp_ready(obj) {
52 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
53}
54
d395a942
AD
55function open_article_callback(transport) {
56 try {
298f3f78 57
d395a942 58 if (transport.responseXML) {
06925d9e 59
d395a942
AD
60 var link = transport.responseXML.getElementsByTagName("link")[0];
61 var id = transport.responseXML.getElementsByTagName("id")[0];
298f3f78 62
06925d9e
AD
63 debug("open_article_callback, received link: " + link);
64
04e91733 65 if (link && id) {
06925d9e 66
04e91733
AD
67 var wname = "ttrss_article_" + id.firstChild.nodeValue;
68
69 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
70
71 var w = window.open(link.firstChild.nodeValue, wname);
4298481d
AD
72
73 if (!w) { notify_error("Failed to load article in new window"); }
e2ccbfab 74
d395a942
AD
75 if (id) {
76 id = id.firstChild.nodeValue;
77 if (!document.getElementById("headlinesList")) {
78 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
e2ccbfab 79 }
298f3f78 80 }
06925d9e
AD
81 } else {
82 notify_error("Can't open article: received invalid article link");
298f3f78 83 }
06925d9e
AD
84 } else {
85 notify_error("Can't open article: received invalid XML");
01a87dff 86 }
01a87dff 87
d395a942
AD
88 } catch (e) {
89 exception_error("open_article_callback", e);
9cfc649a
AD
90 }
91}
92
7726fa02
AD
93function param_escape(arg) {
94 if (typeof encodeURIComponent != 'undefined')
95 return encodeURIComponent(arg);
96 else
97 return escape(arg);
98}
99
100function param_unescape(arg) {
101 if (typeof decodeURIComponent != 'undefined')
102 return decodeURIComponent(arg);
103 else
104 return unescape(arg);
105}
106
508a81e1
AD
107function delay(gap) {
108 var then,now;
109 then=new Date().getTime();
110 now=then;
111 while((now-then)<gap) {
112 now=new Date().getTime();
113 }
114}
7726fa02 115
ce3bf408 116var notify_hide_timerid = false;
59a543f0 117
ce3bf408 118function hide_notify() {
42c32916
AD
119 var n = document.getElementById("notify");
120 if (n) {
d05514a4 121 n.style.display = "none";
8dcfffd0 122 }
d05514a4 123}
c05608c2 124
730dbf19
AD
125function notify_silent_next() {
126 notify_silent = true;
127}
128
42c32916 129function notify_real(msg, no_hide, n_type) {
7726fa02 130
730dbf19
AD
131 if (notify_silent) {
132 notify_silent = false;
133 return;
134 }
135
42c32916
AD
136 var n = document.getElementById("notify");
137 var nb = document.getElementById("notify_body");
7726fa02 138
c05608c2 139 if (!n || !nb) return;
f0601b87 140
0655a1d5
AD
141 if (notify_hide_timerid) {
142 window.clearTimeout(notify_hide_timerid);
143 }
144
8dcfffd0 145 if (msg == "") {
0655a1d5
AD
146 if (n.style.display == "block") {
147 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
148 }
149 return;
7726fa02 150 } else {
0ceded7a 151 n.style.display = "block";
8dcfffd0 152 }
7726fa02 153
42c32916
AD
154 /* types:
155
156 1 - generic
157 2 - progress
158 3 - error
159 4 - info
160
161 */
162
f3977cf5
AD
163 if (typeof __ != 'undefined') {
164 msg = __(msg);
165 }
166
42c32916
AD
167 if (n_type == 1) {
168 n.className = "notify";
169 } else if (n_type == 2) {
170 n.className = "notifyProgress";
171 msg = "<img src='images/indicator_white.gif'> " + msg;
172 } else if (n_type == 3) {
f407c086 173 n.className = "notifyError";
e780d1d2 174 msg = "<img src='images/sign_excl.gif'> " + msg;
42c32916
AD
175 } else if (n_type == 4) {
176 n.className = "notifyInfo";
e780d1d2 177 msg = "<img src='images/sign_info.gif'> " + msg;
0530ddd8
AD
178 }
179
106689b0
AD
180// msg = "<img src='images/live_com_loading.gif'> " + msg;
181
0ceded7a
AD
182 nb.innerHTML = msg;
183
4d4200a8 184 if (!no_hide) {
292a8a12 185 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
4d4200a8 186 }
ce3bf408
AD
187}
188
42c32916
AD
189function notify(msg, no_hide) {
190 notify_real(msg, no_hide, 1);
ce3bf408
AD
191}
192
42c32916
AD
193function notify_progress(msg, no_hide) {
194 notify_real(msg, no_hide, 2);
195}
196
197function notify_error(msg, no_hide) {
198 notify_real(msg, no_hide, 3);
199
200}
201
202function notify_info(msg, no_hide) {
203 notify_real(msg, no_hide, 4);
7726fa02
AD
204}
205
508a81e1 206function printLockingError() {
42c32916
AD
207 notify_info("Please wait until operation finishes.");
208}
508a81e1 209
e828e31e 210function cleanSelectedList(element) {
f0601b87
AD
211 var content = document.getElementById(element);
212
703b632e
AD
213 if (!document.getElementById("feedCatHolder")) {
214 for (i = 0; i < content.childNodes.length; i++) {
215 var child = content.childNodes[i];
d0bb308e
AD
216 try {
217 child.className = child.className.replace("Selected", "");
218 } catch (e) {
219 //
220 }
703b632e
AD
221 }
222 } else {
223 for (i = 0; i < content.childNodes.length; i++) {
224 var child = content.childNodes[i];
703b632e 225 if (child.id == "feedCatHolder") {
9cb99906 226 debug(child.id);
c3f348c2 227 var fcat = child.lastChild;
703b632e 228 for (j = 0; j < fcat.childNodes.length; j++) {
befc807f 229 var feed = fcat.childNodes[j];
703b632e
AD
230 feed.className = feed.className.replace("Selected", "");
231 }
232 }
befc807f 233 }
703b632e 234 }
e828e31e
AD
235}
236
237
238function cleanSelected(element) {
239 var content = document.getElementById(element);
f0601b87
AD
240
241 for (i = 0; i < content.rows.length; i++) {
242 content.rows[i].className = content.rows[i].className.replace("Selected", "");
243 }
f0601b87
AD
244}
245
246function getVisibleUnreadHeadlines() {
247 var content = document.getElementById("headlinesList");
248
249 var rows = new Array();
250
3a40e8a2
AD
251 if (!content) return rows;
252
f0601b87
AD
253 for (i = 0; i < content.rows.length; i++) {
254 var row_id = content.rows[i].id.replace("RROW-", "");
255 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
256 rows.push(row_id);
257 }
258 }
259 return rows;
260}
261
262function getVisibleHeadlineIds() {
263
264 var content = document.getElementById("headlinesList");
265
266 var rows = new Array();
267
3a40e8a2
AD
268 if (!content) return rows;
269
f0601b87
AD
270 for (i = 0; i < content.rows.length; i++) {
271 var row_id = content.rows[i].id.replace("RROW-", "");
272 if (row_id.length > 0) {
273 rows.push(row_id);
274 }
275 }
276 return rows;
277}
278
279function getFirstVisibleHeadlineId() {
5ad9d132
AD
280 if (isCdmMode()) {
281 var rows = cdmGetVisibleArticles();
282 return rows[0];
283 } else {
284 var rows = getVisibleHeadlineIds();
285 return rows[0];
286 }
f0601b87
AD
287}
288
289function getLastVisibleHeadlineId() {
5ad9d132
AD
290 if (isCdmMode()) {
291 var rows = cdmGetVisibleArticles();
292 return rows[rows.length-1];
293 } else {
294 var rows = getVisibleHeadlineIds();
295 return rows[rows.length-1];
296 }
f0601b87
AD
297}
298
299function markHeadline(id) {
300 var row = document.getElementById("RROW-" + id);
301 if (row) {
35f3c923
AD
302 var is_active = false;
303
304 if (row.className.match("Active")) {
305 is_active = true;
306 }
307 row.className = row.className.replace("Selected", "");
308 row.className = row.className.replace("Active", "");
309 row.className = row.className.replace("Insensitive", "");
310
311 if (is_active) {
312 row.className = row.className = "Active";
313 }
314
72020095
AD
315 var check = document.getElementById("RCHK-" + id);
316
317 if (check) {
318 check.checked = true;
319 }
320
35f3c923
AD
321 row.className = row.className + "Selected";
322
f0601b87
AD
323 }
324}
325
326function getFeedIds() {
327 var content = document.getElementById("feedsList");
328
329 var rows = new Array();
330
331 for (i = 0; i < content.rows.length; i++) {
332 var id = content.rows[i].id.replace("FEEDR-", "");
333 if (id.length > 0) {
334 rows.push(id);
335 }
336 }
337
338 return rows;
339}
13ad9102 340
76b4eae1
AD
341function setCookie(name, value, lifetime, path, domain, secure) {
342
343 var d = false;
344
345 if (lifetime) {
346 d = new Date();
be0801a1 347 d.setTime(d.getTime() + (lifetime * 1000));
76b4eae1 348 }
cdbb6dc6
AD
349
350 debug("setCookie: " + name + " => " + value + ": " + d);
76b4eae1
AD
351
352 int_setCookie(name, value, d, path, domain, secure);
353
354}
355
356function int_setCookie(name, value, expires, path, domain, secure) {
ac43eba1
AD
357 document.cookie= name + "=" + escape(value) +
358 ((expires) ? "; expires=" + expires.toGMTString() : "") +
359 ((path) ? "; path=" + path : "") +
360 ((domain) ? "; domain=" + domain : "") +
361 ((secure) ? "; secure" : "");
362}
363
76b4eae1
AD
364function delCookie(name, path, domain) {
365 if (getCookie(name)) {
366 document.cookie = name + "=" +
367 ((path) ? ";path=" + path : "") +
368 ((domain) ? ";domain=" + domain : "" ) +
369 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
370 }
371}
372
373
ac43eba1
AD
374function getCookie(name) {
375
376 var dc = document.cookie;
377 var prefix = name + "=";
378 var begin = dc.indexOf("; " + prefix);
379 if (begin == -1) {
380 begin = dc.indexOf(prefix);
381 if (begin != 0) return null;
382 }
383 else {
384 begin += 2;
385 }
386 var end = document.cookie.indexOf(";", begin);
387 if (end == -1) {
388 end = dc.length;
389 }
390 return unescape(dc.substring(begin + prefix.length, end));
391}
392
1a66d16e
AD
393function disableContainerChildren(id, disable, doc) {
394
395 if (!doc) doc = document;
396
397 var container = doc.getElementById(id);
ac43eba1 398
4220b0bd
AD
399 if (!container) {
400 //alert("disableContainerChildren: element " + id + " not found");
401 return;
402 }
403
ac43eba1
AD
404 for (var i = 0; i < container.childNodes.length; i++) {
405 var child = container.childNodes[i];
406
d5224f0d
AD
407 try {
408 child.disabled = disable;
409 } catch (E) {
410
411 }
ac43eba1
AD
412
413 if (disable) {
414 if (child.className && child.className.match("button")) {
415 child.className = "disabledButton";
416 }
417 } else {
418 if (child.className && child.className.match("disabledButton")) {
419 child.className = "button";
420 }
d5224f0d 421 }
ac43eba1
AD
422 }
423
424}
7726fa02 425
e828e31e
AD
426function gotoPreferences() {
427 document.location.href = "prefs.php";
428}
429
430function gotoMain() {
431 document.location.href = "tt-rss.php";
432}
433
8158c57a
AD
434function gotoExportOpml() {
435 document.location.href = "opml.php?op=Export";
436}
86741347
AD
437
438function getActiveFeedId() {
33d13e72
AD
439// return getCookie("ttrss_vf_actfeed");
440 try {
0feab655
AD
441 debug("gAFID: " + active_feed_id);
442 return active_feed_id;
33d13e72
AD
443 } catch (e) {
444 exception_error("getActiveFeedId", e);
445 }
86741347
AD
446}
447
0a6c4846 448function activeFeedIsCat() {
0feab655 449 return active_feed_is_cat;
0a6c4846
AD
450}
451
86741347 452function setActiveFeedId(id) {
33d13e72
AD
453// return setCookie("ttrss_vf_actfeed", id);
454 try {
5c365f60 455 debug("sAFID(" + id + ")");
0feab655 456 active_feed_id = id;
33d13e72
AD
457 } catch (e) {
458 exception_error("setActiveFeedId", e);
459 }
86741347 460}
090e250b 461
ac378ad4 462function parse_counters(reply, scheduled_call) {
1a6a9555 463 try {
ac378ad4 464
9e397d0f
AD
465 var feeds_found = 0;
466
85bd574b 467 var elems = reply.getElementsByTagName("counter");
f54f515f 468
85bd574b 469 for (var l = 0; l < elems.length; l++) {
6043fb7e 470
85bd574b
AD
471 var id = elems[l].getAttribute("id");
472 var t = elems[l].getAttribute("type");
473 var ctr = elems[l].getAttribute("counter");
474 var error = elems[l].getAttribute("error");
475 var has_img = elems[l].getAttribute("hi");
476 var updated = elems[l].getAttribute("updated");
4ffa126e 477 var title = elems[l].getAttribute("title");
bdb7369b
AD
478 var xmsg = elems[l].getAttribute("xmsg");
479
1a6a9555 480 if (id == "global-unread") {
0feab655
AD
481 global_unread = ctr;
482 updateTitle();
1a6a9555
AD
483 continue;
484 }
7bf7e4d3
AD
485
486 if (id == "subscribed-feeds") {
487 feeds_found = ctr;
488 continue;
489 }
1a6a9555
AD
490
491 if (t == "category") {
0feab655 492 var catctr = document.getElementById("FCATCTR-" + id);
1a6a9555 493 if (catctr) {
67dabe1a
AD
494 catctr.innerHTML = "(" + ctr + ")";
495 if (ctr > 0) {
496 catctr.className = "catCtrHasUnread";
497 } else {
498 catctr.className = "catCtrNoUnread";
499 }
1a6a9555
AD
500 }
501 continue;
502 }
503
0feab655
AD
504 var feedctr = document.getElementById("FEEDCTR-" + id);
505 var feedu = document.getElementById("FEEDU-" + id);
506 var feedr = document.getElementById("FEEDR-" + id);
507 var feed_img = document.getElementById("FIMG-" + id);
508 var feedlink = document.getElementById("FEEDL-" + id);
509 var feedupd = document.getElementById("FLUPD-" + id);
fb1fb4ab
AD
510
511 if (updated && feedlink) {
512 if (error) {
513 feedlink.title = "Error: " + error + " (" + updated + ")";
514 } else {
515 feedlink.title = "Updated: " + updated;
516 }
517 }
023fe037 518
bdb7369b
AD
519 if (feedupd) {
520 if (!updated) updated = "";
521
78d5212c 522 if (error) {
bdb7369b
AD
523 if (xmsg) {
524 feedupd.innerHTML = updated + " " + xmsg + " (Error)";
525 } else {
526 feedupd.innerHTML = updated + " (Error)";
527 }
78d5212c 528 } else {
bdb7369b
AD
529 if (xmsg) {
530 feedupd.innerHTML = updated + " " + xmsg;
531 } else {
532 feedupd.innerHTML = updated;
533 }
78d5212c
AD
534 }
535 }
536
527c3bf0 537 if (has_img && feed_img && !is_msie()) {
f780548a
AD
538 if (!feed_img.src.match(id + ".ico")) {
539 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
540 }
527c3bf0
AD
541 }
542
4ffa126e
AD
543 if (feedlink && title) {
544 feedlink.innerHTML = title;
545 }
546
1a6a9555 547 if (feedctr && feedu && feedr) {
e8ef3b97
AD
548
549 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
5b064721 550 viewCurrentFeed();
e8ef3b97 551 }
8e9141ed
AD
552
553 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
554
1a6a9555 555 feedu.innerHTML = ctr;
023fe037 556
426d3c57
AD
557 if (error) {
558 feedr.className = feedr.className.replace("feed", "error");
559 } else if (id > 0) {
560 feedr.className = feedr.className.replace("error", "feed");
023fe037 561 }
1a6a9555
AD
562
563 if (ctr > 0) {
564 feedctr.className = "odd";
565 if (!feedr.className.match("Unread")) {
566 var is_selected = feedr.className.match("Selected");
567
568 feedr.className = feedr.className.replace("Selected", "");
569 feedr.className = feedr.className.replace("Unread", "");
570
571 feedr.className = feedr.className + "Unread";
572
573 if (is_selected) {
574 feedr.className = feedr.className + "Selected";
8e9141ed
AD
575 }
576
577 }
578
579 if (row_needs_hl) {
1341ea0d
AD
580 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
581 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
1a6a9555
AD
582 }
583 } else {
584 feedctr.className = "invisible";
585 feedr.className = feedr.className.replace("Unread", "");
586 }
587 }
588 }
9e397d0f 589
0feab655 590 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
7553dd8b 591
0feab655 592 var feeds_stored = number_of_feeds;
9e397d0f
AD
593
594 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
595
596 if (feeds_stored != feeds_found) {
0feab655 597 number_of_feeds = feeds_found;
7bf7e4d3 598
2fe69e22 599 if (feeds_stored != 0 && feeds_found != 0) {
9e397d0f 600 debug("Subscribed feed number changed, refreshing feedlist");
0e9dd1ba 601 setTimeout('updateFeedList(false, false)', 50);
9e397d0f
AD
602 }
603 }
604
1a6a9555 605 } catch (e) {
83f043bb 606 exception_error("parse_counters", e);
1a6a9555
AD
607 }
608}
609
288487e4 610function parse_counters_reply(transport, scheduled_call) {
5854573a 611
288487e4 612 if (!transport.responseXML) {
42c32916 613 notify_error("Backend did not return valid XML", true);
5854573a
AD
614 return;
615 }
616
288487e4 617 var reply = transport.responseXML.firstChild;
5854573a
AD
618
619 if (!reply) {
42c32916 620 notify_error("Backend did not return expected XML object", true);
5854573a
AD
621 updateTitle("");
622 return;
623 }
624
625 var error_code = false;
626 var error_msg = false;
627
628 if (reply.firstChild) {
629 error_code = reply.firstChild.getAttribute("error-code");
630 error_msg = reply.firstChild.getAttribute("error-msg");
631 }
632
633 if (!error_code) {
634 error_code = reply.getAttribute("error-code");
635 error_msg = reply.getAttribute("error-msg");
636 }
637
638 if (error_code && error_code != 0) {
639 debug("refetch_callback: got error code " + error_code);
640 return fatalError(error_code, error_msg);
641 }
642
36e05046 643 var counters = reply.getElementsByTagName("counters")[0];
5854573a 644
3ac2f3c7 645 parse_counters(counters, scheduled_call);
5854573a 646
36e05046 647 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
5854573a
AD
648
649 parse_runtime_info(runtime_info);
650
651 if (getInitParam("feeds_sort_by_unread") == 1) {
652 resort_feedlist();
653 }
654
655 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
656
657}
658
1341ea0d
AD
659function all_counters_callback2(transport) {
660 try {
661 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
662 parse_counters_reply(transport);
663 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
664
665 } catch (e) {
666 exception_error("all_counters_callback2", e);
667 }
668}
669
8e9dd206
AD
670function get_feed_unread(id) {
671 try {
672 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);
673 } catch (e) {
674 exception_error("get_feed_unread", e, true);
675 return -1;
676 }
677}
678
c9268ed5
AD
679function get_feed_entry_unread(doc, elem) {
680
681 var id = elem.id.replace("FEEDR-", "");
682
683 if (id <= 0) {
684 return -1;
685 }
686
687 try {
688 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
689 } catch (e) {
690 return -1;
691 }
692}
693
694function resort_category(doc, node) {
695 debug("resort_category: " + node);
696
697 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
698 for (i = 0; i < node.childNodes.length; i++) {
699 if (node.childNodes[i].nodeName != "LI") { continue; }
700
701 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
702 continue;
703 }
704
705 for (j = i+1; j < node.childNodes.length; j++) {
706 if (node.childNodes[j].nodeName != "LI") { continue; }
707
708 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
709 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
710
711 if (cur_val > tmp_val) {
712 tempnode_i = node.childNodes[i].cloneNode(true);
713 tempnode_j = node.childNodes[j].cloneNode(true);
714 node.replaceChild(tempnode_i, node.childNodes[j]);
715 node.replaceChild(tempnode_j, node.childNodes[i]);
716 }
717 }
718
719 }
720 }
721
722}
723
724function resort_feedlist() {
725 debug("resort_feedlist");
726
0feab655 727 var fd = document;
c9268ed5
AD
728
729 if (fd.getElementById("feedCatHolder")) {
730
731 var feeds = fd.getElementById("feedList");
732 var child = feeds.firstChild;
733
734 while (child) {
735
736 if (child.id == "feedCatHolder") {
737 resort_category(fd, child.firstChild);
738 }
739
740 child = child.nextSibling;
741 }
742
743 } else {
744 resort_category(fd, fd.getElementById("feedList"));
745 }
746}
747
b6644d29
AD
748/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
749 * * @author Sundar Dorai-Raj
750 * * Email: sdoraira@vt.edu
751 * * This program is free software; you can redistribute it and/or
752 * * modify it under the terms of the GNU General Public License
753 * * as published by the Free Software Foundation; either version 2
754 * * of the License, or (at your option) any later version,
755 * * provided that any use properly credits the author.
756 * * This program is distributed in the hope that it will be useful,
757 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
758 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
759 * * GNU General Public License for more details at http://www.gnu.org * * */
760
761 var numbers=".0123456789";
762 function isNumeric(x) {
763 // is x a String or a character?
764 if(x.length>1) {
765 // remove negative sign
766 x=Math.abs(x)+"";
767 for(j=0;j<x.length;j++) {
768 // call isNumeric recursively for each character
769 number=isNumeric(x.substring(j,j+1));
770 if(!number) return number;
771 }
772 return number;
773 }
774 else {
775 // if x is number return true
776 if(numbers.indexOf(x)>=0) return true;
777 return false;
778 }
779 }
780
3745788e
AD
781
782function hideOrShowFeeds(doc, hide) {
783
7553dd8b
AD
784 debug("hideOrShowFeeds: " + doc + ", " + hide);
785
0feab655 786 var fd = document;
293fa942
AD
787
788 var list = fd.getElementById("feedList");
789
790 if (fd.getElementById("feedCatHolder")) {
791
792 var feeds = fd.getElementById("feedList");
793 var child = feeds.firstChild;
794
795 while (child) {
796
797 if (child.id == "feedCatHolder") {
798 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
799 }
800
801 child = child.nextSibling;
802 }
803
804 } else {
805 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
806 }
807}
808
809function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
810
811// debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
3ed751d4 812
293fa942 813 var cat_unread = 0;
3745788e 814
4724a093
AD
815 if (!node) {
816 debug("hideOrShowFeeds: passed node is null, aborting");
817 return;
818 }
819
1a9b5b84 820// debug("cat: " + node.id);
2c2b019b 821
293fa942
AD
822 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
823 for (i = 0; i < node.childNodes.length; i++) {
824 if (node.childNodes[i].nodeName != "LI") { continue; }
bbf4d0b2 825
b31c2311 826 if (node.childNodes[i].style != undefined) {
293fa942 827
947c6186 828 var has_unread = (node.childNodes[i].className != "feed" &&
7a64852c 829 node.childNodes[i].className != "label" &&
22f3e356
AD
830 !(!getInitParam("hide_read_shows_special") &&
831 node.childNodes[i].className == "virt") &&
88b47be7 832 node.childNodes[i].className != "error" &&
947c6186 833 node.childNodes[i].className != "tag");
b31c2311 834
2c2b019b 835// debug(node.childNodes[i].id + " --> " + has_unread);
b31c2311
AD
836
837 if (hide && !has_unread) {
225ec0d4 838 //node.childNodes[i].style.display = "none";
f03ce70e
AD
839 var id = node.childNodes[i].id;
840 Effect.Fade(node.childNodes[i], {duration : 0.3,
841 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
b31c2311
AD
842 }
843
844 if (!hide) {
845 node.childNodes[i].style.display = "list-item";
225ec0d4 846 //Effect.Appear(node.childNodes[i], {duration : 0.3});
b31c2311
AD
847 }
848
849 if (has_unread) {
7553dd8b 850 node.childNodes[i].style.display = "list-item";
b31c2311 851 cat_unread++;
225ec0d4
AD
852 //Effect.Appear(node.childNodes[i], {duration : 0.3});
853 //Effect.Highlight(node.childNodes[i]);
b31c2311 854 }
293fa942 855 }
3745788e 856 }
b31c2311 857 }
3745788e 858
1a9b5b84 859// debug("end cat: " + node.id + " unread " + cat_unread);
2c2b019b 860
293fa942 861 if (cat_unread == 0) {
b31c2311
AD
862 if (cat_node.style == undefined) {
863 debug("ERROR: supplied cat_node " + cat_node +
864 " has no styles. WTF?");
865 return;
866 }
293fa942 867 if (hide) {
38c142d9 868 //cat_node.style.display = "none";
f03ce70e 869 Effect.Fade(cat_node, {duration : 0.3,
70ee3028 870 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
293fa942
AD
871 } else {
872 cat_node.style.display = "list-item";
873 }
7553dd8b 874 } else {
0ac2faea
AD
875 try {
876 cat_node.style.display = "list-item";
877 } catch (e) {
878 debug(e);
879 }
293fa942 880 }
3745788e 881
293fa942 882// debug("unread for category: " + cat_unread);
3745788e
AD
883}
884
35f3c923
AD
885function selectTableRow(r, do_select) {
886 r.className = r.className.replace("Selected", "");
887
888 if (do_select) {
889 r.className = r.className + "Selected";
890 }
891}
892
6c12c809
AD
893function selectTableRowById(elem_id, check_id, do_select) {
894
895 try {
896
897 var row = document.getElementById(elem_id);
898
899 if (row) {
900 selectTableRow(row, do_select);
901 }
902
903 var check = document.getElementById(check_id);
904
905 if (check) {
906 check.checked = do_select;
907 }
908 } catch (e) {
909 exception_error("selectTableRowById", e);
910 }
911}
912
1572afe5 913function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
649e0af9 914 classcheck, reset_others) {
3745788e 915
35f3c923
AD
916 var content = document.getElementById(content_id);
917
918 if (!content) {
919 alert("[selectTableRows] Element " + content_id + " not found.");
920 return;
921 }
922
923 for (i = 0; i < content.rows.length; i++) {
7a822893
AD
924 if (Element.visible(content.rows[i])) {
925 if (!classcheck || content.rows[i].className.match(classcheck)) {
926
927 if (content.rows[i].id.match(prefix)) {
928 selectTableRow(content.rows[i], do_select);
929
930 var row_id = content.rows[i].id.replace(prefix, "");
931 var check = document.getElementById(check_prefix + row_id);
932
933 if (check) {
934 check.checked = do_select;
935 }
936 } else if (reset_others) {
937 selectTableRow(content.rows[i], false);
938
939 var row_id = content.rows[i].id.replace(prefix, "");
940 var check = document.getElementById(check_prefix + row_id);
941
942 if (check) {
943 check.checked = false;
944 }
1572afe5 945
649e0af9
AD
946 }
947 } else if (reset_others) {
948 selectTableRow(content.rows[i], false);
7a822893 949
7d8d10c6
AD
950 var row_id = content.rows[i].id.replace(prefix, "");
951 var check = document.getElementById(check_prefix + row_id);
7a822893 952
7d8d10c6
AD
953 if (check) {
954 check.checked = false;
955 }
7a822893 956
7d8d10c6 957 }
3055bc41 958 }
35f3c923 959 }
295f9b42 960}
91ff844a
AD
961
962function getSelectedTableRowIds(content_id, prefix) {
963
964 var content = document.getElementById(content_id);
965
966 if (!content) {
967 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
968 return;
969 }
970
971 var sel_rows = new Array();
972
973 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
974 if (content.rows[i].id.match(prefix) &&
975 content.rows[i].className.match("Selected")) {
976
91ff844a
AD
977 var row_id = content.rows[i].id.replace(prefix + "-", "");
978 sel_rows.push(row_id);
979 }
980 }
981
982 return sel_rows;
983
984}
985
386cbf27
AD
986function toggleSelectRowById(sender, id) {
987 var row = document.getElementById(id);
988
989 if (sender.checked) {
990 if (!row.className.match("Selected")) {
991 row.className = row.className + "Selected";
992 }
993 } else {
994 if (row.className.match("Selected")) {
995 row.className = row.className.replace("Selected", "");
996 }
997 }
998}
999
b92e6209
AD
1000function toggleSelectListRow(sender) {
1001 var parent_row = sender.parentNode;
1002
1003 if (sender.checked) {
1004 if (!parent_row.className.match("Selected")) {
1005 parent_row.className = parent_row.className + "Selected";
1006 }
1007 } else {
1008 if (parent_row.className.match("Selected")) {
1009 parent_row.className = parent_row.className.replace("Selected", "");
1010 }
1011 }
1012}
1013
67343d9f
AD
1014function tSR(sender) {
1015 return toggleSelectRow(sender);
1016}
386cbf27 1017
1572afe5
AD
1018function toggleSelectRow(sender) {
1019 var parent_row = sender.parentNode.parentNode;
1020
1021 if (sender.checked) {
1022 if (!parent_row.className.match("Selected")) {
1023 parent_row.className = parent_row.className + "Selected";
1024 }
1025 } else {
1026 if (parent_row.className.match("Selected")) {
1027 parent_row.className = parent_row.className.replace("Selected", "");
1028 }
1029 }
1030}
1031
1da76274 1032function getRelativeFeedId(list, id, direction, unread_only) {
731b05f4
AD
1033 var rows = list.getElementsByTagName("LI");
1034 var feeds = new Array();
1035
1036 for (var i = 0; i < rows.length; i++) {
1037 if (rows[i].id.match("FEEDR-")) {
1038
8809f484 1039 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
731b05f4
AD
1040
1041 if (!unread_only ||
1042 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1043 feeds.push(rows[i].id.replace("FEEDR-", ""));
1044 }
1045 }
1046 }
1047 }
1048
7b433d8c 1049 if (!id) {
731b05f4
AD
1050 if (direction == "next") {
1051 return feeds.shift();
1052 } else {
1053 return feeds.pop();
1054 }
1055 } else {
1056 if (direction == "next") {
1057 var idx = feeds.indexOf(id);
1058 if (idx != -1 && idx < feeds.length) {
1059 return feeds[idx+1];
07a67863
AD
1060 } else {
1061 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1062 }
1063 } else {
1064 var idx = feeds.indexOf(id);
1065 if (idx > 0) {
1066 return feeds[idx-1];
07a67863
AD
1067 } else {
1068 return getRelativeFeedId(list, false, direction, unread_only);
731b05f4
AD
1069 }
1070 }
1071
1072 }
7b433d8c 1073}
36aab70f 1074
f27de515 1075function showBlockElement(id, h_id) {
36aab70f
AD
1076 var elem = document.getElementById(id);
1077
1078 if (elem) {
1079 elem.style.display = "block";
f27de515
AD
1080
1081 if (h_id) {
1082 elem = document.getElementById(h_id);
1083 if (elem) {
1084 elem.style.display = "none";
1085 }
1086 }
36aab70f
AD
1087 } else {
1088 alert("[showBlockElement] can't find element with id " + id);
1089 }
1090}
1091
b9073cd9
AD
1092function appearBlockElement_afh(effect) {
1093
1094}
1095
1096function checkboxToggleElement(elem, id) {
1097 if (elem.checked) {
b1085d24 1098 Effect.SlideDown(id, {duration : 0.5});
b9073cd9 1099 } else {
b1085d24 1100 Effect.SlideUp(id, {duration : 0.5});
b9073cd9
AD
1101 }
1102}
1103
1104function appearBlockElement(id, h_id) {
1105
1106 try {
a04c8e8d
AD
1107 if (h_id) {
1108 Effect.Fade(h_id);
1109 }
b9073cd9
AD
1110 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1111 } catch (e) {
1112 exception_error("appearBlockElement", e);
1113 }
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) {
5ede560f 1161
569720c5 1162 Element.hide("dialog_overlay");
5ede560f 1163
e5d758e3
AD
1164 var box = document.getElementById('infoBox');
1165 var shadow = document.getElementById('infoBoxShadow');
1166
1167 if (shadow) {
1168 shadow.style.display = "none";
1169 } else if (box) {
1170 box.style.display = "none";
1171 }
1172
86b682ce
AD
1173 if (cleanup) box.innerHTML = "&nbsp;";
1174
e5d758e3 1175 enableHotkeys();
c14b5566 1176
90ac84df 1177 return false;
e5d758e3
AD
1178}
1179
1180
7b5c6012
AD
1181function displayDlg(id, param) {
1182
35a03bdd 1183 notify_progress("Loading, please wait...", true);
7b5c6012 1184
7b5c6012 1185 disableHotkeys();
2371c520 1186
288487e4
AD
1187 var query = "backend.php?op=dlg&id=" +
1188 param_escape(id) + "&param=" + param_escape(param);
1189
1190 new Ajax.Request(query, {
1191 onComplete: function (transport) {
1192 infobox_callback2(transport);
1193 } });
1194
90ac84df 1195 return false;
7b5c6012
AD
1196}
1197
288487e4
AD
1198function infobox_submit_callback2(transport) {
1199 closeInfoBox();
79f3553b 1200
288487e4
AD
1201 try {
1202 // called from prefs, reload tab
438f2ce9 1203 if (typeof active_tab != 'undefined' && active_tab) {
288487e4 1204 selectTab(active_tab, false);
5e6f933a 1205 }
288487e4 1206 } catch (e) { }
79f3553b 1207
288487e4
AD
1208 if (transport.responseText) {
1209 notify_info(transport.responseText);
1210 }
7b5c6012
AD
1211}
1212
d395a942
AD
1213function infobox_callback2(transport) {
1214 try {
5ede560f 1215
d395a942 1216 debug("infobox_callback2");
5ede560f 1217
569720c5
AD
1218 if (!getInitParam("infobox_disable_overlay")) {
1219 Element.show("dialog_overlay");
d395a942
AD
1220 }
1221
1222 var box = document.getElementById('infoBox');
1223 var shadow = document.getElementById('infoBoxShadow');
1224 if (box) {
1dc47c41 1225
d395a942
AD
1226 box.innerHTML=transport.responseText;
1227 if (shadow) {
1228 shadow.style.display = "block";
1229 } else {
1230 box.style.display = "block";
aa8716da 1231 }
d395a942 1232 }
05fcdf52 1233
d395a942 1234 /* FIXME this needs to be moved out somewhere */
05fcdf52 1235
d395a942
AD
1236 if (document.getElementById("tags_choices")) {
1237 new Ajax.Autocompleter('tags_str', 'tags_choices',
1238 "backend.php?op=rpc&subop=completeTags",
1239 { tokens: ',', paramName: "search" });
442d77f1 1240 }
d395a942 1241
6068d33b
AD
1242 disableHotkeys();
1243
d395a942
AD
1244 notify("");
1245 } catch (e) {
1246 exception_error("infobox_callback2", e);
442d77f1
AD
1247 }
1248}
1249
18ab3d7a 1250function createFilter() {
7b5c6012 1251
438f2ce9 1252 try {
6068d33b 1253
438f2ce9
AD
1254 var form = document.forms['filter_add_form'];
1255 var reg_exp = form.reg_exp.value;
1256
1257 if (reg_exp == "") {
1258 alert(__("Can't add filter: nothing to match on."));
1259 return false;
1260 }
288487e4 1261
438f2ce9
AD
1262 var query = Form.serialize("filter_add_form");
1263
1264 // we can be called from some other tab in Prefs
1265 if (typeof active_tab != 'undefined' && active_tab) {
1266 active_tab = "filterConfig";
1267 }
1268
1269 new Ajax.Request("backend.php?" + query, {
1270 onComplete: function (transport) {
1271 infobox_submit_callback2(transport);
1272 } });
1273
1274 return true;
1275
1276 } catch (e) {
1277 exception_error("createFilter", e);
1278 }
7b5c6012
AD
1279}
1280
2371c520
AD
1281function toggleSubmitNotEmpty(e, submit_id) {
1282 try {
1283 document.getElementById(submit_id).disabled = (e.value == "")
1284 } catch (e) {
1285 exception_error("toggleSubmitNotEmpty", e);
1286 }
1287}
1d7bf5a0 1288
605f7d46 1289function isValidURL(s) {
0d32b41e 1290 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
605f7d46 1291}
07eb9178 1292
18ab3d7a 1293function subscribeToFeed() {
07eb9178 1294
c91c2249
AD
1295 var form = document.forms['feed_add_form'];
1296 var feed_url = form.feed_url.value;
1297
1298 if (feed_url == "") {
89cb787e 1299 alert(__("Can't subscribe: no feed URL given."));
c91c2249
AD
1300 return false;
1301 }
1302
1ba6daf7 1303 notify_progress(__("Subscribing to feed..."), true);
07eb9178
AD
1304
1305 closeInfoBox();
1306
0feab655 1307 var feeds_doc = document;
07eb9178 1308
80e4dc34 1309// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
07eb9178
AD
1310
1311 var query = Form.serialize("feed_add_form");
1312
f27de515
AD
1313 debug("subscribe q: " + query);
1314
288487e4
AD
1315 new Ajax.Request("backend.php", {
1316 parameters: query,
1317 onComplete: function(transport) {
1318 dlg_frefresh_callback(transport);
1319 } });
7bc4f251
AD
1320
1321 return false;
07eb9178
AD
1322}
1323
6e6504bc 1324function filterCR(e, f)
86b682ce
AD
1325{
1326 var key;
1327
1328 if(window.event)
1329 key = window.event.keyCode; //IE
1330 else
1331 key = e.which; //firefox
1332
6e6504bc
AD
1333 if (key == 13) {
1334 if (typeof f != 'undefined') {
1335 f();
1336 return false;
1337 } else {
1338 return false;
1339 }
1340 } else {
1341 return true;
1342 }
86b682ce
AD
1343}
1344
ac378ad4 1345function getMainContext() {
6b4163cb 1346 return this.window;
ac378ad4
AD
1347}
1348
33d13e72 1349function getFeedsContext() {
6b4163cb 1350 return this.window;
33d13e72
AD
1351}
1352
0bd411db 1353function getContentContext() {
6b4163cb 1354 return this.window;
0bd411db
AD
1355}
1356
ee1f45f4 1357function getHeadlinesContext() {
6b4163cb 1358 return this.window;
ee1f45f4
AD
1359}
1360
e8614131
AD
1361var debug_last_class = "even";
1362
ac378ad4 1363function debug(msg) {
ac378ad4 1364
0feab655
AD
1365 if (debug_last_class == "even") {
1366 debug_last_class = "odd";
e8614131 1367 } else {
0feab655 1368 debug_last_class = "even";
e8614131
AD
1369 }
1370
0feab655 1371 var c = document.getElementById('debug_output');
8836613c 1372 if (c && Element.visible(c)) {
c9268ed5 1373 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
ac378ad4
AD
1374 c.removeChild(c.lastChild);
1375 }
1376
1377 var d = new Date();
1378 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1379 ":" + leading_zero(d.getSeconds());
0feab655 1380 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
e8614131 1381 msg + "</li>" + c.innerHTML;
ac378ad4
AD
1382 }
1383}
1384
33d13e72 1385function getInitParam(key) {
40496720 1386 return init_params[key];
33d13e72 1387}
3ac2b520 1388
be0801a1 1389function storeInitParam(key, value) {
40496720 1390 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
5158ced9 1391 init_params[key] = value;
be0801a1
AD
1392}
1393
a7565293
AD
1394function fatalError(code, message) {
1395 try {
a7565293 1396
b4c27af7 1397 if (code == 6) {
8e849206 1398 window.location.href = "tt-rss.php";
b4c27af7
AD
1399 } else if (code == 5) {
1400 window.location.href = "update.php";
1401 } else {
4724a093
AD
1402 var fe = document.getElementById("fatal_error");
1403 var fc = document.getElementById("fatal_error_msg");
1404
42c32916
AD
1405 if (message == "") message = "Unknown error";
1406
a0a63217 1407 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
4724a093
AD
1408
1409 fe.style.display = "block";
4724a093 1410 }
a7565293
AD
1411
1412 } catch (e) {
1413 exception_error("fatalError", e);
1414 }
1415}
1416
234e467c 1417function getFeedName(id, is_cat) {
64a2875d 1418 var d = getFeedsContext().document;
234e467c
AD
1419
1420 var e;
1421
1422 if (is_cat) {
1423 e = d.getElementById("FCATN-" + id);
1424 } else {
1425 e = d.getElementById("FEEDN-" + id);
1426 }
64a2875d
AD
1427 if (e) {
1428 return e.innerHTML.stripTags();
1429 } else {
1430 return null;
1431 }
1432}
0bd411db
AD
1433
1434function viewContentUrl(url) {
1435 getContentContext().location = url;
1436}
350f0ad1
AD
1437
1438function filterDlgCheckAction(sender) {
1439
1440 try {
1441
1442 var action = sender[sender.selectedIndex].value;
1443
1444 var form = document.forms["filter_add_form"];
1445
1446 if (!form) {
1447 form = document.forms["filter_edit_form"];
1448 }
1449
1450 if (!form) {
1451 debug("filterDlgCheckAction: can't find form!");
1452 return;
1453 }
1454
1455 var action_param = form.action_param;
1456
1457 if (!action_param) {
1458 debug("filterDlgCheckAction: can't find action param!");
1459 return;
1460 }
1461
1462 // if selected action supports parameters, enable params field
48ddbb33 1463 if (action == 4 || action == 6) {
350f0ad1
AD
1464 action_param.disabled = false;
1465 } else {
1466 action_param.disabled = true;
1467 }
1468
1469 } catch (e) {
438f2ce9 1470 exception_error("filterDlgCheckAction", e);
350f0ad1
AD
1471 }
1472
1473}
ef16ae37
AD
1474
1475function explainError(code) {
1476 return displayDlg("explainError", code);
1477}
01a87dff 1478
e097e8be 1479// this only searches loaded headlines list, not in CDM
aa0fa9df 1480function getRelativePostIds(id, limit) {
e097e8be 1481
aa0fa9df
AD
1482 if (!limit) limit = 3;
1483
1484 debug("getRelativePostIds: " + id + " limit=" + limit);
e097e8be
AD
1485
1486 var ids = new Array();
1487 var container = document.getElementById("headlinesList");
1488
1489 if (container) {
1490 var rows = container.rows;
1491
1492 for (var i = 0; i < rows.length; i++) {
1493 var r_id = rows[i].id.replace("RROW-", "");
1494
1495 if (r_id == id) {
aa0fa9df
AD
1496 for (var k = 1; k <= limit; k++) {
1497 var nid = false;
1498
1499 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1500 if (nid) ids.push(nid);
1501
1502 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1503 if (nid) ids.push(nid);
1504 }
e097e8be
AD
1505
1506 return ids;
1507 }
1508 }
1509 }
1510
1511 return false;
1512}
298f3f78
AD
1513
1514function openArticleInNewWindow(id) {
1515 try {
298f3f78
AD
1516 debug("openArticleInNewWindow: " + id);
1517
1518 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
04e91733
AD
1519 var wname = "ttrss_article_" + id;
1520
1521 debug(query + " " + wname);
1522
1523 var w = window.open("", wname);
298f3f78 1524
04e91733 1525 if (!w) notify_error("Failed to open window for the article");
298f3f78 1526
d395a942
AD
1527 new Ajax.Request(query, {
1528 onComplete: function(transport) {
1529 open_article_callback(transport);
1530 } });
1531
298f3f78
AD
1532
1533 } catch (e) {
1534 exception_error("openArticleInNewWindow", e);
1535 }
1536}
e4914b62 1537
537625c6
AD
1538/* http://textsnippets.com/posts/show/835 */
1539
1540Position.GetWindowSize = function(w) {
1541 w = w ? w : window;
1542 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1543 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1544 return [width, height]
1545}
1546
1547/* http://textsnippets.com/posts/show/836 */
1548
1549Position.Center = function(element, parent) {
1550 var w, h, pw, ph;
1551 var d = Element.getDimensions(element);
1552 w = d.width;
1553 h = d.height;
1554 Position.prepare();
1555 if (!parent) {
1556 var ws = Position.GetWindowSize();
1557 pw = ws[0];
1558 ph = ws[1];
1559 } else {
1560 pw = parent.offsetWidth;
1561 ph = parent.offsetHeight;
1562 }
1563 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1564 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1565}
1566
768858f1 1567
288487e4
AD
1568function labeltest_callback(transport) {
1569 try {
1570 var container = document.getElementById('label_test_result');
1571
1572 container.innerHTML = transport.responseText;
768858f1
AD
1573 if (!Element.visible(container)) {
1574 Effect.SlideDown(container, { duration : 0.5 });
1575 }
288487e4 1576
6f151277 1577 notify("");
288487e4
AD
1578 } catch (e) {
1579 exception_error("labeltest_callback", e);
6f151277
AD
1580 }
1581}
1582
1583function labelTest() {
1584
288487e4
AD
1585 try {
1586 var container = document.getElementById('label_test_result');
1587
1588 var form = document.forms['label_edit_form'];
1589
1590 var sql_exp = form.sql_exp.value;
1591 var description = form.description.value;
1592
1593 notify_progress("Loading, please wait...");
1594
1595 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1596 param_escape(sql_exp) + "&descr=" + param_escape(description);
1597
1598 new Ajax.Request(query, {
1599 onComplete: function (transport) {
1600 labeltest_callback(transport);
1601 } });
1602
1603 return false;
6f151277 1604
288487e4
AD
1605 } catch (e) {
1606 exception_error("labelTest", e);
1607 }
6f151277
AD
1608}
1609
c32cd48a
AD
1610function isCdmMode() {
1611 return !document.getElementById("headlinesList");
1612}
1613
1614function getSelectedArticleIds2() {
1615 var rows = new Array();
1616 var cdm_mode = isCdmMode();
1617
1618 if (cdm_mode) {
1619 rows = cdmGetSelectedArticles();
1620 } else {
1621 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1622 }
1623
1624 var ids = new Array();
1625
1626 for (var i = 0; i < rows.length; i++) {
1627 var chk = document.getElementById("RCHK-" + rows[i]);
1628 if (chk && chk.checked) {
1629 ids.push(rows[i]);
1630 }
1631 }
1632
1633 return ids;
1634}
c4a36709 1635
f6d40ed2 1636function displayHelpInfobox(topic_id) {
c4a36709 1637
f6d40ed2
AD
1638 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1639
1640 var w = window.open(url, "ttrss_help",
1641 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1642
1643 return false;
1644}
e635d56a 1645
477402d8 1646function focus_element(id) {
61992f57 1647 try {
477402d8
AD
1648 var e = document.getElementById(id);
1649 if (e) e.focus();
61992f57 1650 } catch (e) {
438f2ce9 1651 exception_error("focus_element", e);
61992f57 1652 }
477402d8 1653 return false;
61992f57 1654}
e635d56a 1655
99509451 1656function loading_set_progress(p) {
730dbf19 1657 try {
fca95d5f
AD
1658 if (p < last_progress_point || !Element.visible("overlay")) return;
1659
1660 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
99509451 1661
730dbf19 1662 var o = document.getElementById("l_progress_i");
99509451 1663
673c9946
AD
1664// o.style.width = (p * 2) + "px";
1665
99509451
AD
1666 new Effect.Scale(o, p, {
1667 scaleY : false,
1668 scaleFrom : last_progress_point,
1669 scaleMode: { originalWidth : 200 },
673c9946 1670 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
99509451
AD
1671
1672 last_progress_point = p;
730dbf19
AD
1673
1674 } catch (e) {
1675 exception_error("loading_set_progress", e);
1676 }
1677}
08827aaf
AD
1678
1679function remove_splash() {
1680 if (Element.visible("overlay")) {
1681 debug("about to remove splash, OMG!");
1682 Element.hide("overlay");
1683 debug("removed splash!");
1684 }
1685}