]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
patch (from h3) to connect to PGSQL through unix socket
[tt-rss.git] / tt-rss.js
1 /*
2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
4 */
5
6 var xmlhttp = false;
7
8 var total_unread = 0;
9 var first_run = true;
10
11 var search_query = "";
12
13 var display_tags = false;
14
15 /*@cc_on @*/
16 /*@if (@_jscript_version >= 5)
17 // JScript gives us Conditional compilation, we can cope with old IE versions.
18 // and security blocked creation of the objects.
19 try {
20 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
21 } catch (e) {
22 try {
23 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
24 } catch (E) {
25 xmlhttp = false;
26 }
27 }
28 @end @*/
29
30 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
31 xmlhttp = new XMLHttpRequest();
32 }
33
34 function toggleTags() {
35 display_tags = !display_tags;
36
37 var p = document.getElementById("dispSwitchPrompt");
38
39 if (display_tags) {
40 p.innerHTML = "display feeds";
41 } else {
42 p.innerHTML = "display tags";
43 }
44
45 updateFeedList();
46 }
47
48 /*
49 function feedlist_callback() {
50 var container = document.getElementById('feeds');
51 if (xmlhttp.readyState == 4) {
52 container.innerHTML=xmlhttp.responseText;
53
54 if (first_run) {
55 scheduleFeedUpdate(false);
56 if (getCookie("ttrss_vf_actfeed")) {
57 viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
58 }
59 first_run = false;
60 } else {
61 notify("");
62 }
63 }
64 }
65 */
66
67 function refetch_callback() {
68 if (xmlhttp.readyState == 4) {
69
70 document.title = "Tiny Tiny RSS";
71 notify("All feeds updated.");
72
73 var reply = xmlhttp.responseXML.firstChild;
74
75 var f_document = window.frames["feeds-frame"].document;
76
77 for (var l = 0; l < reply.childNodes.length; l++) {
78 var id = reply.childNodes[l].getAttribute("id");
79 var ctr = reply.childNodes[l].getAttribute("counter");
80
81 var feedctr = f_document.getElementById("FEEDCTR-" + id);
82 var feedu = f_document.getElementById("FEEDU-" + id);
83 var feedr = f_document.getElementById("FEEDR-" + id);
84
85 if (feedctr && feedu && feedr) {
86
87 feedu.innerHTML = ctr;
88
89 if (ctr > 0) {
90 feedctr.className = "odd";
91 if (!feedr.className.match("Unread")) {
92 feedr.className = feedr.className + "Unread";
93 }
94 } else {
95 feedctr.className = "invisible";
96 feedr.className = feedr.className.replace("Unread", "");
97 }
98 }
99 }
100 }
101 }
102
103 function updateFeed(feed_id) {
104
105 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
106
107 if (xmlhttp_ready(xmlhttp)) {
108 xmlhttp.open("GET", query_str, true);
109 xmlhttp.onreadystatechange=feed_update_callback;
110 xmlhttp.send(null);
111 } else {
112 printLockingError();
113 }
114
115 }
116
117 function scheduleFeedUpdate(force) {
118
119 notify("Updating feeds in background...");
120
121 document.title = "Tiny Tiny RSS - Updating...";
122
123 var query_str = "backend.php?op=rpc&subop=";
124
125 if (force) {
126 query_str = query_str + "forceUpdateAllFeeds";
127 } else {
128 query_str = query_str + "updateAllFeeds";
129 }
130
131 if (xmlhttp_ready(xmlhttp)) {
132 xmlhttp.open("GET", query_str, true);
133 xmlhttp.onreadystatechange=refetch_callback;
134 xmlhttp.send(null);
135 } else {
136 printLockingError();
137 }
138 }
139
140 function updateFeedList(silent, fetch) {
141
142 // if (silent != true) {
143 // notify("Loading feed list...");
144 // }
145
146 var query_str = "backend.php?op=feeds";
147
148 if (display_tags) {
149 query_str = query_str + "&tags=1";
150 }
151
152 if (getActiveFeedId()) {
153 query_str = query_str + "&actid=" + getActiveFeedId();
154 }
155
156 if (fetch) query_str = query_str + "&fetch=yes";
157
158 var feeds_frame = document.getElementById("feeds-frame");
159
160 feeds_frame.src = query_str;
161 }
162
163 function catchupAllFeeds() {
164
165 var query_str = "backend.php?op=feeds&subop=catchupAll";
166
167 notify("Marking all feeds as read...");
168
169 var feeds_frame = document.getElementById("feeds-frame");
170
171 feeds_frame.src = query_str;
172
173 }
174
175 function viewCurrentFeed(skip, subop) {
176
177 if (getActiveFeedId()) {
178 viewfeed(getActiveFeedId(), skip, subop);
179 }
180 }
181
182 function viewfeed(feed, skip, subop) {
183
184 // notify("Loading headlines...");
185
186 enableHotkeys();
187
188 var searchbox = document.getElementById("searchbox");
189
190 if (searchbox) {
191 search_query = searchbox.value;
192 } else {
193 search_query = "";
194 }
195
196 var viewbox = document.getElementById("viewbox");
197
198 var view_mode;
199
200 if (viewbox) {
201 view_mode = viewbox[viewbox.selectedIndex].text;
202 } else {
203 view_mode = "All Posts";
204 }
205
206 setCookie("ttrss_vf_vmode", view_mode);
207
208 var limitbox = document.getElementById("limitbox");
209
210 var limit;
211
212 if (limitbox) {
213 limit = limitbox[limitbox.selectedIndex].text;
214 setCookie("ttrss_vf_limit", limit);
215 } else {
216 limit = "All";
217 }
218
219 setActiveFeedId(feed);
220
221 var f_doc = frames["feeds-frame"].document;
222
223 // f_doc.getElementById("ACTFEEDID").innerHTML = feed;
224
225 if (subop == "MarkAllRead") {
226
227 var feedr = f_doc.getElementById("FEEDR-" + feed);
228 var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
229
230 feedctr.className = "invisible";
231
232 if (feedr.className.match("Unread")) {
233 feedr.className = feedr.className.replace("Unread", "");
234 }
235 }
236
237 var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
238 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
239 "&view=" + param_escape(view_mode) + "&limit=" + limit;
240
241 if (search_query != "") {
242 query = query + "&search=" + param_escape(search_query);
243 }
244
245 var headlines_frame = parent.frames["headlines-frame"];
246
247 headlines_frame.location.href = query + "&addheader=true";
248
249 cleanSelected("feedsList");
250 var feedr = document.getElementById("FEEDR-" + feed);
251 if (feedr) {
252 feedr.className = feedr.className + "Selected";
253 }
254
255 disableContainerChildren("headlinesToolbar", false, doc);
256
257 // notify("");
258
259 }
260
261
262 function timeout() {
263 scheduleFeedUpdate(true);
264 setTimeout("timeout()", 1800*1000);
265 }
266
267 function resetSearch() {
268 var searchbox = document.getElementById("searchbox")
269
270 if (searchbox.value != "" && getActiveFeedId()) {
271 searchbox.value = "";
272 viewfeed(getActiveFeedId(), 0, "");
273 }
274 }
275
276 function search() {
277 viewCurrentFeed(0, "");
278 }
279
280 function localPiggieFunction(enable) {
281 if (enable) {
282 var query_str = "backend.php?op=feeds&subop=piggie";
283
284 if (xmlhttp_ready(xmlhttp)) {
285
286 xmlhttp.open("GET", query_str, true);
287 xmlhttp.onreadystatechange=feedlist_callback;
288 xmlhttp.send(null);
289 }
290 }
291 }
292
293 function localHotkeyHandler(keycode) {
294
295 /* if (keycode == 78) {
296 return moveToPost('next');
297 }
298
299 if (keycode == 80) {
300 return moveToPost('prev');
301 } */
302
303 if (keycode == 82) {
304 return scheduleFeedUpdate(true);
305 }
306
307 if (keycode == 85) {
308 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
309 }
310
311 // notify("KC: " + keycode);
312
313 }
314
315 function genericSanityCheck() {
316
317 if (!xmlhttp) {
318 document.getElementById("headlines").innerHTML =
319 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
320 "to function properly. Your browser doesn't seem to support it.";
321 return false;
322 }
323
324 setCookie("ttrss_vf_test", "TEST");
325 if (getCookie("ttrss_vf_test") != "TEST") {
326
327 document.getElementById("headlines").innerHTML =
328 "<b>Fatal error:</b> This program requires cookies " +
329 "to function properly. Your browser doesn't seem to support them.";
330
331 return false;
332 }
333
334 return true;
335 }
336
337 function init() {
338
339 disableContainerChildren("headlinesToolbar", true);
340
341 if (!genericSanityCheck())
342 return;
343
344 updateFeedList(false, false);
345 document.onkeydown = hotkey_handler;
346
347 setTimeout("timeout()", 1800*1000);
348 scheduleFeedUpdate(true);
349
350 var content = document.getElementById("content");
351
352 if (getCookie("ttrss_vf_vmode")) {
353 var viewbox = document.getElementById("viewbox");
354 viewbox.value = getCookie("ttrss_vf_vmode");
355 }
356
357 if (getCookie("ttrss_vf_limit")) {
358 var limitbox = document.getElementById("limitbox");
359 limitbox.value = getCookie("ttrss_vf_limit");
360 }
361
362 // if (getCookie("ttrss_vf_actfeed")) {
363 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
364 // }
365
366 setCookie("ttrss_vf_actfeed", "");
367
368 }
369
370