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