]>
git.wh0rd.org - tt-rss.git/blob - viewfeed.js
1 var active_post_id
= false;
3 //var xmlhttp_rpc = Ajax.getTransport();
5 function headlines_callback() {
6 if (xmlhttp
.readyState
== 4) {
7 debug("headlines_callback");
8 var f
= document
.getElementById("headlines-frame");
9 f
.innerHTML
= xmlhttp
.responseText
;
10 update_all_counters();
15 function article_callback() {
16 if (xmlhttp
.readyState
== 4) {
17 debug("article_callback");
18 var f
= document
.getElementById("content-frame");
19 f
.innerHTML
= xmlhttp
.responseText
;
20 update_all_counters();
24 function view(id
, feed_id
) {
27 debug("loading article: " + id
+ "/" + feed_id
);
29 var f_document
= getFeedsContext().document
;
30 var m_document
= document
;
34 var crow
= document
.getElementById("RROW-" + id
);
36 crow
.className
= crow
.className
.replace("Unread", "");
38 cleanSelected("headlinesList");
40 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
43 upd_img_pic
.src
= "images/blank_icon.gif";
47 setActiveFeedId(feed_id
);
49 var content
= m_document
.getElementById("content-frame");
51 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
52 markHeadline(active_post_id
);
54 var query
= "backend.php?op=view&id=" + param_escape(id
) +
55 "&feed=" + param_escape(feed_id
);
57 if (xmlhttp_ready(xmlhttp
)) {
58 xmlhttp
.open("GET", query
, true);
59 xmlhttp
.onreadystatechange
=article_callback
;
62 debug("xmlhttp busy (@view)");
66 exception_error("view", e
);
70 function toggleMark(id
) {
72 var f_document
= document
;
74 if (!xmlhttp_ready(xmlhttp_rpc
)) {
79 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
81 var mark_img
= document
.getElementById("FMARKPIC-" + id
);
82 var vfeedu
= f_document
.getElementById("FEEDU--1");
83 var crow
= document
.getElementById("RROW-" + id
);
85 if (mark_img
.alt
!= "Reset mark") {
86 mark_img
.src
= "images/mark_set.png";
87 mark_img
.alt
= "Reset mark";
88 query
= query
+ "&mark=1";
90 if (vfeedu
&& crow
.className
.match("Unread")) {
91 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) + 1;
95 mark_img
.src
= "images/mark_unset.png";
96 mark_img
.alt
= "Set mark";
97 query
= query
+ "&mark=0";
99 if (vfeedu
&& crow
.className
.match("Unread")) {
100 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) - 1;
105 var vfeedctr
= f_document
.getElementById("FEEDCTR--1");
106 var vfeedr
= f_document
.getElementById("FEEDR--1");
108 if (vfeedu
&& vfeedctr
) {
109 if ((+vfeedu
.innerHTML
) > 0) {
110 if (crow
.className
.match("Unread") && !vfeedr
.className
.match("Unread")) {
111 vfeedr
.className
= vfeedr
.className
+ "Unread";
112 vfeedctr
.className
= "odd";
115 vfeedctr
.className
= "invisible";
116 vfeedr
.className
= vfeedr
.className
.replace("Unread", "");
120 debug("toggle starred for aid " + id
);
122 new Ajax
.Request(query
);
126 function moveToPost(mode
) {
128 // check for combined mode
129 if (!document
.getElementById("headlinesList"))
132 var rows
= getVisibleHeadlineIds();
137 if (active_post_id
== false) {
138 next_id
= getFirstVisibleHeadlineId();
139 prev_id
= getLastVisibleHeadlineId();
141 for (var i
= 0; i
< rows
.length
; i
++) {
142 if (rows
[i
] == active_post_id
) {
149 if (mode
== "next") {
150 if (next_id
!= undefined) {
151 view(next_id
, getActiveFeedId());
155 if (mode
== "prev") {
156 if ( prev_id
!= undefined) {
157 view(prev_id
, getActiveFeedId());
162 function toggleUnread(id
, cmode
) {
164 if (!xmlhttp_ready(xmlhttp_rpc
)) {
169 var row
= document
.getElementById("RROW-" + id
);
171 var nc
= row
.className
;
172 nc
= nc
.replace("Unread", "");
173 nc
= nc
.replace("Selected", "");
175 if (row
.className
.match("Unread")) {
178 row
.className
= nc
+ "Unread";
181 if (!cmode
) cmode
= 2;
183 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
184 param_escape(id
) + "&cmode=" + param_escape(cmode
);
186 xmlhttp_rpc
.open("GET", query
, true);
187 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
188 xmlhttp_rpc
.send(null);
194 exception_error("toggleUnread", e
);
198 function selectionToggleUnread(cdm_mode
, set_state
) {
200 if (!xmlhttp_ready(xmlhttp_rpc
)) {
208 rows
= cdmGetSelectedArticles();
210 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
213 for (i
= 0; i
< rows
.length
; i
++) {
214 var row
= document
.getElementById("RROW-" + rows
[i
]);
216 var nc
= row
.className
;
217 nc
= nc
.replace("Unread", "");
218 nc
= nc
.replace("Selected", "");
220 if (row
.className
.match("Unread")) {
221 row
.className
= nc
+ "Selected";
223 row
.className
= nc
+ "UnreadSelected";
228 if (rows
.length
> 0) {
232 if (set_state
== undefined) {
234 } else if (set_state
== true) {
236 } else if (set_state
== false) {
240 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
241 param_escape(rows
.toString()) + "&cmode=" + cmode
;
243 xmlhttp_rpc
.open("GET", query
, true);
244 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
245 xmlhttp_rpc
.send(null);
250 exception_error("selectionToggleUnread", e
);
254 function selectionToggleMarked(cdm_mode
) {
256 if (!xmlhttp_ready(xmlhttp_rpc
)) {
264 rows
= cdmGetSelectedArticles();
266 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
269 for (i
= 0; i
< rows
.length
; i
++) {
270 var row
= document
.getElementById("RROW-" + rows
[i
]);
271 var mark_img
= document
.getElementById("FMARKPIC-" + rows
[i
]);
273 if (row
&& mark_img
) {
275 if (mark_img
.alt
== "Set mark") {
276 mark_img
.src
= "images/mark_set.png";
277 mark_img
.alt
= "Reset mark";
278 mark_img
.setAttribute('onclick',
279 'javascript:toggleMark('+rows
[i
]+', false)');
282 mark_img
.src
= "images/mark_unset.png";
283 mark_img
.alt
= "Set mark";
284 mark_img
.setAttribute('onclick',
285 'javascript:toggleMark('+rows
[i
]+', true)');
290 if (rows
.length
> 0) {
292 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
293 param_escape(rows
.toString()) + "&cmode=2";
295 xmlhttp_rpc
.open("GET", query
, true);
296 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
297 xmlhttp_rpc
.send(null);
302 exception_error("selectionToggleMarked", e
);
306 function cdmGetSelectedArticles() {
307 var sel_articles
= new Array();
308 var container
= document
.getElementById("headlinesContainer");
310 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
311 var child
= container
.childNodes
[i
];
313 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
314 var c_id
= child
.id
.replace("RROW-", "");
315 sel_articles
.push(c_id
);
322 // mode = all,none,unread
323 function cdmSelectArticles(mode
) {
324 var container
= document
.getElementById("headlinesContainer");
326 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
327 var child
= container
.childNodes
[i
];
329 if (child
.id
.match("RROW-")) {
330 var aid
= child
.id
.replace("RROW-", "");
332 var cb
= document
.getElementById("RCHK-" + aid
);
335 if (!child
.className
.match("Selected")) {
336 child
.className
= child
.className
+ "Selected";
339 } else if (mode
== "unread") {
340 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
341 child
.className
= child
.className
+ "Selected";
345 child
.className
= child
.className
.replace("Selected", "");
352 function catchupPage() {
354 if (document
.getElementById("headlinesList")) {
355 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
356 selectionToggleUnread();
357 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
359 cdmSelectArticles('all');
360 selectionToggleUnread(true, false)
361 cdmSelectArticles('none');
365 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
367 if (!xmlhttp_ready(xmlhttp_rpc
)) {
371 var title
= prompt("Please enter label title:", "");
375 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
376 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
377 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
378 "&title=" + param_escape(title
);
380 debug("LFS: " + query
);
382 xmlhttp_rpc
.open("GET", query
, true);
383 xmlhttp_rpc
.onreadystatechange
=getMainContext().dlg_frefresh_callback
;
384 xmlhttp_rpc
.send(null);
391 function headlines_init() {
392 if (arguments
.callee
.done
) return;
393 arguments
.callee
.done
= true;
395 if (parent
.frames
["feeds-frame"]) {
396 document
.onkeydown
= hotkey_handler
;
399 var hl
= document
.getElementById("headlinesList");
402 hl
= document
.getElementById("headlinesContainer");
405 var hw
= hl
.scrollHeight
;
406 var pw
= parent
.document
.getElementById("headlines").scrollHeight
;
409 var bt
= document
.getElementById("headlineActionsBottom");
410 bt
.className
= "headlinesSubToolbar";