]>
Commit | Line | Data |
---|---|---|
c01f40f4 AD |
1 | var last_feeds = []; |
2 | ||
b41c2549 AD |
3 | function view(feed_id) { |
4 | try { | |
5 | ||
6 | new Ajax.Request("backend.php", { | |
7 | parameters: "backend.php?op=rpc&subop=digest-init&feed_id=" + feed_id, | |
8 | onComplete: function(transport) { | |
9 | digest_update(transport); | |
10 | } }); | |
11 | ||
12 | } catch (e) { | |
13 | exception_error("view", e); | |
14 | } | |
15 | } | |
16 | ||
c01f40f4 AD |
17 | function find_feed(feeds, feed_id) { |
18 | try { | |
19 | for (var i = 0; i < feeds.length; i++) { | |
20 | if (feeds[i].id == feed_id) | |
21 | return feeds[i]; | |
22 | } | |
23 | ||
24 | return false; | |
25 | ||
26 | } catch (e) { | |
27 | exception_error("find_feed", e); | |
28 | } | |
29 | } | |
30 | ||
b41c2549 AD |
31 | function get_feed_icon(feed) { |
32 | try { | |
33 | if (feed.has_icon) | |
34 | return 'icons/' + feed.id + '.ico'; | |
35 | ||
36 | if (feed.id == -1) | |
37 | return 'images/mark_set.png'; | |
38 | ||
39 | if (feed.id == -2) | |
40 | return 'images/pub_set.png'; | |
41 | ||
42 | if (feed.id == -3) | |
43 | return 'images/fresh.png'; | |
44 | ||
45 | if (feed.id == -4) | |
46 | return 'images/tag.png'; | |
47 | ||
48 | if (feed.id < -10) | |
49 | return 'images/label.png'; | |
50 | ||
51 | } catch (e) { | |
52 | exception_error("get_feed_icon", e); | |
53 | } | |
54 | } | |
55 | ||
c01f40f4 AD |
56 | function add_feed_entry(feed) { |
57 | try { | |
58 | var icon_part = ""; | |
59 | ||
b41c2549 | 60 | icon_part = "<img src='" + get_feed_icon(feed) + "'/>"; |
c01f40f4 AD |
61 | |
62 | var tmp_html = "<li>" + | |
63 | icon_part + | |
b41c2549 | 64 | "<a href=\"#\" onclick=\"view("+feed.id+")\">" + feed.title + |
c01f40f4 AD |
65 | "<div class='unread-ctr'>" + feed.unread + "</div>" + |
66 | "</li>"; | |
67 | ||
68 | $("feeds-content").innerHTML += tmp_html; | |
69 | ||
70 | } catch (e) { | |
71 | exception_error("add_feed_entry", e); | |
72 | } | |
73 | } | |
74 | ||
b41c2549 | 75 | function add_latest_entry(article, feed) { |
c01f40f4 | 76 | try { |
b41c2549 AD |
77 | |
78 | ||
79 | //$("latest-content").innerHTML += "bbb"; | |
c01f40f4 AD |
80 | |
81 | } catch (e) { | |
82 | exception_error("add_latest_entry", e); | |
83 | } | |
84 | } | |
85 | ||
86 | function add_headline_entry(article, feed) { | |
87 | try { | |
88 | ||
89 | var icon_part = ""; | |
90 | ||
91 | if (article.has_icon) | |
92 | icon_part = "<img alt='zz' src='icons/" + article.feed_id + ".ico'/>"; | |
93 | ||
94 | var tmp_html = "<li>" + | |
95 | icon_part + | |
96 | "<a class='title'>" + article.title + "</a>" + | |
97 | "<div class='excerpt'>" + article.excerpt + "</div>" + | |
98 | "<div class='info'><a>" + feed.title + "</a> " + " @ " + | |
b41c2549 | 99 | new Date(article.updated * 1000) + "</div>" + |
c01f40f4 AD |
100 | "</li>"; |
101 | ||
102 | $("headlines-content").innerHTML += tmp_html; | |
103 | ||
104 | } catch (e) { | |
105 | exception_error("add_headline_entry", e); | |
106 | } | |
107 | } | |
108 | ||
109 | function digest_update(transport) { | |
110 | try { | |
111 | var feeds = transport.responseXML.getElementsByTagName('feeds')[0]; | |
112 | var headlines = transport.responseXML.getElementsByTagName('headlines')[0]; | |
113 | ||
114 | if (feeds) { | |
115 | last_feeds = feeds; | |
116 | ||
117 | feeds = eval("(" + feeds.firstChild.nodeValue + ")"); | |
118 | ||
b41c2549 AD |
119 | $('feeds-content').innerHTML = ""; |
120 | ||
c01f40f4 AD |
121 | for (var i = 0; i < feeds.length; i++) { |
122 | add_feed_entry(feeds[i]); | |
123 | } | |
124 | } | |
125 | ||
126 | if (headlines) { | |
127 | headlines = eval("(" + headlines.firstChild.nodeValue + ")"); | |
128 | ||
b41c2549 AD |
129 | $('headlines-content').innerHTML = ""; |
130 | ||
c01f40f4 AD |
131 | for (var i = 0; i < headlines.length; i++) { |
132 | add_headline_entry(headlines[i], find_feed(feeds, headlines[i].feed_id)); | |
133 | } | |
b41c2549 AD |
134 | |
135 | $('headlines-content').innerHTML += "<li><a>More articles...</a></li>"; | |
c01f40f4 AD |
136 | } |
137 | ||
138 | } catch (e) { | |
139 | exception_error("digest_update", e); | |
140 | } | |
141 | } | |
142 | ||
143 | function digest_init() { | |
144 | try { | |
145 | ||
146 | new Ajax.Request("backend.php", { | |
147 | parameters: "backend.php?op=rpc&subop=digest-init", | |
148 | onComplete: function(transport) { | |
149 | digest_update(transport); | |
150 | } }); | |
151 | ||
152 | } catch (e) { | |
153 | exception_error("digest_init", e); | |
154 | } | |
155 | } |