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