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