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