]>
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
);
59 if (xmlhttp_ready(xmlhttp
)) {
60 xmlhttp
.open("GET", query
, true);
61 xmlhttp
.onreadystatechange
=article_callback
;
64 debug("xmlhttp busy (@view)");
68 exception_error("view", e
);
72 function toggleMark(id
) {
74 var f_document
= document
;
76 if (!xmlhttp_ready(xmlhttp_rpc
)) {
81 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
83 var mark_img
= document
.getElementById("FMARKPIC-" + id
);
84 var vfeedu
= f_document
.getElementById("FEEDU--1");
85 var crow
= document
.getElementById("RROW-" + id
);
87 if (mark_img
.alt
!= "Reset mark") {
88 mark_img
.src
= "images/mark_set.png";
89 mark_img
.alt
= "Reset mark";
90 query
= query
+ "&mark=1";
92 if (vfeedu
&& crow
.className
.match("Unread")) {
93 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) + 1;
97 mark_img
.src
= "images/mark_unset.png";
98 mark_img
.alt
= "Set mark";
99 query
= query
+ "&mark=0";
101 if (vfeedu
&& crow
.className
.match("Unread")) {
102 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) - 1;
107 var vfeedctr
= f_document
.getElementById("FEEDCTR--1");
108 var vfeedr
= f_document
.getElementById("FEEDR--1");
110 if (vfeedu
&& vfeedctr
) {
111 if ((+vfeedu
.innerHTML
) > 0) {
112 if (crow
.className
.match("Unread") && !vfeedr
.className
.match("Unread")) {
113 vfeedr
.className
= vfeedr
.className
+ "Unread";
114 vfeedctr
.className
= "odd";
117 vfeedctr
.className
= "invisible";
118 vfeedr
.className
= vfeedr
.className
.replace("Unread", "");
122 debug("toggle starred for aid " + id
);
124 new Ajax
.Request(query
);
128 function moveToPost(mode
) {
130 // check for combined mode
131 if (!document
.getElementById("headlinesList"))
134 var rows
= getVisibleHeadlineIds();
139 if (active_post_id
== false) {
140 next_id
= getFirstVisibleHeadlineId();
141 prev_id
= getLastVisibleHeadlineId();
143 for (var i
= 0; i
< rows
.length
; i
++) {
144 if (rows
[i
] == active_post_id
) {
151 if (mode
== "next") {
152 if (next_id
!= undefined) {
153 view(next_id
, getActiveFeedId());
157 if (mode
== "prev") {
158 if ( prev_id
!= undefined) {
159 view(prev_id
, getActiveFeedId());
164 function toggleUnread(id
, cmode
) {
166 if (!xmlhttp_ready(xmlhttp_rpc
)) {
171 var row
= document
.getElementById("RROW-" + id
);
173 var nc
= row
.className
;
174 nc
= nc
.replace("Unread", "");
175 nc
= nc
.replace("Selected", "");
177 if (row
.className
.match("Unread")) {
180 row
.className
= nc
+ "Unread";
183 if (!cmode
) cmode
= 2;
185 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
186 param_escape(id
) + "&cmode=" + param_escape(cmode
);
188 xmlhttp_rpc
.open("GET", query
, true);
189 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
190 xmlhttp_rpc
.send(null);
196 exception_error("toggleUnread", e
);
200 function selectionToggleUnread(cdm_mode
, set_state
) {
202 if (!xmlhttp_ready(xmlhttp_rpc
)) {
210 rows
= cdmGetSelectedArticles();
212 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
215 for (i
= 0; i
< rows
.length
; i
++) {
216 var row
= document
.getElementById("RROW-" + rows
[i
]);
218 var nc
= row
.className
;
219 nc
= nc
.replace("Unread", "");
220 nc
= nc
.replace("Selected", "");
222 if (row
.className
.match("Unread")) {
223 row
.className
= nc
+ "Selected";
225 row
.className
= nc
+ "UnreadSelected";
230 if (rows
.length
> 0) {
234 if (set_state
== undefined) {
236 } else if (set_state
== true) {
238 } else if (set_state
== false) {
242 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
243 param_escape(rows
.toString()) + "&cmode=" + cmode
;
245 xmlhttp_rpc
.open("GET", query
, true);
246 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
247 xmlhttp_rpc
.send(null);
252 exception_error("selectionToggleUnread", e
);
256 function selectionToggleMarked(cdm_mode
) {
258 if (!xmlhttp_ready(xmlhttp_rpc
)) {
266 rows
= cdmGetSelectedArticles();
268 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
271 for (i
= 0; i
< rows
.length
; i
++) {
272 var row
= document
.getElementById("RROW-" + rows
[i
]);
273 var mark_img
= document
.getElementById("FMARKPIC-" + rows
[i
]);
275 if (row
&& mark_img
) {
277 if (mark_img
.alt
== "Set mark") {
278 mark_img
.src
= "images/mark_set.png";
279 mark_img
.alt
= "Reset mark";
280 mark_img
.setAttribute('onclick',
281 'javascript:toggleMark('+rows
[i
]+', false)');
284 mark_img
.src
= "images/mark_unset.png";
285 mark_img
.alt
= "Set mark";
286 mark_img
.setAttribute('onclick',
287 'javascript:toggleMark('+rows
[i
]+', true)');
292 if (rows
.length
> 0) {
294 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
295 param_escape(rows
.toString()) + "&cmode=2";
297 xmlhttp_rpc
.open("GET", query
, true);
298 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
299 xmlhttp_rpc
.send(null);
304 exception_error("selectionToggleMarked", e
);
308 function cdmGetSelectedArticles() {
309 var sel_articles
= new Array();
310 var container
= document
.getElementById("headlinesContainer");
312 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
313 var child
= container
.childNodes
[i
];
315 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
316 var c_id
= child
.id
.replace("RROW-", "");
317 sel_articles
.push(c_id
);
324 // mode = all,none,unread
325 function cdmSelectArticles(mode
) {
326 var container
= document
.getElementById("headlinesContainer");
328 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
329 var child
= container
.childNodes
[i
];
331 if (child
.id
.match("RROW-")) {
332 var aid
= child
.id
.replace("RROW-", "");
334 var cb
= document
.getElementById("RCHK-" + aid
);
337 if (!child
.className
.match("Selected")) {
338 child
.className
= child
.className
+ "Selected";
341 } else if (mode
== "unread") {
342 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
343 child
.className
= child
.className
+ "Selected";
347 child
.className
= child
.className
.replace("Selected", "");
354 function catchupPage() {
356 if (document
.getElementById("headlinesList")) {
357 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
358 selectionToggleUnread();
359 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
361 cdmSelectArticles('all');
362 selectionToggleUnread(true, false)
363 cdmSelectArticles('none');
367 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
369 if (!xmlhttp_ready(xmlhttp_rpc
)) {
373 var title
= prompt("Please enter label title:", "");
377 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
378 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
379 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
380 "&title=" + param_escape(title
);
382 debug("LFS: " + query
);
384 xmlhttp_rpc
.open("GET", query
, true);
385 xmlhttp_rpc
.onreadystatechange
=getMainContext().dlg_frefresh_callback
;
386 xmlhttp_rpc
.send(null);
393 function headlines_init() {
394 if (arguments.callee.done) return;
395 arguments.callee.done = true;
397 if (parent.frames["feeds-frame"]) {
398 document.onkeydown = hotkey_handler;
401 var hl = document.getElementById("headlinesList");
404 hl = document.getElementById("headlinesContainer");
407 var hw = hl.scrollHeight;
408 var pw = parent.document.getElementById("headlines").scrollHeight;
411 var bt = document.getElementById("headlineActionsBottom");
412 bt.className = "headlinesSubToolbar";