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