]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
mark headlines page as read now works (via rpc)
[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
10 /*@cc_on @*/
11 /*@if (@_jscript_version >= 5)
12 // JScript gives us Conditional compilation, we can cope with old IE versions.
13 // and security blocked creation of the objects.
14 try {
15 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
16 } catch (e) {
17 try {
18 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
19 } catch (E) {
20 xmlhttp = false;
21 }
22 }
23 @end @*/
24
25 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
26 xmlhttp = new XMLHttpRequest();
27 }
28
29 function notify_callback() {
30 var container = document.getElementById('notify');
31 if (xmlhttp.readyState == 4) {
32 container.innerHTML=xmlhttp.responseText;
33 }
34 }
35
36 function feedlist_callback() {
37 var container = document.getElementById('feeds');
38 if (xmlhttp.readyState == 4) {
39 container.innerHTML=xmlhttp.responseText;
40
41 var feedtu = document.getElementById("FEEDTU");
42
43 if (feedtu) {
44 total_unread = feedtu.innerHTML;
45 update_title();
46 }
47
48 notify("");
49 }
50 }
51
52 function viewfeed_callback() {
53 var container = document.getElementById('headlines');
54 if (xmlhttp.readyState == 4) {
55 container.innerHTML = xmlhttp.responseText;
56
57 var factive = document.getElementById("FACTIVE");
58 var funread = document.getElementById("FUNREAD");
59 var ftotal = document.getElementById("FTOTAL");
60
61 if (ftotal && factive && funread) {
62 var feed_id = factive.innerHTML;
63
64 var feedr = document.getElementById("FEEDR-" + feed_id);
65 var feedt = document.getElementById("FEEDT-" + feed_id);
66 var feedu = document.getElementById("FEEDU-" + feed_id);
67
68 feedt.innerHTML = ftotal.innerHTML;
69 feedu.innerHTML = funread.innerHTML;
70
71 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
72 feedr.className = feedr.className + "Unread";
73 } else if (feedu.innerHTML <= 0) {
74 feedr.className = feedr.className.replace("Unread", "");
75 }
76
77 }
78
79 notify("");
80
81 }
82 }
83
84 function view_callback() {
85 var container = document.getElementById('content');
86 if (xmlhttp.readyState == 4) {
87 container.innerHTML=xmlhttp.responseText;
88 }
89 }
90
91
92 function updateFeedList(called_from_timer, fetch) {
93
94 if (called_from_timer != true) {
95 //document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
96 notify("Updating feeds...");
97 }
98
99 var query_str = "backend.php?op=feeds";
100
101 if (fetch) query_str = query_str + "&fetch=yes";
102
103 xmlhttp.open("GET", query_str, true);
104 xmlhttp.onreadystatechange=feedlist_callback;
105 xmlhttp.send(null);
106
107 }
108
109 function catchupPage(feed) {
110
111 var content = document.getElementById("headlinesList");
112
113 var rows = new Array();
114
115 for (i = 0; i < content.rows.length; i++) {
116 var row_id = content.rows[i].id.replace("RROW-", "");
117 if (row_id.length > 0) {
118 rows.push(row_id);
119 content.rows[i].className = content.rows[i].className.replace("Unread", "");
120 }
121 }
122
123 var feedr = document.getElementById("FEEDR-" + feed);
124 var feedu = document.getElementById("FEEDU-" + feed);
125
126 feedu.innerHTML = feedu.innerHTML - rows.length;
127
128 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
129 feedr.className = feedr.className + "Unread";
130 } else if (feedu.innerHTML <= 0) {
131 feedr.className = feedr.className.replace("Unread", "");
132 }
133
134 var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" +
135 param_escape(rows.toString());
136
137 notify("Marking this page as read...");
138
139 xmlhttp.open("GET", query_str, true);
140 xmlhttp.onreadystatechange=notify_callback;
141 xmlhttp.send(null);
142
143 }
144
145 function catchupAllFeeds() {
146 var query_str = "backend.php?op=feeds&subop=catchupAll";
147
148 notify("Marking all feeds as read...");
149
150 xmlhttp.open("GET", query_str, true);
151 xmlhttp.onreadystatechange=feedlist_callback;
152 xmlhttp.send(null);
153
154 }
155
156 function viewfeed(feed, skip, subop) {
157
158 // document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
159 // document.getElementById('content').innerHTML='&nbsp;';
160
161 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
162 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
163 xmlhttp.onreadystatechange=viewfeed_callback;
164 xmlhttp.send(null);
165
166 notify("Loading headlines...");
167
168 }
169
170 function view(id,feed_id) {
171
172 var crow = document.getElementById("RROW-" + id);
173
174 if (crow.className.match("Unread")) {
175 var umark = document.getElementById("FEEDU-" + feed_id);
176 umark.innerHTML = umark.innerHTML - 1;
177 crow.className = crow.className.replace("Unread", "");
178
179 if (umark.innerHTML == "0") {
180 var feedr = document.getElementById("FEEDR-" + feed_id);
181 feedr.className = feedr.className.replace("Unread", "");
182 }
183
184 total_unread--;
185
186 update_title();
187 }
188
189 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
190
191 if (upd_img_pic) {
192 upd_img_pic.innerHTML = "";
193 }
194
195 document.getElementById('content').innerHTML='Loading, please wait...';
196
197 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
198 xmlhttp.onreadystatechange=view_callback;
199 xmlhttp.send(null);
200
201 }
202
203 function timeout() {
204
205 updateFeedList(true, true);
206
207 setTimeout("timeout()", 1800*1000);
208
209 }
210
211 function search(feed, sender) {
212
213 notify("Search: " + feed + ", " + sender.value)
214
215 document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
216 document.getElementById('content').innerHTML='&nbsp;';
217
218 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
219 "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
220 xmlhttp.onreadystatechange=viewfeed_callback;
221 xmlhttp.send(null);
222
223 }
224
225 function update_title() {
226 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
227 }
228
229 function init() {
230 updateFeedList(false, false);
231 setTimeout("timeout()", 1800*1000);
232 }