Commit 436007e608958853db43c69da7a12d3447fd1307

  • avatar
  • admin
  • Mon Jan 23 14:27:38 IST 2012
Rolling back ui.js
server/ui.js
(240 / 242)
  
44 elementTagName: " ",
55 elementId: " ",
66 flag : 0,
7 showlinks : 0,
8 showbox : 0,
9 blog_flag : false,
107 testContext : function()
118 {
129
13 $(document).ready(function(){$('body *').contents().filter(function()
14{
15 try{
16 if(this.nodeType == 3)
17 {
18 return (this.nodeType == 3) && this.nodeValue.match(/\S/);}}
19 catch(err)
20 {
21 }}).wrap('<span m4pageedittype=text/>')});
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/>')});
2222
2323
2424 vimg = document.getElementsByTagName('img');
2525 for(i=0; i<vimg.length; i++)
26 {
27 vimg[i].setAttribute('m4pageedittype','image');
28 }
26 {
27 vimg[i].setAttribute('m4pageedittype','image');
28 }
2929
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'));
3044 },
3145
3246 createMenu: function(menu_list) {
33 var xyz = document.getElementById("show-box");
34 xyz.innerHTML = "";
47 var xyz = document.getElementById("menu-button");
3548 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()
3670 {
37 var para = document.createElement("p");
38 var newel = document.createElement("a");
39 newel.textContent = menu_list[i];
40 newel.setAttribute("href", "http://y.a11y.in/web?foruri="+encodeURIComponent(window.location.href)+"&lang="+menu_list[i]+"&interactive=1");
41 para.appendChild(newel);
42 xyz.appendChild(para);
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 }
4382 }
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 }
4493 },
4594 ajax1: function() {
46 var xhr = new XMLHttpRequest();
47 xhr.onreadystatechange = function()
95 if(a11ypi.flag == '0')
4896 {
49 if(xhr.readyState == 4)
97 a11ypi.flag = 1;
98 var xhr = new XMLHttpRequest();
99 xhr.onreadystatechange = function()
100 {
101 if(xhr.readyState == 4)
50102 {
51103 if(xhr.responseText == "empty")
52 { }
104 {
105 a11ypi.clearMenu();
106 }
53107 else
54 {
55 document.getElementById("see-narration").disabled = false;
56 document.getElementById("blog-filter").disabled = false;
57 document.getElementById("go").disabled = false;
58 a11ypi.showbox = JSON.parse(xhr.responseText);
59 }
108 {
109 a11ypi.createMenuFilter(JSON.parse(xhr.responseText));
110 }
60111 }
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) ;
61124 }
62 xhr.open("POST","http://y.a11y.in/menu",true);
63 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
64 xhr.send('url='+encodeURIComponent(window.location.href)) ;
65125 },
66 createDomainMenu: function() {
67 var xyz = document.getElementById("show-links");
68 xyz.innerHTML = "";
69 menu_list = a11ypi.showlinks;
70 for(var i=0; i<menu_list.length;i++)
71 {
72 var para = document.createElement("p");
73 var newel = document.createElement("a");
74 newel.textContent = menu_list[i];
75 newel.setAttribute("href", menu_list[i]);
76 para.appendChild(newel);
77 xyz.appendChild(para);
78 }
79 $('a').hover(
80 function() {
81 var xhr = new XMLHttpRequest();
82 xhr.onreadystatechange = function()
83 {
84 if(xhr.readyState == 4)
85 {
86 if(xhr.responseText == "empty")
87 { }
88 else
89 {
90 menu_list = JSON.parse(xhr.responseText);
91 for(i=0; i<menu_list.length; i++) {
92 x = document.createElement('span');
93 x.setAttribute('style', 'padding:15px;');
94 x.textContent = menu_list[i];
95 document.getElementById('show-links').appendChild(x);
96 }
97 $('span').tooltip();
98 }
99 }
100 }
101 xhr.open("POST","http://y.a11y.in/menu",true);
102 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
103 xhr.send('url='+encodeURIComponent($(this).attr('href'))) ;
104 },
105 function () {$('#show-links').find("span").remove();}
106 );
107 },
108126
109 ajaxLinks1: function() {
127 getURL: function(e) {
128 window.location = window.location.href + "&lang=" + e.value;
129 window.reload();
130 },
131 ren: function()
132 {
110133 var xhr = new XMLHttpRequest();
111134 xhr.onreadystatechange = function()
112135 {
113136 if(xhr.readyState == 4)
137 {
138 if(xhr.responseText =='empty')
114139 {
115 if(xhr.responseText == "empty")
116 { }
117 else
118 {
119 document.getElementById("see-links").disabled = false;
120 a11ypi.showlinks = JSON.parse(xhr.responseText);
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;
121156 }
157 path = d['xpath'];
158 newContent = d['data'];
159 elementType = d['elementtype'];
160 a11ypi.evaluate(path,newContent,elementType);
161 }
122162 }
163 }
123164 }
124 xhr.open("POST","http://y.a11y.in/domain",true);
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);
125175 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
126 xhr.send('url='+encodeURIComponent(window.location.hostname));
176 xhr.send(data);//
127177 },
128
129
130
131
132 editPage: function() {
133 a11ypi.testContext(); page_edit_nele('4seiz', '4l85060vb9', '336e2nootv6nxjsvyjov', 'VISUAL', 'false', '');
134 document.getElementById("renarrated_overlay").style.display = "none";
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 }
135215 },
136
137 showBox: function() {
138 $(function() {
139 $( "#show-box" ).dialog( "destroy" );
140
141 $( "#show-box" ).dialog({
142 width: 300,
143 height: 300,
144 modal: true
145 });
146 });
147 a11ypi.createMenu(a11ypi.showbox);
216 close: function() {
217 document.getElementById('ren_overlay').style.display = 'none';
148218 },
149
150 showBox1: function() {
151 $(function() {
152 $( "#show-links" ).dialog( "destroy" );
153
154 $( "#show-links" ).dialog({
155 width: 500,
156 height: 300,
157 modal: true
158 });
159 });
160 a11ypi.createDomainMenu();
161 },
162
163 blogFilter: function() {
164 if (a11ypi.blog_flag == false) {
165 a11ypi.blog_flag = true;
219 filter: function()
220 {
166221 var xhr = new XMLHttpRequest();
167222 xhr.onreadystatechange = function()
168223 {
169224 if(xhr.readyState == 4)
225 {
226 if(xhr.responseText =='empty')
170227 {
171 if(xhr.responseText == "empty")
172 { }
228 a11ypi.clearMenu();
229 alert("An internal server error occured, please try later.");
230 }
173231 else
174 {
175 var sel = document.getElementById("blog-filter");
176 var menu_list = JSON.parse(xhr.responseText);
177 blogArray = [];
178 for (var i=0; i< menu_list.length; i++)
179 {
180 blogArray[i] = menu_list[i].split("http://")[1].split(".com")[0] + ".com";
181 }
182 blogArray.sort();
183 for (var i=0; i < blogArray.length; i++)
184 {
185 if ( i == 0 )
186 {
187 opt = document.createElement("option");
188 opt.textContent = blogArray[0];
189 sel.appendChild(opt);
190 }
191 else if(blogArray[i] == blogArray[i-1])
192 { }
193 else
194 {
195 opt = document.createElement("option");
196 opt.textContent = blogArray[i];
197 sel.appendChild(opt);
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;
200244 }
245 path = d['xpath'];
246 newContent = d['data'];
247 a11ypi.evaluate(path,newContent);
248 }
201249 }
250 }
202251 }
203 xhr.open("POST","http://y.a11y.in/blog",true);
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);
204263 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
205 xhr.send('url='+encodeURIComponent(window.location.href));
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);
206275 }
207276 },
208 go: function() {
209 if (document.getElementById("blog-filter").value == "Choose a blog name")
210 { }
211 else {
212 window.open("http://y.a11y.in/web?foruri=" + encodeURIComponent(window.location.href) + "&blog=" + document.getElementById("blog-filter").value);
277 clearMenuFilter: function() {
278 var xyz = document.getElementById("menu-button");
279 while(null!= xyz.firstChild)
280 {
281 xyz.removeChild(xyz.firstChild);
213282 }
214283 },
284 getURLFilter: function(e) {
285 window.location = window.location.href + "&lang=" + e.value+"&interactive=1";
286 window.reload();
287 },
215288
216 loadOverlay: function() {
217
218 body = document.body;
219
220 jq = document.createElement("script");
221 jq.setAttribute("type", "text/javascript");
222 jq.setAttribute("src", "http://code.jquery.com/jquery-1.7.min.js");
223 body.appendChild(jq);
224
225 jqlink = document.createElement("link");
226 jqlink.setAttribute("rel", "stylesheet");
227 jqlink.setAttribute("type", "text/css");
228 jqlink.setAttribute("href", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css");
229 body.appendChild(jqlink);
230
231 jscript = document.createElement("script");
232 jscript.setAttribute("type", "text/javascript");
233 jscript.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js");
234 body.appendChild(jscript);
235
236 overlay = document.createElement("div");
237 overlay.setAttribute("id", "renarrated_overlay");
238 overlay.setAttribute("class", "ui-widget-header ui-corner-all");
239 overlay.setAttribute("style", "position:fixed;top:0;width:80%;align:center;text-align:center;");
240 body.appendChild(overlay);
241
242 show_box = document.createElement("div");
243 show_box.setAttribute("id", "show-box");
244 show_box.title = "Please choose one of the languages";
245 body.appendChild(show_box);
246
247 show_links = document.createElement("div");
248 show_links.setAttribute("id", "show-links");
249 show_links.title = "Please choose one of the links";
250 body.appendChild(show_links);
251
252 edit_current = document.createElement("input");
253 edit_current.setAttribute("id", "edit-current");
254 edit_current.setAttribute("type", "submit");
255 edit_current.setAttribute("onclick", "a11ypi.editPage();");
256 edit_current.setAttribute("value", "Re-narrate this page");
257 overlay.appendChild(edit_current);
258
259 see_narration = document.createElement("input");
260 see_narration.setAttribute("id", "see-narration");
261 see_narration.setAttribute("type", "submit");
262 see_narration.setAttribute("onclick", "a11ypi.showBox();");
263 see_narration.setAttribute("value", "See other narrations");
264 see_narration.disabled = true;
265 overlay.appendChild(see_narration);
266 a11ypi.ajax1();
267
268 see_links = document.createElement("input");
269 see_links.setAttribute("id", "see-links");
270 see_links.setAttribute("type", "submit");
271 see_links.setAttribute("onclick", "a11ypi.showBox1();");
272 see_links.setAttribute("value", "Directory of narrations");
273 see_links.disabled = true;
274 overlay.appendChild(see_links);
275 a11ypi.ajaxLinks1();
276
277 blog_filter = document.createElement("select");
278 blog_filter.setAttribute("id", "blog-filter");
279 blog_filter.setAttribute("style", "min-width:200px;max-width:200px;");
280 blog_filter.setAttribute("onclick", "a11ypi.blogFilter();");
281 blog_option = document.createElement("option");
282 blog_option.textContent = "Choose a blog name";
283 blog_filter.appendChild(blog_option);
284 blog_filter.disabled = true;
285 overlay.appendChild(blog_filter);
286
287 go = document.createElement("input");
288 go.setAttribute("id", "go");
289 go.setAttribute("type", "submit");
290 go.setAttribute("onclick", "a11ypi.go();");
291 go.setAttribute("value", "Go");
292 go.disabled = true;
293 overlay.appendChild(go);
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 },
296298};
297
298if (window.location.hostname != "y.a11y.in") {
299 $(document).load(a11ypi.loadOverlay());
300}