]>
Commit | Line | Data |
---|---|---|
760966c1 | 1 | var hotkeys_enabled = true; |
a7565293 | 2 | var xmlhttp_rpc = Ajax.getTransport(); |
730dbf19 | 3 | var notify_silent = false; |
99509451 | 4 | var last_progress_point = 0; |
6cc1fab3 | 5 | var async_counters_work = false; |
61992f57 | 6 | |
b07b61da AD |
7 | /* add method to remove element from array */ |
8 | ||
9 | Array.prototype.remove = function(s) { | |
10 | for (var i=0; i < this.length; i++) { | |
11 | if (s == this[i]) this.splice(i, 1); | |
12 | } | |
13 | } | |
14 | ||
7c620da8 | 15 | function is_opera() { |
ee8768db | 16 | return window.opera; |
583c58b8 AD |
17 | } |
18 | ||
55160955 | 19 | function exception_error(location, e, silent) { |
83f043bb AD |
20 | var msg; |
21 | ||
22 | if (e.fileName) { | |
23 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
24 | ||
25 | msg = "Exception: " + e.name + ", " + e.message + | |
26 | "\nFunction: " + location + "()" + | |
27 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
f74cfded AD |
28 | |
29 | } else if (e.description) { | |
30 | msg = "Exception: " + e.description + "\nFunction: " + location + "()"; | |
83f043bb AD |
31 | } else { |
32 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
33 | } | |
34 | ||
ee1f45f4 AD |
35 | debug("<b>EXCEPTION: " + msg + "</b>"); |
36 | ||
55160955 AD |
37 | if (!silent) { |
38 | alert(msg); | |
39 | } | |
7719618b AD |
40 | } |
41 | ||
760966c1 AD |
42 | function disableHotkeys() { |
43 | hotkeys_enabled = false; | |
44 | } | |
45 | ||
46 | function enableHotkeys() { | |
47 | hotkeys_enabled = true; | |
48 | } | |
49 | ||
c0e5a40e AD |
50 | function xmlhttp_ready(obj) { |
51 | return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState; | |
52 | } | |
53 | ||
d395a942 AD |
54 | function open_article_callback(transport) { |
55 | try { | |
298f3f78 | 56 | |
d395a942 | 57 | if (transport.responseXML) { |
06925d9e | 58 | |
d395a942 AD |
59 | var link = transport.responseXML.getElementsByTagName("link")[0]; |
60 | var id = transport.responseXML.getElementsByTagName("id")[0]; | |
298f3f78 | 61 | |
06925d9e AD |
62 | debug("open_article_callback, received link: " + link); |
63 | ||
04e91733 | 64 | if (link && id) { |
06925d9e | 65 | |
04e91733 AD |
66 | var wname = "ttrss_article_" + id.firstChild.nodeValue; |
67 | ||
68 | debug("link url: " + link.firstChild.nodeValue + ", wname " + wname); | |
69 | ||
70 | var w = window.open(link.firstChild.nodeValue, wname); | |
4298481d AD |
71 | |
72 | if (!w) { notify_error("Failed to load article in new window"); } | |
e2ccbfab | 73 | |
d395a942 AD |
74 | if (id) { |
75 | id = id.firstChild.nodeValue; | |
76 | if (!document.getElementById("headlinesList")) { | |
77 | window.setTimeout("toggleUnread(" + id + ", 0)", 100); | |
e2ccbfab | 78 | } |
298f3f78 | 79 | } |
06925d9e AD |
80 | } else { |
81 | notify_error("Can't open article: received invalid article link"); | |
298f3f78 | 82 | } |
06925d9e AD |
83 | } else { |
84 | notify_error("Can't open article: received invalid XML"); | |
01a87dff | 85 | } |
01a87dff | 86 | |
d395a942 AD |
87 | } catch (e) { |
88 | exception_error("open_article_callback", e); | |
9cfc649a AD |
89 | } |
90 | } | |
91 | ||
7726fa02 AD |
92 | function param_escape(arg) { |
93 | if (typeof encodeURIComponent != 'undefined') | |
94 | return encodeURIComponent(arg); | |
95 | else | |
96 | return escape(arg); | |
97 | } | |
98 | ||
99 | function param_unescape(arg) { | |
100 | if (typeof decodeURIComponent != 'undefined') | |
101 | return decodeURIComponent(arg); | |
102 | else | |
103 | return unescape(arg); | |
104 | } | |
105 | ||
508a81e1 AD |
106 | function delay(gap) { |
107 | var then,now; | |
108 | then=new Date().getTime(); | |
109 | now=then; | |
110 | while((now-then)<gap) { | |
111 | now=new Date().getTime(); | |
112 | } | |
113 | } | |
7726fa02 | 114 | |
ce3bf408 | 115 | var notify_hide_timerid = false; |
59a543f0 | 116 | |
ce3bf408 | 117 | function hide_notify() { |
42c32916 AD |
118 | var n = document.getElementById("notify"); |
119 | if (n) { | |
d05514a4 | 120 | n.style.display = "none"; |
8dcfffd0 | 121 | } |
d05514a4 | 122 | } |
c05608c2 | 123 | |
730dbf19 AD |
124 | function notify_silent_next() { |
125 | notify_silent = true; | |
126 | } | |
127 | ||
42c32916 | 128 | function notify_real(msg, no_hide, n_type) { |
7726fa02 | 129 | |
730dbf19 AD |
130 | if (notify_silent) { |
131 | notify_silent = false; | |
132 | return; | |
133 | } | |
134 | ||
42c32916 AD |
135 | var n = document.getElementById("notify"); |
136 | var nb = document.getElementById("notify_body"); | |
7726fa02 | 137 | |
c05608c2 | 138 | if (!n || !nb) return; |
f0601b87 | 139 | |
0655a1d5 AD |
140 | if (notify_hide_timerid) { |
141 | window.clearTimeout(notify_hide_timerid); | |
142 | } | |
143 | ||
8dcfffd0 | 144 | if (msg == "") { |
0655a1d5 AD |
145 | if (n.style.display == "block") { |
146 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
147 | } | |
148 | return; | |
7726fa02 | 149 | } else { |
0ceded7a | 150 | n.style.display = "block"; |
8dcfffd0 | 151 | } |
7726fa02 | 152 | |
42c32916 AD |
153 | /* types: |
154 | ||
155 | 1 - generic | |
156 | 2 - progress | |
157 | 3 - error | |
158 | 4 - info | |
159 | ||
160 | */ | |
161 | ||
f3977cf5 AD |
162 | if (typeof __ != 'undefined') { |
163 | msg = __(msg); | |
164 | } | |
165 | ||
42c32916 AD |
166 | if (n_type == 1) { |
167 | n.className = "notify"; | |
168 | } else if (n_type == 2) { | |
169 | n.className = "notifyProgress"; | |
170 | msg = "<img src='images/indicator_white.gif'> " + msg; | |
171 | } else if (n_type == 3) { | |
f407c086 | 172 | n.className = "notifyError"; |
e780d1d2 | 173 | msg = "<img src='images/sign_excl.gif'> " + msg; |
42c32916 AD |
174 | } else if (n_type == 4) { |
175 | n.className = "notifyInfo"; | |
e780d1d2 | 176 | msg = "<img src='images/sign_info.gif'> " + msg; |
0530ddd8 AD |
177 | } |
178 | ||
106689b0 AD |
179 | // msg = "<img src='images/live_com_loading.gif'> " + msg; |
180 | ||
0ceded7a AD |
181 | nb.innerHTML = msg; |
182 | ||
4d4200a8 | 183 | if (!no_hide) { |
292a8a12 | 184 | notify_hide_timerid = window.setTimeout("hide_notify()", 3000); |
4d4200a8 | 185 | } |
ce3bf408 AD |
186 | } |
187 | ||
42c32916 AD |
188 | function notify(msg, no_hide) { |
189 | notify_real(msg, no_hide, 1); | |
ce3bf408 AD |
190 | } |
191 | ||
42c32916 AD |
192 | function notify_progress(msg, no_hide) { |
193 | notify_real(msg, no_hide, 2); | |
194 | } | |
195 | ||
196 | function notify_error(msg, no_hide) { | |
197 | notify_real(msg, no_hide, 3); | |
198 | ||
199 | } | |
200 | ||
201 | function notify_info(msg, no_hide) { | |
202 | notify_real(msg, no_hide, 4); | |
7726fa02 AD |
203 | } |
204 | ||
508a81e1 | 205 | function printLockingError() { |
42c32916 AD |
206 | notify_info("Please wait until operation finishes."); |
207 | } | |
508a81e1 | 208 | |
e828e31e AD |
209 | function cleanSelected(element) { |
210 | var content = document.getElementById(element); | |
f0601b87 AD |
211 | |
212 | for (i = 0; i < content.rows.length; i++) { | |
213 | content.rows[i].className = content.rows[i].className.replace("Selected", ""); | |
214 | } | |
f0601b87 AD |
215 | } |
216 | ||
217 | function getVisibleUnreadHeadlines() { | |
218 | var content = document.getElementById("headlinesList"); | |
219 | ||
220 | var rows = new Array(); | |
221 | ||
3a40e8a2 AD |
222 | if (!content) return rows; |
223 | ||
f0601b87 AD |
224 | for (i = 0; i < content.rows.length; i++) { |
225 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
226 | if (row_id.length > 0 && content.rows[i].className.match("Unread")) { | |
227 | rows.push(row_id); | |
228 | } | |
229 | } | |
230 | return rows; | |
231 | } | |
232 | ||
233 | function getVisibleHeadlineIds() { | |
234 | ||
235 | var content = document.getElementById("headlinesList"); | |
236 | ||
237 | var rows = new Array(); | |
238 | ||
3a40e8a2 AD |
239 | if (!content) return rows; |
240 | ||
f0601b87 AD |
241 | for (i = 0; i < content.rows.length; i++) { |
242 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
243 | if (row_id.length > 0) { | |
244 | rows.push(row_id); | |
245 | } | |
246 | } | |
247 | return rows; | |
248 | } | |
249 | ||
250 | function getFirstVisibleHeadlineId() { | |
5ad9d132 AD |
251 | if (isCdmMode()) { |
252 | var rows = cdmGetVisibleArticles(); | |
253 | return rows[0]; | |
254 | } else { | |
255 | var rows = getVisibleHeadlineIds(); | |
256 | return rows[0]; | |
257 | } | |
f0601b87 AD |
258 | } |
259 | ||
260 | function getLastVisibleHeadlineId() { | |
5ad9d132 AD |
261 | if (isCdmMode()) { |
262 | var rows = cdmGetVisibleArticles(); | |
263 | return rows[rows.length-1]; | |
264 | } else { | |
265 | var rows = getVisibleHeadlineIds(); | |
266 | return rows[rows.length-1]; | |
267 | } | |
f0601b87 AD |
268 | } |
269 | ||
270 | function markHeadline(id) { | |
271 | var row = document.getElementById("RROW-" + id); | |
272 | if (row) { | |
35f3c923 AD |
273 | var is_active = false; |
274 | ||
275 | if (row.className.match("Active")) { | |
276 | is_active = true; | |
277 | } | |
278 | row.className = row.className.replace("Selected", ""); | |
279 | row.className = row.className.replace("Active", ""); | |
280 | row.className = row.className.replace("Insensitive", ""); | |
281 | ||
282 | if (is_active) { | |
283 | row.className = row.className = "Active"; | |
284 | } | |
285 | ||
72020095 AD |
286 | var check = document.getElementById("RCHK-" + id); |
287 | ||
288 | if (check) { | |
289 | check.checked = true; | |
290 | } | |
291 | ||
35f3c923 AD |
292 | row.className = row.className + "Selected"; |
293 | ||
f0601b87 AD |
294 | } |
295 | } | |
296 | ||
297 | function getFeedIds() { | |
298 | var content = document.getElementById("feedsList"); | |
299 | ||
300 | var rows = new Array(); | |
301 | ||
302 | for (i = 0; i < content.rows.length; i++) { | |
303 | var id = content.rows[i].id.replace("FEEDR-", ""); | |
304 | if (id.length > 0) { | |
305 | rows.push(id); | |
306 | } | |
307 | } | |
308 | ||
309 | return rows; | |
310 | } | |
13ad9102 | 311 | |
76b4eae1 AD |
312 | function setCookie(name, value, lifetime, path, domain, secure) { |
313 | ||
314 | var d = false; | |
315 | ||
316 | if (lifetime) { | |
317 | d = new Date(); | |
be0801a1 | 318 | d.setTime(d.getTime() + (lifetime * 1000)); |
76b4eae1 | 319 | } |
cdbb6dc6 AD |
320 | |
321 | debug("setCookie: " + name + " => " + value + ": " + d); | |
76b4eae1 AD |
322 | |
323 | int_setCookie(name, value, d, path, domain, secure); | |
324 | ||
325 | } | |
326 | ||
327 | function int_setCookie(name, value, expires, path, domain, secure) { | |
ac43eba1 AD |
328 | document.cookie= name + "=" + escape(value) + |
329 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
330 | ((path) ? "; path=" + path : "") + | |
331 | ((domain) ? "; domain=" + domain : "") + | |
332 | ((secure) ? "; secure" : ""); | |
333 | } | |
334 | ||
76b4eae1 AD |
335 | function delCookie(name, path, domain) { |
336 | if (getCookie(name)) { | |
337 | document.cookie = name + "=" + | |
338 | ((path) ? ";path=" + path : "") + | |
339 | ((domain) ? ";domain=" + domain : "" ) + | |
340 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
341 | } | |
342 | } | |
343 | ||
344 | ||
ac43eba1 AD |
345 | function getCookie(name) { |
346 | ||
347 | var dc = document.cookie; | |
348 | var prefix = name + "="; | |
349 | var begin = dc.indexOf("; " + prefix); | |
350 | if (begin == -1) { | |
351 | begin = dc.indexOf(prefix); | |
352 | if (begin != 0) return null; | |
353 | } | |
354 | else { | |
355 | begin += 2; | |
356 | } | |
357 | var end = document.cookie.indexOf(";", begin); | |
358 | if (end == -1) { | |
359 | end = dc.length; | |
360 | } | |
361 | return unescape(dc.substring(begin + prefix.length, end)); | |
362 | } | |
363 | ||
1a66d16e AD |
364 | function disableContainerChildren(id, disable, doc) { |
365 | ||
366 | if (!doc) doc = document; | |
367 | ||
368 | var container = doc.getElementById(id); | |
ac43eba1 | 369 | |
4220b0bd AD |
370 | if (!container) { |
371 | //alert("disableContainerChildren: element " + id + " not found"); | |
372 | return; | |
373 | } | |
374 | ||
ac43eba1 AD |
375 | for (var i = 0; i < container.childNodes.length; i++) { |
376 | var child = container.childNodes[i]; | |
377 | ||
d5224f0d AD |
378 | try { |
379 | child.disabled = disable; | |
380 | } catch (E) { | |
381 | ||
382 | } | |
ac43eba1 AD |
383 | |
384 | if (disable) { | |
385 | if (child.className && child.className.match("button")) { | |
386 | child.className = "disabledButton"; | |
387 | } | |
388 | } else { | |
389 | if (child.className && child.className.match("disabledButton")) { | |
390 | child.className = "button"; | |
391 | } | |
d5224f0d | 392 | } |
ac43eba1 AD |
393 | } |
394 | ||
395 | } | |
7726fa02 | 396 | |
e828e31e AD |
397 | function gotoPreferences() { |
398 | document.location.href = "prefs.php"; | |
399 | } | |
400 | ||
401 | function gotoMain() { | |
402 | document.location.href = "tt-rss.php"; | |
403 | } | |
404 | ||
8158c57a AD |
405 | function gotoExportOpml() { |
406 | document.location.href = "opml.php?op=Export"; | |
407 | } | |
86741347 AD |
408 | |
409 | function getActiveFeedId() { | |
33d13e72 AD |
410 | // return getCookie("ttrss_vf_actfeed"); |
411 | try { | |
0feab655 AD |
412 | debug("gAFID: " + active_feed_id); |
413 | return active_feed_id; | |
33d13e72 AD |
414 | } catch (e) { |
415 | exception_error("getActiveFeedId", e); | |
416 | } | |
86741347 AD |
417 | } |
418 | ||
0a6c4846 | 419 | function activeFeedIsCat() { |
0feab655 | 420 | return active_feed_is_cat; |
0a6c4846 AD |
421 | } |
422 | ||
86741347 | 423 | function setActiveFeedId(id) { |
33d13e72 AD |
424 | // return setCookie("ttrss_vf_actfeed", id); |
425 | try { | |
5c365f60 | 426 | debug("sAFID(" + id + ")"); |
0feab655 | 427 | active_feed_id = id; |
33d13e72 AD |
428 | } catch (e) { |
429 | exception_error("setActiveFeedId", e); | |
430 | } | |
86741347 | 431 | } |
090e250b | 432 | |
ac378ad4 | 433 | function parse_counters(reply, scheduled_call) { |
1a6a9555 | 434 | try { |
ac378ad4 | 435 | |
9e397d0f AD |
436 | var feeds_found = 0; |
437 | ||
85bd574b | 438 | var elems = reply.getElementsByTagName("counter"); |
f54f515f | 439 | |
85bd574b | 440 | for (var l = 0; l < elems.length; l++) { |
6043fb7e | 441 | |
85bd574b AD |
442 | var id = elems[l].getAttribute("id"); |
443 | var t = elems[l].getAttribute("type"); | |
444 | var ctr = elems[l].getAttribute("counter"); | |
445 | var error = elems[l].getAttribute("error"); | |
446 | var has_img = elems[l].getAttribute("hi"); | |
447 | var updated = elems[l].getAttribute("updated"); | |
4ffa126e | 448 | var title = elems[l].getAttribute("title"); |
bdb7369b AD |
449 | var xmsg = elems[l].getAttribute("xmsg"); |
450 | ||
1a6a9555 | 451 | if (id == "global-unread") { |
0feab655 AD |
452 | global_unread = ctr; |
453 | updateTitle(); | |
1a6a9555 AD |
454 | continue; |
455 | } | |
7bf7e4d3 AD |
456 | |
457 | if (id == "subscribed-feeds") { | |
458 | feeds_found = ctr; | |
459 | continue; | |
460 | } | |
1a6a9555 AD |
461 | |
462 | if (t == "category") { | |
0feab655 | 463 | var catctr = document.getElementById("FCATCTR-" + id); |
1a6a9555 | 464 | if (catctr) { |
67dabe1a AD |
465 | catctr.innerHTML = "(" + ctr + ")"; |
466 | if (ctr > 0) { | |
467 | catctr.className = "catCtrHasUnread"; | |
468 | } else { | |
469 | catctr.className = "catCtrNoUnread"; | |
470 | } | |
1a6a9555 AD |
471 | } |
472 | continue; | |
473 | } | |
474 | ||
0feab655 AD |
475 | var feedctr = document.getElementById("FEEDCTR-" + id); |
476 | var feedu = document.getElementById("FEEDU-" + id); | |
477 | var feedr = document.getElementById("FEEDR-" + id); | |
478 | var feed_img = document.getElementById("FIMG-" + id); | |
479 | var feedlink = document.getElementById("FEEDL-" + id); | |
480 | var feedupd = document.getElementById("FLUPD-" + id); | |
fb1fb4ab AD |
481 | |
482 | if (updated && feedlink) { | |
483 | if (error) { | |
484 | feedlink.title = "Error: " + error + " (" + updated + ")"; | |
485 | } else { | |
486 | feedlink.title = "Updated: " + updated; | |
487 | } | |
488 | } | |
023fe037 | 489 | |
bdb7369b AD |
490 | if (feedupd) { |
491 | if (!updated) updated = ""; | |
492 | ||
78d5212c | 493 | if (error) { |
bdb7369b AD |
494 | if (xmsg) { |
495 | feedupd.innerHTML = updated + " " + xmsg + " (Error)"; | |
496 | } else { | |
497 | feedupd.innerHTML = updated + " (Error)"; | |
498 | } | |
78d5212c | 499 | } else { |
bdb7369b AD |
500 | if (xmsg) { |
501 | feedupd.innerHTML = updated + " " + xmsg; | |
502 | } else { | |
503 | feedupd.innerHTML = updated; | |
504 | } | |
78d5212c AD |
505 | } |
506 | } | |
507 | ||
f74cfded | 508 | if (has_img && feed_img) { |
f780548a AD |
509 | if (!feed_img.src.match(id + ".ico")) { |
510 | feed_img.src = getInitParam("icons_location") + "/" + id + ".ico"; | |
511 | } | |
527c3bf0 AD |
512 | } |
513 | ||
4ffa126e AD |
514 | if (feedlink && title) { |
515 | feedlink.innerHTML = title; | |
516 | } | |
517 | ||
1a6a9555 | 518 | if (feedctr && feedu && feedr) { |
e8ef3b97 AD |
519 | |
520 | if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) { | |
5b064721 | 521 | viewCurrentFeed(); |
e8ef3b97 | 522 | } |
8e9141ed AD |
523 | |
524 | var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML)); | |
525 | ||
1a6a9555 | 526 | feedu.innerHTML = ctr; |
023fe037 | 527 | |
426d3c57 AD |
528 | if (error) { |
529 | feedr.className = feedr.className.replace("feed", "error"); | |
530 | } else if (id > 0) { | |
531 | feedr.className = feedr.className.replace("error", "feed"); | |
023fe037 | 532 | } |
1a6a9555 AD |
533 | |
534 | if (ctr > 0) { | |
535 | feedctr.className = "odd"; | |
536 | if (!feedr.className.match("Unread")) { | |
537 | var is_selected = feedr.className.match("Selected"); | |
538 | ||
539 | feedr.className = feedr.className.replace("Selected", ""); | |
540 | feedr.className = feedr.className.replace("Unread", ""); | |
541 | ||
542 | feedr.className = feedr.className + "Unread"; | |
543 | ||
544 | if (is_selected) { | |
545 | feedr.className = feedr.className + "Selected"; | |
8e9141ed AD |
546 | } |
547 | ||
548 | } | |
549 | ||
550 | if (row_needs_hl) { | |
1341ea0d AD |
551 | new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5", |
552 | queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } ); | |
1a6a9555 AD |
553 | } |
554 | } else { | |
555 | feedctr.className = "invisible"; | |
556 | feedr.className = feedr.className.replace("Unread", ""); | |
557 | } | |
558 | } | |
559 | } | |
9e397d0f | 560 | |
60ea2377 | 561 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); |
7553dd8b | 562 | |
0feab655 | 563 | var feeds_stored = number_of_feeds; |
9e397d0f AD |
564 | |
565 | debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored); | |
566 | ||
567 | if (feeds_stored != feeds_found) { | |
0feab655 | 568 | number_of_feeds = feeds_found; |
7bf7e4d3 | 569 | |
2fe69e22 | 570 | if (feeds_stored != 0 && feeds_found != 0) { |
9e397d0f | 571 | debug("Subscribed feed number changed, refreshing feedlist"); |
0e9dd1ba | 572 | setTimeout('updateFeedList(false, false)', 50); |
9e397d0f AD |
573 | } |
574 | } | |
575 | ||
1a6a9555 | 576 | } catch (e) { |
83f043bb | 577 | exception_error("parse_counters", e); |
1a6a9555 AD |
578 | } |
579 | } | |
580 | ||
288487e4 | 581 | function parse_counters_reply(transport, scheduled_call) { |
5854573a | 582 | |
288487e4 | 583 | if (!transport.responseXML) { |
42c32916 | 584 | notify_error("Backend did not return valid XML", true); |
5854573a AD |
585 | return; |
586 | } | |
587 | ||
288487e4 | 588 | var reply = transport.responseXML.firstChild; |
5854573a AD |
589 | |
590 | if (!reply) { | |
42c32916 | 591 | notify_error("Backend did not return expected XML object", true); |
5854573a AD |
592 | updateTitle(""); |
593 | return; | |
594 | } | |
595 | ||
596 | var error_code = false; | |
597 | var error_msg = false; | |
598 | ||
599 | if (reply.firstChild) { | |
600 | error_code = reply.firstChild.getAttribute("error-code"); | |
601 | error_msg = reply.firstChild.getAttribute("error-msg"); | |
602 | } | |
603 | ||
604 | if (!error_code) { | |
605 | error_code = reply.getAttribute("error-code"); | |
606 | error_msg = reply.getAttribute("error-msg"); | |
607 | } | |
608 | ||
609 | if (error_code && error_code != 0) { | |
610 | debug("refetch_callback: got error code " + error_code); | |
611 | return fatalError(error_code, error_msg); | |
612 | } | |
613 | ||
36e05046 | 614 | var counters = reply.getElementsByTagName("counters")[0]; |
5854573a | 615 | |
3ac2f3c7 | 616 | parse_counters(counters, scheduled_call); |
5854573a | 617 | |
36e05046 | 618 | var runtime_info = reply.getElementsByTagName("runtime-info")[0]; |
5854573a AD |
619 | |
620 | parse_runtime_info(runtime_info); | |
621 | ||
61a20560 AD |
622 | if (feedsSortByUnread()) { |
623 | resort_feedlist(); | |
624 | } | |
5854573a | 625 | |
60ea2377 | 626 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); |
5854573a AD |
627 | |
628 | } | |
629 | ||
6cc1fab3 | 630 | function all_counters_callback2(transport, async_call) { |
1341ea0d | 631 | try { |
6cc1fab3 AD |
632 | if (async_call) async_counters_work = true; |
633 | ||
1341ea0d AD |
634 | debug("<b>all_counters_callback2 IN: " + transport + "</b>"); |
635 | parse_counters_reply(transport); | |
636 | debug("<b>all_counters_callback2 OUT: " + transport + "</b>"); | |
637 | ||
638 | } catch (e) { | |
639 | exception_error("all_counters_callback2", e); | |
640 | } | |
641 | } | |
642 | ||
8e9dd206 AD |
643 | function get_feed_unread(id) { |
644 | try { | |
645 | return parseInt(document.getElementById("FEEDU-" + id).innerHTML); | |
646 | } catch (e) { | |
647 | exception_error("get_feed_unread", e, true); | |
648 | return -1; | |
649 | } | |
650 | } | |
651 | ||
ec37f4f1 AD |
652 | function get_cat_unread(id) { |
653 | try { | |
654 | var ctr = document.getElementById("FCATCTR-" + id).innerHTML; | |
655 | ctr = ctr.replace("(", ""); | |
656 | ctr = ctr.replace(")", ""); | |
657 | return parseInt(ctr); | |
658 | } catch (e) { | |
659 | exception_error("get_feed_unread", e, true); | |
660 | return -1; | |
661 | } | |
662 | } | |
663 | ||
60ea2377 | 664 | function get_feed_entry_unread(elem) { |
c9268ed5 AD |
665 | |
666 | var id = elem.id.replace("FEEDR-", ""); | |
667 | ||
668 | if (id <= 0) { | |
669 | return -1; | |
670 | } | |
671 | ||
672 | try { | |
60ea2377 | 673 | return parseInt(document.getElementById("FEEDU-" + id).innerHTML); |
c9268ed5 AD |
674 | } catch (e) { |
675 | return -1; | |
676 | } | |
677 | } | |
678 | ||
61a20560 AD |
679 | function get_feed_entry_name(elem) { |
680 | var id = elem.id.replace("FEEDR-", ""); | |
681 | return getFeedName(id); | |
682 | } | |
683 | ||
684 | ||
60ea2377 | 685 | function resort_category(node) { |
c9268ed5 | 686 | |
d6586c1d | 687 | try { |
61a20560 | 688 | |
d6586c1d AD |
689 | debug("resort_category: " + node); |
690 | ||
691 | var by_unread = feedsSortByUnread(); | |
692 | ||
693 | var list = node.getElementsByTagName("LI"); | |
694 | ||
695 | for (i = 0; i < list.length; i++) { | |
696 | ||
697 | for (j = i+1; j < list.length; j++) { | |
698 | ||
699 | var tmp_val = get_feed_entry_unread(list[i]); | |
700 | var cur_val = get_feed_entry_unread(list[j]); | |
701 | ||
702 | var tmp_name = get_feed_entry_name(list[i]); | |
703 | var cur_name = get_feed_entry_name(list[j]); | |
704 | ||
61a20560 | 705 | if ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name))) { |
d6586c1d AD |
706 | tempnode_i = list[i].cloneNode(true); |
707 | tempnode_j = list[j].cloneNode(true); | |
708 | node.replaceChild(tempnode_i, list[j]); | |
709 | node.replaceChild(tempnode_j, list[i]); | |
c9268ed5 AD |
710 | } |
711 | } | |
c9268ed5 | 712 | } |
d6586c1d AD |
713 | |
714 | } catch (e) { | |
715 | exception_error("resort_category", e); | |
c9268ed5 AD |
716 | } |
717 | ||
718 | } | |
719 | ||
720 | function resort_feedlist() { | |
721 | debug("resort_feedlist"); | |
722 | ||
60ea2377 | 723 | if (document.getElementById("FCATLIST--1")) { |
c9268ed5 | 724 | |
60ea2377 | 725 | var lists = document.getElementsByTagName("UL"); |
c9268ed5 | 726 | |
60ea2377 AD |
727 | for (var i = 0; i < lists.length; i++) { |
728 | if (lists[i].id && lists[i].id.match("FCATLIST-")) { | |
729 | resort_category(lists[i]); | |
c9268ed5 | 730 | } |
c9268ed5 AD |
731 | } |
732 | ||
733 | } else { | |
60ea2377 | 734 | resort_category(document.getElementById("feedList")); |
c9268ed5 AD |
735 | } |
736 | } | |
737 | ||
b6644d29 AD |
738 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj |
739 | * * @author Sundar Dorai-Raj | |
740 | * * Email: sdoraira@vt.edu | |
741 | * * This program is free software; you can redistribute it and/or | |
742 | * * modify it under the terms of the GNU General Public License | |
743 | * * as published by the Free Software Foundation; either version 2 | |
744 | * * of the License, or (at your option) any later version, | |
745 | * * provided that any use properly credits the author. | |
746 | * * This program is distributed in the hope that it will be useful, | |
747 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
748 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
749 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
750 | ||
751 | var numbers=".0123456789"; | |
752 | function isNumeric(x) { | |
753 | // is x a String or a character? | |
754 | if(x.length>1) { | |
755 | // remove negative sign | |
756 | x=Math.abs(x)+""; | |
757 | for(j=0;j<x.length;j++) { | |
758 | // call isNumeric recursively for each character | |
759 | number=isNumeric(x.substring(j,j+1)); | |
760 | if(!number) return number; | |
761 | } | |
762 | return number; | |
763 | } | |
764 | else { | |
765 | // if x is number return true | |
766 | if(numbers.indexOf(x)>=0) return true; | |
767 | return false; | |
768 | } | |
769 | } | |
770 | ||
3745788e | 771 | |
60ea2377 | 772 | function hideOrShowFeeds(hide) { |
3745788e | 773 | |
60ea2377 | 774 | try { |
293fa942 | 775 | |
60ea2377 | 776 | debug("hideOrShowFeeds: " + hide); |
293fa942 | 777 | |
60ea2377 | 778 | if (document.getElementById("FCATLIST--1")) { |
293fa942 | 779 | |
60ea2377 | 780 | var lists = document.getElementsByTagName("UL"); |
293fa942 | 781 | |
60ea2377 AD |
782 | for (var i = 0; i < lists.length; i++) { |
783 | if (lists[i].id && lists[i].id.match("FCATLIST-")) { | |
293fa942 | 784 | |
60ea2377 AD |
785 | var id = lists[i].id.replace("FCATLIST-", ""); |
786 | hideOrShowFeedsCategory(id, hide); | |
293fa942 | 787 | } |
293fa942 AD |
788 | } |
789 | ||
790 | } else { | |
60ea2377 | 791 | hideOrShowFeedsCategory(null, hide); |
293fa942 | 792 | } |
293fa942 | 793 | |
60ea2377 AD |
794 | } catch (e) { |
795 | exception_error("hideOrShowFeeds", e); | |
4724a093 | 796 | } |
60ea2377 | 797 | } |
4724a093 | 798 | |
60ea2377 | 799 | function hideOrShowFeedsCategory(id, hide) { |
2c2b019b | 800 | |
60ea2377 AD |
801 | try { |
802 | ||
803 | var node = null; | |
804 | var cat_node = null; | |
bbf4d0b2 | 805 | |
60ea2377 AD |
806 | if (id) { |
807 | node = document.getElementById("FCATLIST-" + id); | |
808 | cat_node = document.getElementById("FCAT-" + id); | |
809 | } else { | |
810 | node = document.getElementById("feedList"); // no categories | |
811 | } | |
293fa942 | 812 | |
60ea2377 | 813 | // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")"); |
b31c2311 | 814 | |
60ea2377 | 815 | var cat_unread = 0; |
b31c2311 | 816 | |
60ea2377 AD |
817 | if (!node) { |
818 | debug("hideOrShowFeeds: passed node is null, aborting"); | |
819 | return; | |
820 | } | |
b31c2311 | 821 | |
60ea2377 AD |
822 | // debug("cat: " + node.id); |
823 | ||
824 | if (node.hasChildNodes() && node.firstChild.nextSibling != false) { | |
825 | for (i = 0; i < node.childNodes.length; i++) { | |
826 | if (node.childNodes[i].nodeName != "LI") { continue; } | |
b31c2311 | 827 | |
60ea2377 AD |
828 | if (node.childNodes[i].style != undefined) { |
829 | ||
830 | var has_unread = (node.childNodes[i].className != "feed" && | |
831 | node.childNodes[i].className != "label" && | |
832 | !(!getInitParam("hide_read_shows_special") && | |
833 | node.childNodes[i].className == "virt") && | |
834 | node.childNodes[i].className != "error" && | |
835 | node.childNodes[i].className != "tag"); | |
836 | ||
837 | // debug(node.childNodes[i].id + " --> " + has_unread); | |
838 | ||
839 | if (hide && !has_unread) { | |
840 | //node.childNodes[i].style.display = "none"; | |
841 | var id = node.childNodes[i].id; | |
842 | Effect.Fade(node.childNodes[i], {duration : 0.3, | |
843 | queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); | |
844 | } | |
845 | ||
846 | if (!hide) { | |
847 | node.childNodes[i].style.display = "list-item"; | |
848 | //Effect.Appear(node.childNodes[i], {duration : 0.3}); | |
849 | } | |
850 | ||
851 | if (has_unread) { | |
852 | node.childNodes[i].style.display = "list-item"; | |
853 | cat_unread++; | |
854 | //Effect.Appear(node.childNodes[i], {duration : 0.3}); | |
855 | //Effect.Highlight(node.childNodes[i]); | |
856 | } | |
b31c2311 | 857 | } |
293fa942 | 858 | } |
60ea2377 AD |
859 | } |
860 | ||
861 | // debug("end cat: " + node.id + " unread " + cat_unread); | |
862 | ||
863 | if (cat_unread == 0) { | |
864 | if (cat_node.style == undefined) { | |
865 | debug("ERROR: supplied cat_node " + cat_node + | |
866 | " has no styles. WTF?"); | |
867 | return; | |
868 | } | |
869 | if (hide) { | |
870 | //cat_node.style.display = "none"; | |
871 | Effect.Fade(cat_node, {duration : 0.3, | |
872 | queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }}); | |
873 | } else { | |
874 | cat_node.style.display = "list-item"; | |
875 | } | |
293fa942 | 876 | } else { |
60ea2377 AD |
877 | try { |
878 | cat_node.style.display = "list-item"; | |
879 | } catch (e) { | |
880 | debug(e); | |
881 | } | |
0ac2faea | 882 | } |
3745788e | 883 | |
293fa942 | 884 | // debug("unread for category: " + cat_unread); |
60ea2377 AD |
885 | |
886 | } catch (e) { | |
887 | exception_error("hideOrShowFeedsCategory", e); | |
888 | } | |
3745788e AD |
889 | } |
890 | ||
35f3c923 AD |
891 | function selectTableRow(r, do_select) { |
892 | r.className = r.className.replace("Selected", ""); | |
893 | ||
894 | if (do_select) { | |
895 | r.className = r.className + "Selected"; | |
896 | } | |
897 | } | |
898 | ||
6c12c809 AD |
899 | function selectTableRowById(elem_id, check_id, do_select) { |
900 | ||
901 | try { | |
902 | ||
903 | var row = document.getElementById(elem_id); | |
904 | ||
905 | if (row) { | |
906 | selectTableRow(row, do_select); | |
907 | } | |
908 | ||
909 | var check = document.getElementById(check_id); | |
910 | ||
911 | if (check) { | |
912 | check.checked = do_select; | |
913 | } | |
914 | } catch (e) { | |
915 | exception_error("selectTableRowById", e); | |
916 | } | |
917 | } | |
918 | ||
1572afe5 | 919 | function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select, |
649e0af9 | 920 | classcheck, reset_others) { |
3745788e | 921 | |
35f3c923 AD |
922 | var content = document.getElementById(content_id); |
923 | ||
924 | if (!content) { | |
925 | alert("[selectTableRows] Element " + content_id + " not found."); | |
926 | return; | |
927 | } | |
928 | ||
929 | for (i = 0; i < content.rows.length; i++) { | |
7a822893 AD |
930 | if (Element.visible(content.rows[i])) { |
931 | if (!classcheck || content.rows[i].className.match(classcheck)) { | |
932 | ||
933 | if (content.rows[i].id.match(prefix)) { | |
934 | selectTableRow(content.rows[i], do_select); | |
935 | ||
936 | var row_id = content.rows[i].id.replace(prefix, ""); | |
937 | var check = document.getElementById(check_prefix + row_id); | |
938 | ||
939 | if (check) { | |
940 | check.checked = do_select; | |
941 | } | |
942 | } else if (reset_others) { | |
943 | selectTableRow(content.rows[i], false); | |
944 | ||
945 | var row_id = content.rows[i].id.replace(prefix, ""); | |
946 | var check = document.getElementById(check_prefix + row_id); | |
947 | ||
948 | if (check) { | |
949 | check.checked = false; | |
950 | } | |
1572afe5 | 951 | |
649e0af9 AD |
952 | } |
953 | } else if (reset_others) { | |
954 | selectTableRow(content.rows[i], false); | |
7a822893 | 955 | |
7d8d10c6 AD |
956 | var row_id = content.rows[i].id.replace(prefix, ""); |
957 | var check = document.getElementById(check_prefix + row_id); | |
7a822893 | 958 | |
7d8d10c6 AD |
959 | if (check) { |
960 | check.checked = false; | |
961 | } | |
7a822893 | 962 | |
7d8d10c6 | 963 | } |
3055bc41 | 964 | } |
35f3c923 | 965 | } |
295f9b42 | 966 | } |
91ff844a AD |
967 | |
968 | function getSelectedTableRowIds(content_id, prefix) { | |
969 | ||
970 | var content = document.getElementById(content_id); | |
971 | ||
972 | if (!content) { | |
973 | alert("[getSelectedTableRowIds] Element " + content_id + " not found."); | |
974 | return; | |
975 | } | |
976 | ||
977 | var sel_rows = new Array(); | |
978 | ||
979 | for (i = 0; i < content.rows.length; i++) { | |
1572afe5 AD |
980 | if (content.rows[i].id.match(prefix) && |
981 | content.rows[i].className.match("Selected")) { | |
982 | ||
91ff844a AD |
983 | var row_id = content.rows[i].id.replace(prefix + "-", ""); |
984 | sel_rows.push(row_id); | |
985 | } | |
986 | } | |
987 | ||
988 | return sel_rows; | |
989 | ||
990 | } | |
991 | ||
386cbf27 AD |
992 | function toggleSelectRowById(sender, id) { |
993 | var row = document.getElementById(id); | |
994 | ||
995 | if (sender.checked) { | |
996 | if (!row.className.match("Selected")) { | |
997 | row.className = row.className + "Selected"; | |
998 | } | |
999 | } else { | |
1000 | if (row.className.match("Selected")) { | |
1001 | row.className = row.className.replace("Selected", ""); | |
1002 | } | |
1003 | } | |
1004 | } | |
1005 | ||
b92e6209 AD |
1006 | function toggleSelectListRow(sender) { |
1007 | var parent_row = sender.parentNode; | |
1008 | ||
1009 | if (sender.checked) { | |
1010 | if (!parent_row.className.match("Selected")) { | |
1011 | parent_row.className = parent_row.className + "Selected"; | |
1012 | } | |
1013 | } else { | |
1014 | if (parent_row.className.match("Selected")) { | |
1015 | parent_row.className = parent_row.className.replace("Selected", ""); | |
1016 | } | |
1017 | } | |
1018 | } | |
1019 | ||
67343d9f AD |
1020 | function tSR(sender) { |
1021 | return toggleSelectRow(sender); | |
1022 | } | |
386cbf27 | 1023 | |
1572afe5 AD |
1024 | function toggleSelectRow(sender) { |
1025 | var parent_row = sender.parentNode.parentNode; | |
1026 | ||
1027 | if (sender.checked) { | |
1028 | if (!parent_row.className.match("Selected")) { | |
1029 | parent_row.className = parent_row.className + "Selected"; | |
1030 | } | |
1031 | } else { | |
1032 | if (parent_row.className.match("Selected")) { | |
1033 | parent_row.className = parent_row.className.replace("Selected", ""); | |
1034 | } | |
1035 | } | |
1036 | } | |
1037 | ||
ec37f4f1 AD |
1038 | |
1039 | function getRelativeFeedId2(id, is_cat, direction, unread_only) { | |
1040 | try { | |
1041 | ||
1042 | // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only); | |
1043 | ||
1044 | var rows = document.getElementById("feedList").getElementsByTagName("LI"); | |
1045 | var feeds = new Array(); | |
1046 | ||
1047 | for (var i = 0; i < rows.length; i++) { | |
1048 | if (rows[i].id.match("FEEDR-")) { | |
1049 | ||
1050 | if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) { | |
1051 | ||
1052 | if (!unread_only || | |
1053 | (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) { | |
1054 | feeds.push(rows[i].id.replace("FEEDR-", "")); | |
1055 | } | |
1056 | } | |
1057 | } | |
1058 | ||
1059 | if (rows[i].id.match("FCAT-")) { | |
1060 | if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) { | |
1061 | ||
1062 | var cat_id = parseInt(rows[i].id.replace("FCAT-", "")); | |
1063 | ||
1064 | if (cat_id >= 0) { | |
1065 | if (!unread_only || get_cat_unread(cat_id) > 0) { | |
1066 | feeds.push("CAT:"+cat_id); | |
1067 | } | |
1068 | } | |
1069 | } | |
1070 | } | |
1071 | } | |
1072 | ||
1073 | // alert(feeds.toString()); | |
1074 | ||
1075 | if (!id) { | |
1076 | if (direction == "next") { | |
1077 | return feeds.shift(); | |
1078 | } else { | |
1079 | return feeds.pop(); | |
1080 | } | |
1081 | } else { | |
1082 | if (direction == "next") { | |
1083 | if (is_cat) id = "CAT:" + id; | |
1084 | var idx = feeds.indexOf(id); | |
1085 | if (idx != -1 && idx < feeds.length) { | |
1086 | return feeds[idx+1]; | |
1087 | } else { | |
1088 | return getRelativeFeedId2(false, is_cat, direction, unread_only); | |
1089 | } | |
1090 | } else { | |
1091 | if (is_cat) id = "CAT:" + id; | |
1092 | var idx = feeds.indexOf(id); | |
1093 | if (idx > 0) { | |
1094 | return feeds[idx-1]; | |
1095 | } else { | |
1096 | return getRelativeFeedId2(false, is_cat, direction, unread_only); | |
1097 | } | |
1098 | } | |
1099 | ||
1100 | } | |
1101 | ||
1102 | } catch (e) { | |
1103 | exception_error("getRelativeFeedId2", e); | |
1104 | } | |
1105 | } | |
1106 | ||
1107 | ||
1da76274 | 1108 | function getRelativeFeedId(list, id, direction, unread_only) { |
731b05f4 AD |
1109 | var rows = list.getElementsByTagName("LI"); |
1110 | var feeds = new Array(); | |
1111 | ||
1112 | for (var i = 0; i < rows.length; i++) { | |
1113 | if (rows[i].id.match("FEEDR-")) { | |
1114 | ||
8809f484 | 1115 | if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) { |
731b05f4 AD |
1116 | |
1117 | if (!unread_only || | |
1118 | (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) { | |
1119 | feeds.push(rows[i].id.replace("FEEDR-", "")); | |
1120 | } | |
1121 | } | |
1122 | } | |
1123 | } | |
1124 | ||
7b433d8c | 1125 | if (!id) { |
731b05f4 AD |
1126 | if (direction == "next") { |
1127 | return feeds.shift(); | |
1128 | } else { | |
1129 | return feeds.pop(); | |
1130 | } | |
1131 | } else { | |
1132 | if (direction == "next") { | |
1133 | var idx = feeds.indexOf(id); | |
1134 | if (idx != -1 && idx < feeds.length) { | |
1135 | return feeds[idx+1]; | |
07a67863 AD |
1136 | } else { |
1137 | return getRelativeFeedId(list, false, direction, unread_only); | |
731b05f4 AD |
1138 | } |
1139 | } else { | |
1140 | var idx = feeds.indexOf(id); | |
1141 | if (idx > 0) { | |
1142 | return feeds[idx-1]; | |
07a67863 AD |
1143 | } else { |
1144 | return getRelativeFeedId(list, false, direction, unread_only); | |
731b05f4 AD |
1145 | } |
1146 | } | |
1147 | ||
1148 | } | |
7b433d8c | 1149 | } |
36aab70f | 1150 | |
f27de515 | 1151 | function showBlockElement(id, h_id) { |
36aab70f AD |
1152 | var elem = document.getElementById(id); |
1153 | ||
1154 | if (elem) { | |
1155 | elem.style.display = "block"; | |
f27de515 AD |
1156 | |
1157 | if (h_id) { | |
1158 | elem = document.getElementById(h_id); | |
1159 | if (elem) { | |
1160 | elem.style.display = "none"; | |
1161 | } | |
1162 | } | |
36aab70f AD |
1163 | } else { |
1164 | alert("[showBlockElement] can't find element with id " + id); | |
1165 | } | |
1166 | } | |
1167 | ||
b9073cd9 AD |
1168 | function appearBlockElement_afh(effect) { |
1169 | ||
1170 | } | |
1171 | ||
1172 | function checkboxToggleElement(elem, id) { | |
1173 | if (elem.checked) { | |
ecace165 | 1174 | Effect.Appear(id, {duration : 0.5}); |
b9073cd9 | 1175 | } else { |
ecace165 | 1176 | Effect.Fade(id, {duration : 0.5}); |
b9073cd9 AD |
1177 | } |
1178 | } | |
1179 | ||
1180 | function appearBlockElement(id, h_id) { | |
1181 | ||
1182 | try { | |
a04c8e8d AD |
1183 | if (h_id) { |
1184 | Effect.Fade(h_id); | |
1185 | } | |
b9073cd9 AD |
1186 | Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh}); |
1187 | } catch (e) { | |
1188 | exception_error("appearBlockElement", e); | |
1189 | } | |
1190 | ||
1191 | } | |
1192 | ||
a9b0bfd5 AD |
1193 | function hideParentElement(e) { |
1194 | e.parentNode.style.display = "none"; | |
1195 | } | |
1b0809ae AD |
1196 | |
1197 | function dropboxSelect(e, v) { | |
1198 | for (i = 0; i < e.length; i++) { | |
1199 | if (e[i].value == v) { | |
1200 | e.selectedIndex = i; | |
1201 | break; | |
1202 | } | |
1203 | } | |
1204 | } | |
0ee1d1a0 AD |
1205 | |
1206 | // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z | |
1207 | // bugfixed just a little bit :-) | |
1208 | function getURLParam(strParamName){ | |
1209 | var strReturn = ""; | |
1210 | var strHref = window.location.href; | |
1211 | ||
1212 | if (strHref.indexOf("#") == strHref.length-1) { | |
1213 | strHref = strHref.substring(0, strHref.length-1); | |
1214 | } | |
1215 | ||
1216 | if ( strHref.indexOf("?") > -1 ){ | |
1217 | var strQueryString = strHref.substr(strHref.indexOf("?")); | |
1218 | var aQueryString = strQueryString.split("&"); | |
1219 | for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ | |
1220 | if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ | |
1221 | var aParam = aQueryString[iParam].split("="); | |
1222 | strReturn = aParam[1]; | |
1223 | break; | |
1224 | } | |
1225 | } | |
1226 | } | |
1227 | return strReturn; | |
1228 | } | |
1229 | ||
cf1bc085 AD |
1230 | function leading_zero(p) { |
1231 | var s = String(p); | |
1232 | if (s.length == 1) s = "0" + s; | |
1233 | return s; | |
1234 | } | |
c38c2b69 | 1235 | |
86b682ce | 1236 | function closeInfoBox(cleanup) { |
5ede560f | 1237 | |
569720c5 | 1238 | Element.hide("dialog_overlay"); |
5ede560f | 1239 | |
e5d758e3 AD |
1240 | var box = document.getElementById('infoBox'); |
1241 | var shadow = document.getElementById('infoBoxShadow'); | |
1242 | ||
1243 | if (shadow) { | |
1244 | shadow.style.display = "none"; | |
1245 | } else if (box) { | |
1246 | box.style.display = "none"; | |
1247 | } | |
1248 | ||
86b682ce AD |
1249 | if (cleanup) box.innerHTML = " "; |
1250 | ||
e5d758e3 | 1251 | enableHotkeys(); |
c14b5566 | 1252 | |
90ac84df | 1253 | return false; |
e5d758e3 AD |
1254 | } |
1255 | ||
1256 | ||
7b5c6012 AD |
1257 | function displayDlg(id, param) { |
1258 | ||
35a03bdd | 1259 | notify_progress("Loading, please wait...", true); |
7b5c6012 | 1260 | |
7b5c6012 | 1261 | disableHotkeys(); |
2371c520 | 1262 | |
288487e4 AD |
1263 | var query = "backend.php?op=dlg&id=" + |
1264 | param_escape(id) + "¶m=" + param_escape(param); | |
1265 | ||
1266 | new Ajax.Request(query, { | |
1267 | onComplete: function (transport) { | |
1268 | infobox_callback2(transport); | |
1269 | } }); | |
1270 | ||
90ac84df | 1271 | return false; |
7b5c6012 AD |
1272 | } |
1273 | ||
288487e4 AD |
1274 | function infobox_submit_callback2(transport) { |
1275 | closeInfoBox(); | |
79f3553b | 1276 | |
288487e4 AD |
1277 | try { |
1278 | // called from prefs, reload tab | |
438f2ce9 | 1279 | if (typeof active_tab != 'undefined' && active_tab) { |
288487e4 | 1280 | selectTab(active_tab, false); |
5e6f933a | 1281 | } |
288487e4 | 1282 | } catch (e) { } |
79f3553b | 1283 | |
288487e4 AD |
1284 | if (transport.responseText) { |
1285 | notify_info(transport.responseText); | |
1286 | } | |
7b5c6012 AD |
1287 | } |
1288 | ||
d395a942 AD |
1289 | function infobox_callback2(transport) { |
1290 | try { | |
5ede560f | 1291 | |
d395a942 | 1292 | debug("infobox_callback2"); |
5ede560f | 1293 | |
569720c5 AD |
1294 | if (!getInitParam("infobox_disable_overlay")) { |
1295 | Element.show("dialog_overlay"); | |
d395a942 AD |
1296 | } |
1297 | ||
1298 | var box = document.getElementById('infoBox'); | |
1299 | var shadow = document.getElementById('infoBoxShadow'); | |
1300 | if (box) { | |
1dc47c41 | 1301 | |
d395a942 AD |
1302 | box.innerHTML=transport.responseText; |
1303 | if (shadow) { | |
1304 | shadow.style.display = "block"; | |
1305 | } else { | |
1306 | box.style.display = "block"; | |
aa8716da | 1307 | } |
d395a942 | 1308 | } |
05fcdf52 | 1309 | |
d395a942 | 1310 | /* FIXME this needs to be moved out somewhere */ |
05fcdf52 | 1311 | |
d395a942 AD |
1312 | if (document.getElementById("tags_choices")) { |
1313 | new Ajax.Autocompleter('tags_str', 'tags_choices', | |
1314 | "backend.php?op=rpc&subop=completeTags", | |
1315 | { tokens: ',', paramName: "search" }); | |
442d77f1 | 1316 | } |
d395a942 | 1317 | |
6068d33b AD |
1318 | disableHotkeys(); |
1319 | ||
d395a942 AD |
1320 | notify(""); |
1321 | } catch (e) { | |
1322 | exception_error("infobox_callback2", e); | |
442d77f1 AD |
1323 | } |
1324 | } | |
1325 | ||
18ab3d7a | 1326 | function createFilter() { |
7b5c6012 | 1327 | |
438f2ce9 | 1328 | try { |
6068d33b | 1329 | |
438f2ce9 AD |
1330 | var form = document.forms['filter_add_form']; |
1331 | var reg_exp = form.reg_exp.value; | |
1332 | ||
1333 | if (reg_exp == "") { | |
1334 | alert(__("Can't add filter: nothing to match on.")); | |
1335 | return false; | |
1336 | } | |
288487e4 | 1337 | |
438f2ce9 AD |
1338 | var query = Form.serialize("filter_add_form"); |
1339 | ||
1340 | // we can be called from some other tab in Prefs | |
1341 | if (typeof active_tab != 'undefined' && active_tab) { | |
1342 | active_tab = "filterConfig"; | |
1343 | } | |
1344 | ||
1345 | new Ajax.Request("backend.php?" + query, { | |
1346 | onComplete: function (transport) { | |
1347 | infobox_submit_callback2(transport); | |
1348 | } }); | |
1349 | ||
1350 | return true; | |
1351 | ||
1352 | } catch (e) { | |
1353 | exception_error("createFilter", e); | |
1354 | } | |
7b5c6012 AD |
1355 | } |
1356 | ||
2371c520 AD |
1357 | function toggleSubmitNotEmpty(e, submit_id) { |
1358 | try { | |
1359 | document.getElementById(submit_id).disabled = (e.value == "") | |
1360 | } catch (e) { | |
1361 | exception_error("toggleSubmitNotEmpty", e); | |
1362 | } | |
1363 | } | |
1d7bf5a0 | 1364 | |
605f7d46 | 1365 | function isValidURL(s) { |
0d32b41e | 1366 | return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null; |
605f7d46 | 1367 | } |
07eb9178 | 1368 | |
18ab3d7a | 1369 | function subscribeToFeed() { |
07eb9178 | 1370 | |
c91c2249 AD |
1371 | var form = document.forms['feed_add_form']; |
1372 | var feed_url = form.feed_url.value; | |
1373 | ||
1374 | if (feed_url == "") { | |
89cb787e | 1375 | alert(__("Can't subscribe: no feed URL given.")); |
c91c2249 AD |
1376 | return false; |
1377 | } | |
1378 | ||
1ba6daf7 | 1379 | notify_progress(__("Subscribing to feed..."), true); |
07eb9178 AD |
1380 | |
1381 | closeInfoBox(); | |
1382 | ||
0feab655 | 1383 | var feeds_doc = document; |
07eb9178 | 1384 | |
80e4dc34 | 1385 | // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; |
07eb9178 AD |
1386 | |
1387 | var query = Form.serialize("feed_add_form"); | |
1388 | ||
f27de515 AD |
1389 | debug("subscribe q: " + query); |
1390 | ||
288487e4 AD |
1391 | new Ajax.Request("backend.php", { |
1392 | parameters: query, | |
1393 | onComplete: function(transport) { | |
1394 | dlg_frefresh_callback(transport); | |
1395 | } }); | |
7bc4f251 AD |
1396 | |
1397 | return false; | |
07eb9178 AD |
1398 | } |
1399 | ||
6e6504bc | 1400 | function filterCR(e, f) |
86b682ce AD |
1401 | { |
1402 | var key; | |
1403 | ||
1404 | if(window.event) | |
1405 | key = window.event.keyCode; //IE | |
1406 | else | |
1407 | key = e.which; //firefox | |
1408 | ||
6e6504bc AD |
1409 | if (key == 13) { |
1410 | if (typeof f != 'undefined') { | |
1411 | f(); | |
1412 | return false; | |
1413 | } else { | |
1414 | return false; | |
1415 | } | |
1416 | } else { | |
1417 | return true; | |
1418 | } | |
86b682ce AD |
1419 | } |
1420 | ||
e8614131 AD |
1421 | var debug_last_class = "even"; |
1422 | ||
ac378ad4 | 1423 | function debug(msg) { |
ac378ad4 | 1424 | |
0feab655 AD |
1425 | if (debug_last_class == "even") { |
1426 | debug_last_class = "odd"; | |
e8614131 | 1427 | } else { |
0feab655 | 1428 | debug_last_class = "even"; |
e8614131 AD |
1429 | } |
1430 | ||
0feab655 | 1431 | var c = document.getElementById('debug_output'); |
8836613c | 1432 | if (c && Element.visible(c)) { |
c9268ed5 | 1433 | while (c.lastChild != 'undefined' && c.childNodes.length > 100) { |
ac378ad4 AD |
1434 | c.removeChild(c.lastChild); |
1435 | } | |
1436 | ||
1437 | var d = new Date(); | |
1438 | var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) + | |
1439 | ":" + leading_zero(d.getSeconds()); | |
0feab655 | 1440 | c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " + |
e8614131 | 1441 | msg + "</li>" + c.innerHTML; |
ac378ad4 AD |
1442 | } |
1443 | } | |
1444 | ||
33d13e72 | 1445 | function getInitParam(key) { |
40496720 | 1446 | return init_params[key]; |
33d13e72 | 1447 | } |
3ac2b520 | 1448 | |
be0801a1 | 1449 | function storeInitParam(key, value) { |
40496720 | 1450 | debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>"); |
5158ced9 | 1451 | init_params[key] = value; |
be0801a1 AD |
1452 | } |
1453 | ||
a7565293 AD |
1454 | function fatalError(code, message) { |
1455 | try { | |
a7565293 | 1456 | |
b4c27af7 | 1457 | if (code == 6) { |
8e849206 | 1458 | window.location.href = "tt-rss.php"; |
b4c27af7 AD |
1459 | } else if (code == 5) { |
1460 | window.location.href = "update.php"; | |
1461 | } else { | |
4724a093 AD |
1462 | var fe = document.getElementById("fatal_error"); |
1463 | var fc = document.getElementById("fatal_error_msg"); | |
1464 | ||
42c32916 AD |
1465 | if (message == "") message = "Unknown error"; |
1466 | ||
a0a63217 | 1467 | fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")"; |
4724a093 AD |
1468 | |
1469 | fe.style.display = "block"; | |
4724a093 | 1470 | } |
a7565293 AD |
1471 | |
1472 | } catch (e) { | |
1473 | exception_error("fatalError", e); | |
1474 | } | |
1475 | } | |
1476 | ||
234e467c | 1477 | function getFeedName(id, is_cat) { |
234e467c AD |
1478 | var e; |
1479 | ||
1480 | if (is_cat) { | |
5fc13f63 | 1481 | e = document.getElementById("FCATN-" + id); |
234e467c | 1482 | } else { |
5fc13f63 | 1483 | e = document.getElementById("FEEDN-" + id); |
234e467c | 1484 | } |
64a2875d AD |
1485 | if (e) { |
1486 | return e.innerHTML.stripTags(); | |
1487 | } else { | |
1488 | return null; | |
1489 | } | |
1490 | } | |
0bd411db | 1491 | |
350f0ad1 AD |
1492 | function filterDlgCheckAction(sender) { |
1493 | ||
1494 | try { | |
1495 | ||
1496 | var action = sender[sender.selectedIndex].value; | |
1497 | ||
1498 | var form = document.forms["filter_add_form"]; | |
1499 | ||
1500 | if (!form) { | |
1501 | form = document.forms["filter_edit_form"]; | |
1502 | } | |
1503 | ||
1504 | if (!form) { | |
1505 | debug("filterDlgCheckAction: can't find form!"); | |
1506 | return; | |
1507 | } | |
1508 | ||
1509 | var action_param = form.action_param; | |
1510 | ||
1511 | if (!action_param) { | |
1512 | debug("filterDlgCheckAction: can't find action param!"); | |
1513 | return; | |
1514 | } | |
1515 | ||
1516 | // if selected action supports parameters, enable params field | |
48ddbb33 | 1517 | if (action == 4 || action == 6) { |
350f0ad1 AD |
1518 | action_param.disabled = false; |
1519 | } else { | |
1520 | action_param.disabled = true; | |
1521 | } | |
1522 | ||
1523 | } catch (e) { | |
438f2ce9 | 1524 | exception_error("filterDlgCheckAction", e); |
350f0ad1 AD |
1525 | } |
1526 | ||
1527 | } | |
ef16ae37 AD |
1528 | |
1529 | function explainError(code) { | |
1530 | return displayDlg("explainError", code); | |
1531 | } | |
01a87dff | 1532 | |
e097e8be | 1533 | // this only searches loaded headlines list, not in CDM |
aa0fa9df | 1534 | function getRelativePostIds(id, limit) { |
e097e8be | 1535 | |
aa0fa9df AD |
1536 | if (!limit) limit = 3; |
1537 | ||
1538 | debug("getRelativePostIds: " + id + " limit=" + limit); | |
e097e8be AD |
1539 | |
1540 | var ids = new Array(); | |
1541 | var container = document.getElementById("headlinesList"); | |
1542 | ||
1543 | if (container) { | |
1544 | var rows = container.rows; | |
1545 | ||
1546 | for (var i = 0; i < rows.length; i++) { | |
1547 | var r_id = rows[i].id.replace("RROW-", ""); | |
1548 | ||
1549 | if (r_id == id) { | |
aa0fa9df AD |
1550 | for (var k = 1; k <= limit; k++) { |
1551 | var nid = false; | |
1552 | ||
1553 | if (i > k-1) var nid = rows[i-k].id.replace("RROW-", ""); | |
1554 | if (nid) ids.push(nid); | |
1555 | ||
1556 | if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", ""); | |
1557 | if (nid) ids.push(nid); | |
1558 | } | |
e097e8be AD |
1559 | |
1560 | return ids; | |
1561 | } | |
1562 | } | |
1563 | } | |
1564 | ||
1565 | return false; | |
1566 | } | |
298f3f78 AD |
1567 | |
1568 | function openArticleInNewWindow(id) { | |
1569 | try { | |
298f3f78 AD |
1570 | debug("openArticleInNewWindow: " + id); |
1571 | ||
1572 | var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id; | |
04e91733 AD |
1573 | var wname = "ttrss_article_" + id; |
1574 | ||
1575 | debug(query + " " + wname); | |
1576 | ||
1577 | var w = window.open("", wname); | |
298f3f78 | 1578 | |
04e91733 | 1579 | if (!w) notify_error("Failed to open window for the article"); |
298f3f78 | 1580 | |
d395a942 AD |
1581 | new Ajax.Request(query, { |
1582 | onComplete: function(transport) { | |
1583 | open_article_callback(transport); | |
1584 | } }); | |
1585 | ||
298f3f78 AD |
1586 | |
1587 | } catch (e) { | |
1588 | exception_error("openArticleInNewWindow", e); | |
1589 | } | |
1590 | } | |
e4914b62 | 1591 | |
537625c6 AD |
1592 | /* http://textsnippets.com/posts/show/835 */ |
1593 | ||
1594 | Position.GetWindowSize = function(w) { | |
1595 | w = w ? w : window; | |
1596 | var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth); | |
1597 | var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight); | |
1598 | return [width, height] | |
1599 | } | |
1600 | ||
1601 | /* http://textsnippets.com/posts/show/836 */ | |
1602 | ||
1603 | Position.Center = function(element, parent) { | |
1604 | var w, h, pw, ph; | |
1605 | var d = Element.getDimensions(element); | |
1606 | w = d.width; | |
1607 | h = d.height; | |
1608 | Position.prepare(); | |
1609 | if (!parent) { | |
1610 | var ws = Position.GetWindowSize(); | |
1611 | pw = ws[0]; | |
1612 | ph = ws[1]; | |
1613 | } else { | |
1614 | pw = parent.offsetWidth; | |
1615 | ph = parent.offsetHeight; | |
1616 | } | |
1617 | element.style.top = (ph/2) - (h/2) - Position.deltaY + "px"; | |
1618 | element.style.left = (pw/2) - (w/2) - Position.deltaX + "px"; | |
1619 | } | |
1620 | ||
768858f1 | 1621 | |
288487e4 AD |
1622 | function labeltest_callback(transport) { |
1623 | try { | |
1624 | var container = document.getElementById('label_test_result'); | |
1625 | ||
1626 | container.innerHTML = transport.responseText; | |
768858f1 AD |
1627 | if (!Element.visible(container)) { |
1628 | Effect.SlideDown(container, { duration : 0.5 }); | |
1629 | } | |
288487e4 | 1630 | |
6f151277 | 1631 | notify(""); |
288487e4 AD |
1632 | } catch (e) { |
1633 | exception_error("labeltest_callback", e); | |
6f151277 AD |
1634 | } |
1635 | } | |
1636 | ||
1637 | function labelTest() { | |
1638 | ||
288487e4 AD |
1639 | try { |
1640 | var container = document.getElementById('label_test_result'); | |
1641 | ||
1642 | var form = document.forms['label_edit_form']; | |
1643 | ||
1644 | var sql_exp = form.sql_exp.value; | |
1645 | var description = form.description.value; | |
1646 | ||
1647 | notify_progress("Loading, please wait..."); | |
1648 | ||
1649 | var query = "backend.php?op=pref-labels&subop=test&expr=" + | |
1650 | param_escape(sql_exp) + "&descr=" + param_escape(description); | |
1651 | ||
1652 | new Ajax.Request(query, { | |
1653 | onComplete: function (transport) { | |
1654 | labeltest_callback(transport); | |
1655 | } }); | |
1656 | ||
1657 | return false; | |
6f151277 | 1658 | |
288487e4 AD |
1659 | } catch (e) { |
1660 | exception_error("labelTest", e); | |
1661 | } | |
6f151277 AD |
1662 | } |
1663 | ||
c32cd48a AD |
1664 | function isCdmMode() { |
1665 | return !document.getElementById("headlinesList"); | |
1666 | } | |
1667 | ||
1668 | function getSelectedArticleIds2() { | |
1669 | var rows = new Array(); | |
1670 | var cdm_mode = isCdmMode(); | |
1671 | ||
1672 | if (cdm_mode) { | |
1673 | rows = cdmGetSelectedArticles(); | |
1674 | } else { | |
1675 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
1676 | } | |
1677 | ||
1678 | var ids = new Array(); | |
1679 | ||
1680 | for (var i = 0; i < rows.length; i++) { | |
1681 | var chk = document.getElementById("RCHK-" + rows[i]); | |
1682 | if (chk && chk.checked) { | |
1683 | ids.push(rows[i]); | |
1684 | } | |
1685 | } | |
1686 | ||
1687 | return ids; | |
1688 | } | |
c4a36709 | 1689 | |
f6d40ed2 | 1690 | function displayHelpInfobox(topic_id) { |
c4a36709 | 1691 | |
f6d40ed2 AD |
1692 | var url = "backend.php?op=help&tid=" + param_escape(topic_id); |
1693 | ||
1694 | var w = window.open(url, "ttrss_help", | |
1695 | "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0"); | |
1696 | ||
1697 | return false; | |
1698 | } | |
e635d56a | 1699 | |
477402d8 | 1700 | function focus_element(id) { |
61992f57 | 1701 | try { |
477402d8 AD |
1702 | var e = document.getElementById(id); |
1703 | if (e) e.focus(); | |
61992f57 | 1704 | } catch (e) { |
438f2ce9 | 1705 | exception_error("focus_element", e); |
61992f57 | 1706 | } |
477402d8 | 1707 | return false; |
61992f57 | 1708 | } |
e635d56a | 1709 | |
99509451 | 1710 | function loading_set_progress(p) { |
730dbf19 | 1711 | try { |
fca95d5f AD |
1712 | if (p < last_progress_point || !Element.visible("overlay")) return; |
1713 | ||
1714 | debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>"); | |
99509451 | 1715 | |
730dbf19 | 1716 | var o = document.getElementById("l_progress_i"); |
99509451 | 1717 | |
673c9946 AD |
1718 | // o.style.width = (p * 2) + "px"; |
1719 | ||
99509451 AD |
1720 | new Effect.Scale(o, p, { |
1721 | scaleY : false, | |
1722 | scaleFrom : last_progress_point, | |
1723 | scaleMode: { originalWidth : 200 }, | |
673c9946 | 1724 | queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); |
99509451 AD |
1725 | |
1726 | last_progress_point = p; | |
730dbf19 AD |
1727 | |
1728 | } catch (e) { | |
1729 | exception_error("loading_set_progress", e); | |
1730 | } | |
1731 | } | |
08827aaf AD |
1732 | |
1733 | function remove_splash() { | |
1734 | if (Element.visible("overlay")) { | |
1735 | debug("about to remove splash, OMG!"); | |
1736 | Element.hide("overlay"); | |
1737 | debug("removed splash!"); | |
1738 | } | |
1739 | } |