]> git.wh0rd.org - tt-rss.git/blob - functions.js
headlines subtoolbar, misc api changes
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2
3 function exception_error(location, e) {
4 alert("Exception: " + e.name + "\nMessage: " + e.message +
5 "\nLocation: " + location);
6 }
7
8 function disableHotkeys() {
9 hotkeys_enabled = false;
10 }
11
12 function enableHotkeys() {
13 hotkeys_enabled = true;
14 }
15
16 function xmlhttp_ready(obj) {
17 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
18 }
19
20
21 function notify_callback() {
22 var container = document.getElementById('notify');
23 if (xmlhttp.readyState == 4) {
24 container.innerHTML=xmlhttp.responseText;
25 }
26 }
27
28 function rpc_notify_callback() {
29 var container = document.getElementById('notify');
30 if (xmlhttp_rpc.readyState == 4) {
31 container.innerHTML=xmlhttp_rpc.responseText;
32 }
33 }
34
35 function 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
42 function param_escape(arg) {
43 if (typeof encodeURIComponent != 'undefined')
44 return encodeURIComponent(arg);
45 else
46 return escape(arg);
47 }
48
49 function param_unescape(arg) {
50 if (typeof decodeURIComponent != 'undefined')
51 return decodeURIComponent(arg);
52 else
53 return unescape(arg);
54 }
55
56 function 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 }
64
65 function 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
72 if (msg == "") {
73 nb.innerHTML = "&nbsp;";
74 // n.style.background = "#ffffff";
75 } else {
76 nb.innerHTML = msg;
77 // n.style.background = "#fffff0";
78 }
79 }
80
81 function notify(msg) {
82
83 var n = document.getElementById("notify");
84 var nb = document.getElementById("notify_body");
85
86 if (!n || !nb) return;
87
88 if (msg == "") {
89 nb.innerHTML = "&nbsp;";
90 // n.style.background = "#ffffff";
91 } else {
92 nb.innerHTML = msg;
93 // n.style.background = "#fffff0";
94 }
95
96 }
97
98 function printLockingError() {
99 notify("Please wait until operation finishes");}
100
101 var seq = "";
102
103 function hotkey_handler(e) {
104
105 var keycode;
106
107 if (!hotkeys_enabled) return;
108
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
123 if (piggie) {
124
125 if (seq.match("807371717369")) {
126 localPiggieFunction(true);
127 } else {
128 localPiggieFunction(false);
129 }
130 }
131
132 if (typeof localHotkeyHandler != 'undefined') {
133 localHotkeyHandler(keycode);
134 }
135
136 }
137
138 function cleanSelectedList(element) {
139 var content = document.getElementById(element);
140
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 }
158
159 }
160 }
161
162
163 function cleanSelected(element) {
164 var content = document.getElementById(element);
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
172 function 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
186 function 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
201 function getFirstVisibleHeadlineId() {
202 var rows = getVisibleHeadlineIds();
203 return rows[0];
204 }
205
206 function getLastVisibleHeadlineId() {
207 var rows = getVisibleHeadlineIds();
208 return rows[rows.length-1];
209 }
210
211 function markHeadline(id) {
212 var row = document.getElementById("RROW-" + id);
213 if (row) {
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
229 }
230 }
231
232 function 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 }
246
247 function 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
255 function 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
274 function disableContainerChildren(id, disable, doc) {
275
276 if (!doc) doc = document;
277
278 var container = doc.getElementById(id);
279
280 for (var i = 0; i < container.childNodes.length; i++) {
281 var child = container.childNodes[i];
282
283 try {
284 child.disabled = disable;
285 } catch (E) {
286
287 }
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 }
297 }
298 }
299
300 }
301
302 function gotoPreferences() {
303 document.location.href = "prefs.php";
304 }
305
306 function gotoMain() {
307 document.location.href = "tt-rss.php";
308 }
309
310 function gotoExportOpml() {
311 document.location.href = "opml.php?op=Export";
312 }
313
314 function getActiveFeedId() {
315 return getCookie("ttrss_vf_actfeed");
316 }
317
318 function setActiveFeedId(id) {
319 return setCookie("ttrss_vf_actfeed", id);
320 }
321
322 var 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.
328 try {
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
339 if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
340 xmlhttp_rpc = new XMLHttpRequest();
341 }
342
343 function all_counters_callback() {
344 if (xmlhttp_rpc.readyState == 4) {
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 }
380
381 }
382 } else {
383 feedctr.className = "invisible";
384 feedr.className = feedr.className.replace("Unread", "");
385 }
386 }
387 }
388 } catch (e) {
389 exception_error("all_counters_callback", e);
390 }
391 }
392 }
393
394 function update_all_counters(feed) {
395 if (xmlhttp_ready(xmlhttp_rpc)) {
396 var query = "backend.php?op=rpc&subop=getAllCounters";
397
398 if (feed > 0) {
399 query = query + "&aid=" + feed;
400 }
401
402 xmlhttp_rpc.open("GET", query, true);
403 xmlhttp_rpc.onreadystatechange=all_counters_callback;
404 xmlhttp_rpc.send(null);
405 }
406 }
407
408 function 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 }
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
447
448 function 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
467 function fatalError(code) {
468 window.location = "error.php?c=" + param_escape(code);
469 }
470
471 function 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
479 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
480 classcheck) {
481
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++) {
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 }
495
496 var row_id = content.rows[i].id.replace(prefix, "");
497 var check = document.getElementById(check_prefix + row_id);
498
499 if (check) {
500 check.checked = do_select;
501 }
502 }
503 }
504 }
505
506 function 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++) {
518 if (content.rows[i].id.match(prefix) &&
519 content.rows[i].className.match("Selected")) {
520
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
530 function 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