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