]> git.wh0rd.org - tt-rss.git/blame - functions.js
don't allow duplicate feeds for user
[tt-rss.git] / functions.js
CommitLineData
760966c1
AD
1var hotkeys_enabled = true;
2
3function disableHotkeys() {
4 hotkeys_enabled = false;
5}
6
7function enableHotkeys() {
8 hotkeys_enabled = true;
9}
10
c0e5a40e
AD
11function xmlhttp_ready(obj) {
12 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
13}
14
15
9cfc649a
AD
16function notify_callback() {
17 var container = document.getElementById('notify');
18 if (xmlhttp.readyState == 4) {
19 container.innerHTML=xmlhttp.responseText;
20 }
21}
22
23function rpc_notify_callback() {
24 var container = document.getElementById('notify');
25 if (xmlhttp_rpc.readyState == 4) {
26 container.innerHTML=xmlhttp_rpc.responseText;
27 }
28}
29
7726fa02
AD
30function param_escape(arg) {
31 if (typeof encodeURIComponent != 'undefined')
32 return encodeURIComponent(arg);
33 else
34 return escape(arg);
35}
36
37function param_unescape(arg) {
38 if (typeof decodeURIComponent != 'undefined')
39 return decodeURIComponent(arg);
40 else
41 return unescape(arg);
42}
43
508a81e1
AD
44function 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}
7726fa02 52
c05608c2
AD
53function 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
828a8ecc
AD
60 if (msg == "") msg = "&nbsp;";
61
c05608c2
AD
62 nb.innerHTML = msg;
63
828a8ecc 64/* if (msg.length == 0) {
c05608c2
AD
65 n.style.display = "none";
66 } else {
67 n.style.display = "block";
828a8ecc 68 } */
c05608c2
AD
69
70}
71
7726fa02
AD
72function notify(msg) {
73
74 var n = document.getElementById("notify");
c05608c2 75 var nb = document.getElementById("notify_body");
7726fa02 76
c05608c2 77 if (!n || !nb) return;
f0601b87 78
828a8ecc
AD
79 if (msg == "") msg = "&nbsp;";
80
c05608c2 81 nb.innerHTML = msg;
7726fa02 82
828a8ecc 83/* if (msg.length == 0) {
7726fa02
AD
84 n.style.display = "none";
85 } else {
86 n.style.display = "block";
828a8ecc 87 } */
7726fa02
AD
88
89}
90
508a81e1 91function printLockingError() {
f0601b87 92 notify("Please wait until operation finishes");}
508a81e1 93
13ad9102
AD
94var seq = "";
95
96function hotkey_handler(e) {
760966c1 97
13ad9102
AD
98 var keycode;
99
760966c1
AD
100 if (!hotkeys_enabled) return;
101
13ad9102
AD
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
bb7cface 116 if (piggie) {
13ad9102 117
bb7cface
AD
118 if (seq.match("807371717369")) {
119 localPiggieFunction(true);
120 } else {
121 localPiggieFunction(false);
122 }
123 }
124
9cfc649a
AD
125 if (typeof localHotkeyHandler != 'undefined') {
126 localHotkeyHandler(keycode);
127 }
128
13ad9102
AD
129}
130
e828e31e 131function cleanSelectedList(element) {
f0601b87
AD
132 var content = document.getElementById(element);
133
e828e31e 134 for (i = 0; i < content.childNodes.length; i++) {
4ce19859
AD
135 content.childNodes[i].className =
136 content.childNodes[i].className.replace("Selected", "");
e828e31e
AD
137 }
138
139}
140
141
142function cleanSelected(element) {
143 var content = document.getElementById(element);
f0601b87
AD
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
151function 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
165function 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
180function getFirstVisibleHeadlineId() {
181 var rows = getVisibleHeadlineIds();
182 return rows[0];
183}
184
185function getLastVisibleHeadlineId() {
186 var rows = getVisibleHeadlineIds();
187 return rows[rows.length-1];
188}
189
190function markHeadline(id) {
191 var row = document.getElementById("RROW-" + id);
192 if (row) {
193 row.className = row.className + "Selected";
194 }
195}
196
197function 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}
13ad9102 211
ac43eba1
AD
212function 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
220function 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
1a66d16e
AD
239function disableContainerChildren(id, disable, doc) {
240
241 if (!doc) doc = document;
242
243 var container = doc.getElementById(id);
ac43eba1
AD
244
245 for (var i = 0; i < container.childNodes.length; i++) {
246 var child = container.childNodes[i];
247
d5224f0d
AD
248 try {
249 child.disabled = disable;
250 } catch (E) {
251
252 }
ac43eba1
AD
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 }
d5224f0d 262 }
ac43eba1
AD
263 }
264
265}
7726fa02 266
e828e31e
AD
267function gotoPreferences() {
268 document.location.href = "prefs.php";
269}
270
271function gotoMain() {
272 document.location.href = "tt-rss.php";
273}
274
8158c57a
AD
275function gotoExportOpml() {
276 document.location.href = "opml.php?op=Export";
277}
86741347
AD
278
279function getActiveFeedId() {
280 return getCookie("ttrss_vf_actfeed");
281}
282
283function setActiveFeedId(id) {
284 return setCookie("ttrss_vf_actfeed", id);
285}
090e250b
AD
286
287var 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.
293try {
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
304if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
305 xmlhttp_rpc = new XMLHttpRequest();
306}
307
308function label_counters_callback() {
309 if (xmlhttp_rpc.readyState == 4) {
bc18bcdd 310
9cab3250 311 if (!xmlhttp_rpc.responseXML) {
bc18bcdd
AD
312 notify("label_counters_callback: backend did not return valid XML");
313 return;
314 }
315
090e250b
AD
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);
392d4563 326 var feedr = f_document.getElementById("FEEDR-" + id);
090e250b 327
8143ae1f
AD
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 }
090e250b
AD
342 }
343 }
344}
345
8073cce7 346function update_label_counters(feed) {
090e250b 347 if (xmlhttp_ready(xmlhttp_rpc)) {
8143ae1f 348 var query = "backend.php?op=rpc&subop=getAllCounters";
e47cfe37
AD
349
350 if (feed > 0) {
351 query = query + "&aid=" + feed;
352 }
353
090e250b
AD
354 xmlhttp_rpc.open("GET", query, true);
355 xmlhttp_rpc.onreadystatechange=label_counters_callback;
356 xmlhttp_rpc.send(null);
357 }
358}
7dc66a61
AD
359
360function 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}
b6644d29
AD
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
3745788e
AD
399
400function 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
295f9b42
AD
419function fatalError(code) {
420 window.location = "error.php?c=" + param_escape(code);
3745788e 421
295f9b42 422}