Commit 436007e608958853db43c69da7a12d3447fd1307
- server/ui.js 482 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Diff rendering mode:
- inline
- side by side
server/ui.js
4 | elementTagName: " ", | 4 | elementTagName: " ", |
---|---|---|---|
5 | elementId: " ", | 5 | elementId: " ", |
6 | flag : 0, | 6 | flag : 0, |
7 | |||
8 | |||
9 | |||
10 | testContext : function() | 7 | testContext : function() |
11 | { | 8 | { |
12 | 9 | ||
13 | |||
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
20 | |||
21 | 10 | $(document).ready(function(){$('body *').contents().filter(function() | |
11 | { | ||
12 | //console.log(this.nodeName); | ||
13 | try{ | ||
14 | if(this.nodeType == 3) | ||
15 | { | ||
16 | return (this.nodeType == 3) && this.nodeValue.match(/\S/);}} | ||
17 | catch(err) | ||
18 | { | ||
19 | // console.log(err.message); | ||
20 | // console.log(this); | ||
21 | }}).wrap('<span m4pageedittype=text/>')}); | ||
22 | 22 | ||
23 | 23 | ||
24 | vimg = document.getElementsByTagName('img'); | 24 | vimg = document.getElementsByTagName('img'); |
25 | for(i=0; i<vimg.length; i++) | 25 | for(i=0; i<vimg.length; i++) |
26 | |||
27 | |||
28 | 26 | { | |
27 | vimg[i].setAttribute('m4pageedittype','image'); | ||
28 | } | ||
29 | 29 | ||
30 | var v = document.getElementsByTagName("body"); | ||
31 | // var a = document.createElement("script"); | ||
32 | // a.setAttribute("src","http://dev.a11y.in/alipi/wsgi/page_edit.js"); | ||
33 | // // a.setAttribute("src","http://localhost/alipi-1/server/wsgi/page_edit.js"); | ||
34 | // a.setAttribute("type","text/javascript"); | ||
35 | // v[0].appendChild(a); | ||
36 | var alltags = document.getElementsByTagName('*'); | ||
37 | for (x=0; x<alltags.length; x++) { | ||
38 | if (alltags[x].id == 'ren_overlay' || alltags[x].id == 'overlay1' ) { | ||
39 | v[0].removeChild(document.getElementById('ren_overlay')); | ||
40 | v[0].removeChild(document.getElementById('overlay1')); | ||
41 | } | ||
42 | } | ||
43 | v[0].removeChild(document.getElementById('overlay2')); | ||
30 | }, | 44 | }, |
31 | 45 | ||
32 | createMenu: function(menu_list) { | 46 | createMenu: function(menu_list) { |
33 | |||
34 | 47 | var xyz = document.getElementById("menu-button"); | |
35 | for(var i=0;i<menu_list.length;i++) | 48 | for(var i=0;i<menu_list.length;i++) |
49 | { | ||
50 | var newel = document.createElement("option"); | ||
51 | newel.textContent = menu_list[i]; | ||
52 | newel.setAttribute("value",menu_list[i]); | ||
53 | newel.setAttribute("onclick","a11ypi.getURL(event.target);"); | ||
54 | xyz.appendChild(newel); | ||
55 | } | ||
56 | }, | ||
57 | clearMenu: function() { | ||
58 | var xyz = document.getElementById("menu-button"); | ||
59 | while(null!= xyz.firstChild) | ||
60 | { | ||
61 | xyz.removeChild(xyz.firstChild); | ||
62 | } | ||
63 | }, | ||
64 | ajax: function() { | ||
65 | if(a11ypi.flag == '0') | ||
66 | { | ||
67 | a11ypi.flag = 1; | ||
68 | var xhr = new XMLHttpRequest(); | ||
69 | xhr.onreadystatechange = function() | ||
36 | { | 70 | { |
37 | |||
38 | |||
39 | |||
40 | |||
41 | |||
42 | 71 | if(xhr.readyState == 4) | |
72 | { | ||
73 | if(xhr.responseText == "empty") | ||
74 | { | ||
75 | a11ypi.clearMenu(); | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | a11ypi.createMenu(JSON.parse(xhr.responseText)); | ||
80 | } | ||
81 | } | ||
43 | } | 82 | } |
83 | xhr.open("POST","http://localhost/menu",true); | ||
84 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | ||
85 | d = window.location.search.split('?')[1]; | ||
86 | var a =[]; | ||
87 | for (var i = 0;i<d.split('&').length;i++){ | ||
88 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | ||
89 | } | ||
90 | var url = a['foruri']; | ||
91 | xhr.send('url='+url); | ||
92 | } | ||
44 | }, | 93 | }, |
45 | ajax1: function() { | 94 | ajax1: function() { |
46 | |||
47 | 95 | if(a11ypi.flag == '0') | |
48 | { | 96 | { |
49 | 97 | a11ypi.flag = 1; | |
98 | var xhr = new XMLHttpRequest(); | ||
99 | xhr.onreadystatechange = function() | ||
100 | { | ||
101 | if(xhr.readyState == 4) | ||
50 | { | 102 | { |
51 | if(xhr.responseText == "empty") | 103 | if(xhr.responseText == "empty") |
52 | 104 | { | |
105 | a11ypi.clearMenu(); | ||
106 | } | ||
53 | else | 107 | else |
54 | |||
55 | |||
56 | |||
57 | |||
58 | |||
59 | 108 | { | |
109 | a11ypi.createMenuFilter(JSON.parse(xhr.responseText)); | ||
110 | } | ||
60 | } | 111 | } |
112 | } | ||
113 | xhr.open("POST","http://localhost/menu",true); | ||
114 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | ||
115 | d = window.location.search.split('?')[1]; | ||
116 | var a =[]; | ||
117 | for (var i = 0;i<d.split('&').length;i++){ | ||
118 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | ||
119 | } | ||
120 | var url = a['foruri']; | ||
121 | var option = a['blog']; | ||
122 | data = 'url='+url+'&option='+option; | ||
123 | xhr.send(data) ; | ||
61 | } | 124 | } |
62 | |||
63 | |||
64 | |||
65 | }, | 125 | }, |
66 | |||
67 | |||
68 | |||
69 | |||
70 | |||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
77 | |||
78 | |||
79 | |||
80 | |||
81 | |||
82 | |||
83 | |||
84 | |||
85 | |||
86 | |||
87 | |||
88 | |||
89 | |||
90 | |||
91 | |||
92 | |||
93 | |||
94 | |||
95 | |||
96 | |||
97 | |||
98 | |||
99 | |||
100 | |||
101 | |||
102 | |||
103 | |||
104 | |||
105 | |||
106 | |||
107 | |||
108 | 126 | ||
109 | 127 | getURL: function(e) { | |
128 | window.location = window.location.href + "&lang=" + e.value; | ||
129 | window.reload(); | ||
130 | }, | ||
131 | ren: function() | ||
132 | { | ||
110 | var xhr = new XMLHttpRequest(); | 133 | var xhr = new XMLHttpRequest(); |
111 | xhr.onreadystatechange = function() | 134 | xhr.onreadystatechange = function() |
112 | { | 135 | { |
113 | if(xhr.readyState == 4) | 136 | if(xhr.readyState == 4) |
137 | { | ||
138 | if(xhr.responseText =='empty') | ||
114 | { | 139 | { |
115 | |||
116 | |||
117 | |||
118 | |||
119 | |||
120 | 140 | a11ypi.clearMenu(); | |
141 | alert("An internal server error occured, please try later."); | ||
142 | } | ||
143 | else | ||
144 | { | ||
145 | |||
146 | d ={}; | ||
147 | var response=xhr.responseText.substring(3).split('###'); | ||
148 | for (var j= 0; j< response.length ; j++){ | ||
149 | chunk = response[j].substring(1).split('&'); | ||
150 | |||
151 | for (var i= 0; i< chunk.length ; i++){ | ||
152 | pair =chunk[i].split("::"); | ||
153 | key = pair[0]; | ||
154 | value = pair[1]; | ||
155 | d[key] = value; | ||
121 | } | 156 | } |
157 | path = d['xpath']; | ||
158 | newContent = d['data']; | ||
159 | elementType = d['elementtype']; | ||
160 | a11ypi.evaluate(path,newContent,elementType); | ||
161 | } | ||
122 | } | 162 | } |
163 | } | ||
123 | } | 164 | } |
124 | 165 | d = window.location.search.split('?')[1]; | |
166 | var a =[]; | ||
167 | for (var i = 0;i<d.split('&').length;i++){ | ||
168 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | ||
169 | } | ||
170 | var url = a['foruri']; | ||
171 | var lang= a['lang']; | ||
172 | var data="url="+url+"&lang="+encodeURIComponent(lang); | ||
173 | |||
174 | xhr.open("POST","http://localhost/replace",true); | ||
125 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | 175 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); |
126 | 176 | xhr.send(data);// | |
127 | }, | 177 | }, |
128 | |||
129 | |||
130 | |||
131 | |||
132 | |||
133 | |||
134 | 178 | evaluate: function() | |
179 | { | ||
180 | try{ | ||
181 | var nodes = document.evaluate(path, document, null, XPathResult.ANY_TYPE,null); | ||
182 | } | ||
183 | catch(e) | ||
184 | { | ||
185 | console.log(e); | ||
186 | } | ||
187 | try{ | ||
188 | var result = nodes.iterateNext(); | ||
189 | while (result) | ||
190 | { | ||
191 | if (elementType == 'image') | ||
192 | { | ||
193 | result.setAttribute('src',newContent.split(',')[1]); //A hack to display images properly, the size has been saved in the database. | ||
194 | width = newContent.split(',')[0].split('x')[0]; | ||
195 | height = newContent.split(',')[0].split('x')[1]; | ||
196 | result.setAttribute('width',width); | ||
197 | result.setAttribute('height', height); | ||
198 | } | ||
199 | else if(elementType =='audio/ogg') | ||
200 | { | ||
201 | newContent = decodeURIComponent(newContent); | ||
202 | audio = '<audio controls="controls" src="'+newContent+'"></audio>'; | ||
203 | $(result).before(audio); | ||
204 | } | ||
205 | else{ | ||
206 | result.textContent = newContent; | ||
207 | } | ||
208 | result=nodes.iterateNext(); | ||
209 | } | ||
210 | } | ||
211 | catch (e) | ||
212 | { | ||
213 | dump( 'error: Document tree modified during iteration ' + e ); | ||
214 | } | ||
135 | }, | 215 | }, |
136 | |||
137 | |||
138 | |||
139 | |||
140 | |||
141 | |||
142 | |||
143 | |||
144 | |||
145 | |||
146 | |||
147 | 216 | close: function() { | |
217 | document.getElementById('ren_overlay').style.display = 'none'; | ||
148 | }, | 218 | }, |
149 | |||
150 | |||
151 | |||
152 | |||
153 | |||
154 | |||
155 | |||
156 | |||
157 | |||
158 | |||
159 | |||
160 | |||
161 | |||
162 | |||
163 | |||
164 | |||
165 | 219 | filter: function() | |
220 | { | ||
166 | var xhr = new XMLHttpRequest(); | 221 | var xhr = new XMLHttpRequest(); |
167 | xhr.onreadystatechange = function() | 222 | xhr.onreadystatechange = function() |
168 | { | 223 | { |
169 | if(xhr.readyState == 4) | 224 | if(xhr.readyState == 4) |
225 | { | ||
226 | if(xhr.responseText =='empty') | ||
170 | { | 227 | { |
171 | |||
172 | 228 | a11ypi.clearMenu(); | |
229 | alert("An internal server error occured, please try later."); | ||
230 | } | ||
173 | else | 231 | else |
174 | |||
175 | |||
176 | |||
177 | |||
178 | |||
179 | |||
180 | |||
181 | |||
182 | |||
183 | |||
184 | |||
185 | |||
186 | |||
187 | |||
188 | |||
189 | |||
190 | |||
191 | |||
192 | |||
193 | |||
194 | |||
195 | |||
196 | |||
197 | |||
198 | |||
199 | 232 | { | |
233 | |||
234 | d ={}; | ||
235 | var response=xhr.responseText.substring(3).split('###'); | ||
236 | for (var j= 0; j< response.length ; j++){ | ||
237 | chunk = response[j].substring(1).split('&'); | ||
238 | |||
239 | for (var i= 0; i< chunk.length ; i++){ | ||
240 | pair =chunk[i].split("::"); | ||
241 | key = pair[0]; | ||
242 | value = pair[1]; | ||
243 | d[key] = value; | ||
200 | } | 244 | } |
245 | path = d['xpath']; | ||
246 | newContent = d['data']; | ||
247 | a11ypi.evaluate(path,newContent); | ||
248 | } | ||
201 | } | 249 | } |
250 | } | ||
202 | } | 251 | } |
203 | 252 | d = window.location.search.split('?')[1]; | |
253 | var a =[]; | ||
254 | for (var i = 0;i<d.split('&').length;i++){ | ||
255 | a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1]; | ||
256 | } | ||
257 | var url = a['foruri']; | ||
258 | var lang= a['lang']; | ||
259 | var blog= a['blog']; | ||
260 | var data="url="+encodeURIComponent(url)+"&lang="+encodeURIComponent(lang)+"&blog="+encodeURIComponent(blog); | ||
261 | |||
262 | xhr.open("POST","http://localhost/filter",true); | ||
204 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | 263 | xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); |
205 | 264 | xhr.send(data);// | |
265 | }, | ||
266 | createMenuFilter: function(menu_list) { | ||
267 | var xyz = document.getElementById("menu-button"); | ||
268 | for(var i in menu_list) | ||
269 | { | ||
270 | var newel = document.createElement("option"); | ||
271 | newel.textContent = menu_list[i]; | ||
272 | newel.setAttribute("value",menu_list[i]); | ||
273 | newel.setAttribute("onclick","a11ypi.getURLFilter(event.target);"); | ||
274 | xyz.appendChild(newel); | ||
206 | } | 275 | } |
207 | }, | 276 | }, |
208 | |||
209 | |||
210 | |||
211 | |||
212 | 277 | clearMenuFilter: function() { | |
278 | var xyz = document.getElementById("menu-button"); | ||
279 | while(null!= xyz.firstChild) | ||
280 | { | ||
281 | xyz.removeChild(xyz.firstChild); | ||
213 | } | 282 | } |
214 | }, | 283 | }, |
284 | getURLFilter: function(e) { | ||
285 | window.location = window.location.href + "&lang=" + e.value+"&interactive=1"; | ||
286 | window.reload(); | ||
287 | }, | ||
215 | 288 | ||
216 | |||
217 | |||
218 | |||
219 | |||
220 | |||
221 | |||
222 | |||
223 | |||
224 | |||
225 | |||
226 | |||
227 | |||
228 | |||
229 | |||
230 | |||
231 | |||
232 | |||
233 | |||
234 | |||
235 | |||
236 | |||
237 | |||
238 | |||
239 | |||
240 | |||
241 | |||
242 | |||
243 | |||
244 | |||
245 | |||
246 | |||
247 | |||
248 | |||
249 | |||
250 | |||
251 | |||
252 | |||
253 | |||
254 | |||
255 | |||
256 | |||
257 | |||
258 | |||
259 | |||
260 | |||
261 | |||
262 | |||
263 | |||
264 | |||
265 | |||
266 | |||
267 | |||
268 | |||
269 | |||
270 | |||
271 | |||
272 | |||
273 | |||
274 | |||
275 | |||
276 | |||
277 | |||
278 | |||
279 | |||
280 | |||
281 | |||
282 | |||
283 | |||
284 | |||
285 | |||
286 | |||
287 | |||
288 | |||
289 | |||
290 | |||
291 | |||
292 | |||
293 | |||
294 | |||
295 | 289 | checkbox: function() { | |
290 | if(document.getElementById("our-check").checked == false) { | ||
291 | document.getElementById("our-check").checked = true; | ||
292 | document.getElementById("your-check").checked = false; | ||
293 | } else { | ||
294 | document.getElementById("our-check").checked = false; | ||
295 | document.getElementById("your-check").checked = true; | ||
296 | } | ||
297 | }, | ||
296 | }; | 298 | }; |
297 | |||
298 | |||
299 | |||
300 |