]> git.wh0rd.org Git - tt-rss.git/blob - viewfeed.js
add dialogue to remove current feed, overall quick meny improvements (shamelessly...
[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         crow.className = crow.className.replace("Unread", "");
58
59         cleanSelected("headlinesList");
60
61         var upd_img_pic = h_document.getElementById("FUPDPIC-" + id);
62
63         if (upd_img_pic) {
64                 upd_img_pic.src = "images/blank_icon.gif";
65         } 
66
67         active_post_id = id; 
68         setActiveFeedId(feed_id);
69
70         var content = m_document.getElementById("content-frame");
71
72         if (content) {
73                 content.src = "backend.php?op=view&addheader=true&id=" + param_escape(id) +
74                         "&feed=" + param_escape(feed_id);
75                 markHeadline(active_post_id);
76         }
77
78 }
79
80
81 function toggleMark(id, toggle) {
82
83         var f_document = parent.frames["feeds-frame"].document;
84
85         if (!xmlhttp_ready(xmlhttp_rpc)) {
86                 printLockingError();
87                 return;
88         }
89
90         var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
91
92         var mark_img = document.getElementById("FMARKPIC-" + id);
93         var vfeedu = f_document.getElementById("FEEDU--1");
94         var crow = document.getElementById("RROW-" + id);
95
96 //      alert(vfeedu);
97
98         if (toggle == true) {
99                 mark_img.src = "images/mark_set.png";
100                 mark_img.alt = "Reset mark";
101                 mark_img.setAttribute('onclick', 'javascript:toggleMark('+id+', false)');
102                 query = query + "&mark=1";
103
104                 if (vfeedu && crow.className.match("Unread")) {
105                         vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
106                 }
107
108         } else {
109                 mark_img.src = "images/mark_unset.png";
110                 mark_img.alt = "Set mark";
111                 mark_img.setAttribute('onclick', 'javascript:toggleMark('+id+', true)');
112                 query = query + "&mark=0";
113
114                 if (vfeedu && crow.className.match("Unread")) {
115                         vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
116                 }
117
118         }
119
120         var vfeedctr = f_document.getElementById("FEEDCTR--1");
121         var vfeedr = f_document.getElementById("FEEDR--1");
122
123         if (vfeedu && vfeedctr) {
124                 if ((+vfeedu.innerHTML) > 0) {
125                         if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
126                                 vfeedr.className = vfeedr.className + "Unread";
127                                 vfeedctr.className = "odd";
128                         }
129                 } else {
130                         vfeedctr.className = "invisible";
131                         vfeedr.className = vfeedr.className.replace("Unread", "");
132                 }
133         }
134
135         xmlhttp_rpc.open("GET", query, true);
136         xmlhttp_rpc.onreadystatechange=rpc_notify_callback;
137         xmlhttp_rpc.send(null);
138
139 }
140
141 function moveToPost(mode) {
142
143         var rows = getVisibleHeadlineIds();
144
145         var prev_id;
146         var next_id;
147
148         if (active_post_id == false) {
149                 next_id = getFirstVisibleHeadlineId();
150                 prev_id = getLastVisibleHeadlineId();
151         } else {        
152                 for (var i = 0; i < rows.length; i++) {
153                         if (rows[i] == active_post_id) {
154                                 prev_id = rows[i-1];
155                                 next_id = rows[i+1];                    
156                         }
157                 }
158         }
159
160         if (mode == "next") {
161                 if (next_id != undefined) {
162                         view(next_id, getActiveFeedId());
163                 }
164         }
165
166         if (mode == "prev") {
167                 if ( prev_id != undefined) {
168                         view(prev_id, getActiveFeedId());
169                 }
170         } 
171 }
172
173 function localHotkeyHandler(keycode) {
174
175         if (keycode == 78) {
176                 return moveToPost('next');
177         }
178
179         if (keycode == 80) {
180                 return moveToPost('prev');
181         } 
182
183 // FIXME
184 //      if (keycode == 85) {
185 //              return viewfeed(active_feed_id, active_offset, "ForceUpdate");
186 //      }
187
188 //      alert("KC: " + keycode);
189
190 }