]>
Commit | Line | Data |
---|---|---|
1 | var active_post_id = false; | |
2 | var total_unread = 0; | |
3 | ||
4 | var xmlhttp_rpc = false; | |
5 | ||
6 | /*@cc_on @*/ | |
7 | /*@if (@_jscript_version >= 5) | |
8 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
9 | // and security blocked creation of the objects. | |
10 | try { | |
11 | xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP"); | |
12 | } catch (e) { | |
13 | try { | |
14 | xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); | |
15 | } catch (E) { | |
16 | xmlhttp_rpc = false; | |
17 | } | |
18 | } | |
19 | @end @*/ | |
20 | ||
21 | if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') { | |
22 | xmlhttp_rpc = new XMLHttpRequest(); | |
23 | } | |
24 | ||
25 | function view(id, feed_id) { | |
26 | ||
27 | // p_notify("Loading article..."); | |
28 | ||
29 | var f_document = parent.frames["feeds-frame"].document; | |
30 | var h_document = document; | |
31 | var m_document = parent.document; | |
32 | ||
33 | enableHotkeys(); | |
34 | ||
35 | var crow = h_document.getElementById("RROW-" + id); | |
36 | ||
37 | /* if (crow.className.match("Unread")) { | |
38 | var umark = f_document.getElementById("FEEDU-" + feed_id); | |
39 | ||
40 | umark.innerHTML = umark.innerHTML - 1; | |
41 | crow.className = crow.className.replace("Unread", ""); | |
42 | ||
43 | if (umark.innerHTML == "0") { | |
44 | var feedr = f_document.getElementById("FEEDR-" + feed_id); | |
45 | feedr.className = feedr.className.replace("Unread", ""); | |
46 | ||
47 | var feedctr = f_document.getElementById("FEEDCTR-" + feed_id); | |
48 | ||
49 | if (feedctr) { | |
50 | feedctr.className = "invisible"; | |
51 | } | |
52 | } | |
53 | ||
54 | total_unread--; | |
55 | } */ | |
56 | ||
57 | crow.className = crow.className.replace("Unread", ""); | |
58 | ||
59 | cleanSelected("headlinesList"); | |
60 | ||
61 | var upd_img_pic = h_document.getElementById("FUPDPIC-" + id); | |
62 | ||
63 | if (upd_img_pic) { | |
64 | upd_img_pic.src = "images/blank_icon.gif"; | |
65 | } | |
66 | ||
67 | active_post_id = id; | |
68 | setActiveFeedId(feed_id); | |
69 | ||
70 | var content = m_document.getElementById("content-frame"); | |
71 | ||
72 | if (content) { | |
73 | content.src = "backend.php?op=view&addheader=true&id=" + param_escape(id) + | |
74 | "&feed=" + param_escape(feed_id); | |
75 | markHeadline(active_post_id); | |
76 | } | |
77 | ||
78 | } | |
79 | ||
80 | function toggleMark(id) { | |
81 | ||
82 | var f_document = parent.frames["feeds-frame"].document; | |
83 | ||
84 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
85 | printLockingError(); | |
86 | return; | |
87 | } | |
88 | ||
89 | var query = "backend.php?op=rpc&id=" + id + "&subop=mark"; | |
90 | ||
91 | var mark_img = document.getElementById("FMARKPIC-" + id); | |
92 | var vfeedu = f_document.getElementById("FEEDU--1"); | |
93 | var crow = document.getElementById("RROW-" + id); | |
94 | ||
95 | // alert(vfeedu); | |
96 | ||
97 | if (mark_img.alt != "Reset mark") { | |
98 | mark_img.src = "images/mark_set.png"; | |
99 | mark_img.alt = "Reset mark"; | |
100 | mark_img.setAttribute('onclick', 'javascript:toggleMark('+id+')'); | |
101 | query = query + "&mark=1"; | |
102 | ||
103 | if (vfeedu && crow.className.match("Unread")) { | |
104 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; | |
105 | } | |
106 | ||
107 | } else { | |
108 | mark_img.src = "images/mark_unset.png"; | |
109 | mark_img.alt = "Set mark"; | |
110 | mark_img.setAttribute('onclick', 'javascript:toggleMark('+id+')'); | |
111 | query = query + "&mark=0"; | |
112 | ||
113 | if (vfeedu && crow.className.match("Unread")) { | |
114 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; | |
115 | } | |
116 | ||
117 | } | |
118 | ||
119 | var vfeedctr = f_document.getElementById("FEEDCTR--1"); | |
120 | var vfeedr = f_document.getElementById("FEEDR--1"); | |
121 | ||
122 | if (vfeedu && vfeedctr) { | |
123 | if ((+vfeedu.innerHTML) > 0) { | |
124 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { | |
125 | vfeedr.className = vfeedr.className + "Unread"; | |
126 | vfeedctr.className = "odd"; | |
127 | } | |
128 | } else { | |
129 | vfeedctr.className = "invisible"; | |
130 | vfeedr.className = vfeedr.className.replace("Unread", ""); | |
131 | } | |
132 | } | |
133 | ||
134 | xmlhttp_rpc.open("GET", query, true); | |
135 | xmlhttp_rpc.onreadystatechange=rpc_pnotify_callback; | |
136 | xmlhttp_rpc.send(null); | |
137 | ||
138 | } | |
139 | ||
140 | function moveToPost(mode) { | |
141 | ||
142 | // check for combined mode | |
143 | if (!document.getElementById("headlinesList")) | |
144 | return; | |
145 | ||
146 | var rows = getVisibleHeadlineIds(); | |
147 | ||
148 | var prev_id; | |
149 | var next_id; | |
150 | ||
151 | if (active_post_id == false) { | |
152 | next_id = getFirstVisibleHeadlineId(); | |
153 | prev_id = getLastVisibleHeadlineId(); | |
154 | } else { | |
155 | for (var i = 0; i < rows.length; i++) { | |
156 | if (rows[i] == active_post_id) { | |
157 | prev_id = rows[i-1]; | |
158 | next_id = rows[i+1]; | |
159 | } | |
160 | } | |
161 | } | |
162 | ||
163 | if (mode == "next") { | |
164 | if (next_id != undefined) { | |
165 | view(next_id, getActiveFeedId()); | |
166 | } | |
167 | } | |
168 | ||
169 | if (mode == "prev") { | |
170 | if ( prev_id != undefined) { | |
171 | view(prev_id, getActiveFeedId()); | |
172 | } | |
173 | } | |
174 | } | |
175 | ||
176 | function viewfeed(id) { | |
177 | var f = parent.frames["feeds-frame"]; | |
178 | f.viewfeed(id, 0); | |
179 | } | |
180 | ||
181 | function localHotkeyHandler(keycode) { | |
182 | ||
183 | if (keycode == 78 || keycode == 40) { // n, down | |
184 | return moveToPost('next'); | |
185 | } | |
186 | ||
187 | if (keycode == 80 || keycode == 38) { // p, up | |
188 | return moveToPost('prev'); | |
189 | } | |
190 | ||
191 | if (keycode == 65) { // a | |
192 | return parent.toggleDispRead(); | |
193 | } | |
194 | ||
195 | if (keycode == 85) { // u | |
196 | if (parent.getActiveFeedId()) { | |
197 | return parent.viewfeed(parent.getActiveFeedId(), 0, "ForceUpdate"); | |
198 | } | |
199 | } | |
200 | ||
201 | if (keycode == 82) { // r | |
202 | return parent.scheduleFeedUpdate(true); | |
203 | } | |
204 | ||
205 | var f_doc = parent.frames["feeds-frame"].document; | |
206 | var feedlist = f_doc.getElementById('feedList'); | |
207 | ||
208 | if (keycode == 74) { // j | |
209 | var feed = getActiveFeedId(); | |
210 | var new_feed = getRelativeFeedId(feedlist, feed, 'prev'); | |
211 | if (new_feed) viewfeed(new_feed, 0, ''); | |
212 | } | |
213 | ||
214 | if (keycode == 75) { // k | |
215 | var feed = getActiveFeedId(); | |
216 | var new_feed = getRelativeFeedId(feedlist, feed, 'next'); | |
217 | if (new_feed) viewfeed(new_feed, 0, ''); | |
218 | } | |
219 | ||
220 | // FIXME | |
221 | // if (keycode == 85) { | |
222 | // return viewfeed(active_feed_id, active_offset, "ForceUpdate"); | |
223 | // } | |
224 | ||
225 | if (keycode == 83) { // s | |
226 | selectionToggleMarked(); | |
227 | } | |
228 | ||
229 | // alert("KC: " + keycode); | |
230 | ||
231 | } | |
232 | ||
233 | function selectionToggleUnread(cdm_mode) { | |
234 | try { | |
235 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
236 | printLockingError(); | |
237 | return; | |
238 | } | |
239 | ||
240 | var rows; | |
241 | ||
242 | if (cdm_mode) { | |
243 | rows = cdmGetSelectedArticles(); | |
244 | } else { | |
245 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
246 | } | |
247 | ||
248 | for (i = 0; i < rows.length; i++) { | |
249 | var row = document.getElementById("RROW-" + rows[i]); | |
250 | if (row) { | |
251 | var nc = row.className; | |
252 | nc = nc.replace("Unread", ""); | |
253 | nc = nc.replace("Selected", ""); | |
254 | ||
255 | if (row.className.match("Unread")) { | |
256 | row.className = nc + "Selected"; | |
257 | } else { | |
258 | row.className = nc + "UnreadSelected"; | |
259 | } | |
260 | } | |
261 | } | |
262 | ||
263 | if (rows.length > 0) { | |
264 | ||
265 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
266 | param_escape(rows.toString()) + "&cmode=2"; | |
267 | ||
268 | xmlhttp_rpc.open("GET", query, true); | |
269 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
270 | xmlhttp_rpc.send(null); | |
271 | ||
272 | } | |
273 | ||
274 | } catch (e) { | |
275 | exception_error("selectionToggleUnread", e); | |
276 | } | |
277 | } | |
278 | ||
279 | function selectionToggleMarked(cdm_mode) { | |
280 | try { | |
281 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
282 | printLockingError(); | |
283 | return; | |
284 | } | |
285 | ||
286 | var rows; | |
287 | ||
288 | if (cdm_mode) { | |
289 | rows = cdmGetSelectedArticles(); | |
290 | } else { | |
291 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
292 | } | |
293 | ||
294 | for (i = 0; i < rows.length; i++) { | |
295 | var row = document.getElementById("RROW-" + rows[i]); | |
296 | var mark_img = document.getElementById("FMARKPIC-" + rows[i]); | |
297 | ||
298 | if (row && mark_img) { | |
299 | ||
300 | if (mark_img.alt == "Set mark") { | |
301 | mark_img.src = "images/mark_set.png"; | |
302 | mark_img.alt = "Reset mark"; | |
303 | mark_img.setAttribute('onclick', | |
304 | 'javascript:toggleMark('+rows[i]+', false)'); | |
305 | ||
306 | } else { | |
307 | mark_img.src = "images/mark_unset.png"; | |
308 | mark_img.alt = "Set mark"; | |
309 | mark_img.setAttribute('onclick', | |
310 | 'javascript:toggleMark('+rows[i]+', true)'); | |
311 | } | |
312 | } | |
313 | } | |
314 | ||
315 | if (rows.length > 0) { | |
316 | ||
317 | var query = "backend.php?op=rpc&subop=markSelected&ids=" + | |
318 | param_escape(rows.toString()) + "&cmode=2"; | |
319 | ||
320 | xmlhttp_rpc.open("GET", query, true); | |
321 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
322 | xmlhttp_rpc.send(null); | |
323 | ||
324 | } | |
325 | ||
326 | } catch (e) { | |
327 | exception_error("selectionToggleMarked", e); | |
328 | } | |
329 | } | |
330 | ||
331 | function cdmGetSelectedArticles() { | |
332 | var sel_articles = new Array(); | |
333 | var container = document.getElementById("headlinesContainer"); | |
334 | ||
335 | for (i = 0; i < container.childNodes.length; i++) { | |
336 | var child = container.childNodes[i]; | |
337 | ||
338 | if (child.id.match("RROW-") && child.className.match("Selected")) { | |
339 | var c_id = child.id.replace("RROW-", ""); | |
340 | sel_articles.push(c_id); | |
341 | } | |
342 | } | |
343 | ||
344 | return sel_articles; | |
345 | } | |
346 | ||
347 | // mode = all,none,unread | |
348 | function cdmSelectArticles(mode) { | |
349 | var container = document.getElementById("headlinesContainer"); | |
350 | ||
351 | for (i = 0; i < container.childNodes.length; i++) { | |
352 | var child = container.childNodes[i]; | |
353 | ||
354 | if (child.id.match("RROW-")) { | |
355 | // var aid = child.id.replace("RROW-", ""); | |
356 | if (mode == "all") { | |
357 | if (!child.className.match("Selected")) { | |
358 | child.className = child.className + "Selected"; | |
359 | } | |
360 | } else if (mode == "unread") { | |
361 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
362 | child.className = child.className + "Selected"; | |
363 | } | |
364 | } else { | |
365 | child.className = child.className.replace("Selected", ""); | |
366 | } | |
367 | } | |
368 | } | |
369 | } | |
370 | ||
371 | function init() { | |
372 | document.onkeydown = hotkey_handler; | |
373 | } |