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