]> git.wh0rd.org - tt-rss.git/blame - viewfeed.js
rework label counter behaviour
[tt-rss.git] / viewfeed.js
CommitLineData
bb7cface 1var active_post_id = false;
f0601b87
AD
2var total_unread = 0;
3
4var 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.
10try {
090e250b 11 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
f0601b87
AD
12} catch (e) {
13 try {
14 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
15 } catch (E) {
16 xmlhttp_rpc = false;
17 }
18}
19@end @*/
20
21if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
22 xmlhttp_rpc = new XMLHttpRequest();
23}
24
bb7cface 25function view(id, feed_id) {
f0601b87 26
90e395dc 27// p_notify("Loading article...");
c05608c2 28
090e250b
AD
29 var f_document = parent.frames["feeds-frame"].document;
30 var h_document = document;
31 var m_document = parent.document;
f0601b87 32
090e250b 33 enableHotkeys();
f0601b87 34
090e250b 35 var crow = h_document.getElementById("RROW-" + id);
e828e31e 36
f0601b87 37 if (crow.className.match("Unread")) {
090e250b 38 var umark = f_document.getElementById("FEEDU-" + feed_id);
e828e31e 39
f0601b87
AD
40 umark.innerHTML = umark.innerHTML - 1;
41 crow.className = crow.className.replace("Unread", "");
42
43 if (umark.innerHTML == "0") {
090e250b 44 var feedr = f_document.getElementById("FEEDR-" + feed_id);
f0601b87 45 feedr.className = feedr.className.replace("Unread", "");
e828e31e 46
090e250b 47 var feedctr = f_document.getElementById("FEEDCTR-" + feed_id);
e828e31e
AD
48
49 if (feedctr) {
0c674406 50 feedctr.className = "invisible";
e828e31e 51 }
f0601b87
AD
52 }
53
54 total_unread--;
55 }
56
e828e31e 57
f0601b87
AD
58 cleanSelected("headlinesList");
59
090e250b 60 var upd_img_pic = h_document.getElementById("FUPDPIC-" + id);
f0601b87
AD
61
62 if (upd_img_pic) {
397f428b 63 upd_img_pic.src = "images/blank_icon.gif";
f0601b87
AD
64 }
65
66 var unread_rows = getVisibleUnreadHeadlines();
67
68 if (unread_rows.length == 0) {
090e250b 69 var button = h_document.getElementById("btnCatchupPage");
f0601b87
AD
70 if (button) {
71 button.className = "disabledButton";
72 button.href = "";
73 }
74 }
75
76 active_post_id = id;
86741347 77 setActiveFeedId(feed_id);
f0601b87 78
090e250b 79 var content = m_document.getElementById("content-frame");
f0601b87
AD
80
81 if (content) {
82 content.src = "backend.php?op=view&addheader=true&id=" + param_escape(id);
83 markHeadline(active_post_id);
84 }
090e250b 85
f0601b87
AD
86}
87
f0601b87 88
c05608c2 89function toggleMark(id, toggle) {
f0601b87 90
090e250b
AD
91 var f_document = parent.frames["feeds-frame"].document;
92
f0601b87
AD
93 if (!xmlhttp_ready(xmlhttp_rpc)) {
94 printLockingError();
95 return;
96 }
97
98 var mark_img = document.getElementById("FMARKPIC-" + id);
99
100 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
101
090e250b 102 var vfeedu = f_document.getElementById("FEEDU--1");
254e0e4b 103
090e250b 104// alert(vfeedu);
254e0e4b 105
f0601b87
AD
106 if (toggle == true) {
107 mark_img.src = "images/mark_set.png";
108 mark_img.alt = "Reset mark";
109 mark_img.setAttribute('onclick', 'javascript:toggleMark('+id+', false)');
110 query = query + "&mark=1";
254e0e4b
AD
111
112 if (vfeedu) vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
113
f0601b87
AD
114 } else {
115 mark_img.src = "images/mark_unset.png";
116 mark_img.alt = "Set mark";
117 mark_img.setAttribute('onclick', 'javascript:toggleMark('+id+', true)');
118 query = query + "&mark=0";
254e0e4b
AD
119
120 if (vfeedu) vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
121
122 }
123
090e250b 124 var vfeedctr = f_document.getElementById("FEEDCTR--1");
254e0e4b
AD
125
126 if (vfeedu && vfeedctr) {
127 if ((+vfeedu.innerHTML) > 0) {
128 vfeedctr.className = "odd";
129 } else {
130 vfeedctr.className = "invisible";
131 }
f0601b87
AD
132 }
133
134 xmlhttp_rpc.open("GET", query, true);
135 xmlhttp_rpc.onreadystatechange=rpc_notify_callback;
136 xmlhttp_rpc.send(null);
137
138}
139
bb7cface 140function moveToPost(mode) {
f0601b87 141
bb7cface
AD
142 var rows = getVisibleHeadlineIds();
143
144 var prev_id;
145 var next_id;
146
147 if (active_post_id == false) {
148 next_id = getFirstVisibleHeadlineId();
149 prev_id = getLastVisibleHeadlineId();
150 } else {
151 for (var i = 0; i < rows.length; i++) {
152 if (rows[i] == active_post_id) {
153 prev_id = rows[i-1];
154 next_id = rows[i+1];
155 }
156 }
157 }
158
159 if (mode == "next") {
160 if (next_id != undefined) {
86741347 161 view(next_id, getActiveFeedId());
bb7cface
AD
162 }
163 }
164
165 if (mode == "prev") {
166 if ( prev_id != undefined) {
86741347 167 view(prev_id, getActiveFeedId());
bb7cface
AD
168 }
169 }
170}
171
172function localHotkeyHandler(keycode) {
173
174 if (keycode == 78) {
175 return moveToPost('next');
176 }
177
178 if (keycode == 80) {
179 return moveToPost('prev');
180 }
181
182// FIXME
183// if (keycode == 85) {
184// return viewfeed(active_feed_id, active_offset, "ForceUpdate");
185// }
186
187// alert("KC: " + keycode);
188
189}