]>
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 | ||
31 | ||
9cfc649a AD |
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 | ||
1572afe5 AD |
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 | ||
7726fa02 AD |
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 | ||
508a81e1 AD |
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 | } | |
7726fa02 | 75 | |
c05608c2 AD |
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 | ||
8dcfffd0 AD |
83 | if (msg == "") { |
84 | nb.innerHTML = " "; | |
e93919dd | 85 | // n.style.background = "#ffffff"; |
c05608c2 | 86 | } else { |
8dcfffd0 | 87 | nb.innerHTML = msg; |
e93919dd | 88 | // n.style.background = "#fffff0"; |
8dcfffd0 | 89 | } |
c05608c2 AD |
90 | } |
91 | ||
7726fa02 AD |
92 | function notify(msg) { |
93 | ||
94 | var n = document.getElementById("notify"); | |
c05608c2 | 95 | var nb = document.getElementById("notify_body"); |
7726fa02 | 96 | |
c05608c2 | 97 | if (!n || !nb) return; |
f0601b87 | 98 | |
8dcfffd0 AD |
99 | if (msg == "") { |
100 | nb.innerHTML = " "; | |
e93919dd | 101 | // n.style.background = "#ffffff"; |
7726fa02 | 102 | } else { |
8dcfffd0 | 103 | nb.innerHTML = msg; |
e93919dd | 104 | // n.style.background = "#fffff0"; |
8dcfffd0 | 105 | } |
7726fa02 AD |
106 | |
107 | } | |
108 | ||
508a81e1 | 109 | function printLockingError() { |
f0601b87 | 110 | notify("Please wait until operation finishes");} |
508a81e1 | 111 | |
13ad9102 AD |
112 | var seq = ""; |
113 | ||
114 | function hotkey_handler(e) { | |
760966c1 | 115 | |
13ad9102 AD |
116 | var keycode; |
117 | ||
760966c1 AD |
118 | if (!hotkeys_enabled) return; |
119 | ||
13ad9102 AD |
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 | ||
2e02b896 AD |
132 | if (document.getElementById("piggie")) { |
133 | ||
134 | if (seq.match("807371717369")) { | |
135 | seq = ""; | |
136 | localPiggieFunction(true); | |
137 | } else { | |
138 | localPiggieFunction(false); | |
139 | } | |
bb7cface AD |
140 | } |
141 | ||
9cfc649a | 142 | if (typeof localHotkeyHandler != 'undefined') { |
7b433d8c AD |
143 | try { |
144 | localHotkeyHandler(keycode); | |
145 | } catch (e) { | |
83f043bb | 146 | exception_error("hotkey_handler", e); |
7b433d8c | 147 | } |
9cfc649a AD |
148 | } |
149 | ||
13ad9102 AD |
150 | } |
151 | ||
e828e31e | 152 | function cleanSelectedList(element) { |
f0601b87 AD |
153 | var content = document.getElementById(element); |
154 | ||
703b632e AD |
155 | if (!document.getElementById("feedCatHolder")) { |
156 | for (i = 0; i < content.childNodes.length; i++) { | |
157 | var child = content.childNodes[i]; | |
d0bb308e AD |
158 | try { |
159 | child.className = child.className.replace("Selected", ""); | |
160 | } catch (e) { | |
161 | // | |
162 | } | |
703b632e AD |
163 | } |
164 | } else { | |
165 | for (i = 0; i < content.childNodes.length; i++) { | |
166 | var child = content.childNodes[i]; | |
167 | ||
168 | if (child.id == "feedCatHolder") { | |
c3f348c2 | 169 | var fcat = child.lastChild; |
703b632e | 170 | for (j = 0; j < fcat.childNodes.length; j++) { |
937881b5 | 171 | var feed = fcat.childNodes[j]; |
703b632e AD |
172 | feed.className = feed.className.replace("Selected", ""); |
173 | } | |
174 | } | |
175 | } | |
e828e31e | 176 | |
703b632e | 177 | } |
e828e31e AD |
178 | } |
179 | ||
180 | ||
181 | function cleanSelected(element) { | |
182 | var content = document.getElementById(element); | |
f0601b87 AD |
183 | |
184 | for (i = 0; i < content.rows.length; i++) { | |
185 | content.rows[i].className = content.rows[i].className.replace("Selected", ""); | |
186 | } | |
f0601b87 AD |
187 | } |
188 | ||
189 | function getVisibleUnreadHeadlines() { | |
190 | var content = document.getElementById("headlinesList"); | |
191 | ||
192 | var rows = new Array(); | |
193 | ||
194 | for (i = 0; i < content.rows.length; i++) { | |
195 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
196 | if (row_id.length > 0 && content.rows[i].className.match("Unread")) { | |
197 | rows.push(row_id); | |
198 | } | |
199 | } | |
200 | return rows; | |
201 | } | |
202 | ||
203 | function getVisibleHeadlineIds() { | |
204 | ||
205 | var content = document.getElementById("headlinesList"); | |
206 | ||
207 | var rows = new Array(); | |
208 | ||
209 | for (i = 0; i < content.rows.length; i++) { | |
210 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
211 | if (row_id.length > 0) { | |
212 | rows.push(row_id); | |
213 | } | |
214 | } | |
215 | return rows; | |
216 | } | |
217 | ||
218 | function getFirstVisibleHeadlineId() { | |
219 | var rows = getVisibleHeadlineIds(); | |
220 | return rows[0]; | |
221 | } | |
222 | ||
223 | function getLastVisibleHeadlineId() { | |
224 | var rows = getVisibleHeadlineIds(); | |
225 | return rows[rows.length-1]; | |
226 | } | |
227 | ||
228 | function markHeadline(id) { | |
229 | var row = document.getElementById("RROW-" + id); | |
230 | if (row) { | |
35f3c923 AD |
231 | var is_active = false; |
232 | ||
233 | if (row.className.match("Active")) { | |
234 | is_active = true; | |
235 | } | |
236 | row.className = row.className.replace("Selected", ""); | |
237 | row.className = row.className.replace("Active", ""); | |
238 | row.className = row.className.replace("Insensitive", ""); | |
239 | ||
240 | if (is_active) { | |
241 | row.className = row.className = "Active"; | |
242 | } | |
243 | ||
72020095 AD |
244 | var check = document.getElementById("RCHK-" + id); |
245 | ||
246 | if (check) { | |
247 | check.checked = true; | |
248 | } | |
249 | ||
35f3c923 AD |
250 | row.className = row.className + "Selected"; |
251 | ||
f0601b87 AD |
252 | } |
253 | } | |
254 | ||
255 | function getFeedIds() { | |
256 | var content = document.getElementById("feedsList"); | |
257 | ||
258 | var rows = new Array(); | |
259 | ||
260 | for (i = 0; i < content.rows.length; i++) { | |
261 | var id = content.rows[i].id.replace("FEEDR-", ""); | |
262 | if (id.length > 0) { | |
263 | rows.push(id); | |
264 | } | |
265 | } | |
266 | ||
267 | return rows; | |
268 | } | |
13ad9102 | 269 | |
ac43eba1 AD |
270 | function setCookie(name, value, expires, path, domain, secure) { |
271 | document.cookie= name + "=" + escape(value) + | |
272 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
273 | ((path) ? "; path=" + path : "") + | |
274 | ((domain) ? "; domain=" + domain : "") + | |
275 | ((secure) ? "; secure" : ""); | |
276 | } | |
277 | ||
278 | function getCookie(name) { | |
279 | ||
280 | var dc = document.cookie; | |
281 | var prefix = name + "="; | |
282 | var begin = dc.indexOf("; " + prefix); | |
283 | if (begin == -1) { | |
284 | begin = dc.indexOf(prefix); | |
285 | if (begin != 0) return null; | |
286 | } | |
287 | else { | |
288 | begin += 2; | |
289 | } | |
290 | var end = document.cookie.indexOf(";", begin); | |
291 | if (end == -1) { | |
292 | end = dc.length; | |
293 | } | |
294 | return unescape(dc.substring(begin + prefix.length, end)); | |
295 | } | |
296 | ||
1a66d16e AD |
297 | function disableContainerChildren(id, disable, doc) { |
298 | ||
299 | if (!doc) doc = document; | |
300 | ||
301 | var container = doc.getElementById(id); | |
ac43eba1 AD |
302 | |
303 | for (var i = 0; i < container.childNodes.length; i++) { | |
304 | var child = container.childNodes[i]; | |
305 | ||
d5224f0d AD |
306 | try { |
307 | child.disabled = disable; | |
308 | } catch (E) { | |
309 | ||
310 | } | |
ac43eba1 AD |
311 | |
312 | if (disable) { | |
313 | if (child.className && child.className.match("button")) { | |
314 | child.className = "disabledButton"; | |
315 | } | |
316 | } else { | |
317 | if (child.className && child.className.match("disabledButton")) { | |
318 | child.className = "button"; | |
319 | } | |
d5224f0d | 320 | } |
ac43eba1 AD |
321 | } |
322 | ||
323 | } | |
7726fa02 | 324 | |
e828e31e AD |
325 | function gotoPreferences() { |
326 | document.location.href = "prefs.php"; | |
327 | } | |
328 | ||
329 | function gotoMain() { | |
330 | document.location.href = "tt-rss.php"; | |
331 | } | |
332 | ||
8158c57a AD |
333 | function gotoExportOpml() { |
334 | document.location.href = "opml.php?op=Export"; | |
335 | } | |
86741347 AD |
336 | |
337 | function getActiveFeedId() { | |
338 | return getCookie("ttrss_vf_actfeed"); | |
339 | } | |
340 | ||
341 | function setActiveFeedId(id) { | |
342 | return setCookie("ttrss_vf_actfeed", id); | |
343 | } | |
090e250b AD |
344 | |
345 | var xmlhttp_rpc = false; | |
346 | ||
347 | /*@cc_on @*/ | |
348 | /*@if (@_jscript_version >= 5) | |
349 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
350 | // and security blocked creation of the objects. | |
351 | try { | |
352 | xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP"); | |
353 | } catch (e) { | |
354 | try { | |
355 | xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); | |
356 | } catch (E) { | |
357 | xmlhttp_rpc = false; | |
358 | } | |
359 | } | |
360 | @end @*/ | |
361 | ||
362 | if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') { | |
363 | xmlhttp_rpc = new XMLHttpRequest(); | |
364 | } | |
365 | ||
e8ef3b97 | 366 | function parse_counters(reply, f_document, title_obj, scheduled_call) { |
1a6a9555 AD |
367 | try { |
368 | for (var l = 0; l < reply.childNodes.length; l++) { | |
9cbca41f AD |
369 | if (!reply.childNodes[l] || |
370 | typeof(reply.childNodes[l].getAttribute) == "undefined") { | |
6043fb7e AD |
371 | // where did this come from? |
372 | continue; | |
373 | } | |
374 | ||
1a6a9555 AD |
375 | var id = reply.childNodes[l].getAttribute("id"); |
376 | var t = reply.childNodes[l].getAttribute("type"); | |
377 | var ctr = reply.childNodes[l].getAttribute("counter"); | |
023fe037 AD |
378 | var error = reply.childNodes[l].getAttribute("error"); |
379 | var has_img = reply.childNodes[l].getAttribute("hi"); | |
1a6a9555 AD |
380 | |
381 | if (id == "global-unread") { | |
3bdb368b AD |
382 | title_obj.global_unread = ctr; |
383 | title_obj.updateTitle(); | |
1a6a9555 AD |
384 | continue; |
385 | } | |
386 | ||
387 | if (t == "category") { | |
388 | var catctr = f_document.getElementById("FCATCTR-" + id); | |
389 | if (catctr) { | |
390 | catctr.innerHTML = "(" + ctr + " unread)"; | |
391 | } | |
392 | continue; | |
393 | } | |
394 | ||
395 | var feedctr = f_document.getElementById("FEEDCTR-" + id); | |
396 | var feedu = f_document.getElementById("FEEDU-" + id); | |
397 | var feedr = f_document.getElementById("FEEDR-" + id); | |
023fe037 AD |
398 | var feed_img = f_document.getElementById("FIMG-" + id); |
399 | ||
1a6a9555 | 400 | if (feedctr && feedu && feedr) { |
e8ef3b97 AD |
401 | |
402 | if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) { | |
403 | var hf = title_obj.parent.frames["headlines-frame"]; | |
404 | hf.location.reload(true); | |
405 | } | |
1a6a9555 AD |
406 | |
407 | feedu.innerHTML = ctr; | |
023fe037 | 408 | |
426d3c57 AD |
409 | if (error) { |
410 | feedr.className = feedr.className.replace("feed", "error"); | |
411 | } else if (id > 0) { | |
412 | feedr.className = feedr.className.replace("error", "feed"); | |
023fe037 | 413 | } |
1a6a9555 AD |
414 | |
415 | if (ctr > 0) { | |
416 | feedctr.className = "odd"; | |
417 | if (!feedr.className.match("Unread")) { | |
418 | var is_selected = feedr.className.match("Selected"); | |
419 | ||
420 | feedr.className = feedr.className.replace("Selected", ""); | |
421 | feedr.className = feedr.className.replace("Unread", ""); | |
422 | ||
423 | feedr.className = feedr.className + "Unread"; | |
424 | ||
425 | if (is_selected) { | |
426 | feedr.className = feedr.className + "Selected"; | |
427 | } | |
428 | ||
429 | } | |
430 | } else { | |
431 | feedctr.className = "invisible"; | |
432 | feedr.className = feedr.className.replace("Unread", ""); | |
433 | } | |
434 | } | |
435 | } | |
436 | } catch (e) { | |
83f043bb | 437 | exception_error("parse_counters", e); |
1a6a9555 AD |
438 | } |
439 | } | |
440 | ||
3bdb368b AD |
441 | // this one is called from feedlist context |
442 | // thus title_obj passed to parse_counters is parent (e.g. main ttrss window) | |
443 | ||
4f3a84f4 | 444 | function all_counters_callback() { |
090e250b | 445 | if (xmlhttp_rpc.readyState == 4) { |
7719618b | 446 | try { |
3866b046 | 447 | if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) { |
7719618b AD |
448 | notify("[all_counters_callback] backend did not return valid XML"); |
449 | return; | |
450 | } | |
451 | ||
452 | var reply = xmlhttp_rpc.responseXML.firstChild; | |
7719618b | 453 | var f_document = parent.frames["feeds-frame"].document; |
280ee9a3 | 454 | |
3bdb368b | 455 | parse_counters(reply, f_document, parent); |
7719618b | 456 | |
7719618b AD |
457 | } catch (e) { |
458 | exception_error("all_counters_callback", e); | |
090e250b AD |
459 | } |
460 | } | |
461 | } | |
462 | ||
4f3a84f4 | 463 | function update_all_counters(feed) { |
090e250b | 464 | if (xmlhttp_ready(xmlhttp_rpc)) { |
8143ae1f | 465 | var query = "backend.php?op=rpc&subop=getAllCounters"; |
e47cfe37 AD |
466 | |
467 | if (feed > 0) { | |
468 | query = query + "&aid=" + feed; | |
469 | } | |
470 | ||
090e250b | 471 | xmlhttp_rpc.open("GET", query, true); |
4f3a84f4 | 472 | xmlhttp_rpc.onreadystatechange=all_counters_callback; |
090e250b AD |
473 | xmlhttp_rpc.send(null); |
474 | } | |
475 | } | |
7dc66a61 AD |
476 | |
477 | function popupHelp(tid) { | |
478 | var w = window.open("backend.php?op=help&tid=" + tid, | |
479 | "Popup Help", | |
480 | "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no"); | |
481 | } | |
b6644d29 AD |
482 | |
483 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj | |
484 | * * @author Sundar Dorai-Raj | |
485 | * * Email: sdoraira@vt.edu | |
486 | * * This program is free software; you can redistribute it and/or | |
487 | * * modify it under the terms of the GNU General Public License | |
488 | * * as published by the Free Software Foundation; either version 2 | |
489 | * * of the License, or (at your option) any later version, | |
490 | * * provided that any use properly credits the author. | |
491 | * * This program is distributed in the hope that it will be useful, | |
492 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
493 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
494 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
495 | ||
496 | var numbers=".0123456789"; | |
497 | function isNumeric(x) { | |
498 | // is x a String or a character? | |
499 | if(x.length>1) { | |
500 | // remove negative sign | |
501 | x=Math.abs(x)+""; | |
502 | for(j=0;j<x.length;j++) { | |
503 | // call isNumeric recursively for each character | |
504 | number=isNumeric(x.substring(j,j+1)); | |
505 | if(!number) return number; | |
506 | } | |
507 | return number; | |
508 | } | |
509 | else { | |
510 | // if x is number return true | |
511 | if(numbers.indexOf(x)>=0) return true; | |
512 | return false; | |
513 | } | |
514 | } | |
515 | ||
3745788e AD |
516 | |
517 | function hideOrShowFeeds(doc, hide) { | |
518 | ||
3ed751d4 AD |
519 | if (!doc.styleSheets) return; |
520 | ||
3745788e AD |
521 | var css_rules = doc.styleSheets[0].cssRules; |
522 | ||
bbf4d0b2 AD |
523 | if (!css_rules || !css_rules.length) return; |
524 | ||
3745788e AD |
525 | for (i = 0; i < css_rules.length; i++) { |
526 | var rule = css_rules[i]; | |
527 | ||
528 | if (rule.selectorText == "ul.feedList li.feed") { | |
529 | if (!hide) { | |
530 | rule.style.display = "block"; | |
531 | } else { | |
532 | rule.style.display = "none"; | |
533 | } | |
534 | } | |
535 | ||
536 | } | |
537 | ||
538 | } | |
539 | ||
91d612b3 AD |
540 | function fatalError(code, params) { |
541 | if (!params) { | |
542 | window.location = "error.php?c=" + param_escape(code); | |
543 | } else { | |
544 | window.location = "error.php?c=" + param_escape(code) + | |
545 | "&p=" + param_escape(params); | |
546 | } | |
35f3c923 AD |
547 | } |
548 | ||
549 | function selectTableRow(r, do_select) { | |
550 | r.className = r.className.replace("Selected", ""); | |
551 | ||
552 | if (do_select) { | |
553 | r.className = r.className + "Selected"; | |
554 | } | |
555 | } | |
556 | ||
6c12c809 AD |
557 | function selectTableRowById(elem_id, check_id, do_select) { |
558 | ||
559 | try { | |
560 | ||
561 | var row = document.getElementById(elem_id); | |
562 | ||
563 | if (row) { | |
564 | selectTableRow(row, do_select); | |
565 | } | |
566 | ||
567 | var check = document.getElementById(check_id); | |
568 | ||
569 | if (check) { | |
570 | check.checked = do_select; | |
571 | } | |
572 | } catch (e) { | |
573 | exception_error("selectTableRowById", e); | |
574 | } | |
575 | } | |
576 | ||
1572afe5 | 577 | function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select, |
649e0af9 | 578 | classcheck, reset_others) { |
3745788e | 579 | |
35f3c923 AD |
580 | var content = document.getElementById(content_id); |
581 | ||
582 | if (!content) { | |
583 | alert("[selectTableRows] Element " + content_id + " not found."); | |
584 | return; | |
585 | } | |
586 | ||
587 | for (i = 0; i < content.rows.length; i++) { | |
1572afe5 AD |
588 | if (!classcheck || content.rows[i].className.match(classcheck)) { |
589 | ||
590 | if (content.rows[i].id.match(prefix)) { | |
591 | selectTableRow(content.rows[i], do_select); | |
649e0af9 AD |
592 | |
593 | var row_id = content.rows[i].id.replace(prefix, ""); | |
594 | var check = document.getElementById(check_prefix + row_id); | |
3055bc41 | 595 | |
649e0af9 AD |
596 | if (check) { |
597 | check.checked = do_select; | |
598 | } | |
599 | } else if (reset_others) { | |
600 | selectTableRow(content.rows[i], false); | |
7d8d10c6 AD |
601 | |
602 | var row_id = content.rows[i].id.replace(prefix, ""); | |
603 | var check = document.getElementById(check_prefix + row_id); | |
604 | ||
605 | if (check) { | |
606 | check.checked = false; | |
607 | } | |
608 | ||
1572afe5 | 609 | } |
649e0af9 AD |
610 | } else if (reset_others) { |
611 | selectTableRow(content.rows[i], false); | |
7d8d10c6 AD |
612 | |
613 | var row_id = content.rows[i].id.replace(prefix, ""); | |
614 | var check = document.getElementById(check_prefix + row_id); | |
615 | ||
616 | if (check) { | |
617 | check.checked = false; | |
618 | } | |
619 | ||
3055bc41 | 620 | } |
35f3c923 | 621 | } |
295f9b42 | 622 | } |
91ff844a AD |
623 | |
624 | function getSelectedTableRowIds(content_id, prefix) { | |
625 | ||
626 | var content = document.getElementById(content_id); | |
627 | ||
628 | if (!content) { | |
629 | alert("[getSelectedTableRowIds] Element " + content_id + " not found."); | |
630 | return; | |
631 | } | |
632 | ||
633 | var sel_rows = new Array(); | |
634 | ||
635 | for (i = 0; i < content.rows.length; i++) { | |
1572afe5 AD |
636 | if (content.rows[i].id.match(prefix) && |
637 | content.rows[i].className.match("Selected")) { | |
638 | ||
91ff844a AD |
639 | var row_id = content.rows[i].id.replace(prefix + "-", ""); |
640 | sel_rows.push(row_id); | |
641 | } | |
642 | } | |
643 | ||
644 | return sel_rows; | |
645 | ||
646 | } | |
647 | ||
386cbf27 AD |
648 | function toggleSelectRowById(sender, id) { |
649 | var row = document.getElementById(id); | |
650 | ||
651 | if (sender.checked) { | |
652 | if (!row.className.match("Selected")) { | |
653 | row.className = row.className + "Selected"; | |
654 | } | |
655 | } else { | |
656 | if (row.className.match("Selected")) { | |
657 | row.className = row.className.replace("Selected", ""); | |
658 | } | |
659 | } | |
660 | } | |
661 | ||
b92e6209 AD |
662 | function toggleSelectListRow(sender) { |
663 | var parent_row = sender.parentNode; | |
664 | ||
665 | if (sender.checked) { | |
666 | if (!parent_row.className.match("Selected")) { | |
667 | parent_row.className = parent_row.className + "Selected"; | |
668 | } | |
669 | } else { | |
670 | if (parent_row.className.match("Selected")) { | |
671 | parent_row.className = parent_row.className.replace("Selected", ""); | |
672 | } | |
673 | } | |
674 | } | |
675 | ||
386cbf27 | 676 | |
1572afe5 AD |
677 | function toggleSelectRow(sender) { |
678 | var parent_row = sender.parentNode.parentNode; | |
679 | ||
680 | if (sender.checked) { | |
681 | if (!parent_row.className.match("Selected")) { | |
682 | parent_row.className = parent_row.className + "Selected"; | |
683 | } | |
684 | } else { | |
685 | if (parent_row.className.match("Selected")) { | |
686 | parent_row.className = parent_row.className.replace("Selected", ""); | |
687 | } | |
688 | } | |
689 | } | |
690 | ||
3866b046 AD |
691 | function openExternalUrl(url) { |
692 | var w = window.open(url); | |
693 | } | |
1572afe5 | 694 | |
7b433d8c AD |
695 | |
696 | function getRelativeFeedId(list, id, direction) { | |
697 | if (!id) { | |
698 | if (direction == "next") { | |
699 | for (i = 0; i < list.childNodes.length; i++) { | |
700 | var child = list.childNodes[i]; | |
701 | if (child.id == "feedCatHolder") { | |
c3f348c2 | 702 | if (child.lastChild) { |
7b433d8c AD |
703 | var cr = getRelativeFeedId(child.firstChild, id, direction); |
704 | if (cr) return cr; | |
705 | } | |
706 | } else if (child.id.match("FEEDR-")) { | |
707 | return child.id.replace('FEEDR-', ''); | |
708 | } | |
709 | } | |
710 | } | |
711 | ||
712 | // FIXME select last feed doesn't work when only unread feeds are visible | |
713 | ||
714 | if (direction == "prev") { | |
715 | for (i = list.childNodes.length-1; i >= 0; i--) { | |
716 | var child = list.childNodes[i]; | |
717 | if (child.id == "feedCatHolder") { | |
718 | if (child.firstChild) { | |
719 | var cr = getRelativeFeedId(child.firstChild, id, direction); | |
720 | if (cr) return cr; | |
721 | } | |
722 | } else if (child.id.match("FEEDR-")) { | |
723 | ||
724 | if (getCookie("ttrss_vf_hreadf") == 1) { | |
725 | if (child.className != "feed") { | |
726 | alert(child.className); | |
727 | return child.id.replace('FEEDR-', ''); | |
728 | } | |
729 | } else { | |
730 | return child.id.replace('FEEDR-', ''); | |
731 | } | |
732 | } | |
733 | } | |
734 | } | |
735 | } else { | |
736 | ||
737 | var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId()); | |
738 | ||
739 | if (direction == "next") { | |
740 | ||
741 | if (feed.nextSibling) { | |
742 | ||
743 | var next_feed = feed.nextSibling; | |
744 | ||
745 | while (!next_feed.id && next_feed.nextSibling) { | |
746 | next_feed = next_feed.nextSibling; | |
747 | } | |
748 | ||
749 | if (getCookie("ttrss_vf_hreadf") == 1) { | |
750 | while (next_feed && next_feed.className == "feed") { | |
751 | next_feed = next_feed.nextSibling; | |
752 | } | |
753 | } | |
754 | ||
755 | if (next_feed && next_feed.id.match("FEEDR-")) { | |
756 | return next_feed.id.replace("FEEDR-", ""); | |
757 | } | |
758 | } | |
759 | ||
760 | var this_cat = feed.parentNode.parentNode; | |
761 | ||
762 | if (this_cat && this_cat.nextSibling) { | |
763 | while (this_cat = this_cat.nextSibling) { | |
764 | if (this_cat.firstChild && this_cat.firstChild.firstChild) { | |
765 | var next_feed = this_cat.firstChild.firstChild; | |
766 | if (getCookie("ttrss_vf_hreadf") == 1) { | |
767 | while (next_feed && next_feed.className == "feed") { | |
768 | next_feed = next_feed.nextSibling; | |
769 | } | |
770 | } | |
771 | if (next_feed && next_feed.id.match("FEEDR-")) { | |
772 | return next_feed.id.replace("FEEDR-", ""); | |
773 | } | |
774 | } | |
775 | } | |
776 | } | |
777 | } else if (direction == "prev") { | |
778 | ||
779 | if (feed.previousSibling) { | |
780 | ||
781 | var prev_feed = feed.previousSibling; | |
782 | ||
783 | if (getCookie("ttrss_vf_hreadf") == 1) { | |
784 | while (prev_feed && prev_feed.className == "feed") { | |
785 | prev_feed = prev_feed.previousSibling; | |
786 | } | |
787 | } | |
788 | ||
789 | while (!prev_feed.id && prev_feed.previousSibling) { | |
790 | prev_feed = prev_feed.previousSibling; | |
791 | } | |
792 | ||
793 | if (prev_feed && prev_feed.id.match("FEEDR-")) { | |
794 | return prev_feed.id.replace("FEEDR-", ""); | |
795 | } | |
796 | } | |
797 | ||
798 | var this_cat = feed.parentNode.parentNode; | |
799 | ||
800 | if (this_cat && this_cat.previousSibling) { | |
801 | while (this_cat = this_cat.previousSibling) { | |
802 | if (this_cat.lastChild && this_cat.firstChild.lastChild) { | |
803 | var prev_feed = this_cat.firstChild.lastChild; | |
804 | if (getCookie("ttrss_vf_hreadf") == 1) { | |
805 | while (prev_feed && prev_feed.className == "feed") { | |
806 | prev_feed = prev_feed.previousSibling; | |
807 | } | |
808 | } | |
809 | if (prev_feed && prev_feed.id.match("FEEDR-")) { | |
810 | return prev_feed.id.replace("FEEDR-", ""); | |
811 | } | |
812 | } | |
813 | } | |
814 | } | |
815 | } | |
816 | } | |
817 | } | |
36aab70f AD |
818 | |
819 | function showBlockElement(id) { | |
820 | var elem = document.getElementById(id); | |
821 | ||
822 | if (elem) { | |
823 | elem.style.display = "block"; | |
824 | } else { | |
825 | alert("[showBlockElement] can't find element with id " + id); | |
826 | } | |
827 | } | |
828 | ||
a9b0bfd5 AD |
829 | function hideParentElement(e) { |
830 | e.parentNode.style.display = "none"; | |
831 | } | |
1b0809ae AD |
832 | |
833 | function dropboxSelect(e, v) { | |
834 | for (i = 0; i < e.length; i++) { | |
835 | if (e[i].value == v) { | |
836 | e.selectedIndex = i; | |
837 | break; | |
838 | } | |
839 | } | |
840 | } | |
0ee1d1a0 AD |
841 | |
842 | // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z | |
843 | // bugfixed just a little bit :-) | |
844 | function getURLParam(strParamName){ | |
845 | var strReturn = ""; | |
846 | var strHref = window.location.href; | |
847 | ||
848 | if (strHref.indexOf("#") == strHref.length-1) { | |
849 | strHref = strHref.substring(0, strHref.length-1); | |
850 | } | |
851 | ||
852 | if ( strHref.indexOf("?") > -1 ){ | |
853 | var strQueryString = strHref.substr(strHref.indexOf("?")); | |
854 | var aQueryString = strQueryString.split("&"); | |
855 | for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ | |
856 | if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ | |
857 | var aParam = aQueryString[iParam].split("="); | |
858 | strReturn = aParam[1]; | |
859 | break; | |
860 | } | |
861 | } | |
862 | } | |
863 | return strReturn; | |
864 | } | |
865 | ||
cf1bc085 AD |
866 | function leading_zero(p) { |
867 | var s = String(p); | |
868 | if (s.length == 1) s = "0" + s; | |
869 | return s; | |
870 | } | |
c38c2b69 AD |
871 | |
872 | function center_element(e) { | |
c38c2b69 | 873 | |
5917a8e4 AD |
874 | try { |
875 | var c_width = document.body.clientWidth; | |
876 | var c_height = document.body.clientHeight; | |
877 | ||
878 | var c_scroll = document.body.scrollTop; | |
c38c2b69 | 879 | |
5917a8e4 AD |
880 | var e_width = e.clientWidth; |
881 | var e_height = e.clientHeight; | |
882 | ||
883 | var set_y = (c_height / 2) + c_scroll - (e_height / 2); | |
884 | var set_x = (c_width / 2) - (e_width / 2); | |
885 | ||
886 | e.style.top = set_y + "px"; | |
887 | e.style.left = set_x + "px"; | |
888 | } catch (e) { | |
889 | exception_error("center_element", e); | |
890 | } | |
c38c2b69 | 891 | } |