]>
git.wh0rd.org - tt-rss.git/blob - viewfeed.js
1 var active_post_id
= false;
3 function headlines_callback() {
4 if (xmlhttp
.readyState
== 4) {
5 debug("headlines_callback");
6 var f
= document
.getElementById("headlines-frame");
7 f
.innerHTML
= xmlhttp
.responseText
;
9 if (typeof correctPNG
!= 'undefined') {
16 function article_callback() {
17 if (xmlhttp
.readyState
== 4) {
18 debug("article_callback");
19 var f
= document
.getElementById("content-frame");
20 f
.innerHTML
= xmlhttp
.responseText
;
21 if (typeof correctPNG
!= 'undefined') {
24 update_all_counters();
28 function view(id
, feed_id
) {
31 debug("loading article: " + id
+ "/" + feed_id
);
33 var f_document
= getFeedsContext().document
;
34 var m_document
= document
;
38 var crow
= document
.getElementById("RROW-" + id
);
40 crow
.className
= crow
.className
.replace("Unread", "");
42 cleanSelected("headlinesList");
44 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
47 upd_img_pic
.src
= "images/blank_icon.gif";
51 setActiveFeedId(feed_id
);
53 var content
= m_document
.getElementById("content-frame");
55 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
56 markHeadline(active_post_id
);
58 var query
= "backend.php?op=view&id=" + param_escape(id
) +
59 "&feed=" + param_escape(feed_id
);
61 if (xmlhttp_ready(xmlhttp
)) {
62 xmlhttp
.open("GET", query
, true);
63 xmlhttp
.onreadystatechange
=article_callback
;
66 debug("xmlhttp busy (@view)");
70 exception_error("view", e
);
74 function toggleMark(id
) {
76 var f_document
= document
;
78 if (!xmlhttp_ready(xmlhttp_rpc
)) {
83 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
85 var mark_img
= document
.getElementById("FMARKPIC-" + id
);
86 var vfeedu
= f_document
.getElementById("FEEDU--1");
87 var crow
= document
.getElementById("RROW-" + id
);
89 if (mark_img
.alt
!= "Reset mark") {
90 mark_img
.src
= "images/mark_set.png";
91 mark_img
.alt
= "Reset mark";
92 query
= query
+ "&mark=1";
94 if (vfeedu
&& crow
.className
.match("Unread")) {
95 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) + 1;
99 mark_img
.src
= "images/mark_unset.png";
100 mark_img
.alt
= "Set mark";
101 query
= query
+ "&mark=0";
103 if (vfeedu
&& crow
.className
.match("Unread")) {
104 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) - 1;
109 var vfeedctr
= f_document
.getElementById("FEEDCTR--1");
110 var vfeedr
= f_document
.getElementById("FEEDR--1");
112 if (vfeedu
&& vfeedctr
) {
113 if ((+vfeedu
.innerHTML
) > 0) {
114 if (crow
.className
.match("Unread") && !vfeedr
.className
.match("Unread")) {
115 vfeedr
.className
= vfeedr
.className
+ "Unread";
116 vfeedctr
.className
= "odd";
119 vfeedctr
.className
= "invisible";
120 vfeedr
.className
= vfeedr
.className
.replace("Unread", "");
124 debug("toggle starred for aid " + id
);
126 new Ajax
.Request(query
);
130 function moveToPost(mode
) {
132 // check for combined mode
133 if (!document
.getElementById("headlinesList"))
136 var rows
= getVisibleHeadlineIds();
141 if (active_post_id
== false) {
142 next_id
= getFirstVisibleHeadlineId();
143 prev_id
= getLastVisibleHeadlineId();
145 for (var i
= 0; i
< rows
.length
; i
++) {
146 if (rows
[i
] == active_post_id
) {
153 if (mode
== "next") {
154 if (next_id
!= undefined) {
155 view(next_id
, getActiveFeedId());
159 if (mode
== "prev") {
160 if ( prev_id
!= undefined) {
161 view(prev_id
, getActiveFeedId());
166 function toggleUnread(id
, cmode
) {
168 if (!xmlhttp_ready(xmlhttp_rpc
)) {
173 var row
= document
.getElementById("RROW-" + id
);
175 var nc
= row
.className
;
176 nc
= nc
.replace("Unread", "");
177 nc
= nc
.replace("Selected", "");
179 if (row
.className
.match("Unread")) {
182 row
.className
= nc
+ "Unread";
185 if (!cmode
) cmode
= 2;
187 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
188 param_escape(id
) + "&cmode=" + param_escape(cmode
);
190 xmlhttp_rpc
.open("GET", query
, true);
191 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
192 xmlhttp_rpc
.send(null);
198 exception_error("toggleUnread", e
);
202 function selectionToggleUnread(cdm_mode
, set_state
) {
204 if (!xmlhttp_ready(xmlhttp_rpc
)) {
212 rows
= cdmGetSelectedArticles();
214 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
217 for (i
= 0; i
< rows
.length
; i
++) {
218 var row
= document
.getElementById("RROW-" + rows
[i
]);
220 var nc
= row
.className
;
221 nc
= nc
.replace("Unread", "");
222 nc
= nc
.replace("Selected", "");
224 if (row
.className
.match("Unread")) {
225 row
.className
= nc
+ "Selected";
227 row
.className
= nc
+ "UnreadSelected";
232 if (rows
.length
> 0) {
236 if (set_state
== undefined) {
238 } else if (set_state
== true) {
240 } else if (set_state
== false) {
244 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
245 param_escape(rows
.toString()) + "&cmode=" + cmode
;
247 xmlhttp_rpc
.open("GET", query
, true);
248 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
249 xmlhttp_rpc
.send(null);
254 exception_error("selectionToggleUnread", e
);
258 function selectionToggleMarked(cdm_mode
) {
260 if (!xmlhttp_ready(xmlhttp_rpc
)) {
268 rows
= cdmGetSelectedArticles();
270 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
273 for (i
= 0; i
< rows
.length
; i
++) {
274 var row
= document
.getElementById("RROW-" + rows
[i
]);
275 var mark_img
= document
.getElementById("FMARKPIC-" + rows
[i
]);
277 if (row
&& mark_img
) {
279 if (mark_img
.alt
== "Set mark") {
280 mark_img
.src
= "images/mark_set.png";
281 mark_img
.alt
= "Reset mark";
282 mark_img
.setAttribute('onclick',
283 'javascript:toggleMark('+rows
[i
]+', false)');
286 mark_img
.src
= "images/mark_unset.png";
287 mark_img
.alt
= "Set mark";
288 mark_img
.setAttribute('onclick',
289 'javascript:toggleMark('+rows
[i
]+', true)');
294 if (rows
.length
> 0) {
296 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
297 param_escape(rows
.toString()) + "&cmode=2";
299 xmlhttp_rpc
.open("GET", query
, true);
300 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
301 xmlhttp_rpc
.send(null);
306 exception_error("selectionToggleMarked", e
);
310 function cdmGetSelectedArticles() {
311 var sel_articles
= new Array();
312 var container
= document
.getElementById("headlinesContainer");
314 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
315 var child
= container
.childNodes
[i
];
317 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
318 var c_id
= child
.id
.replace("RROW-", "");
319 sel_articles
.push(c_id
);
326 // mode = all,none,unread
327 function cdmSelectArticles(mode
) {
328 var container
= document
.getElementById("headlinesContainer");
330 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
331 var child
= container
.childNodes
[i
];
333 if (child
.id
.match("RROW-")) {
334 var aid
= child
.id
.replace("RROW-", "");
336 var cb
= document
.getElementById("RCHK-" + aid
);
339 if (!child
.className
.match("Selected")) {
340 child
.className
= child
.className
+ "Selected";
343 } else if (mode
== "unread") {
344 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
345 child
.className
= child
.className
+ "Selected";
349 child
.className
= child
.className
.replace("Selected", "");
356 function catchupPage() {
358 if (document
.getElementById("headlinesList")) {
359 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
360 selectionToggleUnread();
361 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
363 cdmSelectArticles('all');
364 selectionToggleUnread(true, false)
365 cdmSelectArticles('none');
369 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
371 if (!xmlhttp_ready(xmlhttp_rpc
)) {
375 var title
= prompt("Please enter label title:", "");
379 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
380 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
381 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
382 "&title=" + param_escape(title
);
384 debug("LFS: " + query
);
386 xmlhttp_rpc
.open("GET", query
, true);
387 xmlhttp_rpc
.onreadystatechange
=getMainContext().dlg_frefresh_callback
;
388 xmlhttp_rpc
.send(null);
395 function headlines_init() {
396 if (arguments.callee.done) return;
397 arguments.callee.done = true;
399 if (parent.frames["feeds-frame"]) {
400 document.onkeydown = hotkey_handler;
403 var hl = document.getElementById("headlinesList");
406 hl = document.getElementById("headlinesContainer");
409 var hw = hl.scrollHeight;
410 var pw = parent.document.getElementById("headlines").scrollHeight;
413 var bt = document.getElementById("headlineActionsBottom");
414 bt.className = "headlinesSubToolbar";