]> git.wh0rd.org - tt-rss.git/blame - functions.js
headlines subtoolbar, misc api changes
[tt-rss.git] / functions.js
CommitLineData
760966c1
AD
1var hotkeys_enabled = true;
2
7719618b
AD
3function exception_error(location, e) {
4 alert("Exception: " + e.name + "\nMessage: " + e.message +
5 "\nLocation: " + location);
6}
7
760966c1
AD
8function disableHotkeys() {
9 hotkeys_enabled = false;
10}
11
12function enableHotkeys() {
13 hotkeys_enabled = true;
14}
15
c0e5a40e
AD
16function xmlhttp_ready(obj) {
17 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
18}
19
20
9cfc649a
AD
21function notify_callback() {
22 var container = document.getElementById('notify');
23 if (xmlhttp.readyState == 4) {
24 container.innerHTML=xmlhttp.responseText;
25 }
26}
27
28function rpc_notify_callback() {
29 var container = document.getElementById('notify');
30 if (xmlhttp_rpc.readyState == 4) {
31 container.innerHTML=xmlhttp_rpc.responseText;
32 }
33}
34
1572afe5
AD
35function rpc_pnotify_callback() {
36 var container = parent.document.getElementById('notify');
37 if (xmlhttp_rpc.readyState == 4) {
38 container.innerHTML=xmlhttp_rpc.responseText;
39 }
40}
41
7726fa02
AD
42function param_escape(arg) {
43 if (typeof encodeURIComponent != 'undefined')
44 return encodeURIComponent(arg);
45 else
46 return escape(arg);
47}
48
49function param_unescape(arg) {
50 if (typeof decodeURIComponent != 'undefined')
51 return decodeURIComponent(arg);
52 else
53 return unescape(arg);
54}
55
508a81e1
AD
56function delay(gap) {
57 var then,now;
58 then=new Date().getTime();
59 now=then;
60 while((now-then)<gap) {
61 now=new Date().getTime();
62 }
63}
7726fa02 64
c05608c2
AD
65function p_notify(msg) {
66
67 var n = parent.document.getElementById("notify");
68 var nb = parent.document.getElementById("notify_body");
69
70 if (!n || !nb) return;
71
8dcfffd0
AD
72 if (msg == "") {
73 nb.innerHTML = "&nbsp;";
e93919dd 74// n.style.background = "#ffffff";
c05608c2 75 } else {
8dcfffd0 76 nb.innerHTML = msg;
e93919dd 77// n.style.background = "#fffff0";
8dcfffd0 78 }
c05608c2
AD
79}
80
7726fa02
AD
81function notify(msg) {
82
83 var n = document.getElementById("notify");
c05608c2 84 var nb = document.getElementById("notify_body");
7726fa02 85
c05608c2 86 if (!n || !nb) return;
f0601b87 87
8dcfffd0
AD
88 if (msg == "") {
89 nb.innerHTML = "&nbsp;";
e93919dd 90// n.style.background = "#ffffff";
7726fa02 91 } else {
8dcfffd0 92 nb.innerHTML = msg;
e93919dd 93// n.style.background = "#fffff0";
8dcfffd0 94 }
7726fa02
AD
95
96}
97
508a81e1 98function printLockingError() {
f0601b87 99 notify("Please wait until operation finishes");}
508a81e1 100
13ad9102
AD
101var seq = "";
102
103function hotkey_handler(e) {
760966c1 104
13ad9102
AD
105 var keycode;
106
760966c1
AD
107 if (!hotkeys_enabled) return;
108
13ad9102
AD
109 if (window.event) {
110 keycode = window.event.keyCode;
111 } else if (e) {
112 keycode = e.which;
113 }
114
115 if (keycode == 13 || keycode == 27) {
116 seq = "";
117 } else {
118 seq = seq + "" + keycode;
119 }
120
121 var piggie = document.getElementById("piggie");
122
bb7cface 123 if (piggie) {
13ad9102 124
bb7cface
AD
125 if (seq.match("807371717369")) {
126 localPiggieFunction(true);
127 } else {
128 localPiggieFunction(false);
129 }
130 }
131
9cfc649a
AD
132 if (typeof localHotkeyHandler != 'undefined') {
133 localHotkeyHandler(keycode);
134 }
135
13ad9102
AD
136}
137
e828e31e 138function cleanSelectedList(element) {
f0601b87
AD
139 var content = document.getElementById(element);
140
703b632e
AD
141 if (!document.getElementById("feedCatHolder")) {
142 for (i = 0; i < content.childNodes.length; i++) {
143 var child = content.childNodes[i];
144 child.className = child.className.replace("Selected", "");
145 }
146 } else {
147 for (i = 0; i < content.childNodes.length; i++) {
148 var child = content.childNodes[i];
149
150 if (child.id == "feedCatHolder") {
151 var fcat = child.firstChild;
152 for (j = 0; j < fcat.childNodes.length; j++) {
153 var feed = fcat.childNodes[j];
154 feed.className = feed.className.replace("Selected", "");
155 }
156 }
157 }
e828e31e 158
703b632e 159 }
e828e31e
AD
160}
161
162
163function cleanSelected(element) {
164 var content = document.getElementById(element);
f0601b87
AD
165
166 for (i = 0; i < content.rows.length; i++) {
167 content.rows[i].className = content.rows[i].className.replace("Selected", "");
168 }
169
170}
171
172function getVisibleUnreadHeadlines() {
173 var content = document.getElementById("headlinesList");
174
175 var rows = new Array();
176
177 for (i = 0; i < content.rows.length; i++) {
178 var row_id = content.rows[i].id.replace("RROW-", "");
179 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
180 rows.push(row_id);
181 }
182 }
183 return rows;
184}
185
186function getVisibleHeadlineIds() {
187
188 var content = document.getElementById("headlinesList");
189
190 var rows = new Array();
191
192 for (i = 0; i < content.rows.length; i++) {
193 var row_id = content.rows[i].id.replace("RROW-", "");
194 if (row_id.length > 0) {
195 rows.push(row_id);
196 }
197 }
198 return rows;
199}
200
201function getFirstVisibleHeadlineId() {
202 var rows = getVisibleHeadlineIds();
203 return rows[0];
204}
205
206function getLastVisibleHeadlineId() {
207 var rows = getVisibleHeadlineIds();
208 return rows[rows.length-1];
209}
210
211function markHeadline(id) {
212 var row = document.getElementById("RROW-" + id);
213 if (row) {
35f3c923
AD
214 var is_active = false;
215
216 if (row.className.match("Active")) {
217 is_active = true;
218 }
219 row.className = row.className.replace("Selected", "");
220 row.className = row.className.replace("Active", "");
221 row.className = row.className.replace("Insensitive", "");
222
223 if (is_active) {
224 row.className = row.className = "Active";
225 }
226
227 row.className = row.className + "Selected";
228
f0601b87
AD
229 }
230}
231
232function getFeedIds() {
233 var content = document.getElementById("feedsList");
234
235 var rows = new Array();
236
237 for (i = 0; i < content.rows.length; i++) {
238 var id = content.rows[i].id.replace("FEEDR-", "");
239 if (id.length > 0) {
240 rows.push(id);
241 }
242 }
243
244 return rows;
245}
13ad9102 246
ac43eba1
AD
247function setCookie(name, value, expires, path, domain, secure) {
248 document.cookie= name + "=" + escape(value) +
249 ((expires) ? "; expires=" + expires.toGMTString() : "") +
250 ((path) ? "; path=" + path : "") +
251 ((domain) ? "; domain=" + domain : "") +
252 ((secure) ? "; secure" : "");
253}
254
255function getCookie(name) {
256
257 var dc = document.cookie;
258 var prefix = name + "=";
259 var begin = dc.indexOf("; " + prefix);
260 if (begin == -1) {
261 begin = dc.indexOf(prefix);
262 if (begin != 0) return null;
263 }
264 else {
265 begin += 2;
266 }
267 var end = document.cookie.indexOf(";", begin);
268 if (end == -1) {
269 end = dc.length;
270 }
271 return unescape(dc.substring(begin + prefix.length, end));
272}
273
1a66d16e
AD
274function disableContainerChildren(id, disable, doc) {
275
276 if (!doc) doc = document;
277
278 var container = doc.getElementById(id);
ac43eba1
AD
279
280 for (var i = 0; i < container.childNodes.length; i++) {
281 var child = container.childNodes[i];
282
d5224f0d
AD
283 try {
284 child.disabled = disable;
285 } catch (E) {
286
287 }
ac43eba1
AD
288
289 if (disable) {
290 if (child.className && child.className.match("button")) {
291 child.className = "disabledButton";
292 }
293 } else {
294 if (child.className && child.className.match("disabledButton")) {
295 child.className = "button";
296 }
d5224f0d 297 }
ac43eba1
AD
298 }
299
300}
7726fa02 301
e828e31e
AD
302function gotoPreferences() {
303 document.location.href = "prefs.php";
304}
305
306function gotoMain() {
307 document.location.href = "tt-rss.php";
308}
309
8158c57a
AD
310function gotoExportOpml() {
311 document.location.href = "opml.php?op=Export";
312}
86741347
AD
313
314function getActiveFeedId() {
315 return getCookie("ttrss_vf_actfeed");
316}
317
318function setActiveFeedId(id) {
319 return setCookie("ttrss_vf_actfeed", id);
320}
090e250b
AD
321
322var xmlhttp_rpc = false;
323
324/*@cc_on @*/
325/*@if (@_jscript_version >= 5)
326// JScript gives us Conditional compilation, we can cope with old IE versions.
327// and security blocked creation of the objects.
328try {
329 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
330} catch (e) {
331 try {
332 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
333 } catch (E) {
334 xmlhttp_rpc = false;
335 }
336}
337@end @*/
338
339if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
340 xmlhttp_rpc = new XMLHttpRequest();
341}
342
4f3a84f4 343function all_counters_callback() {
090e250b 344 if (xmlhttp_rpc.readyState == 4) {
7719618b
AD
345 try {
346 if (!xmlhttp_rpc.responseXML) {
347 notify("[all_counters_callback] backend did not return valid XML");
348 return;
349 }
350
351 var reply = xmlhttp_rpc.responseXML.firstChild;
352
353 var f_document = parent.frames["feeds-frame"].document;
354
355 for (var l = 0; l < reply.childNodes.length; l++) {
356 var id = reply.childNodes[l].getAttribute("id");
357 var ctr = reply.childNodes[l].getAttribute("counter");
358
359 var feedctr = f_document.getElementById("FEEDCTR-" + id);
360 var feedu = f_document.getElementById("FEEDU-" + id);
361 var feedr = f_document.getElementById("FEEDR-" + id);
362
363 if (feedctr && feedu && feedr) {
364
365 feedu.innerHTML = ctr;
366
367 if (ctr > 0) {
368 feedctr.className = "odd";
369 if (!feedr.className.match("Unread")) {
370 var is_selected = feedr.className.match("Selected");
371
372 feedr.className = feedr.className.replace("Selected", "");
373 feedr.className = feedr.className.replace("Unread", "");
374
375 feedr.className = feedr.className + "Unread";
376
377 if (is_selected) {
378 feedr.className = feedr.className + "Selected";
379 }
8143ae1f 380
4f3a84f4 381 }
7719618b
AD
382 } else {
383 feedctr.className = "invisible";
384 feedr.className = feedr.className.replace("Unread", "");
385 }
386 }
8143ae1f 387 }
7719618b
AD
388 } catch (e) {
389 exception_error("all_counters_callback", e);
090e250b
AD
390 }
391 }
392}
393
4f3a84f4 394function update_all_counters(feed) {
090e250b 395 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 396 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
397
398 if (feed > 0) {
399 query = query + "&aid=" + feed;
400 }
401
090e250b 402 xmlhttp_rpc.open("GET", query, true);
4f3a84f4 403 xmlhttp_rpc.onreadystatechange=all_counters_callback;
090e250b
AD
404 xmlhttp_rpc.send(null);
405 }
406}
7dc66a61
AD
407
408function popupHelp(tid) {
409 var w = window.open("backend.php?op=help&tid=" + tid,
410 "Popup Help",
411 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
412}
b6644d29
AD
413
414/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
415 * * @author Sundar Dorai-Raj
416 * * Email: sdoraira@vt.edu
417 * * This program is free software; you can redistribute it and/or
418 * * modify it under the terms of the GNU General Public License
419 * * as published by the Free Software Foundation; either version 2
420 * * of the License, or (at your option) any later version,
421 * * provided that any use properly credits the author.
422 * * This program is distributed in the hope that it will be useful,
423 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
424 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
425 * * GNU General Public License for more details at http://www.gnu.org * * */
426
427 var numbers=".0123456789";
428 function isNumeric(x) {
429 // is x a String or a character?
430 if(x.length>1) {
431 // remove negative sign
432 x=Math.abs(x)+"";
433 for(j=0;j<x.length;j++) {
434 // call isNumeric recursively for each character
435 number=isNumeric(x.substring(j,j+1));
436 if(!number) return number;
437 }
438 return number;
439 }
440 else {
441 // if x is number return true
442 if(numbers.indexOf(x)>=0) return true;
443 return false;
444 }
445 }
446
3745788e
AD
447
448function hideOrShowFeeds(doc, hide) {
449
450 var css_rules = doc.styleSheets[0].cssRules;
451
452 for (i = 0; i < css_rules.length; i++) {
453 var rule = css_rules[i];
454
455 if (rule.selectorText == "ul.feedList li.feed") {
456 if (!hide) {
457 rule.style.display = "block";
458 } else {
459 rule.style.display = "none";
460 }
461 }
462
463 }
464
465}
466
295f9b42
AD
467function fatalError(code) {
468 window.location = "error.php?c=" + param_escape(code);
35f3c923
AD
469}
470
471function selectTableRow(r, do_select) {
472 r.className = r.className.replace("Selected", "");
473
474 if (do_select) {
475 r.className = r.className + "Selected";
476 }
477}
478
1572afe5
AD
479function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
480 classcheck) {
3745788e 481
35f3c923
AD
482 var content = document.getElementById(content_id);
483
484 if (!content) {
485 alert("[selectTableRows] Element " + content_id + " not found.");
486 return;
487 }
488
489 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
490 if (!classcheck || content.rows[i].className.match(classcheck)) {
491
492 if (content.rows[i].id.match(prefix)) {
493 selectTableRow(content.rows[i], do_select);
494 }
3055bc41 495
1572afe5
AD
496 var row_id = content.rows[i].id.replace(prefix, "");
497 var check = document.getElementById(check_prefix + row_id);
3055bc41 498
1572afe5
AD
499 if (check) {
500 check.checked = do_select;
501 }
3055bc41 502 }
35f3c923 503 }
295f9b42 504}
91ff844a
AD
505
506function getSelectedTableRowIds(content_id, prefix) {
507
508 var content = document.getElementById(content_id);
509
510 if (!content) {
511 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
512 return;
513 }
514
515 var sel_rows = new Array();
516
517 for (i = 0; i < content.rows.length; i++) {
1572afe5
AD
518 if (content.rows[i].id.match(prefix) &&
519 content.rows[i].className.match("Selected")) {
520
91ff844a
AD
521 var row_id = content.rows[i].id.replace(prefix + "-", "");
522 sel_rows.push(row_id);
523 }
524 }
525
526 return sel_rows;
527
528}
529
1572afe5
AD
530function toggleSelectRow(sender) {
531 var parent_row = sender.parentNode.parentNode;
532
533 if (sender.checked) {
534 if (!parent_row.className.match("Selected")) {
535 parent_row.className = parent_row.className + "Selected";
536 }
537 } else {
538 if (parent_row.className.match("Selected")) {
539 parent_row.className = parent_row.className.replace("Selected", "");
540 }
541 }
542}
543
544