]> git.wh0rd.org - tt-rss.git/blob - viewfeed.js
automagically updating labels with cute XML RPC
[tt-rss.git] / viewfeed.js
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
58 cleanSelected("headlinesList");
59
60 var upd_img_pic = h_document.getElementById("FUPDPIC-" + id);
61
62 if (upd_img_pic) {
63 upd_img_pic.src = "images/blank_icon.gif";
64 }
65
66 var unread_rows = getVisibleUnreadHeadlines();
67
68 if (unread_rows.length == 0) {
69 var button = h_document.getElementById("btnCatchupPage");
70 if (button) {
71 button.className = "disabledButton";
72 button.href = "";
73 }
74 }
75
76 active_post_id = id;
77 setActiveFeedId(feed_id);
78
79 var content = m_document.getElementById("content-frame");
80
81 if (content) {
82 content.src = "backend.php?op=view&addheader=true&id=" + param_escape(id);
83 markHeadline(active_post_id);
84 }
85
86 }
87
88
89 function toggleMark(id, toggle) {
90
91 var f_document = parent.frames["feeds-frame"].document;
92
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
102 var vfeedu = f_document.getElementById("FEEDU--1");
103
104 // alert(vfeedu);
105
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";
111
112 if (vfeedu) vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
113
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";
119
120 if (vfeedu) vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
121
122 }
123
124 var vfeedctr = f_document.getElementById("FEEDCTR--1");
125
126 if (vfeedu && vfeedctr) {
127 if ((+vfeedu.innerHTML) > 0) {
128 vfeedctr.className = "odd";
129 } else {
130 vfeedctr.className = "invisible";
131 }
132 }
133
134 xmlhttp_rpc.open("GET", query, true);
135 xmlhttp_rpc.onreadystatechange=rpc_notify_callback;
136 xmlhttp_rpc.send(null);
137
138 }
139
140 function moveToPost(mode) {
141
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) {
161 view(next_id, getActiveFeedId());
162 }
163 }
164
165 if (mode == "prev") {
166 if ( prev_id != undefined) {
167 view(prev_id, getActiveFeedId());
168 }
169 }
170 }
171
172 function 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 }