]>
Commit | Line | Data |
---|---|---|
1 | var hotkeys_enabled = true; | |
2 | ||
3 | function browser_has_opacity() { | |
4 | return navigator.userAgent.match("Gecko") != null || | |
5 | navigator.userAgent.match("Opera") != null; | |
6 | } | |
7 | ||
8 | function exception_error(location, e) { | |
9 | var msg; | |
10 | ||
11 | if (e.fileName) { | |
12 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
13 | ||
14 | msg = "Exception: " + e.name + ", " + e.message + | |
15 | "\nFunction: " + location + "()" + | |
16 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
17 | } else { | |
18 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
19 | } | |
20 | ||
21 | alert(msg); | |
22 | } | |
23 | ||
24 | function disableHotkeys() { | |
25 | hotkeys_enabled = false; | |
26 | } | |
27 | ||
28 | function enableHotkeys() { | |
29 | hotkeys_enabled = true; | |
30 | } | |
31 | ||
32 | function xmlhttp_ready(obj) { | |
33 | return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState; | |
34 | } | |
35 | ||
36 | function notify_callback() { | |
37 | var container = document.getElementById('notify'); | |
38 | if (xmlhttp.readyState == 4) { | |
39 | container.innerHTML=xmlhttp.responseText; | |
40 | } | |
41 | } | |
42 | ||
43 | function rpc_notify_callback() { | |
44 | var container = document.getElementById('notify'); | |
45 | if (xmlhttp_rpc.readyState == 4) { | |
46 | container.innerHTML=xmlhttp_rpc.responseText; | |
47 | } | |
48 | } | |
49 | ||
50 | function rpc_pnotify_callback() { | |
51 | var container = parent.document.getElementById('notify'); | |
52 | if (xmlhttp_rpc.readyState == 4) { | |
53 | container.innerHTML=xmlhttp_rpc.responseText; | |
54 | } | |
55 | } | |
56 | ||
57 | function param_escape(arg) { | |
58 | if (typeof encodeURIComponent != 'undefined') | |
59 | return encodeURIComponent(arg); | |
60 | else | |
61 | return escape(arg); | |
62 | } | |
63 | ||
64 | function param_unescape(arg) { | |
65 | if (typeof decodeURIComponent != 'undefined') | |
66 | return decodeURIComponent(arg); | |
67 | else | |
68 | return unescape(arg); | |
69 | } | |
70 | ||
71 | function delay(gap) { | |
72 | var then,now; | |
73 | then=new Date().getTime(); | |
74 | now=then; | |
75 | while((now-then)<gap) { | |
76 | now=new Date().getTime(); | |
77 | } | |
78 | } | |
79 | ||
80 | var notify_hide_timerid = false; | |
81 | var notify_last_doc = false; | |
82 | ||
83 | function hide_notify() { | |
84 | if (notify_last_doc) { | |
85 | var n = notify_last_doc.getElementById("notify"); | |
86 | if (browser_has_opacity()) { | |
87 | if (notify_opacity >= 0) { | |
88 | notify_opacity = notify_opacity - 0.1; | |
89 | n.style.opacity = notify_opacity; | |
90 | notify_hide_timerid = window.setTimeout("hide_notify()", 20); | |
91 | } else { | |
92 | n.style.display = "none"; | |
93 | n.style.opacity = 1; | |
94 | } | |
95 | } else { | |
96 | n.style.display = "none"; | |
97 | } | |
98 | } | |
99 | } | |
100 | ||
101 | function notify_real(msg, doc, no_hide, is_err) { | |
102 | ||
103 | var n = doc.getElementById("notify"); | |
104 | var nb = doc.getElementById("notify_body"); | |
105 | ||
106 | if (!n || !nb) return; | |
107 | ||
108 | if (notify_hide_timerid) { | |
109 | window.clearTimeout(notify_hide_timerid); | |
110 | } | |
111 | ||
112 | notify_last_doc = doc; | |
113 | notify_opacity = 1; | |
114 | ||
115 | if (msg == "") { | |
116 | if (n.style.display == "block") { | |
117 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
118 | } | |
119 | return; | |
120 | } else { | |
121 | n.style.display = "block"; | |
122 | } | |
123 | ||
124 | if (is_err) { | |
125 | n.style.backgroundColor = "#ffcccc"; | |
126 | n.style.color = "black"; | |
127 | n.style.borderColor = "#ff0000"; | |
128 | } else { | |
129 | n.style.backgroundColor = "#fff7d5"; | |
130 | n.style.borderColor = "#d7c47a"; | |
131 | n.style.color = "black"; | |
132 | } | |
133 | ||
134 | nb.innerHTML = msg; | |
135 | ||
136 | if (!no_hide) { | |
137 | notify_hide_timerid = window.setTimeout("hide_notify()", 3000); | |
138 | } | |
139 | } | |
140 | ||
141 | function p_notify(msg, no_hide, is_err) { | |
142 | notify_real(msg, parent.document, no_hide, is_err); | |
143 | } | |
144 | ||
145 | function notify(msg, no_hide, is_err) { | |
146 | notify_real(msg, document, no_hide, is_err); | |
147 | } | |
148 | ||
149 | function printLockingError() { | |
150 | notify("Please wait until operation finishes");} | |
151 | ||
152 | var seq = ""; | |
153 | ||
154 | function hotkey_handler(e) { | |
155 | ||
156 | var keycode; | |
157 | ||
158 | if (!hotkeys_enabled) return; | |
159 | ||
160 | if (window.event) { | |
161 | keycode = window.event.keyCode; | |
162 | } else if (e) { | |
163 | keycode = e.which; | |
164 | } | |
165 | ||
166 | if (keycode == 13 || keycode == 27) { | |
167 | seq = ""; | |
168 | } else { | |
169 | seq = seq + "" + keycode; | |
170 | } | |
171 | ||
172 | if (document.getElementById("piggie")) { | |
173 | ||
174 | if (seq.match("807371717369")) { | |
175 | seq = ""; | |
176 | localPiggieFunction(true); | |
177 | } else { | |
178 | localPiggieFunction(false); | |
179 | } | |
180 | } | |
181 | ||
182 | if (typeof localHotkeyHandler != 'undefined') { | |
183 | try { | |
184 | localHotkeyHandler(keycode); | |
185 | } catch (e) { | |
186 | exception_error("hotkey_handler", e); | |
187 | } | |
188 | } | |
189 | ||
190 | } | |
191 | ||
192 | function cleanSelectedList(element) { | |
193 | var content = document.getElementById(element); | |
194 | ||
195 | if (!document.getElementById("feedCatHolder")) { | |
196 | for (i = 0; i < content.childNodes.length; i++) { | |
197 | var child = content.childNodes[i]; | |
198 | try { | |
199 | child.className = child.className.replace("Selected", ""); | |
200 | } catch (e) { | |
201 | // | |
202 | } | |
203 | } | |
204 | } else { | |
205 | for (i = 0; i < content.childNodes.length; i++) { | |
206 | var child = content.childNodes[i]; | |
207 | if (child.id == "feedCatHolder") { | |
208 | parent.debug(child.id); | |
209 | var fcat = child.lastChild; | |
210 | for (j = 0; j < fcat.childNodes.length; j++) { | |
211 | var feed = fcat.childNodes[j]; | |
212 | feed.className = feed.className.replace("Selected", ""); | |
213 | } | |
214 | } | |
215 | } | |
216 | } | |
217 | } | |
218 | ||
219 | ||
220 | function cleanSelected(element) { | |
221 | var content = document.getElementById(element); | |
222 | ||
223 | for (i = 0; i < content.rows.length; i++) { | |
224 | content.rows[i].className = content.rows[i].className.replace("Selected", ""); | |
225 | } | |
226 | } | |
227 | ||
228 | function getVisibleUnreadHeadlines() { | |
229 | var content = document.getElementById("headlinesList"); | |
230 | ||
231 | var rows = new Array(); | |
232 | ||
233 | for (i = 0; i < content.rows.length; i++) { | |
234 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
235 | if (row_id.length > 0 && content.rows[i].className.match("Unread")) { | |
236 | rows.push(row_id); | |
237 | } | |
238 | } | |
239 | return rows; | |
240 | } | |
241 | ||
242 | function getVisibleHeadlineIds() { | |
243 | ||
244 | var content = document.getElementById("headlinesList"); | |
245 | ||
246 | var rows = new Array(); | |
247 | ||
248 | for (i = 0; i < content.rows.length; i++) { | |
249 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
250 | if (row_id.length > 0) { | |
251 | rows.push(row_id); | |
252 | } | |
253 | } | |
254 | return rows; | |
255 | } | |
256 | ||
257 | function getFirstVisibleHeadlineId() { | |
258 | var rows = getVisibleHeadlineIds(); | |
259 | return rows[0]; | |
260 | } | |
261 | ||
262 | function getLastVisibleHeadlineId() { | |
263 | var rows = getVisibleHeadlineIds(); | |
264 | return rows[rows.length-1]; | |
265 | } | |
266 | ||
267 | function markHeadline(id) { | |
268 | var row = document.getElementById("RROW-" + id); | |
269 | if (row) { | |
270 | var is_active = false; | |
271 | ||
272 | if (row.className.match("Active")) { | |
273 | is_active = true; | |
274 | } | |
275 | row.className = row.className.replace("Selected", ""); | |
276 | row.className = row.className.replace("Active", ""); | |
277 | row.className = row.className.replace("Insensitive", ""); | |
278 | ||
279 | if (is_active) { | |
280 | row.className = row.className = "Active"; | |
281 | } | |
282 | ||
283 | var check = document.getElementById("RCHK-" + id); | |
284 | ||
285 | if (check) { | |
286 | check.checked = true; | |
287 | } | |
288 | ||
289 | row.className = row.className + "Selected"; | |
290 | ||
291 | } | |
292 | } | |
293 | ||
294 | function getFeedIds() { | |
295 | var content = document.getElementById("feedsList"); | |
296 | ||
297 | var rows = new Array(); | |
298 | ||
299 | for (i = 0; i < content.rows.length; i++) { | |
300 | var id = content.rows[i].id.replace("FEEDR-", ""); | |
301 | if (id.length > 0) { | |
302 | rows.push(id); | |
303 | } | |
304 | } | |
305 | ||
306 | return rows; | |
307 | } | |
308 | ||
309 | function setCookie(name, value, lifetime, path, domain, secure) { | |
310 | ||
311 | var d = false; | |
312 | ||
313 | if (lifetime) { | |
314 | d = new Date(); | |
315 | d.setTime(lifetime * 1000); | |
316 | } | |
317 | ||
318 | int_setCookie(name, value, d, path, domain, secure); | |
319 | ||
320 | } | |
321 | ||
322 | function int_setCookie(name, value, expires, path, domain, secure) { | |
323 | document.cookie= name + "=" + escape(value) + | |
324 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
325 | ((path) ? "; path=" + path : "") + | |
326 | ((domain) ? "; domain=" + domain : "") + | |
327 | ((secure) ? "; secure" : ""); | |
328 | } | |
329 | ||
330 | function delCookie(name, path, domain) { | |
331 | if (getCookie(name)) { | |
332 | document.cookie = name + "=" + | |
333 | ((path) ? ";path=" + path : "") + | |
334 | ((domain) ? ";domain=" + domain : "" ) + | |
335 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
336 | } | |
337 | } | |
338 | ||
339 | ||
340 | function getCookie(name) { | |
341 | ||
342 | var dc = document.cookie; | |
343 | var prefix = name + "="; | |
344 | var begin = dc.indexOf("; " + prefix); | |
345 | if (begin == -1) { | |
346 | begin = dc.indexOf(prefix); | |
347 | if (begin != 0) return null; | |
348 | } | |
349 | else { | |
350 | begin += 2; | |
351 | } | |
352 | var end = document.cookie.indexOf(";", begin); | |
353 | if (end == -1) { | |
354 | end = dc.length; | |
355 | } | |
356 | return unescape(dc.substring(begin + prefix.length, end)); | |
357 | } | |
358 | ||
359 | function disableContainerChildren(id, disable, doc) { | |
360 | ||
361 | if (!doc) doc = document; | |
362 | ||
363 | var container = doc.getElementById(id); | |
364 | ||
365 | for (var i = 0; i < container.childNodes.length; i++) { | |
366 | var child = container.childNodes[i]; | |
367 | ||
368 | try { | |
369 | child.disabled = disable; | |
370 | } catch (E) { | |
371 | ||
372 | } | |
373 | ||
374 | if (disable) { | |
375 | if (child.className && child.className.match("button")) { | |
376 | child.className = "disabledButton"; | |
377 | } | |
378 | } else { | |
379 | if (child.className && child.className.match("disabledButton")) { | |
380 | child.className = "button"; | |
381 | } | |
382 | } | |
383 | } | |
384 | ||
385 | } | |
386 | ||
387 | function gotoPreferences() { | |
388 | document.location.href = "prefs.php"; | |
389 | } | |
390 | ||
391 | function gotoMain() { | |
392 | document.location.href = "tt-rss.php"; | |
393 | } | |
394 | ||
395 | function gotoExportOpml() { | |
396 | document.location.href = "opml.php?op=Export"; | |
397 | } | |
398 | ||
399 | function getActiveFeedId() { | |
400 | return getCookie("ttrss_vf_actfeed"); | |
401 | } | |
402 | ||
403 | function setActiveFeedId(id) { | |
404 | return setCookie("ttrss_vf_actfeed", id); | |
405 | } | |
406 | ||
407 | var xmlhttp_rpc = false; | |
408 | ||
409 | /*@cc_on @*/ | |
410 | /*@if (@_jscript_version >= 5) | |
411 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
412 | // and security blocked creation of the objects. | |
413 | try { | |
414 | xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP"); | |
415 | } catch (e) { | |
416 | try { | |
417 | xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); | |
418 | } catch (E) { | |
419 | xmlhttp_rpc = false; | |
420 | } | |
421 | } | |
422 | @end @*/ | |
423 | ||
424 | if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') { | |
425 | xmlhttp_rpc = new XMLHttpRequest(); | |
426 | } | |
427 | ||
428 | function parse_counters(reply, f_document, title_obj, scheduled_call) { | |
429 | try { | |
430 | for (var l = 0; l < reply.childNodes.length; l++) { | |
431 | if (!reply.childNodes[l] || | |
432 | typeof(reply.childNodes[l].getAttribute) == "undefined") { | |
433 | // where did this come from? | |
434 | continue; | |
435 | } | |
436 | ||
437 | var id = reply.childNodes[l].getAttribute("id"); | |
438 | var t = reply.childNodes[l].getAttribute("type"); | |
439 | var ctr = reply.childNodes[l].getAttribute("counter"); | |
440 | var error = reply.childNodes[l].getAttribute("error"); | |
441 | var has_img = reply.childNodes[l].getAttribute("hi"); | |
442 | var updated = reply.childNodes[l].getAttribute("updated"); | |
443 | ||
444 | if (id == "global-unread") { | |
445 | title_obj.global_unread = ctr; | |
446 | title_obj.updateTitle(); | |
447 | continue; | |
448 | } | |
449 | ||
450 | if (t == "category") { | |
451 | var catctr = f_document.getElementById("FCATCTR-" + id); | |
452 | if (catctr) { | |
453 | catctr.innerHTML = "(" + ctr + " unread)"; | |
454 | } | |
455 | continue; | |
456 | } | |
457 | ||
458 | var feedctr = f_document.getElementById("FEEDCTR-" + id); | |
459 | var feedu = f_document.getElementById("FEEDU-" + id); | |
460 | var feedr = f_document.getElementById("FEEDR-" + id); | |
461 | var feed_img = f_document.getElementById("FIMG-" + id); | |
462 | var feedlink = f_document.getElementById("FEEDL-" + id); | |
463 | ||
464 | if (updated && feedlink) { | |
465 | if (error) { | |
466 | feedlink.title = "Error: " + error + " (" + updated + ")"; | |
467 | } else { | |
468 | feedlink.title = "Updated: " + updated; | |
469 | } | |
470 | } | |
471 | ||
472 | if (feedctr && feedu && feedr) { | |
473 | ||
474 | if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) { | |
475 | var hf = title_obj.parent.frames["headlines-frame"]; | |
476 | hf.location.reload(true); | |
477 | } | |
478 | ||
479 | feedu.innerHTML = ctr; | |
480 | ||
481 | if (error) { | |
482 | feedr.className = feedr.className.replace("feed", "error"); | |
483 | } else if (id > 0) { | |
484 | feedr.className = feedr.className.replace("error", "feed"); | |
485 | } | |
486 | ||
487 | if (ctr > 0) { | |
488 | feedctr.className = "odd"; | |
489 | if (!feedr.className.match("Unread")) { | |
490 | var is_selected = feedr.className.match("Selected"); | |
491 | ||
492 | feedr.className = feedr.className.replace("Selected", ""); | |
493 | feedr.className = feedr.className.replace("Unread", ""); | |
494 | ||
495 | feedr.className = feedr.className + "Unread"; | |
496 | ||
497 | if (is_selected) { | |
498 | feedr.className = feedr.className + "Selected"; | |
499 | } | |
500 | ||
501 | } | |
502 | } else { | |
503 | feedctr.className = "invisible"; | |
504 | feedr.className = feedr.className.replace("Unread", ""); | |
505 | } | |
506 | } | |
507 | } | |
508 | } catch (e) { | |
509 | exception_error("parse_counters", e); | |
510 | } | |
511 | } | |
512 | ||
513 | // this one is called from feedlist context | |
514 | // thus title_obj passed to parse_counters is parent (e.g. main ttrss window) | |
515 | ||
516 | function all_counters_callback() { | |
517 | if (xmlhttp_rpc.readyState == 4) { | |
518 | try { | |
519 | if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) { | |
520 | notify("[all_counters_callback] backend did not return valid XML"); | |
521 | return; | |
522 | } | |
523 | ||
524 | if (!parent.frames["feeds-frame"]) { | |
525 | notify("[all_counters_callback] no parent feeds-frame"); | |
526 | return; | |
527 | } | |
528 | ||
529 | var reply = xmlhttp_rpc.responseXML.firstChild; | |
530 | var f_document = parent.frames["feeds-frame"].document; | |
531 | ||
532 | parse_counters(reply, f_document, parent); | |
533 | ||
534 | } catch (e) { | |
535 | exception_error("all_counters_callback", e); | |
536 | } | |
537 | } | |
538 | } | |
539 | ||
540 | function update_all_counters(feed) { | |
541 | if (xmlhttp_ready(xmlhttp_rpc)) { | |
542 | var query = "backend.php?op=rpc&subop=getAllCounters"; | |
543 | ||
544 | if (feed > 0) { | |
545 | query = query + "&aid=" + feed; | |
546 | } | |
547 | ||
548 | xmlhttp_rpc.open("GET", query, true); | |
549 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
550 | xmlhttp_rpc.send(null); | |
551 | } | |
552 | } | |
553 | ||
554 | function popupHelp(tid) { | |
555 | var w = window.open("backend.php?op=help&tid=" + tid, | |
556 | "Popup Help", | |
557 | "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no"); | |
558 | } | |
559 | ||
560 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj | |
561 | * * @author Sundar Dorai-Raj | |
562 | * * Email: sdoraira@vt.edu | |
563 | * * This program is free software; you can redistribute it and/or | |
564 | * * modify it under the terms of the GNU General Public License | |
565 | * * as published by the Free Software Foundation; either version 2 | |
566 | * * of the License, or (at your option) any later version, | |
567 | * * provided that any use properly credits the author. | |
568 | * * This program is distributed in the hope that it will be useful, | |
569 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
570 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
571 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
572 | ||
573 | var numbers=".0123456789"; | |
574 | function isNumeric(x) { | |
575 | // is x a String or a character? | |
576 | if(x.length>1) { | |
577 | // remove negative sign | |
578 | x=Math.abs(x)+""; | |
579 | for(j=0;j<x.length;j++) { | |
580 | // call isNumeric recursively for each character | |
581 | number=isNumeric(x.substring(j,j+1)); | |
582 | if(!number) return number; | |
583 | } | |
584 | return number; | |
585 | } | |
586 | else { | |
587 | // if x is number return true | |
588 | if(numbers.indexOf(x)>=0) return true; | |
589 | return false; | |
590 | } | |
591 | } | |
592 | ||
593 | ||
594 | function hideOrShowFeeds(doc, hide) { | |
595 | ||
596 | if (!doc.styleSheets) return; | |
597 | ||
598 | var css_rules = doc.styleSheets[0].cssRules; | |
599 | ||
600 | if (!css_rules || !css_rules.length) return; | |
601 | ||
602 | for (i = 0; i < css_rules.length; i++) { | |
603 | var rule = css_rules[i]; | |
604 | ||
605 | if (rule.selectorText == "ul.feedList li.feed") { | |
606 | if (!hide) { | |
607 | rule.style.display = "block"; | |
608 | } else { | |
609 | rule.style.display = "none"; | |
610 | } | |
611 | } | |
612 | ||
613 | } | |
614 | ||
615 | } | |
616 | ||
617 | function selectTableRow(r, do_select) { | |
618 | r.className = r.className.replace("Selected", ""); | |
619 | ||
620 | if (do_select) { | |
621 | r.className = r.className + "Selected"; | |
622 | } | |
623 | } | |
624 | ||
625 | function selectTableRowById(elem_id, check_id, do_select) { | |
626 | ||
627 | try { | |
628 | ||
629 | var row = document.getElementById(elem_id); | |
630 | ||
631 | if (row) { | |
632 | selectTableRow(row, do_select); | |
633 | } | |
634 | ||
635 | var check = document.getElementById(check_id); | |
636 | ||
637 | if (check) { | |
638 | check.checked = do_select; | |
639 | } | |
640 | } catch (e) { | |
641 | exception_error("selectTableRowById", e); | |
642 | } | |
643 | } | |
644 | ||
645 | function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select, | |
646 | classcheck, reset_others) { | |
647 | ||
648 | var content = document.getElementById(content_id); | |
649 | ||
650 | if (!content) { | |
651 | alert("[selectTableRows] Element " + content_id + " not found."); | |
652 | return; | |
653 | } | |
654 | ||
655 | for (i = 0; i < content.rows.length; i++) { | |
656 | if (!classcheck || content.rows[i].className.match(classcheck)) { | |
657 | ||
658 | if (content.rows[i].id.match(prefix)) { | |
659 | selectTableRow(content.rows[i], do_select); | |
660 | ||
661 | var row_id = content.rows[i].id.replace(prefix, ""); | |
662 | var check = document.getElementById(check_prefix + row_id); | |
663 | ||
664 | if (check) { | |
665 | check.checked = do_select; | |
666 | } | |
667 | } else if (reset_others) { | |
668 | selectTableRow(content.rows[i], false); | |
669 | ||
670 | var row_id = content.rows[i].id.replace(prefix, ""); | |
671 | var check = document.getElementById(check_prefix + row_id); | |
672 | ||
673 | if (check) { | |
674 | check.checked = false; | |
675 | } | |
676 | ||
677 | } | |
678 | } else if (reset_others) { | |
679 | selectTableRow(content.rows[i], false); | |
680 | ||
681 | var row_id = content.rows[i].id.replace(prefix, ""); | |
682 | var check = document.getElementById(check_prefix + row_id); | |
683 | ||
684 | if (check) { | |
685 | check.checked = false; | |
686 | } | |
687 | ||
688 | } | |
689 | } | |
690 | } | |
691 | ||
692 | function getSelectedTableRowIds(content_id, prefix) { | |
693 | ||
694 | var content = document.getElementById(content_id); | |
695 | ||
696 | if (!content) { | |
697 | alert("[getSelectedTableRowIds] Element " + content_id + " not found."); | |
698 | return; | |
699 | } | |
700 | ||
701 | var sel_rows = new Array(); | |
702 | ||
703 | for (i = 0; i < content.rows.length; i++) { | |
704 | if (content.rows[i].id.match(prefix) && | |
705 | content.rows[i].className.match("Selected")) { | |
706 | ||
707 | var row_id = content.rows[i].id.replace(prefix + "-", ""); | |
708 | sel_rows.push(row_id); | |
709 | } | |
710 | } | |
711 | ||
712 | return sel_rows; | |
713 | ||
714 | } | |
715 | ||
716 | function toggleSelectRowById(sender, id) { | |
717 | var row = document.getElementById(id); | |
718 | ||
719 | if (sender.checked) { | |
720 | if (!row.className.match("Selected")) { | |
721 | row.className = row.className + "Selected"; | |
722 | } | |
723 | } else { | |
724 | if (row.className.match("Selected")) { | |
725 | row.className = row.className.replace("Selected", ""); | |
726 | } | |
727 | } | |
728 | } | |
729 | ||
730 | function toggleSelectListRow(sender) { | |
731 | var parent_row = sender.parentNode; | |
732 | ||
733 | if (sender.checked) { | |
734 | if (!parent_row.className.match("Selected")) { | |
735 | parent_row.className = parent_row.className + "Selected"; | |
736 | } | |
737 | } else { | |
738 | if (parent_row.className.match("Selected")) { | |
739 | parent_row.className = parent_row.className.replace("Selected", ""); | |
740 | } | |
741 | } | |
742 | } | |
743 | ||
744 | ||
745 | function toggleSelectRow(sender) { | |
746 | var parent_row = sender.parentNode.parentNode; | |
747 | ||
748 | if (sender.checked) { | |
749 | if (!parent_row.className.match("Selected")) { | |
750 | parent_row.className = parent_row.className + "Selected"; | |
751 | } | |
752 | } else { | |
753 | if (parent_row.className.match("Selected")) { | |
754 | parent_row.className = parent_row.className.replace("Selected", ""); | |
755 | } | |
756 | } | |
757 | } | |
758 | ||
759 | function openExternalUrl(url) { | |
760 | var w = window.open(url); | |
761 | } | |
762 | ||
763 | function getRelativeFeedId(list, id, direction, unread_only) { | |
764 | if (!id) { | |
765 | if (direction == "next") { | |
766 | for (i = 0; i < list.childNodes.length; i++) { | |
767 | var child = list.childNodes[i]; | |
768 | if (child.id && child.id == "feedCatHolder") { | |
769 | if (child.lastChild) { | |
770 | var cr = getRelativeFeedId(child.firstChild, id, direction); | |
771 | if (cr) return cr; | |
772 | } | |
773 | } else if (child.id && child.id.match("FEEDR-")) { | |
774 | return child.id.replace('FEEDR-', ''); | |
775 | } | |
776 | } | |
777 | } | |
778 | ||
779 | // FIXME select last feed doesn't work when only unread feeds are visible | |
780 | ||
781 | if (direction == "prev") { | |
782 | for (i = list.childNodes.length-1; i >= 0; i--) { | |
783 | var child = list.childNodes[i]; | |
784 | if (child.id == "feedCatHolder") { | |
785 | if (child.firstChild) { | |
786 | var cr = getRelativeFeedId(child.firstChild, id, direction); | |
787 | if (cr) return cr; | |
788 | } | |
789 | } else if (child.id.match("FEEDR-")) { | |
790 | ||
791 | if (getCookie("ttrss_vf_hreadf") == 1) { | |
792 | if (child.className != "feed") { | |
793 | alert(child.className); | |
794 | return child.id.replace('FEEDR-', ''); | |
795 | } | |
796 | } else { | |
797 | return child.id.replace('FEEDR-', ''); | |
798 | } | |
799 | } | |
800 | } | |
801 | } | |
802 | } else { | |
803 | ||
804 | var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId()); | |
805 | ||
806 | if (getCookie("ttrss_vf_hreadf") == 1) { | |
807 | unread_only = true; | |
808 | } | |
809 | ||
810 | if (direction == "next") { | |
811 | ||
812 | var e = feed; | |
813 | ||
814 | while (e) { | |
815 | ||
816 | if (e.nextSibling) { | |
817 | ||
818 | e = e.nextSibling; | |
819 | ||
820 | } else if (e.parentNode.parentNode.nextSibling) { | |
821 | ||
822 | var this_cat = e.parentNode.parentNode; | |
823 | ||
824 | e = false; | |
825 | ||
826 | if (this_cat && this_cat.nextSibling) { | |
827 | while (!e && this_cat.nextSibling) { | |
828 | this_cat = this_cat.nextSibling; | |
829 | if (this_cat.id == "feedCatHolder") { | |
830 | e = this_cat.firstChild.firstChild; | |
831 | } | |
832 | } | |
833 | } | |
834 | ||
835 | } else { | |
836 | e = false; | |
837 | } | |
838 | ||
839 | if (e) { | |
840 | if (!unread_only || (unread_only && e.className != "feed" && | |
841 | e.className != "error")) { | |
842 | return e.id.replace("FEEDR-", ""); | |
843 | } | |
844 | } | |
845 | } | |
846 | ||
847 | } else if (direction == "prev") { | |
848 | ||
849 | var e = feed; | |
850 | ||
851 | while (e) { | |
852 | ||
853 | if (e.previousSibling) { | |
854 | ||
855 | e = e.previousSibling; | |
856 | ||
857 | } else if (e.parentNode.parentNode.previousSibling) { | |
858 | ||
859 | var this_cat = e.parentNode.parentNode; | |
860 | ||
861 | e = false; | |
862 | ||
863 | if (this_cat && this_cat.previousSibling) { | |
864 | while (!e && this_cat.previousSibling) { | |
865 | this_cat = this_cat.previousSibling; | |
866 | if (this_cat.id == "feedCatHolder") { | |
867 | e = this_cat.firstChild.lastChild; | |
868 | } | |
869 | } | |
870 | } | |
871 | ||
872 | } else { | |
873 | e = false; | |
874 | } | |
875 | ||
876 | if (e) { | |
877 | if (!unread_only || (unread_only && e.className != "feed" && | |
878 | e.className != "error")) { | |
879 | return e.id.replace("FEEDR-", ""); | |
880 | } | |
881 | } | |
882 | } | |
883 | } | |
884 | } | |
885 | } | |
886 | ||
887 | function showBlockElement(id) { | |
888 | var elem = document.getElementById(id); | |
889 | ||
890 | if (elem) { | |
891 | elem.style.display = "block"; | |
892 | } else { | |
893 | alert("[showBlockElement] can't find element with id " + id); | |
894 | } | |
895 | } | |
896 | ||
897 | function hideParentElement(e) { | |
898 | e.parentNode.style.display = "none"; | |
899 | } | |
900 | ||
901 | function dropboxSelect(e, v) { | |
902 | for (i = 0; i < e.length; i++) { | |
903 | if (e[i].value == v) { | |
904 | e.selectedIndex = i; | |
905 | break; | |
906 | } | |
907 | } | |
908 | } | |
909 | ||
910 | // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z | |
911 | // bugfixed just a little bit :-) | |
912 | function getURLParam(strParamName){ | |
913 | var strReturn = ""; | |
914 | var strHref = window.location.href; | |
915 | ||
916 | if (strHref.indexOf("#") == strHref.length-1) { | |
917 | strHref = strHref.substring(0, strHref.length-1); | |
918 | } | |
919 | ||
920 | if ( strHref.indexOf("?") > -1 ){ | |
921 | var strQueryString = strHref.substr(strHref.indexOf("?")); | |
922 | var aQueryString = strQueryString.split("&"); | |
923 | for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ | |
924 | if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ | |
925 | var aParam = aQueryString[iParam].split("="); | |
926 | strReturn = aParam[1]; | |
927 | break; | |
928 | } | |
929 | } | |
930 | } | |
931 | return strReturn; | |
932 | } | |
933 | ||
934 | function leading_zero(p) { | |
935 | var s = String(p); | |
936 | if (s.length == 1) s = "0" + s; | |
937 | return s; | |
938 | } | |
939 | ||
940 | function center_element(e) { | |
941 | ||
942 | try { | |
943 | var c_width = document.body.clientWidth; | |
944 | var c_height = document.body.clientHeight; | |
945 | ||
946 | var c_scroll = document.body.scrollTop; | |
947 | ||
948 | var e_width = e.clientWidth; | |
949 | var e_height = e.clientHeight; | |
950 | ||
951 | var set_y = (c_height / 2) + c_scroll - (e_height / 2); | |
952 | var set_x = (c_width / 2) - (e_width / 2); | |
953 | ||
954 | e.style.top = set_y + "px"; | |
955 | e.style.left = set_x + "px"; | |
956 | } catch (e) { | |
957 | exception_error("center_element", e); | |
958 | } | |
959 | } | |
960 | ||
961 | function closeInfoBox() { | |
962 | var box = document.getElementById('infoBox'); | |
963 | var shadow = document.getElementById('infoBoxShadow'); | |
964 | ||
965 | if (shadow) { | |
966 | shadow.style.display = "none"; | |
967 | } else if (box) { | |
968 | box.style.display = "none"; | |
969 | } | |
970 | ||
971 | enableHotkeys(); | |
972 | } | |
973 | ||
974 | ||
975 | function displayDlg(id, param) { | |
976 | ||
977 | if (!xmlhttp_ready(xmlhttp)) { | |
978 | printLockingError(); | |
979 | return | |
980 | } | |
981 | ||
982 | notify(""); | |
983 | ||
984 | xmlhttp.open("GET", "backend.php?op=dlg&id=" + | |
985 | param_escape(id) + "¶m=" + param_escape(param), true); | |
986 | xmlhttp.onreadystatechange=infobox_callback; | |
987 | xmlhttp.send(null); | |
988 | ||
989 | disableHotkeys(); | |
990 | ||
991 | } | |
992 | ||
993 | function infobox_submit_callback() { | |
994 | if (xmlhttp.readyState == 4) { | |
995 | notify(xmlhttp.responseText); | |
996 | closeInfoBox(); | |
997 | ||
998 | // called from prefs, reload tab | |
999 | if (active_tab) { | |
1000 | selectTab(active_tab, false); | |
1001 | } | |
1002 | } | |
1003 | } | |
1004 | ||
1005 | function infobox_callback() { | |
1006 | if (xmlhttp.readyState == 4) { | |
1007 | var box = document.getElementById('infoBox'); | |
1008 | var shadow = document.getElementById('infoBoxShadow'); | |
1009 | if (box) { | |
1010 | box.innerHTML=xmlhttp.responseText; | |
1011 | if (shadow) { | |
1012 | shadow.style.display = "block"; | |
1013 | } else { | |
1014 | box.style.display = "block"; | |
1015 | } | |
1016 | } | |
1017 | } | |
1018 | } | |
1019 | ||
1020 | function qaddFilter() { | |
1021 | ||
1022 | if (!xmlhttp_ready(xmlhttp)) { | |
1023 | printLockingError(); | |
1024 | return | |
1025 | } | |
1026 | ||
1027 | var regexp = document.getElementById("fadd_regexp"); | |
1028 | var match = document.getElementById("fadd_match"); | |
1029 | var feed = document.getElementById("fadd_feed"); | |
1030 | var action = document.getElementById("fadd_action"); | |
1031 | ||
1032 | if (regexp.value.length == 0) { | |
1033 | alert("Missing filter expression."); | |
1034 | } else { | |
1035 | notify("Adding filter..."); | |
1036 | ||
1037 | var v_match = match[match.selectedIndex].text; | |
1038 | var feed_id = feed[feed.selectedIndex].id; | |
1039 | var action_id = action[action.selectedIndex].id; | |
1040 | ||
1041 | xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" + | |
1042 | param_escape(regexp.value) + "&match=" + v_match + | |
1043 | "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true); | |
1044 | ||
1045 | xmlhttp.onreadystatechange=infobox_submit_callback; | |
1046 | xmlhttp.send(null); | |
1047 | ||
1048 | regexp.value = ""; | |
1049 | } | |
1050 | ||
1051 | } | |
1052 | ||
1053 | function toggleSubmitNotEmpty(e, submit_id) { | |
1054 | try { | |
1055 | document.getElementById(submit_id).disabled = (e.value == "") | |
1056 | } catch (e) { | |
1057 | exception_error("toggleSubmitNotEmpty", e); | |
1058 | } | |
1059 | } | |
1060 | ||
1061 | function isValidURL(s) { | |
1062 | return s.match("http://") != null || s.match("https://") != null; | |
1063 | } |