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