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