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