]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
mark headlines page as read now works (via rpc)
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
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
6var xmlhttp = false;
7
76798ff3
AD
8var total_unread = 0;
9
1cd17194
AD
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.
14try {
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
25if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
26 xmlhttp = new XMLHttpRequest();
27}
28
175847de
AD
29function notify_callback() {
30 var container = document.getElementById('notify');
31 if (xmlhttp.readyState == 4) {
32 container.innerHTML=xmlhttp.responseText;
33 }
34}
35
1cd17194 36function feedlist_callback() {
d76a3b03 37 var container = document.getElementById('feeds');
1cd17194 38 if (xmlhttp.readyState == 4) {
d76a3b03 39 container.innerHTML=xmlhttp.responseText;
76798ff3
AD
40
41 var feedtu = document.getElementById("FEEDTU");
42
43 if (feedtu) {
44 total_unread = feedtu.innerHTML;
45 update_title();
46 }
476cac42
AD
47
48 notify("");
1cd17194
AD
49 }
50}
51
52function viewfeed_callback() {
d76a3b03 53 var container = document.getElementById('headlines');
1cd17194 54 if (xmlhttp.readyState == 4) {
d76a3b03 55 container.innerHTML = xmlhttp.responseText;
a1a8a2be
AD
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 }
1c37c607
AD
78
79 notify("");
80
81 }
1cd17194
AD
82}
83
84function view_callback() {
d76a3b03 85 var container = document.getElementById('content');
1cd17194 86 if (xmlhttp.readyState == 4) {
d76a3b03 87 container.innerHTML=xmlhttp.responseText;
1cd17194
AD
88 }
89}
90
91
476cac42 92function updateFeedList(called_from_timer, fetch) {
1cd17194 93
40d13c28 94 if (called_from_timer != true) {
476cac42
AD
95 //document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
96 notify("Updating feeds...");
40d13c28 97 }
82baad4a 98
331900c6
AD
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);
1cd17194
AD
104 xmlhttp.onreadystatechange=feedlist_callback;
105 xmlhttp.send(null);
106
107}
108
175847de
AD
109function 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
476cac42
AD
145function 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}
1cd17194 155
476cac42 156function viewfeed(feed, skip, subop) {
1cd17194 157
1c37c607
AD
158// document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
159// document.getElementById('content').innerHTML='&nbsp;';
d76a3b03
AD
160
161 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
476cac42 162 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
1cd17194
AD
163 xmlhttp.onreadystatechange=viewfeed_callback;
164 xmlhttp.send(null);
165
1c37c607
AD
166 notify("Loading headlines...");
167
1cd17194
AD
168}
169
a1a8a2be 170function view(id,feed_id) {
d76a3b03
AD
171
172 var crow = document.getElementById("RROW-" + id);
173
a1a8a2be
AD
174 if (crow.className.match("Unread")) {
175 var umark = document.getElementById("FEEDU-" + feed_id);
176 umark.innerHTML = umark.innerHTML - 1;
d76a3b03 177 crow.className = crow.className.replace("Unread", "");
d76a3b03 178
a1a8a2be
AD
179 if (umark.innerHTML == "0") {
180 var feedr = document.getElementById("FEEDR-" + feed_id);
181 feedr.className = feedr.className.replace("Unread", "");
182 }
b197f117 183
76798ff3
AD
184 total_unread--;
185
b197f117 186 update_title();
76798ff3 187 }
1cd17194 188
b197f117
AD
189 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
190
191 if (upd_img_pic) {
192 upd_img_pic.innerHTML = "";
193 }
194
d76a3b03 195 document.getElementById('content').innerHTML='Loading, please wait...';
1cd17194 196
d76a3b03 197 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
1cd17194
AD
198 xmlhttp.onreadystatechange=view_callback;
199 xmlhttp.send(null);
200
201}
202
40d13c28
AD
203function timeout() {
204
5d348fee 205 updateFeedList(true, true);
40d13c28 206
ac53063a
AD
207 setTimeout("timeout()", 1800*1000);
208
209}
210
211function 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);
40d13c28
AD
222
223}
224
76798ff3
AD
225function update_title() {
226 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
227}
1cd17194 228
76798ff3 229function init() {
476cac42 230 updateFeedList(false, false);
ac53063a 231 setTimeout("timeout()", 1800*1000);
1cd17194 232}