]> git.wh0rd.org Git - tt-rss.git/blob - functions.js
iframify main interface, numerous javascript cleanups
[tt-rss.git] / functions.js
1 var hotkeys_enabled = true;
2
3 function disableHotkeys() {
4         hotkeys_enabled = false;
5 }
6
7 function enableHotkeys() {
8         hotkeys_enabled = true;
9 }
10
11 function xmlhttp_ready(obj) {
12         return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
13 }
14
15
16 function notify_callback() {
17         var container = document.getElementById('notify');
18         if (xmlhttp.readyState == 4) {
19                 container.innerHTML=xmlhttp.responseText;
20         }
21 }
22
23 function rpc_notify_callback() {
24         var container = document.getElementById('notify');
25         if (xmlhttp_rpc.readyState == 4) {
26                 container.innerHTML=xmlhttp_rpc.responseText;
27         }
28 }
29
30 function param_escape(arg) {
31         if (typeof encodeURIComponent != 'undefined')
32                 return encodeURIComponent(arg); 
33         else
34                 return escape(arg);
35 }
36
37 function param_unescape(arg) {
38         if (typeof decodeURIComponent != 'undefined')
39                 return decodeURIComponent(arg); 
40         else
41                 return unescape(arg);
42 }
43
44 function delay(gap) {
45         var then,now; 
46         then=new Date().getTime();
47         now=then;
48         while((now-then)<gap) {
49                 now=new Date().getTime();
50         }
51 }
52
53 function notify(msg) {
54
55         var n = document.getElementById("notify");
56
57         if (!n) return;
58
59         n.innerHTML = msg;
60
61         if (msg.length == 0) {
62                 n.style.display = "none";
63         } else {
64                 n.style.display = "block";
65         }
66
67 }
68
69 function printLockingError() {
70         notify("Please wait until operation finishes");}
71
72 var seq = "";
73
74 function hotkey_handler(e) {
75
76         var keycode;
77
78         if (!hotkeys_enabled) return;
79
80         if (window.event) {
81                 keycode = window.event.keyCode;
82         } else if (e) {
83                 keycode = e.which;
84         }
85
86         if (keycode == 13 || keycode == 27) {
87                 seq = "";
88         } else {
89                 seq = seq + "" + keycode;
90         }
91
92         var piggie = document.getElementById("piggie");
93
94         if (seq.match("807371717369")) {
95                 localPiggieFunction(true);
96         } else {
97                 localPiggieFunction(false);
98         }
99
100         if (typeof localHotkeyHandler != 'undefined') {
101                 localHotkeyHandler(keycode);
102         }
103
104 }
105
106 function cleanSelected(element) {
107         var content = document.getElementById(element);
108
109         var rows = new Array();
110
111         for (i = 0; i < content.rows.length; i++) {
112                 content.rows[i].className = content.rows[i].className.replace("Selected", "");
113         }
114
115 }
116
117 function getVisibleUnreadHeadlines() {
118         var content = document.getElementById("headlinesList");
119
120         var rows = new Array();
121
122         for (i = 0; i < content.rows.length; i++) {
123                 var row_id = content.rows[i].id.replace("RROW-", "");
124                 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
125                                 rows.push(row_id);      
126                 }
127         }
128         return rows;
129 }
130
131 function getVisibleHeadlineIds() {
132
133         var content = document.getElementById("headlinesList");
134
135         var rows = new Array();
136
137         for (i = 0; i < content.rows.length; i++) {
138                 var row_id = content.rows[i].id.replace("RROW-", "");
139                 if (row_id.length > 0) {
140                                 rows.push(row_id);      
141                 }
142         }
143         return rows;
144 }
145
146 function getFirstVisibleHeadlineId() {
147         var rows = getVisibleHeadlineIds();
148         return rows[0];
149 }
150
151 function getLastVisibleHeadlineId() {
152         var rows = getVisibleHeadlineIds();
153         return rows[rows.length-1];
154 }
155
156 function markHeadline(id) {
157         var row = document.getElementById("RROW-" + id);
158         if (row) {
159                 row.className = row.className + "Selected";
160         }
161 }
162
163 function getFeedIds() {
164         var content = document.getElementById("feedsList");
165
166         var rows = new Array();
167
168         for (i = 0; i < content.rows.length; i++) {
169                 var id = content.rows[i].id.replace("FEEDR-", "");
170                 if (id.length > 0) {
171                         rows.push(id);
172                 }
173         }
174
175         return rows;
176 }
177
178