]>
Commit | Line | Data |
---|---|---|
1 | var hotkeys_enabled = true; | |
2 | var debug_mode_enabled = false; | |
3 | var xmlhttp_rpc = Ajax.getTransport(); | |
4 | ||
5 | /* add method to remove element from array */ | |
6 | ||
7 | Array.prototype.remove = function(s) { | |
8 | for (var i=0; i < this.length; i++) { | |
9 | if (s == this[i]) this.splice(i, 1); | |
10 | } | |
11 | } | |
12 | ||
13 | function browser_has_opacity() { | |
14 | return navigator.userAgent.match("Gecko") != null || | |
15 | navigator.userAgent.match("Opera") != null; | |
16 | } | |
17 | ||
18 | function is_msie() { | |
19 | return navigator.userAgent.match("MSIE"); | |
20 | } | |
21 | ||
22 | function is_opera() { | |
23 | return navigator.userAgent.match("Opera"); | |
24 | } | |
25 | ||
26 | function is_khtml() { | |
27 | return navigator.userAgent.match("KHTML"); | |
28 | } | |
29 | ||
30 | function is_safari() { | |
31 | return navigator.userAgent.match("Safari"); | |
32 | } | |
33 | ||
34 | function exception_error(location, e, silent) { | |
35 | var msg; | |
36 | ||
37 | if (e.fileName) { | |
38 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
39 | ||
40 | msg = "Exception: " + e.name + ", " + e.message + | |
41 | "\nFunction: " + location + "()" + | |
42 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
43 | ||
44 | } else { | |
45 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
46 | } | |
47 | ||
48 | debug("<b>EXCEPTION: " + msg + "</b>"); | |
49 | ||
50 | if (!silent) { | |
51 | alert(msg); | |
52 | } | |
53 | } | |
54 | ||
55 | function disableHotkeys() { | |
56 | hotkeys_enabled = false; | |
57 | } | |
58 | ||
59 | function enableHotkeys() { | |
60 | hotkeys_enabled = true; | |
61 | } | |
62 | ||
63 | function xmlhttp_ready(obj) { | |
64 | return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState; | |
65 | } | |
66 | ||
67 | function open_article_callback() { | |
68 | if (xmlhttp_rpc.readyState == 4) { | |
69 | try { | |
70 | ||
71 | if (xmlhttp_rpc.responseXML) { | |
72 | var link = xmlhttp_rpc.responseXML.getElementsByTagName("link")[0]; | |
73 | var id = xmlhttp_rpc.responseXML.getElementsByTagName("id")[0]; | |
74 | ||
75 | if (link) { | |
76 | window.open(link.firstChild.nodeValue, "_blank"); | |
77 | ||
78 | if (id) { | |
79 | id = id.firstChild.nodeValue; | |
80 | if (!document.getElementById("headlinesList")) { | |
81 | window.setTimeout("toggleUnread(" + id + ", 0)", 100); | |
82 | } | |
83 | } | |
84 | } | |
85 | } | |
86 | ||
87 | } catch (e) { | |
88 | exception_error("open_article_callback", e); | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | function logout_callback() { | |
94 | var container = document.getElementById('notify'); | |
95 | if (xmlhttp.readyState == 4) { | |
96 | try { | |
97 | var date = new Date(); | |
98 | var timestamp = Math.round(date.getTime() / 1000); | |
99 | window.location.href = "tt-rss.php"; | |
100 | } catch (e) { | |
101 | exception_error("logout_callback", e); | |
102 | } | |
103 | } | |
104 | } | |
105 | ||
106 | function notify_callback() { | |
107 | var container = document.getElementById('notify'); | |
108 | if (xmlhttp.readyState == 4) { | |
109 | container.innerHTML=xmlhttp.responseText; | |
110 | } | |
111 | } | |
112 | ||
113 | function rpc_notify_callback() { | |
114 | var container = document.getElementById('notify'); | |
115 | if (xmlhttp_rpc.readyState == 4) { | |
116 | container.innerHTML=xmlhttp_rpc.responseText; | |
117 | } | |
118 | } | |
119 | ||
120 | function param_escape(arg) { | |
121 | if (typeof encodeURIComponent != 'undefined') | |
122 | return encodeURIComponent(arg); | |
123 | else | |
124 | return escape(arg); | |
125 | } | |
126 | ||
127 | function param_unescape(arg) { | |
128 | if (typeof decodeURIComponent != 'undefined') | |
129 | return decodeURIComponent(arg); | |
130 | else | |
131 | return unescape(arg); | |
132 | } | |
133 | ||
134 | function delay(gap) { | |
135 | var then,now; | |
136 | then=new Date().getTime(); | |
137 | now=then; | |
138 | while((now-then)<gap) { | |
139 | now=new Date().getTime(); | |
140 | } | |
141 | } | |
142 | ||
143 | var notify_hide_timerid = false; | |
144 | ||
145 | function hide_notify() { | |
146 | var n = document.getElementById("notify"); | |
147 | if (n) { | |
148 | n.style.display = "none"; | |
149 | } | |
150 | } | |
151 | ||
152 | function notify_real(msg, no_hide, n_type) { | |
153 | ||
154 | var n = document.getElementById("notify"); | |
155 | var nb = document.getElementById("notify_body"); | |
156 | ||
157 | if (!n || !nb) return; | |
158 | ||
159 | if (notify_hide_timerid) { | |
160 | window.clearTimeout(notify_hide_timerid); | |
161 | } | |
162 | ||
163 | if (msg == "") { | |
164 | if (n.style.display == "block") { | |
165 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
166 | } | |
167 | return; | |
168 | } else { | |
169 | n.style.display = "block"; | |
170 | } | |
171 | ||
172 | /* types: | |
173 | ||
174 | 1 - generic | |
175 | 2 - progress | |
176 | 3 - error | |
177 | 4 - info | |
178 | ||
179 | */ | |
180 | ||
181 | if (typeof __ != 'undefined') { | |
182 | msg = __(msg); | |
183 | } | |
184 | ||
185 | if (n_type == 1) { | |
186 | n.className = "notify"; | |
187 | } else if (n_type == 2) { | |
188 | n.className = "notifyProgress"; | |
189 | msg = "<img src='images/indicator_white.gif'> " + msg; | |
190 | } else if (n_type == 3) { | |
191 | n.className = "notifyError"; | |
192 | msg = "<img src='images/sign_excl.png'> " + msg; | |
193 | } else if (n_type == 4) { | |
194 | n.className = "notifyInfo"; | |
195 | msg = "<img src='images/sign_info.png'> " + msg; | |
196 | } | |
197 | ||
198 | // msg = "<img src='images/live_com_loading.gif'> " + msg; | |
199 | ||
200 | nb.innerHTML = msg; | |
201 | ||
202 | if (!no_hide) { | |
203 | notify_hide_timerid = window.setTimeout("hide_notify()", 3000); | |
204 | } | |
205 | } | |
206 | ||
207 | function notify(msg, no_hide) { | |
208 | notify_real(msg, no_hide, 1); | |
209 | } | |
210 | ||
211 | function notify_progress(msg, no_hide) { | |
212 | notify_real(msg, no_hide, 2); | |
213 | } | |
214 | ||
215 | function notify_error(msg, no_hide) { | |
216 | notify_real(msg, no_hide, 3); | |
217 | ||
218 | } | |
219 | ||
220 | function notify_info(msg, no_hide) { | |
221 | notify_real(msg, no_hide, 4); | |
222 | } | |
223 | ||
224 | function printLockingError() { | |
225 | notify_info("Please wait until operation finishes."); | |
226 | } | |
227 | ||
228 | function hotkey_handler(e) { | |
229 | ||
230 | try { | |
231 | ||
232 | var keycode; | |
233 | var shift_key = false; | |
234 | ||
235 | try { | |
236 | shift_key = e.shiftKey; | |
237 | } catch (e) { | |
238 | ||
239 | } | |
240 | ||
241 | if (!hotkeys_enabled) return; | |
242 | ||
243 | if (window.event) { | |
244 | keycode = window.event.keyCode; | |
245 | } else if (e) { | |
246 | keycode = e.which; | |
247 | } | |
248 | ||
249 | if (keycode == 82) { // r | |
250 | return scheduleFeedUpdate(true); | |
251 | } | |
252 | ||
253 | if (keycode == 83) { // s | |
254 | return displayDlg("search", getActiveFeedId()); | |
255 | } | |
256 | ||
257 | if (keycode == 85) { // u | |
258 | if (getActiveFeedId()) { | |
259 | return viewfeed(getActiveFeedId(), "ForceUpdate"); | |
260 | } | |
261 | } | |
262 | ||
263 | if (keycode == 65) { // a | |
264 | return toggleDispRead(); | |
265 | } | |
266 | ||
267 | var feedlist = document.getElementById('feedList'); | |
268 | ||
269 | if (keycode == 74) { // j | |
270 | var feed = getActiveFeedId(); | |
271 | var new_feed = getRelativeFeedId(feedlist, feed, 'prev'); | |
272 | if (new_feed) viewfeed(new_feed, ''); | |
273 | } | |
274 | ||
275 | if (keycode == 75) { // k | |
276 | var feed = getActiveFeedId(); | |
277 | var new_feed = getRelativeFeedId(feedlist, feed, 'next'); | |
278 | if (new_feed) viewfeed(new_feed, ''); | |
279 | } | |
280 | ||
281 | if (keycode == 78 || keycode == 40) { // n, down | |
282 | if (typeof moveToPost != 'undefined') { | |
283 | return moveToPost('next'); | |
284 | } | |
285 | } | |
286 | ||
287 | if (keycode == 80 || keycode == 38) { // p, up | |
288 | if (typeof moveToPost != 'undefined') { | |
289 | return moveToPost('prev'); | |
290 | } | |
291 | } | |
292 | ||
293 | if (keycode == 68 && shift_key) { // d | |
294 | if (!debug_mode_enabled) { | |
295 | document.getElementById('debug_output').style.display = 'block'; | |
296 | debug('debug mode activated'); | |
297 | } else { | |
298 | document.getElementById('debug_output').style.display = 'none'; | |
299 | } | |
300 | ||
301 | debug_mode_enabled = !debug_mode_enabled; | |
302 | } | |
303 | ||
304 | if (keycode == 190 && shift_key) { // > | |
305 | viewFeedGoPage(1); | |
306 | } | |
307 | ||
308 | if (keycode == 188 && shift_key) { // < | |
309 | viewFeedGoPage(-1); | |
310 | } | |
311 | ||
312 | if (keycode == 191 && shift_key) { // ? | |
313 | viewFeedGoPage(0); | |
314 | } | |
315 | ||
316 | if (keycode == 69 && shift_key) { // e | |
317 | return editFeedDlg(getActiveFeedId()); | |
318 | } | |
319 | ||
320 | if (keycode == 70 && shift_key) { // f | |
321 | if (getActiveFeedId()) { | |
322 | return catchupCurrentFeed(); | |
323 | } | |
324 | } | |
325 | ||
326 | if (keycode == 80 && shift_key) { // p | |
327 | if (getActiveFeedId()) { | |
328 | return catchupPage(); | |
329 | } | |
330 | } | |
331 | ||
332 | if (keycode == 86) { // v | |
333 | if (getActiveArticleId()) { | |
334 | openArticleInNewWindow(getActiveArticleId()); | |
335 | } | |
336 | } | |
337 | ||
338 | if (keycode == 84) { // t | |
339 | ||
340 | var id = getActiveArticleId(); | |
341 | ||
342 | if (id) { | |
343 | ||
344 | var cb = document.getElementById("RCHK-" + id); | |
345 | ||
346 | if (cb) { | |
347 | cb.checked = !cb.checked; | |
348 | toggleSelectRowById(cb, "RROW-" + id); | |
349 | } | |
350 | } | |
351 | } | |
352 | ||
353 | if (keycode == 67) { // c | |
354 | var id = getActiveArticleId(); | |
355 | ||
356 | if (id) { | |
357 | toggleUnread(id, 0); | |
358 | } | |
359 | } | |
360 | ||
361 | if (typeof localHotkeyHandler != 'undefined') { | |
362 | try { | |
363 | return localHotkeyHandler(e); | |
364 | } catch (e) { | |
365 | exception_error("hotkey_handler, local:", e); | |
366 | } | |
367 | } | |
368 | ||
369 | debug("KP=" + keycode); | |
370 | } catch (e) { | |
371 | exception_error("hotkey_handler", e); | |
372 | } | |
373 | } | |
374 | ||
375 | function cleanSelectedList(element) { | |
376 | var content = document.getElementById(element); | |
377 | ||
378 | if (!document.getElementById("feedCatHolder")) { | |
379 | for (i = 0; i < content.childNodes.length; i++) { | |
380 | var child = content.childNodes[i]; | |
381 | try { | |
382 | child.className = child.className.replace("Selected", ""); | |
383 | } catch (e) { | |
384 | // | |
385 | } | |
386 | } | |
387 | } else { | |
388 | for (i = 0; i < content.childNodes.length; i++) { | |
389 | var child = content.childNodes[i]; | |
390 | if (child.id == "feedCatHolder") { | |
391 | debug(child.id); | |
392 | var fcat = child.lastChild; | |
393 | for (j = 0; j < fcat.childNodes.length; j++) { | |
394 | var feed = fcat.childNodes[j]; | |
395 | feed.className = feed.className.replace("Selected", ""); | |
396 | } | |
397 | } | |
398 | } | |
399 | } | |
400 | } | |
401 | ||
402 | ||
403 | function cleanSelected(element) { | |
404 | var content = document.getElementById(element); | |
405 | ||
406 | for (i = 0; i < content.rows.length; i++) { | |
407 | content.rows[i].className = content.rows[i].className.replace("Selected", ""); | |
408 | } | |
409 | } | |
410 | ||
411 | function getVisibleUnreadHeadlines() { | |
412 | var content = document.getElementById("headlinesList"); | |
413 | ||
414 | var rows = new Array(); | |
415 | ||
416 | for (i = 0; i < content.rows.length; i++) { | |
417 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
418 | if (row_id.length > 0 && content.rows[i].className.match("Unread")) { | |
419 | rows.push(row_id); | |
420 | } | |
421 | } | |
422 | return rows; | |
423 | } | |
424 | ||
425 | function getVisibleHeadlineIds() { | |
426 | ||
427 | var content = document.getElementById("headlinesList"); | |
428 | ||
429 | var rows = new Array(); | |
430 | ||
431 | for (i = 0; i < content.rows.length; i++) { | |
432 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
433 | if (row_id.length > 0) { | |
434 | rows.push(row_id); | |
435 | } | |
436 | } | |
437 | return rows; | |
438 | } | |
439 | ||
440 | function getFirstVisibleHeadlineId() { | |
441 | var rows = getVisibleHeadlineIds(); | |
442 | return rows[0]; | |
443 | } | |
444 | ||
445 | function getLastVisibleHeadlineId() { | |
446 | var rows = getVisibleHeadlineIds(); | |
447 | return rows[rows.length-1]; | |
448 | } | |
449 | ||
450 | function markHeadline(id) { | |
451 | var row = document.getElementById("RROW-" + id); | |
452 | if (row) { | |
453 | var is_active = false; | |
454 | ||
455 | if (row.className.match("Active")) { | |
456 | is_active = true; | |
457 | } | |
458 | row.className = row.className.replace("Selected", ""); | |
459 | row.className = row.className.replace("Active", ""); | |
460 | row.className = row.className.replace("Insensitive", ""); | |
461 | ||
462 | if (is_active) { | |
463 | row.className = row.className = "Active"; | |
464 | } | |
465 | ||
466 | var check = document.getElementById("RCHK-" + id); | |
467 | ||
468 | if (check) { | |
469 | check.checked = true; | |
470 | } | |
471 | ||
472 | row.className = row.className + "Selected"; | |
473 | ||
474 | } | |
475 | } | |
476 | ||
477 | function getFeedIds() { | |
478 | var content = document.getElementById("feedsList"); | |
479 | ||
480 | var rows = new Array(); | |
481 | ||
482 | for (i = 0; i < content.rows.length; i++) { | |
483 | var id = content.rows[i].id.replace("FEEDR-", ""); | |
484 | if (id.length > 0) { | |
485 | rows.push(id); | |
486 | } | |
487 | } | |
488 | ||
489 | return rows; | |
490 | } | |
491 | ||
492 | function setCookie(name, value, lifetime, path, domain, secure) { | |
493 | ||
494 | var d = false; | |
495 | ||
496 | if (lifetime) { | |
497 | d = new Date(); | |
498 | d.setTime(d.getTime() + (lifetime * 1000)); | |
499 | } | |
500 | ||
501 | debug("setCookie: " + name + " => " + value + ": " + d); | |
502 | ||
503 | int_setCookie(name, value, d, path, domain, secure); | |
504 | ||
505 | } | |
506 | ||
507 | function int_setCookie(name, value, expires, path, domain, secure) { | |
508 | document.cookie= name + "=" + escape(value) + | |
509 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
510 | ((path) ? "; path=" + path : "") + | |
511 | ((domain) ? "; domain=" + domain : "") + | |
512 | ((secure) ? "; secure" : ""); | |
513 | } | |
514 | ||
515 | function delCookie(name, path, domain) { | |
516 | if (getCookie(name)) { | |
517 | document.cookie = name + "=" + | |
518 | ((path) ? ";path=" + path : "") + | |
519 | ((domain) ? ";domain=" + domain : "" ) + | |
520 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
521 | } | |
522 | } | |
523 | ||
524 | ||
525 | function getCookie(name) { | |
526 | ||
527 | var dc = document.cookie; | |
528 | var prefix = name + "="; | |
529 | var begin = dc.indexOf("; " + prefix); | |
530 | if (begin == -1) { | |
531 | begin = dc.indexOf(prefix); | |
532 | if (begin != 0) return null; | |
533 | } | |
534 | else { | |
535 | begin += 2; | |
536 | } | |
537 | var end = document.cookie.indexOf(";", begin); | |
538 | if (end == -1) { | |
539 | end = dc.length; | |
540 | } | |
541 | return unescape(dc.substring(begin + prefix.length, end)); | |
542 | } | |
543 | ||
544 | function disableContainerChildren(id, disable, doc) { | |
545 | ||
546 | if (!doc) doc = document; | |
547 | ||
548 | var container = doc.getElementById(id); | |
549 | ||
550 | if (!container) { | |
551 | //alert("disableContainerChildren: element " + id + " not found"); | |
552 | return; | |
553 | } | |
554 | ||
555 | for (var i = 0; i < container.childNodes.length; i++) { | |
556 | var child = container.childNodes[i]; | |
557 | ||
558 | try { | |
559 | child.disabled = disable; | |
560 | } catch (E) { | |
561 | ||
562 | } | |
563 | ||
564 | if (disable) { | |
565 | if (child.className && child.className.match("button")) { | |
566 | child.className = "disabledButton"; | |
567 | } | |
568 | } else { | |
569 | if (child.className && child.className.match("disabledButton")) { | |
570 | child.className = "button"; | |
571 | } | |
572 | } | |
573 | } | |
574 | ||
575 | } | |
576 | ||
577 | function gotoPreferences() { | |
578 | document.location.href = "prefs.php"; | |
579 | } | |
580 | ||
581 | function gotoMain() { | |
582 | document.location.href = "tt-rss.php"; | |
583 | } | |
584 | ||
585 | function gotoExportOpml() { | |
586 | document.location.href = "opml.php?op=Export"; | |
587 | } | |
588 | ||
589 | function getActiveFeedId() { | |
590 | // return getCookie("ttrss_vf_actfeed"); | |
591 | try { | |
592 | debug("gAFID: " + active_feed_id); | |
593 | return active_feed_id; | |
594 | } catch (e) { | |
595 | exception_error("getActiveFeedId", e); | |
596 | } | |
597 | } | |
598 | ||
599 | function activeFeedIsCat() { | |
600 | return active_feed_is_cat; | |
601 | } | |
602 | ||
603 | function setActiveFeedId(id) { | |
604 | // return setCookie("ttrss_vf_actfeed", id); | |
605 | try { | |
606 | debug("sAFID(" + id + ")"); | |
607 | active_feed_id = id; | |
608 | } catch (e) { | |
609 | exception_error("setActiveFeedId", e); | |
610 | } | |
611 | } | |
612 | ||
613 | function parse_counters(reply, scheduled_call) { | |
614 | try { | |
615 | ||
616 | var feeds_found = 0; | |
617 | ||
618 | if (reply.firstChild && reply.firstChild.firstChild) { | |
619 | debug("<b>wrong element passed to parse_counters, adjusting.</b>"); | |
620 | reply = reply.firstChild; | |
621 | } | |
622 | ||
623 | for (var l = 0; l < reply.childNodes.length; l++) { | |
624 | if (!reply.childNodes[l] || | |
625 | typeof(reply.childNodes[l].getAttribute) == "undefined") { | |
626 | // where did this come from? | |
627 | continue; | |
628 | } | |
629 | ||
630 | var id = reply.childNodes[l].getAttribute("id"); | |
631 | var t = reply.childNodes[l].getAttribute("type"); | |
632 | var ctr = reply.childNodes[l].getAttribute("counter"); | |
633 | var error = reply.childNodes[l].getAttribute("error"); | |
634 | var has_img = reply.childNodes[l].getAttribute("hi"); | |
635 | var updated = reply.childNodes[l].getAttribute("updated"); | |
636 | ||
637 | if (id == "global-unread") { | |
638 | global_unread = ctr; | |
639 | updateTitle(); | |
640 | continue; | |
641 | } | |
642 | ||
643 | if (id == "subscribed-feeds") { | |
644 | feeds_found = ctr; | |
645 | continue; | |
646 | } | |
647 | ||
648 | if (t == "category") { | |
649 | var catctr = document.getElementById("FCATCTR-" + id); | |
650 | if (catctr) { | |
651 | catctr.innerHTML = "(" + ctr + ")"; | |
652 | if (ctr > 0) { | |
653 | catctr.className = "catCtrHasUnread"; | |
654 | } else { | |
655 | catctr.className = "catCtrNoUnread"; | |
656 | } | |
657 | } | |
658 | continue; | |
659 | } | |
660 | ||
661 | var feedctr = document.getElementById("FEEDCTR-" + id); | |
662 | var feedu = document.getElementById("FEEDU-" + id); | |
663 | var feedr = document.getElementById("FEEDR-" + id); | |
664 | var feed_img = document.getElementById("FIMG-" + id); | |
665 | var feedlink = document.getElementById("FEEDL-" + id); | |
666 | var feedupd = document.getElementById("FLUPD-" + id); | |
667 | ||
668 | if (updated && feedlink) { | |
669 | if (error) { | |
670 | feedlink.title = "Error: " + error + " (" + updated + ")"; | |
671 | } else { | |
672 | feedlink.title = "Updated: " + updated; | |
673 | } | |
674 | } | |
675 | ||
676 | if (updated && feedupd) { | |
677 | if (error) { | |
678 | feedupd.innerHTML = updated + " (Error)"; | |
679 | } else { | |
680 | feedupd.innerHTML = updated; | |
681 | } | |
682 | } | |
683 | ||
684 | if (has_img && feed_img && !is_msie()) { | |
685 | if (!feed_img.src.match(id + ".ico")) { | |
686 | feed_img.src = getInitParam("icons_location") + "/" + id + ".ico"; | |
687 | } | |
688 | } | |
689 | ||
690 | if (feedctr && feedu && feedr) { | |
691 | ||
692 | if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) { | |
693 | viewCurrentFeed(); | |
694 | } | |
695 | ||
696 | var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML)); | |
697 | ||
698 | feedu.innerHTML = ctr; | |
699 | ||
700 | if (error) { | |
701 | feedr.className = feedr.className.replace("feed", "error"); | |
702 | } else if (id > 0) { | |
703 | feedr.className = feedr.className.replace("error", "feed"); | |
704 | } | |
705 | ||
706 | if (ctr > 0) { | |
707 | feedctr.className = "odd"; | |
708 | if (!feedr.className.match("Unread")) { | |
709 | var is_selected = feedr.className.match("Selected"); | |
710 | ||
711 | feedr.className = feedr.className.replace("Selected", ""); | |
712 | feedr.className = feedr.className.replace("Unread", ""); | |
713 | ||
714 | feedr.className = feedr.className + "Unread"; | |
715 | ||
716 | if (is_selected) { | |
717 | feedr.className = feedr.className + "Selected"; | |
718 | } | |
719 | ||
720 | } | |
721 | ||
722 | if (row_needs_hl) { | |
723 | new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5"}); | |
724 | } | |
725 | } else { | |
726 | feedctr.className = "invisible"; | |
727 | feedr.className = feedr.className.replace("Unread", ""); | |
728 | } | |
729 | } | |
730 | } | |
731 | ||
732 | hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); | |
733 | ||
734 | var feeds_stored = number_of_feeds; | |
735 | ||
736 | debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored); | |
737 | ||
738 | if (feeds_stored != feeds_found) { | |
739 | number_of_feeds = feeds_found; | |
740 | ||
741 | if (feeds_stored != 0 && feeds_found != 0) { | |
742 | debug("Subscribed feed number changed, refreshing feedlist"); | |
743 | setTimeout('updateFeedList(false, false)', 50); | |
744 | } | |
745 | } | |
746 | ||
747 | } catch (e) { | |
748 | exception_error("parse_counters", e); | |
749 | } | |
750 | } | |
751 | ||
752 | function parse_counters_reply(xmlhttp, scheduled_call) { | |
753 | ||
754 | if (!xmlhttp.responseXML) { | |
755 | notify_error("Backend did not return valid XML", true); | |
756 | return; | |
757 | } | |
758 | ||
759 | var reply = xmlhttp.responseXML.firstChild; | |
760 | ||
761 | if (!reply) { | |
762 | notify_error("Backend did not return expected XML object", true); | |
763 | updateTitle(""); | |
764 | return; | |
765 | } | |
766 | ||
767 | var error_code = false; | |
768 | var error_msg = false; | |
769 | ||
770 | if (reply.firstChild) { | |
771 | error_code = reply.firstChild.getAttribute("error-code"); | |
772 | error_msg = reply.firstChild.getAttribute("error-msg"); | |
773 | } | |
774 | ||
775 | if (!error_code) { | |
776 | error_code = reply.getAttribute("error-code"); | |
777 | error_msg = reply.getAttribute("error-msg"); | |
778 | } | |
779 | ||
780 | if (error_code && error_code != 0) { | |
781 | debug("refetch_callback: got error code " + error_code); | |
782 | return fatalError(error_code, error_msg); | |
783 | } | |
784 | ||
785 | var counters = reply.getElementsByTagName("counters")[0]; | |
786 | ||
787 | parse_counters(counters, scheduled_call); | |
788 | ||
789 | var runtime_info = reply.getElementsByTagName("runtime-info")[0]; | |
790 | ||
791 | parse_runtime_info(runtime_info); | |
792 | ||
793 | if (getInitParam("feeds_sort_by_unread") == 1) { | |
794 | resort_feedlist(); | |
795 | } | |
796 | ||
797 | hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); | |
798 | ||
799 | } | |
800 | ||
801 | function all_counters_callback() { | |
802 | if (xmlhttp_rpc.readyState == 4) { | |
803 | try { | |
804 | /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) { | |
805 | debug("[all_counters_callback] backend did not return valid XML"); | |
806 | return; | |
807 | } | |
808 | ||
809 | debug("in all_counters_callback : " + xmlhttp_rpc.responseXML); | |
810 | ||
811 | var reply = xmlhttp_rpc.responseXML.firstChild; | |
812 | ||
813 | var counters = reply.firstChild; | |
814 | ||
815 | parse_counters(counters); | |
816 | ||
817 | var runtime = counters.nextSibling; | |
818 | ||
819 | if (runtime) { | |
820 | parse_runtime_info(runtime); | |
821 | } | |
822 | ||
823 | if (getInitParam("feeds_sort_by_unread") == 1) { | |
824 | resort_feedlist(); | |
825 | } | |
826 | ||
827 | hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */ | |
828 | ||
829 | debug("in all_counters_callback"); | |
830 | ||
831 | parse_counters_reply(xmlhttp_rpc); | |
832 | ||
833 | } catch (e) { | |
834 | exception_error("all_counters_callback", e); | |
835 | } | |
836 | } | |
837 | } | |
838 | ||
839 | function get_feed_entry_unread(doc, elem) { | |
840 | ||
841 | var id = elem.id.replace("FEEDR-", ""); | |
842 | ||
843 | if (id <= 0) { | |
844 | return -1; | |
845 | } | |
846 | ||
847 | try { | |
848 | return parseInt(doc.getElementById("FEEDU-" + id).innerHTML); | |
849 | } catch (e) { | |
850 | return -1; | |
851 | } | |
852 | } | |
853 | ||
854 | function resort_category(doc, node) { | |
855 | debug("resort_category: " + node); | |
856 | ||
857 | if (node.hasChildNodes() && node.firstChild.nextSibling != false) { | |
858 | for (i = 0; i < node.childNodes.length; i++) { | |
859 | if (node.childNodes[i].nodeName != "LI") { continue; } | |
860 | ||
861 | if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) { | |
862 | continue; | |
863 | } | |
864 | ||
865 | for (j = i+1; j < node.childNodes.length; j++) { | |
866 | if (node.childNodes[j].nodeName != "LI") { continue; } | |
867 | ||
868 | var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]); | |
869 | var cur_val = get_feed_entry_unread(doc, node.childNodes[j]); | |
870 | ||
871 | if (cur_val > tmp_val) { | |
872 | tempnode_i = node.childNodes[i].cloneNode(true); | |
873 | tempnode_j = node.childNodes[j].cloneNode(true); | |
874 | node.replaceChild(tempnode_i, node.childNodes[j]); | |
875 | node.replaceChild(tempnode_j, node.childNodes[i]); | |
876 | } | |
877 | } | |
878 | ||
879 | } | |
880 | } | |
881 | ||
882 | } | |
883 | ||
884 | function resort_feedlist() { | |
885 | debug("resort_feedlist"); | |
886 | ||
887 | var fd = document; | |
888 | ||
889 | if (fd.getElementById("feedCatHolder")) { | |
890 | ||
891 | var feeds = fd.getElementById("feedList"); | |
892 | var child = feeds.firstChild; | |
893 | ||
894 | while (child) { | |
895 | ||
896 | if (child.id == "feedCatHolder") { | |
897 | resort_category(fd, child.firstChild); | |
898 | } | |
899 | ||
900 | child = child.nextSibling; | |
901 | } | |
902 | ||
903 | } else { | |
904 | resort_category(fd, fd.getElementById("feedList")); | |
905 | } | |
906 | } | |
907 | ||
908 | function update_all_counters(feed) { | |
909 | if (xmlhttp_ready(xmlhttp_rpc)) { | |
910 | var query = "backend.php?op=rpc&subop=getAllCounters"; | |
911 | ||
912 | if (feed > 0) { | |
913 | query = query + "&aid=" + feed; | |
914 | } | |
915 | ||
916 | if (tagsAreDisplayed()) { | |
917 | query = query + "&omode=lt"; | |
918 | } else { | |
919 | query = query + "&omode=flc"; | |
920 | } | |
921 | ||
922 | debug("update_all_counters QUERY: " + query); | |
923 | ||
924 | var date = new Date(); | |
925 | var timestamp = Math.round(date.getTime() / 1000); | |
926 | query = query + "&ts=" + timestamp | |
927 | ||
928 | xmlhttp_rpc.open("GET", query, true); | |
929 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
930 | xmlhttp_rpc.send(null); | |
931 | } | |
932 | } | |
933 | ||
934 | function popupHelp(tid) { | |
935 | var w = window.open("backend.php?op=help&tid=" + tid, | |
936 | "Popup Help", | |
937 | "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no"); | |
938 | } | |
939 | ||
940 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj | |
941 | * * @author Sundar Dorai-Raj | |
942 | * * Email: sdoraira@vt.edu | |
943 | * * This program is free software; you can redistribute it and/or | |
944 | * * modify it under the terms of the GNU General Public License | |
945 | * * as published by the Free Software Foundation; either version 2 | |
946 | * * of the License, or (at your option) any later version, | |
947 | * * provided that any use properly credits the author. | |
948 | * * This program is distributed in the hope that it will be useful, | |
949 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
950 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
951 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
952 | ||
953 | var numbers=".0123456789"; | |
954 | function isNumeric(x) { | |
955 | // is x a String or a character? | |
956 | if(x.length>1) { | |
957 | // remove negative sign | |
958 | x=Math.abs(x)+""; | |
959 | for(j=0;j<x.length;j++) { | |
960 | // call isNumeric recursively for each character | |
961 | number=isNumeric(x.substring(j,j+1)); | |
962 | if(!number) return number; | |
963 | } | |
964 | return number; | |
965 | } | |
966 | else { | |
967 | // if x is number return true | |
968 | if(numbers.indexOf(x)>=0) return true; | |
969 | return false; | |
970 | } | |
971 | } | |
972 | ||
973 | ||
974 | function hideOrShowFeeds(doc, hide) { | |
975 | ||
976 | debug("hideOrShowFeeds: " + doc + ", " + hide); | |
977 | ||
978 | var fd = document; | |
979 | ||
980 | var list = fd.getElementById("feedList"); | |
981 | ||
982 | if (fd.getElementById("feedCatHolder")) { | |
983 | ||
984 | var feeds = fd.getElementById("feedList"); | |
985 | var child = feeds.firstChild; | |
986 | ||
987 | while (child) { | |
988 | ||
989 | if (child.id == "feedCatHolder") { | |
990 | hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling); | |
991 | } | |
992 | ||
993 | child = child.nextSibling; | |
994 | } | |
995 | ||
996 | } else { | |
997 | hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide); | |
998 | } | |
999 | } | |
1000 | ||
1001 | function hideOrShowFeedsCategory(doc, node, hide, cat_node) { | |
1002 | ||
1003 | // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")"); | |
1004 | ||
1005 | var cat_unread = 0; | |
1006 | ||
1007 | if (!node) { | |
1008 | debug("hideOrShowFeeds: passed node is null, aborting"); | |
1009 | return; | |
1010 | } | |
1011 | ||
1012 | if (node.hasChildNodes() && node.firstChild.nextSibling != false) { | |
1013 | for (i = 0; i < node.childNodes.length; i++) { | |
1014 | if (node.childNodes[i].nodeName != "LI") { continue; } | |
1015 | ||
1016 | if (node.childNodes[i].style != undefined) { | |
1017 | ||
1018 | var has_unread = (node.childNodes[i].className != "feed" && | |
1019 | node.childNodes[i].className != "label" && | |
1020 | node.childNodes[i].className != "virt" && | |
1021 | node.childNodes[i].className != "tag"); | |
1022 | ||
1023 | // debug(node.childNodes[i].id + " --> " + has_unread); | |
1024 | ||
1025 | if (hide && !has_unread) { | |
1026 | //node.childNodes[i].style.display = "none"; | |
1027 | Effect.Fade(node.childNodes[i], {duration : 0.3}); | |
1028 | } | |
1029 | ||
1030 | if (!hide) { | |
1031 | node.childNodes[i].style.display = "list-item"; | |
1032 | //Effect.Appear(node.childNodes[i], {duration : 0.3}); | |
1033 | } | |
1034 | ||
1035 | if (has_unread) { | |
1036 | node.childNodes[i].style.display = "list-item"; | |
1037 | cat_unread++; | |
1038 | //Effect.Appear(node.childNodes[i], {duration : 0.3}); | |
1039 | //Effect.Highlight(node.childNodes[i]); | |
1040 | } | |
1041 | } | |
1042 | } | |
1043 | } | |
1044 | ||
1045 | if (cat_unread == 0) { | |
1046 | if (cat_node.style == undefined) { | |
1047 | debug("ERROR: supplied cat_node " + cat_node + | |
1048 | " has no styles. WTF?"); | |
1049 | return; | |
1050 | } | |
1051 | if (hide) { | |
1052 | //cat_node.style.display = "none"; | |
1053 | Effect.Fade(cat_node, {duration : 0.3}); | |
1054 | } else { | |
1055 | cat_node.style.display = "list-item"; | |
1056 | } | |
1057 | } else { | |
1058 | try { | |
1059 | cat_node.style.display = "list-item"; | |
1060 | } catch (e) { | |
1061 | debug(e); | |
1062 | } | |
1063 | } | |
1064 | ||
1065 | // debug("unread for category: " + cat_unread); | |
1066 | } | |
1067 | ||
1068 | function selectTableRow(r, do_select) { | |
1069 | r.className = r.className.replace("Selected", ""); | |
1070 | ||
1071 | if (do_select) { | |
1072 | r.className = r.className + "Selected"; | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | function selectTableRowById(elem_id, check_id, do_select) { | |
1077 | ||
1078 | try { | |
1079 | ||
1080 | var row = document.getElementById(elem_id); | |
1081 | ||
1082 | if (row) { | |
1083 | selectTableRow(row, do_select); | |
1084 | } | |
1085 | ||
1086 | var check = document.getElementById(check_id); | |
1087 | ||
1088 | if (check) { | |
1089 | check.checked = do_select; | |
1090 | } | |
1091 | } catch (e) { | |
1092 | exception_error("selectTableRowById", e); | |
1093 | } | |
1094 | } | |
1095 | ||
1096 | function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select, | |
1097 | classcheck, reset_others) { | |
1098 | ||
1099 | var content = document.getElementById(content_id); | |
1100 | ||
1101 | if (!content) { | |
1102 | alert("[selectTableRows] Element " + content_id + " not found."); | |
1103 | return; | |
1104 | } | |
1105 | ||
1106 | for (i = 0; i < content.rows.length; i++) { | |
1107 | if (!classcheck || content.rows[i].className.match(classcheck)) { | |
1108 | ||
1109 | if (content.rows[i].id.match(prefix)) { | |
1110 | selectTableRow(content.rows[i], do_select); | |
1111 | ||
1112 | var row_id = content.rows[i].id.replace(prefix, ""); | |
1113 | var check = document.getElementById(check_prefix + row_id); | |
1114 | ||
1115 | if (check) { | |
1116 | check.checked = do_select; | |
1117 | } | |
1118 | } else if (reset_others) { | |
1119 | selectTableRow(content.rows[i], false); | |
1120 | ||
1121 | var row_id = content.rows[i].id.replace(prefix, ""); | |
1122 | var check = document.getElementById(check_prefix + row_id); | |
1123 | ||
1124 | if (check) { | |
1125 | check.checked = false; | |
1126 | } | |
1127 | ||
1128 | } | |
1129 | } else if (reset_others) { | |
1130 | selectTableRow(content.rows[i], false); | |
1131 | ||
1132 | var row_id = content.rows[i].id.replace(prefix, ""); | |
1133 | var check = document.getElementById(check_prefix + row_id); | |
1134 | ||
1135 | if (check) { | |
1136 | check.checked = false; | |
1137 | } | |
1138 | ||
1139 | } | |
1140 | } | |
1141 | } | |
1142 | ||
1143 | function getSelectedTableRowIds(content_id, prefix) { | |
1144 | ||
1145 | var content = document.getElementById(content_id); | |
1146 | ||
1147 | if (!content) { | |
1148 | alert("[getSelectedTableRowIds] Element " + content_id + " not found."); | |
1149 | return; | |
1150 | } | |
1151 | ||
1152 | var sel_rows = new Array(); | |
1153 | ||
1154 | for (i = 0; i < content.rows.length; i++) { | |
1155 | if (content.rows[i].id.match(prefix) && | |
1156 | content.rows[i].className.match("Selected")) { | |
1157 | ||
1158 | var row_id = content.rows[i].id.replace(prefix + "-", ""); | |
1159 | sel_rows.push(row_id); | |
1160 | } | |
1161 | } | |
1162 | ||
1163 | return sel_rows; | |
1164 | ||
1165 | } | |
1166 | ||
1167 | function toggleSelectRowById(sender, id) { | |
1168 | var row = document.getElementById(id); | |
1169 | ||
1170 | if (sender.checked) { | |
1171 | if (!row.className.match("Selected")) { | |
1172 | row.className = row.className + "Selected"; | |
1173 | } | |
1174 | } else { | |
1175 | if (row.className.match("Selected")) { | |
1176 | row.className = row.className.replace("Selected", ""); | |
1177 | } | |
1178 | } | |
1179 | } | |
1180 | ||
1181 | function toggleSelectListRow(sender) { | |
1182 | var parent_row = sender.parentNode; | |
1183 | ||
1184 | if (sender.checked) { | |
1185 | if (!parent_row.className.match("Selected")) { | |
1186 | parent_row.className = parent_row.className + "Selected"; | |
1187 | } | |
1188 | } else { | |
1189 | if (parent_row.className.match("Selected")) { | |
1190 | parent_row.className = parent_row.className.replace("Selected", ""); | |
1191 | } | |
1192 | } | |
1193 | } | |
1194 | ||
1195 | function tSR(sender) { | |
1196 | return toggleSelectRow(sender); | |
1197 | } | |
1198 | ||
1199 | function toggleSelectRow(sender) { | |
1200 | var parent_row = sender.parentNode.parentNode; | |
1201 | ||
1202 | if (sender.checked) { | |
1203 | if (!parent_row.className.match("Selected")) { | |
1204 | parent_row.className = parent_row.className + "Selected"; | |
1205 | } | |
1206 | } else { | |
1207 | if (parent_row.className.match("Selected")) { | |
1208 | parent_row.className = parent_row.className.replace("Selected", ""); | |
1209 | } | |
1210 | } | |
1211 | } | |
1212 | ||
1213 | function openExternalUrl(url) { | |
1214 | var w = window.open(url); | |
1215 | } | |
1216 | ||
1217 | function getRelativeFeedId(list, id, direction, unread_only) { | |
1218 | var rows = list.getElementsByTagName("LI"); | |
1219 | var feeds = new Array(); | |
1220 | ||
1221 | for (var i = 0; i < rows.length; i++) { | |
1222 | if (rows[i].id.match("FEEDR-")) { | |
1223 | ||
1224 | if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) { | |
1225 | ||
1226 | if (!unread_only || | |
1227 | (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) { | |
1228 | feeds.push(rows[i].id.replace("FEEDR-", "")); | |
1229 | } | |
1230 | } | |
1231 | } | |
1232 | } | |
1233 | ||
1234 | if (!id) { | |
1235 | if (direction == "next") { | |
1236 | return feeds.shift(); | |
1237 | } else { | |
1238 | return feeds.pop(); | |
1239 | } | |
1240 | } else { | |
1241 | if (direction == "next") { | |
1242 | var idx = feeds.indexOf(id); | |
1243 | if (idx != -1 && idx < feeds.length) { | |
1244 | return feeds[idx+1]; | |
1245 | } else { | |
1246 | return getRelativeFeedId(list, false, direction, unread_only); | |
1247 | } | |
1248 | } else { | |
1249 | var idx = feeds.indexOf(id); | |
1250 | if (idx > 0) { | |
1251 | return feeds[idx-1]; | |
1252 | } else { | |
1253 | return getRelativeFeedId(list, false, direction, unread_only); | |
1254 | } | |
1255 | } | |
1256 | ||
1257 | } | |
1258 | ||
1259 | /* if (!id) { | |
1260 | if (direction == "next") { | |
1261 | for (i = 0; i < list.childNodes.length; i++) { | |
1262 | var child = list.childNodes[i]; | |
1263 | if (child.id && child.id == "feedCatHolder") { | |
1264 | if (child.lastChild) { | |
1265 | var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only); | |
1266 | if (cr) return cr; | |
1267 | } | |
1268 | } else if (child.id && child.id.match("FEEDR-")) { | |
1269 | return child.id.replace('FEEDR-', ''); | |
1270 | } | |
1271 | } | |
1272 | } | |
1273 | ||
1274 | // FIXME select last feed doesn't work when only unread feeds are visible | |
1275 | ||
1276 | if (direction == "prev") { | |
1277 | for (i = list.childNodes.length-1; i >= 0; i--) { | |
1278 | var child = list.childNodes[i]; | |
1279 | if (child.id == "feedCatHolder" && Element.visible(child)) { | |
1280 | if (child.firstChild) { | |
1281 | var cr = getRelativeFeedId(child.firstChild, id, direction); | |
1282 | if (cr) return cr; | |
1283 | } | |
1284 | } else if (child.id.match("FEEDR-")) { | |
1285 | ||
1286 | if (getInitParam("hide_read_feeds") == 1) { | |
1287 | if (child.className != "feed") { | |
1288 | // alert(child.className); | |
1289 | return child.id.replace('FEEDR-', ''); | |
1290 | } | |
1291 | } else { | |
1292 | return child.id.replace('FEEDR-', ''); | |
1293 | } | |
1294 | } | |
1295 | } | |
1296 | } | |
1297 | } else { | |
1298 | ||
1299 | var feed = list.ownerDocument.getElementById("FEEDR-" + id); | |
1300 | ||
1301 | if (getInitParam("hide_read_feeds") == 1) { | |
1302 | unread_only = true; | |
1303 | } | |
1304 | ||
1305 | if (direction == "next") { | |
1306 | ||
1307 | var e = feed; | |
1308 | ||
1309 | while (e) { | |
1310 | ||
1311 | if (e.nextSibling) { | |
1312 | ||
1313 | e = e.nextSibling; | |
1314 | ||
1315 | } else if (e.parentNode.parentNode.nextSibling) { | |
1316 | ||
1317 | var this_cat = e.parentNode.parentNode; | |
1318 | ||
1319 | e = false; | |
1320 | ||
1321 | if (this_cat && this_cat.nextSibling) { | |
1322 | while (!e && this_cat.nextSibling) { | |
1323 | this_cat = this_cat.nextSibling; | |
1324 | if (this_cat.id == "feedCatHolder") { | |
1325 | e = this_cat.firstChild.firstChild; | |
1326 | } | |
1327 | } | |
1328 | } | |
1329 | ||
1330 | } else { | |
1331 | e = false; | |
1332 | } | |
1333 | ||
1334 | if (e) { | |
1335 | if (!unread_only || (unread_only && e.className != "feed" && | |
1336 | e.className.match("feed"))) { | |
1337 | if (e.parentNode.parentNode && | |
1338 | Element.visible(e.parentNode.parentNode)) { | |
1339 | return e.id.replace("FEEDR-", ""); | |
1340 | } | |
1341 | } | |
1342 | } | |
1343 | } | |
1344 | ||
1345 | } else if (direction == "prev") { | |
1346 | ||
1347 | var e = feed; | |
1348 | ||
1349 | while (e) { | |
1350 | ||
1351 | if (e.previousSibling) { | |
1352 | ||
1353 | e = e.previousSibling; | |
1354 | ||
1355 | } else if (e.parentNode.parentNode.previousSibling) { | |
1356 | ||
1357 | var this_cat = e.parentNode.parentNode; | |
1358 | ||
1359 | e = false; | |
1360 | ||
1361 | if (this_cat && this_cat.previousSibling) { | |
1362 | while (!e && this_cat.previousSibling) { | |
1363 | this_cat = this_cat.previousSibling; | |
1364 | if (this_cat.id == "feedCatHolder") { | |
1365 | e = this_cat.firstChild.lastChild; | |
1366 | } | |
1367 | } | |
1368 | } | |
1369 | ||
1370 | } else { | |
1371 | e = false; | |
1372 | } | |
1373 | ||
1374 | if (e) { | |
1375 | if (!unread_only || (unread_only && e.className != "feed" && | |
1376 | e.className.match("feed"))) { | |
1377 | if (e.parentNode.parentNode && | |
1378 | Element.visible(e.parentNode.parentNode)) { | |
1379 | return e.id.replace("FEEDR-", ""); | |
1380 | } | |
1381 | } | |
1382 | } | |
1383 | } | |
1384 | } | |
1385 | } */ | |
1386 | } | |
1387 | ||
1388 | function showBlockElement(id, h_id) { | |
1389 | var elem = document.getElementById(id); | |
1390 | ||
1391 | if (elem) { | |
1392 | elem.style.display = "block"; | |
1393 | ||
1394 | if (h_id) { | |
1395 | elem = document.getElementById(h_id); | |
1396 | if (elem) { | |
1397 | elem.style.display = "none"; | |
1398 | } | |
1399 | } | |
1400 | } else { | |
1401 | alert("[showBlockElement] can't find element with id " + id); | |
1402 | } | |
1403 | } | |
1404 | ||
1405 | function appearBlockElement_afh(effect) { | |
1406 | ||
1407 | } | |
1408 | ||
1409 | function checkboxToggleElement(elem, id) { | |
1410 | if (elem.checked) { | |
1411 | Effect.SlideDown(id, {duration : 0.5}); | |
1412 | } else { | |
1413 | Effect.SlideUp(id, {duration : 0.5}); | |
1414 | } | |
1415 | } | |
1416 | ||
1417 | function appearBlockElement(id, h_id) { | |
1418 | ||
1419 | try { | |
1420 | Effect.Fade(h_id); | |
1421 | Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh}); | |
1422 | } catch (e) { | |
1423 | exception_error("appearBlockElement", e); | |
1424 | } | |
1425 | ||
1426 | } | |
1427 | ||
1428 | ||
1429 | function hideParentElement(e) { | |
1430 | e.parentNode.style.display = "none"; | |
1431 | } | |
1432 | ||
1433 | function dropboxSelect(e, v) { | |
1434 | for (i = 0; i < e.length; i++) { | |
1435 | if (e[i].value == v) { | |
1436 | e.selectedIndex = i; | |
1437 | break; | |
1438 | } | |
1439 | } | |
1440 | } | |
1441 | ||
1442 | // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z | |
1443 | // bugfixed just a little bit :-) | |
1444 | function getURLParam(strParamName){ | |
1445 | var strReturn = ""; | |
1446 | var strHref = window.location.href; | |
1447 | ||
1448 | if (strHref.indexOf("#") == strHref.length-1) { | |
1449 | strHref = strHref.substring(0, strHref.length-1); | |
1450 | } | |
1451 | ||
1452 | if ( strHref.indexOf("?") > -1 ){ | |
1453 | var strQueryString = strHref.substr(strHref.indexOf("?")); | |
1454 | var aQueryString = strQueryString.split("&"); | |
1455 | for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ | |
1456 | if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ | |
1457 | var aParam = aQueryString[iParam].split("="); | |
1458 | strReturn = aParam[1]; | |
1459 | break; | |
1460 | } | |
1461 | } | |
1462 | } | |
1463 | return strReturn; | |
1464 | } | |
1465 | ||
1466 | function leading_zero(p) { | |
1467 | var s = String(p); | |
1468 | if (s.length == 1) s = "0" + s; | |
1469 | return s; | |
1470 | } | |
1471 | ||
1472 | function closeInfoBox(cleanup) { | |
1473 | ||
1474 | if (!is_msie() && !getInitParam("infobox_disable_overlay")) { | |
1475 | var overlay = document.getElementById("dialog_overlay"); | |
1476 | if (overlay) { | |
1477 | overlay.style.display = "none"; | |
1478 | } | |
1479 | } | |
1480 | ||
1481 | var box = document.getElementById('infoBox'); | |
1482 | var shadow = document.getElementById('infoBoxShadow'); | |
1483 | ||
1484 | if (shadow) { | |
1485 | shadow.style.display = "none"; | |
1486 | } else if (box) { | |
1487 | box.style.display = "none"; | |
1488 | } | |
1489 | ||
1490 | if (cleanup) box.innerHTML = " "; | |
1491 | ||
1492 | enableHotkeys(); | |
1493 | ||
1494 | return false; | |
1495 | } | |
1496 | ||
1497 | ||
1498 | function displayDlg(id, param) { | |
1499 | ||
1500 | if (!xmlhttp_ready(xmlhttp)) { | |
1501 | printLockingError(); | |
1502 | return | |
1503 | } | |
1504 | ||
1505 | notify_progress("Loading, please wait...", true); | |
1506 | ||
1507 | xmlhttp.open("GET", "backend.php?op=dlg&id=" + | |
1508 | param_escape(id) + "¶m=" + param_escape(param), true); | |
1509 | xmlhttp.onreadystatechange=infobox_callback; | |
1510 | xmlhttp.send(null); | |
1511 | ||
1512 | disableHotkeys(); | |
1513 | ||
1514 | return false; | |
1515 | } | |
1516 | ||
1517 | function infobox_submit_callback() { | |
1518 | if (xmlhttp.readyState == 4) { | |
1519 | closeInfoBox(); | |
1520 | ||
1521 | try { | |
1522 | // called from prefs, reload tab | |
1523 | if (active_tab) { | |
1524 | selectTab(active_tab, false); | |
1525 | } | |
1526 | } catch (e) { } | |
1527 | ||
1528 | if (xmlhttp.responseText) { | |
1529 | notify_info(xmlhttp.responseText); | |
1530 | } | |
1531 | ||
1532 | } | |
1533 | } | |
1534 | ||
1535 | function infobox_callback() { | |
1536 | if (xmlhttp.readyState == 4) { | |
1537 | ||
1538 | try { | |
1539 | ||
1540 | if (!is_msie() && !getInitParam("infobox_disable_overlay")) { | |
1541 | var overlay = document.getElementById("dialog_overlay"); | |
1542 | if (overlay) { | |
1543 | overlay.style.display = "block"; | |
1544 | } | |
1545 | } | |
1546 | ||
1547 | var box = document.getElementById('infoBox'); | |
1548 | var shadow = document.getElementById('infoBoxShadow'); | |
1549 | if (box) { | |
1550 | ||
1551 | /* if (!is_safari()) { | |
1552 | new Draggable(shadow); | |
1553 | } */ | |
1554 | ||
1555 | box.innerHTML=xmlhttp.responseText; | |
1556 | if (shadow) { | |
1557 | shadow.style.display = "block"; | |
1558 | } else { | |
1559 | box.style.display = "block"; | |
1560 | } | |
1561 | } | |
1562 | ||
1563 | /* FIXME this needs to be moved out somewhere */ | |
1564 | ||
1565 | if (document.getElementById("tags_choices")) { | |
1566 | new Ajax.Autocompleter('tags_str', 'tags_choices', | |
1567 | "backend.php?op=rpc&subop=completeTags", | |
1568 | { tokens: ',', paramName: "search" }); | |
1569 | } | |
1570 | ||
1571 | notify(""); | |
1572 | } catch (e) { | |
1573 | exception_error("infobox_callback", e); | |
1574 | } | |
1575 | } | |
1576 | } | |
1577 | ||
1578 | function helpbox_callback() { | |
1579 | if (xmlhttp.readyState == 4) { | |
1580 | var box = document.getElementById('helpBox'); | |
1581 | var shadow = document.getElementById('helpBoxShadow'); | |
1582 | if (box) { | |
1583 | box.innerHTML=xmlhttp.responseText; | |
1584 | if (shadow) { | |
1585 | shadow.style.display = "block"; | |
1586 | } else { | |
1587 | box.style.display = "block"; | |
1588 | } | |
1589 | } | |
1590 | notify(""); | |
1591 | } | |
1592 | } | |
1593 | ||
1594 | function addFilter() { | |
1595 | ||
1596 | if (!xmlhttp_ready(xmlhttp)) { | |
1597 | printLockingError(); | |
1598 | return | |
1599 | } | |
1600 | ||
1601 | var form = document.forms['filter_add_form']; | |
1602 | var reg_exp = form.reg_exp.value; | |
1603 | ||
1604 | if (reg_exp == "") { | |
1605 | alert(__("Can't add filter: nothing to match on.")); | |
1606 | return false; | |
1607 | } | |
1608 | ||
1609 | var query = Form.serialize("filter_add_form"); | |
1610 | ||
1611 | xmlhttp.open("GET", "backend.php?" + query, true); | |
1612 | xmlhttp.onreadystatechange=infobox_submit_callback; | |
1613 | xmlhttp.send(null); | |
1614 | ||
1615 | return true; | |
1616 | } | |
1617 | ||
1618 | function toggleSubmitNotEmpty(e, submit_id) { | |
1619 | try { | |
1620 | document.getElementById(submit_id).disabled = (e.value == "") | |
1621 | } catch (e) { | |
1622 | exception_error("toggleSubmitNotEmpty", e); | |
1623 | } | |
1624 | } | |
1625 | ||
1626 | function isValidURL(s) { | |
1627 | return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null; | |
1628 | } | |
1629 | ||
1630 | function qaddFeed() { | |
1631 | ||
1632 | if (!xmlhttp_ready(xmlhttp)) { | |
1633 | printLockingError(); | |
1634 | return | |
1635 | } | |
1636 | ||
1637 | var form = document.forms['feed_add_form']; | |
1638 | var feed_url = form.feed_url.value; | |
1639 | ||
1640 | if (feed_url == "") { | |
1641 | alert(__("Can't subscribe: no feed URL given.")); | |
1642 | return false; | |
1643 | } | |
1644 | ||
1645 | notify_progress(__("Subscribing to feed..."), true); | |
1646 | ||
1647 | closeInfoBox(); | |
1648 | ||
1649 | var feeds_doc = document; | |
1650 | ||
1651 | // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; | |
1652 | ||
1653 | var query = Form.serialize("feed_add_form"); | |
1654 | ||
1655 | debug("subscribe q: " + query); | |
1656 | ||
1657 | /* xmlhttp.open("GET", "backend.php?" + query, true); | |
1658 | xmlhttp.onreadystatechange=dlg_frefresh_callback; | |
1659 | xmlhttp.send(null); */ | |
1660 | ||
1661 | xmlhttp.open("POST", "backend.php", true); | |
1662 | xmlhttp.onreadystatechange=dlg_frefresh_callback; | |
1663 | xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
1664 | xmlhttp.send(query); | |
1665 | ||
1666 | return false; | |
1667 | } | |
1668 | ||
1669 | function filterCR(e, f) | |
1670 | { | |
1671 | var key; | |
1672 | ||
1673 | if(window.event) | |
1674 | key = window.event.keyCode; //IE | |
1675 | else | |
1676 | key = e.which; //firefox | |
1677 | ||
1678 | if (key == 13) { | |
1679 | if (typeof f != 'undefined') { | |
1680 | f(); | |
1681 | return false; | |
1682 | } else { | |
1683 | return false; | |
1684 | } | |
1685 | } else { | |
1686 | return true; | |
1687 | } | |
1688 | } | |
1689 | ||
1690 | function getMainContext() { | |
1691 | return this.window; | |
1692 | } | |
1693 | ||
1694 | function getFeedsContext() { | |
1695 | return this.window; | |
1696 | } | |
1697 | ||
1698 | function getContentContext() { | |
1699 | return this.window; | |
1700 | } | |
1701 | ||
1702 | function getHeadlinesContext() { | |
1703 | return this.window; | |
1704 | } | |
1705 | ||
1706 | var debug_last_class = "even"; | |
1707 | ||
1708 | function debug(msg) { | |
1709 | ||
1710 | if (debug_last_class == "even") { | |
1711 | debug_last_class = "odd"; | |
1712 | } else { | |
1713 | debug_last_class = "even"; | |
1714 | } | |
1715 | ||
1716 | var c = document.getElementById('debug_output'); | |
1717 | if (c && c.style.display == "block") { | |
1718 | while (c.lastChild != 'undefined' && c.childNodes.length > 100) { | |
1719 | c.removeChild(c.lastChild); | |
1720 | } | |
1721 | ||
1722 | var d = new Date(); | |
1723 | var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) + | |
1724 | ":" + leading_zero(d.getSeconds()); | |
1725 | c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " + | |
1726 | msg + "</li>" + c.innerHTML; | |
1727 | } | |
1728 | } | |
1729 | ||
1730 | function getInitParam(key) { | |
1731 | return init_params[key]; | |
1732 | } | |
1733 | ||
1734 | function storeInitParam(key, value) { | |
1735 | debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>"); | |
1736 | init_params[key] = value; | |
1737 | } | |
1738 | ||
1739 | function fatalError(code, message) { | |
1740 | try { | |
1741 | ||
1742 | if (code == 6) { | |
1743 | window.location.href = "tt-rss.php"; | |
1744 | } else if (code == 5) { | |
1745 | window.location.href = "update.php"; | |
1746 | } else { | |
1747 | var fe = document.getElementById("fatal_error"); | |
1748 | var fc = document.getElementById("fatal_error_msg"); | |
1749 | ||
1750 | if (message == "") message = "Unknown error"; | |
1751 | ||
1752 | fc.innerHTML = "<img src='images/sign_excl.png'> " + message + " (Code " + code + ")"; | |
1753 | ||
1754 | fe.style.display = "block"; | |
1755 | } | |
1756 | ||
1757 | } catch (e) { | |
1758 | exception_error("fatalError", e); | |
1759 | } | |
1760 | } | |
1761 | ||
1762 | function getFeedName(id, is_cat) { | |
1763 | var d = getFeedsContext().document; | |
1764 | ||
1765 | var e; | |
1766 | ||
1767 | if (is_cat) { | |
1768 | e = d.getElementById("FCATN-" + id); | |
1769 | } else { | |
1770 | e = d.getElementById("FEEDN-" + id); | |
1771 | } | |
1772 | if (e) { | |
1773 | return e.innerHTML.stripTags(); | |
1774 | } else { | |
1775 | return null; | |
1776 | } | |
1777 | } | |
1778 | ||
1779 | function viewContentUrl(url) { | |
1780 | getContentContext().location = url; | |
1781 | } | |
1782 | ||
1783 | function filterDlgCheckAction(sender) { | |
1784 | ||
1785 | try { | |
1786 | ||
1787 | var action = sender[sender.selectedIndex].value; | |
1788 | ||
1789 | var form = document.forms["filter_add_form"]; | |
1790 | ||
1791 | if (!form) { | |
1792 | form = document.forms["filter_edit_form"]; | |
1793 | } | |
1794 | ||
1795 | if (!form) { | |
1796 | debug("filterDlgCheckAction: can't find form!"); | |
1797 | return; | |
1798 | } | |
1799 | ||
1800 | var action_param = form.action_param; | |
1801 | ||
1802 | if (!action_param) { | |
1803 | debug("filterDlgCheckAction: can't find action param!"); | |
1804 | return; | |
1805 | } | |
1806 | ||
1807 | // if selected action supports parameters, enable params field | |
1808 | if (action == 4) { | |
1809 | action_param.disabled = false; | |
1810 | } else { | |
1811 | action_param.disabled = true; | |
1812 | } | |
1813 | ||
1814 | } catch (e) { | |
1815 | exception_error(e, "filterDlgCheckAction"); | |
1816 | } | |
1817 | ||
1818 | } | |
1819 | ||
1820 | function explainError(code) { | |
1821 | return displayDlg("explainError", code); | |
1822 | } | |
1823 | ||
1824 | function logoutUser() { | |
1825 | try { | |
1826 | if (xmlhttp_ready(xmlhttp_rpc)) { | |
1827 | ||
1828 | notify_progress("Logging out, please wait...", true); | |
1829 | ||
1830 | xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=logout", true); | |
1831 | xmlhttp_rpc.onreadystatechange=logout_callback; | |
1832 | xmlhttp_rpc.send(null); | |
1833 | } else { | |
1834 | printLockingError(); | |
1835 | } | |
1836 | } catch (e) { | |
1837 | exception_error("logoutUser", e); | |
1838 | } | |
1839 | } | |
1840 | ||
1841 | // this only searches loaded headlines list, not in CDM | |
1842 | function getRelativePostIds(id) { | |
1843 | ||
1844 | debug("getRelativePostIds: " + id); | |
1845 | ||
1846 | var ids = new Array(); | |
1847 | var container = document.getElementById("headlinesList"); | |
1848 | ||
1849 | if (container) { | |
1850 | var rows = container.rows; | |
1851 | ||
1852 | for (var i = 0; i < rows.length; i++) { | |
1853 | var r_id = rows[i].id.replace("RROW-", ""); | |
1854 | ||
1855 | if (r_id == id) { | |
1856 | if (i > 0) ids.push(rows[i-1].id.replace("RROW-", "")); | |
1857 | if (i > 1) ids.push(rows[i-2].id.replace("RROW-", "")); | |
1858 | if (i > 2) ids.push(rows[i-3].id.replace("RROW-", "")); | |
1859 | ||
1860 | if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", "")); | |
1861 | if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", "")); | |
1862 | if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", "")); | |
1863 | ||
1864 | return ids; | |
1865 | } | |
1866 | } | |
1867 | } | |
1868 | ||
1869 | return false; | |
1870 | } | |
1871 | ||
1872 | function openArticleInNewWindow(id) { | |
1873 | try { | |
1874 | ||
1875 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
1876 | printLockingError(); | |
1877 | return | |
1878 | } | |
1879 | ||
1880 | debug("openArticleInNewWindow: " + id); | |
1881 | ||
1882 | var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id; | |
1883 | ||
1884 | debug(query); | |
1885 | ||
1886 | xmlhttp_rpc.open("GET", query, true); | |
1887 | xmlhttp_rpc.onreadystatechange=open_article_callback; | |
1888 | xmlhttp_rpc.send(null); | |
1889 | ||
1890 | } catch (e) { | |
1891 | exception_error("openArticleInNewWindow", e); | |
1892 | } | |
1893 | } | |
1894 | ||
1895 | /* http://textsnippets.com/posts/show/835 */ | |
1896 | ||
1897 | Position.GetWindowSize = function(w) { | |
1898 | w = w ? w : window; | |
1899 | var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth); | |
1900 | var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight); | |
1901 | return [width, height] | |
1902 | } | |
1903 | ||
1904 | /* http://textsnippets.com/posts/show/836 */ | |
1905 | ||
1906 | Position.Center = function(element, parent) { | |
1907 | var w, h, pw, ph; | |
1908 | var d = Element.getDimensions(element); | |
1909 | w = d.width; | |
1910 | h = d.height; | |
1911 | Position.prepare(); | |
1912 | if (!parent) { | |
1913 | var ws = Position.GetWindowSize(); | |
1914 | pw = ws[0]; | |
1915 | ph = ws[1]; | |
1916 | } else { | |
1917 | pw = parent.offsetWidth; | |
1918 | ph = parent.offsetHeight; | |
1919 | } | |
1920 | element.style.top = (ph/2) - (h/2) - Position.deltaY + "px"; | |
1921 | element.style.left = (pw/2) - (w/2) - Position.deltaX + "px"; | |
1922 | } | |
1923 | ||
1924 | function labeltest_callback() { | |
1925 | var container = document.getElementById('label_test_result'); | |
1926 | if (xmlhttp.readyState == 4) { | |
1927 | ||
1928 | container.innerHTML=xmlhttp.responseText; | |
1929 | if (!Element.visible(container)) { | |
1930 | Effect.SlideDown(container, { duration : 0.5 }); | |
1931 | } | |
1932 | notify(""); | |
1933 | } | |
1934 | } | |
1935 | ||
1936 | function labelTest() { | |
1937 | ||
1938 | var container = document.getElementById('label_test_result'); | |
1939 | ||
1940 | var form = document.forms['label_edit_form']; | |
1941 | ||
1942 | var sql_exp = form.sql_exp.value; | |
1943 | var description = form.description.value; | |
1944 | ||
1945 | notify_progress("Loading, please wait..."); | |
1946 | ||
1947 | xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" + | |
1948 | param_escape(sql_exp) + "&descr=" + param_escape(description), true); | |
1949 | ||
1950 | xmlhttp.onreadystatechange=labeltest_callback; | |
1951 | xmlhttp.send(null); | |
1952 | ||
1953 | return false; | |
1954 | } | |
1955 |