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