Commit dad095b7f02422e98c16f9895024fef43b4d8a40

  • avatar
  • arvind
  • Tue Jan 21 11:49:56 IST 2014
Bug fixes and library update
    - Updating the code to jquery UI 1.10.3 version.
    - Removing pageEditor.js and adding code to ui.js
alipi/ui.js
(1653 / 1049)
  
11//-*-coding: utf-8 -*-
2var a11ypi = {
3 auth : " ",
4 loc:" ",
5 elementTagName: " ",
6 elementId: " ",
7 flag : 0,
8 fflag : 0,
9 showbox : 0,
10 showlinks : 0,
11 blog_flag: false,
12 target : false,
13 pageHtml:'',
14 d: {},
15 responseJSON:'',
16 testContext : function()
17 {
18 if(document.getElementById('social_overlay') != null)
19 document.body.removeChild(document.getElementById('social_overlay'));
20 $(document).ready(function(){
21 try{
22 $('body *').not('iframe').contents().filter(function(){
23 try{
2//window.jQuery = window.jQuery || {};
3window.onload = function() {
4 yepnope([{
5 test: window.jQuery,
6 nope:['//code.jquery.com/jquery-1.10.2.min.js'],
7 load:['//code.jquery.com/ui/1.10.3/jquery-ui.js'],
8 complete:function(){
9 jQuery.noConflict();
10 (function($) {
2411
25 if(this.nodeType == 3 && !($(this).hasClass('alipi'))){
26 return (this.nodeType == 3) && this.nodeValue.match(/\S/);}}
27 catch(err){
28 console.log(err);
29 }
30 }).parent().attr('m4pageedittype','text');
31 }
32 catch(e){
33 console.log(this);
34 }
35 });
12 $(function() {
13 var a11ypi = {
14 auth : " ",
15 loc:" ",
16 elementTagName: " ",
17 elementId: " ",
18 flag : 0,
19 fflag : 0,
20 showbox : 0,
21 showlinks : 0,
22 blog_flag: false,
23 target : false,
24 pageHtml:'',
25 d: {},
26 responseJSON:'',
27 testContext : function()
28 {
29 if(document.getElementById('social_overlay') != null)
30 document.body.removeChild(document.getElementById('social_overlay'));
31 $(document).ready(function(){
32 try{
33 $('body *').not('iframe').contents().filter(function(){
34 try{
3635
37 vimg = document.getElementsByTagName('img');
38 for(i=0; i<vimg.length; i++)
39 {
40 vimg[i].setAttribute('m4pageedittype','image');
41 }
42 },
36 if(this.nodeType == 3 && !($(this).hasClass('alipi'))){
37 return (this.nodeType == 3) && this.nodeValue.match(/\S/);}}
38 catch(err){
39 console.log(err);
40 }
41 }).parent().attr('m4pageedittype','text');
42 }
43 catch(e){
44 console.log(this);
45 }
46 });
4347
44 createMenu: function(type) {
45 var xyz = '';
46 if(type === 're-narration')
47 xyz = document.getElementById("show-box");
48 else
49 xyz = document.getElementById("show-comment");
50 xyz.innerHTML = '';
51 a = a11ypi.getParams();
52 for(var i in a11ypi.showbox)
53 {
54 if(a11ypi.showbox[i]['type'] == type)
55 {
56 var para = document.createElement("p");
57 var newel = document.createElement("a");
58 newel.textContent = a11ypi.showbox[i]['lang'];
59 if(type === 're-narration')
60 $(newel).attr("href",config.deploy+"/?foruri="+encodeURIComponent(a['foruri'])+"&lang="+a11ypi.showbox[i]['lang']+"&interactive=1"+"&type="+type);
61 else
62 $(newel).attr("href",config.deploy+"/?foruri="+a['foruri']+"&tags="+a11ypi.showbox[i]['lang']+"&interactive=0"+"&type="+type);
63 para.appendChild(newel);
64 xyz.appendChild(para);
65 }
66 }
67 },
48 vimg = document.getElementsByTagName('img');
49 for(i=0; i<vimg.length; i++)
50 {
51 vimg[i].setAttribute('m4pageedittype','image');
52 }
53 },
6854
69 ajax: function() {
70 if(a11ypi.flag == '0')
71 {
72 a11ypi.flag = 1;
73 a = a11ypi.getParams();
74 $.getJSON(config.deploy+'/menu?', {"url":a['foruri']}, function(data)
75 {
76 a11ypi.showbox = data;
77 $('#see-narration').show();
78 // $("#blog-filter").show(); a11ypi.blogFilter();
79 //$("#go").show();
80 });
55 createMenu: function(type) {
56 var xyz = '';
57 if(type === 're-narration')
58 xyz = document.getElementById("show-box");
59 else
60 xyz = document.getElementById("show-comment");
61 xyz.innerHTML = '';
62 a = a11ypi.getParams();
63 for(var i in a11ypi.showbox)
64 {
65 if(a11ypi.showbox[i]['type'] == type)
66 {
67 var para = document.createElement("p");
68 var newel = document.createElement("a");
69 newel.textContent = a11ypi.showbox[i]['lang'];
70 if(type === 're-narration')
71 $(newel).attr("href",config.deploy+"/?foruri="+encodeURIComponent(a['foruri'])+"&lang="+a11ypi.showbox[i]['lang']+"&interactive=1"+"&type="+type);
72 else
73 $(newel).attr("href",config.deploy+"/?foruri="+a['foruri']+"&tags="+a11ypi.showbox[i]['lang']+"&interactive=0"+"&type="+type);
74 para.appendChild(newel);
75 xyz.appendChild(para);
76 }
77 }
78 },
8179
82 if(a['lang'])
83 {req = {"about":decodeURIComponent(a['foruri']), "lang":a['lang']};
84 $.getJSON(config.deploy+'/info?', req, function(data)
85 {
86 a11ypi.responseJSON = data;
87 });
88 }
89 }
90 },
91 ajax1: function() {
92 if(a11ypi.fflag == '0')
93 {
94 a11ypi.fflag = 1;
95 // var xhr = new XMLHttpRequest();
96 // xhr.onreadystatechange = function()
97 // {
98 // if(xhr.readyState == 4)
99 // {
100 // if(xhr.responseText == "empty")
101 // {
102 // // a11ypi.clearMenu();
103 // }
104 // else
105 // {
106 // a11ypi.createMenuFilter(JSON.parse(xhr.responseText));
107 // }
108 // }
109 // }
110 // xhr.open("POST",config.deploy+"/menu",true);
111 // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
112 // a = a11ypi.getParams();
113 // data = 'url='+a['foruri']+'&option='+a['blog'];
114 // xhr.send(data) ;
115 // }
116 var request = {};
117 request['url'] = a['foruri'];
118 request['option'] = a['blog'];
119 $.get(config.deploy+"/menu", {"url":a["foruri"], "option":a['blog']}, function(data){
120 a11ypi.createMenuFilter(JSON.parse(data));
80 ajax: function() {
81 if(a11ypi.flag == '0')
82 {
83 a11ypi.flag = 1;
84 a = a11ypi.getParams();
85 $.getJSON(config.deploy+'/menu?', {"url":a['foruri']}, function(data)
86 {
87 a11ypi.showbox = data;
88 //$('#see-narration').show();
89 // $("#blog-filter").show(); a11ypi.blogFilter();
90 //$("#go").show();
91 });
12192
122 });
123 }
124 },
93 if(a['lang'])
94 {req = {"about":decodeURIComponent(a['foruri']), "lang":a['lang']};
95 $.getJSON(config.deploy+'/info?', req, function(data)
96 {
97 a11ypi.responseJSON = data;
98 });
99 }
100 }
101 },
102 ajax1: function() {
103 if(a11ypi.fflag == '0')
104 {
105 a11ypi.fflag = 1;
106 // var xhr = new XMLHttpRequest();
107 // xhr.onreadystatechange = function()
108 // {
109 // if(xhr.readyState == 4)
110 // {
111 // if(xhr.responseText == "empty")
112 // {
113 // // a11ypi.clearMenu();
114 // }
115 // else
116 // {
117 // a11ypi.createMenuFilter(JSON.parse(xhr.responseText));
118 // }
119 // }
120 // }
121 // xhr.open("POST",config.deploy+"/menu",true);
122 // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
123 // a = a11ypi.getParams();
124 // data = 'url='+a['foruri']+'&option='+a['blog'];
125 // xhr.send(data) ;
126 // }
127 var request = {};
128 request['url'] = a['foruri'];
129 request['option'] = a['blog'];
130 $.get(config.deploy+"/menu", {"url":a["foruri"], "option":a['blog']}, function(data){
131 a11ypi.createMenuFilter(JSON.parse(data));
125132
126 getURL: function(e) {
127 window.location = window.location.href + "&lang=" + e.value;
128 window.reload();
129 },
130 ren: function()
131 {
132 a = a11ypi.getParams();
133 var url = a['foruri'];
134 // var url = decodeURIComponent(a['foruri']);
135 var type;
136 if(a['type'])
137 type = a['type'];
138 else
139 type = 're-narration'
140 var lang = '';
133 });
134 }
135 },
141136
142 if( type != 're-narration')
143 lang = a['tags'];
144 else
145 lang = a['lang'];
137 getURL: function(e) {
138 window.location = window.location.href + "&lang=" + e.value;
139 window.reload();
140 },
141 ren: function()
142 {
143 a = a11ypi.getParams();
144 var url = a['foruri'];
145 // var url = decodeURIComponent(a['foruri']);
146 var type;
147 if(a['type'])
148 type = a['type'];
149 else
150 type = 're-narration'
151 var lang = '';
146152
147 $.getJSON(config.deploy+"/replace?",{"url":url,"lang":lang,"type":type},function(data)
148 {
149 for(var i=0;i<data['r'].length;i++)
150 {
151 for(var x in data['r'][i]['narration'])
152 {
153 // path = data['r'][i]['narration'][x]['xpath'];
154 // newContent = data['r'][i]['narration'][x]['data'];
155 // elementType = data['r'][i]['narration'][x]['elementtype'];
153 if( type != 're-narration')
154 lang = a['tags'];
155 else
156 lang = a['lang'];
156157
157 a11ypi.evaluate(data['r'][i]['narration'][x]);
158 }
159 }
160 });
161 },
162 evaluate: function(a)
163 {
164 try{
165 var nodes = document.evaluate(a['xpath'], document, null, XPathResult.ANY_TYPE,null);
158 $.getJSON(config.deploy+"/replace?",{"url":url,"lang":lang,"type":type},function(data)
159 {
160 for(var i=0;i<data['r'].length;i++)
161 {
162 for(var x in data['r'][i]['narration'])
163 {
164 // path = data['r'][i]['narration'][x]['xpath'];
165 // newContent = data['r'][i]['narration'][x]['data'];
166 // elementType = data['r'][i]['narration'][x]['elementtype'];
166167
167 }
168 catch(e)
169 {
170 console.log(e);
171 }
172 if(a['type'] == 're-narration')
173 {
174 try{
175 var result = nodes.iterateNext();
176 while (result)
177 {
178 if (a['elementtype'] == 'image')
179 {
180 if(a['data'] != '')
181 {
182 result.setAttribute('src',a['data'].split(',')[1]); //A hack to display images properly, the size has been saved in the database.
183 width = a['data'].split(',')[0].split('x')[0];
184 height = a['data'].split(',')[0].split('x')[1];
185 result.setAttribute('width',width);
186 result.setAttribute('height', height);
187 result.setAttribute('class','blink');
188 }
189 else
190 $(result).hide();
191 }
192 else if(a['elementtype'] == 'audio/ogg')
193 {
194 a['data'] = decodeURIComponent(a['data']);
195 audio = '<audio controls="controls" src="'+a['data']+'" style="display:table;"></audio>';
196 $(result).before(audio);
197 result.setAttribute('class','blink');
198 }
199 else{
200 result.innerHTML = a['data'];
201 result.setAttribute('class','blink');
202 }
203 result=nodes.iterateNext();
204 }
205 }
206 catch (e)
207 {
208 // dump( 'error: Document tree modified during iteration ' + e );
209 }
210 }
211 else if(a['type']=='5el')
212 {
168 a11ypi.evaluate(data['r'][i]['narration'][x]);
169 }
170 }
171 });
172 },
173 evaluate: function(a)
174 {
175 try{
176 var nodes = document.evaluate(a['xpath'], document, null, XPathResult.ANY_TYPE,null);
213177
214 try{
215 var result = nodes.iterateNext();
216 while (result)
217 {
218 $(result).html($(result).html()+a['data']);
219 $(result).get(0).scrollIntoView();
220 result=nodes.iterateNext();
221 }
222 }
223 catch (e)
224 {
225 //dump( 'error: Document tree modified during iteration ' + e );
226 }
227 }
228 },
229 filter: function()
230 {
231 var xhr = new XMLHttpRequest();
232 xhr.onreadystatechange = function()
233 {
234 if(xhr.readyState == 4)
235 {
236 if(xhr.responseText =='empty')
237 {
238 // a11ypi.clearMenu();
239 // alert("An internal server error occured, please try later.");
240 }
241 else
242 {
178 }
179 catch(e)
180 {
181 console.log(e);
182 }
183 if(a['type'] == 're-narration')
184 {
185 try{
186 var result = nodes.iterateNext();
187 while (result)
188 {
189 if (a['elementtype'] == 'image')
190 {
191 if(a['data'] != '')
192 {
193 result.setAttribute('src',a['data'].split(',')[1]); //A hack to display images properly, the size has been saved in the database.
194 width = a['data'].split(',')[0].split('x')[0];
195 height = a['data'].split(',')[0].split('x')[1];
196 result.setAttribute('width',width);
197 result.setAttribute('height', height);
198 result.setAttribute('class','blink');
199 }
200 else
201 $(result).hide();
202 }
203 else if(a['elementtype'] == 'audio/ogg')
204 {
205 a['data'] = decodeURIComponent(a['data']);
206 audio = '<audio controls="controls" src="'+a['data']+'" style="display:table;"></audio>';
207 $(result).before(audio);
208 result.setAttribute('class','blink');
209 }
210 else{
211 result.innerHTML = a['data'];
212 result.setAttribute('class','blink');
213 }
214 result=nodes.iterateNext();
215 }
216 }
217 catch (e)
218 {
219 // dump( 'error: Document tree modified during iteration ' + e );
220 }
221 }
222 else if(a['type']=='5el')
223 {
243224
244 d ={};
245 var response=xhr.responseText.substring(3).split('###');
246 for (var j= 0; j< response.length ; j++){
247 chunk = response[j].substring(1).split('&');
225 try{
226 var result = nodes.iterateNext();
227 while (result)
228 {
229 $(result).html($(result).html()+a['data']);
230 $(result).get(0).scrollIntoView();
231 result=nodes.iterateNext();
232 }
233 }
234 catch (e)
235 {
236 //dump( 'error: Document tree modified during iteration ' + e );
237 }
238 }
239 },
240 filter: function()
241 {
242 var xhr = new XMLHttpRequest();
243 xhr.onreadystatechange = function()
244 {
245 if(xhr.readyState == 4)
246 {
247 if(xhr.responseText =='empty')
248 {
249 // a11ypi.clearMenu();
250 // alert("An internal server error occured, please try later.");
251 }
252 else
253 {
248254
249 for (var i= 0; i< chunk.length ; i++){
250 pair =chunk[i].split("::");
251 key = pair[0];
252 value = pair[1];
253 d[key] = value;
254 }
255 path = d['xpath'];
256 newContent = d['data'];
257 elementType = d['elementtype'];
258 a11ypi.evaluate(path,newContent,elementType);
259 }
260 }
261 }
262 }
263 a = a11ypi.getParams();
264 var url = a['foruri'];
265 var lang= a['lang'];
266 var blog= a['blog'];
267 var data="url="+url+"&lang="+encodeURIComponent(lang)+"&blog="+encodeURIComponent(blog);
255 d ={};
256 var response=xhr.responseText.substring(3).split('###');
257 for (var j= 0; j< response.length ; j++){
258 chunk = response[j].substring(1).split('&');
268259
269 xhr.open("POST",config.root+"/filter",true);
270 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
271 xhr.send(data);//
272 },
273 createMenuFilter: function(menu_list) {
274 var xyz = document.getElementById("show-box");
275 xyz.innerHTML = '';
276 d = window.location.search.split('?')[1];
277 a = a11ypi.getParams();
278 var page = a['foruri'];
279 var blog = a['blog'];
280 for(var i=0;i<menu_list.length;i++)
281 {
282 var para = document.createElement("p");
283 var newel = document.createElement("a");
284 newel.textContent = menu_list[i];
285 $(newel).attr("href",config.deploy+"/?foruri="+page+"&blog="+blog+"&lang="+menu_list[i]+"&interactive=1");
286 para.appendChild(newel);
287 xyz.appendChild(para);
288 }
289 },
290 clearMenuFilter: function() {
291 var xyz = document.getElementById("menu-button");
292 while(null!= xyz.firstChild)
293 {
294 xyz.removeChild(xyz.firstChild);
295 }
296 },
297 getURLFilter: function(e) {
298 a= a11ypi.getParams();
299 window.location = config.deploy+"/?foruri="+a['foruri']+"&blog="+a['blog'] + "&lang=" + e.value+"&interactive=1";
300 window.reload();
301 },
302 showOriginal: function(){
303 var url=decodeURIComponent(window.location.search.split("=")[1].split("&")[0]);
304 window.open(url);
305 },
306 tweet:function(){
307 !function(d,s,id){
308 var js,fjs=d.getElementsByTagName(s)[0];
309 if(!d.getElementById(id)){
310 js=d.createElement(s);
311 js.id=id;js.src="//platform.twitter.com/widgets.js";
312 fjs.parentNode.insertBefore(js,fjs);
313 }
314 }
315 (document,"script","twitter-wjs");
316 },
317 facebook: function() {
318 (function(d, s, id) {
319 var js, fjs = d.getElementsByTagName(s)[0];
320 if (d.getElementById(id)) return;
321 js = d.createElement(s); js.id = id;
322 js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
323 fjs.parentNode.insertBefore(js, fjs);
324 }
325 (document, 'script', 'facebook-jssdk'));
326 },
327 loadOverlay: function()
328 {
329 yepnope([{
330 test: window.jQuery,
331 nope:['//code.jquery.com/jquery-1.10.2.min.js'],
332 load:['//code.jquery.com/ui/1.10.3/jquery-ui.js'],
333 complete:function(){
334 var overlay_template = '<div id="renarrated_overlay" class="alipi ui-widget-header ui-corner-all">'+
335 '<button id="outter-down-button" class="alipi" onclick="a11ypi.outterToggle();" up="true" title="Move this bar to top">Move</button> '+
336 '<button id="outter-up-button" class="alipi" onclick="a11ypi.outterToggle();" title="Move this bar to bottom">Move</button> '+
337 '<button id="edit-current" class="alipi" title="Allow to edit this page">Re-narrate</button> '+
338 '<button id="see-narration" class="alipi" onclick="a11ypi.showBox();" title="See other renarrations, which are in same or other languages"> '+
339 'Re-narrations</button>'+
340 // '<button id="see-comment" class="alipi" onclick="a11ypi.showComment();" title="5el"> '+
341 // '5el</button>'+
342 '<button id="see-links" class="alipi" onclick="a11ypi.showBox1();" title="See other re-narrated pages of this domain">Re-narrated Pages '+
343 '</button>'+
344 // '<select id="blog-filter" class="alipi" onChange="a11ypi.checkSelect();" title="Select one of the blog name"></select>'+
345 '<button id="go" class="alipi ui-icon-circle-arrow-e" onclick="a11ypi.go();" title="Filter by blog" >|Y|</button>'+
346 '<div id="show-box" title="Choose a narration"></div> '+
347 '<div id="show-comment" title="Comments for"></div> '+
348 '<div id="show-links" title="List of pages narrated in this domain" class="alipi"></div> '+
349 '<div id="share-box" class="alipi" title="Share this page in any following social network"></div>';
260 for (var i= 0; i< chunk.length ; i++){
261 pair =chunk[i].split("::");
262 key = pair[0];
263 value = pair[1];
264 d[key] = value;
265 }
266 path = d['xpath'];
267 newContent = d['data'];
268 elementType = d['elementtype'];
269 a11ypi.evaluate(path,newContent,elementType);
270 }
271 }
272 }
273 }
274 a = a11ypi.getParams();
275 var url = a['foruri'];
276 var lang= a['lang'];
277 var blog= a['blog'];
278 var data="url="+url+"&lang="+encodeURIComponent(lang)+"&blog="+encodeURIComponent(blog);
350279
351 var pub_overlay_template = '<div id="pub_overlay" class="alipi ui-widget-header ui-corner-all">'+
352 '<button id="icon-up" class="alipi" down="true" onClick="a11ypi.hide_overlays();" title="Move this bar to top">Move</button>'+ //&#x25B2
353 '<button id="icon-down" class="alipi" onClick="a11ypi.hide_overlays();" title="Move this bar to bottom">Move</button>'+ //&#x25BC
354 '<button id="exit-mode" class="alipi" onclick="a11ypi.exitMode();" title="Do not want to save any changes, just take me out of this editing"> '+
355 'Exit</button>'+
356 '<button id="help-window" class="alipi" onclick="a11ypi.help_window();" title="How may I help you in editing this page?">Help</button>'+
357 '<button id="undo-button" class="alipi" onclick="util.undoChanges();"title="Undo previous change, one by one">Undo changes</button>'+
358 '<button id="publish-button" class="alipi" onclick="a11ypi.loginToSwtStore();"title="Publish your changes to blog">Publish</button></div>';
280 xhr.open("POST",config.root+"/filter",true);
281 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
282 xhr.send(data);//
283 },
284 createMenuFilter: function(menu_list) {
285 var xyz = document.getElementById("show-box");
286 xyz.innerHTML = '';
287 d = window.location.search.split('?')[1];
288 a = a11ypi.getParams();
289 var page = a['foruri'];
290 var blog = a['blog'];
291 for(var i=0;i<menu_list.length;i++)
292 {
293 var para = document.createElement("p");
294 var newel = document.createElement("a");
295 newel.textContent = menu_list[i];
296 $(newel).attr("href",config.deploy+"/?foruri="+page+"&blog="+blog+"&lang="+menu_list[i]+"&interactive=1");
297 para.appendChild(newel);
298 xyz.appendChild(para);
299 }
300 },
301 clearMenuFilter: function() {
302 var xyz = document.getElementById("menu-button");
303 while(null!= xyz.firstChild)
304 {
305 xyz.removeChild(xyz.firstChild);
306 }
307 },
308 getURLFilter: function(e) {
309 a= a11ypi.getParams();
310 window.location = config.deploy+"/?foruri="+a['foruri']+"&blog="+a['blog'] + "&lang=" + e.value+"&interactive=1";
311 window.reload();
312 },
313 showOriginal: function(){
314 var url=decodeURIComponent(window.location.search.split("=")[1].split("&")[0]);
315 window.open(url);
316 },
317 tweet:function(){
318 !function(d,s,id){
319 var js,fjs=d.getElementsByTagName(s)[0];
320 if(!d.getElementById(id)){
321 js=d.createElement(s);
322 js.id=id;js.src="//platform.twitter.com/widgets.js";
323 fjs.parentNode.insertBefore(js,fjs);
324 }
325 }
326 (document,"script","twitter-wjs");
327 },
328 facebook: function() {
329 (function(d, s, id) {
330 var js, fjs = d.getElementsByTagName(s)[0];
331 if (d.getElementById(id)) return;
332 js = d.createElement(s); js.id = id;
333 js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
334 fjs.parentNode.insertBefore(js, fjs);
335 }
336 (document, 'script', 'facebook-jssdk'));
337 },
338 loadOverlay: function()
339 {
340 var overlay_template = '<div id="renarrated_overlay" class="alipi ui-widget-header ui-corner-all">'+
341 '<button id="outter-down-button" class="alipi" onclick="a11ypi.outterToggle();" up="true" title="Move this bar to top">Move</button> '+
342 '<button id="outter-up-button" class="alipi" onclick="a11ypi.outterToggle();" title="Move this bar to bottom">Move</button> '+
343 '<button id="edit-current" class="alipi" title="Allow to edit this page">Re-narrate</button> '+
344 '<button id="see-narration" class="alipi" title="See other renarrations, which are in same or other languages"> '+
345 'Re-narrations</button>'+
346 // '<button id="see-comment" class="alipi" onclick="a11ypi.showComment();" title="5el"> '+
347 // '5el</button>'+
348 '<button id="see-links" class="alipi" title="See other re-narrated pages of this domain">Re-narrated Pages '+
349 '</button>'+
350 // '<select id="blog-filter" class="alipi" onChange="a11ypi.checkSelect();" title="Select one of the blog name"></select>'+
351 '<button id="go" class="alipi ui-icon-circle-arrow-e" onclick="a11ypi.go();" title="Filter by blog" >|Y|</button>'+
352 '<div id="show-box" title="Choose a narration"></div> '+
353 '<div id="show-comment" title="Comments for"></div> '+
354 '<div id="show-links" title="List of pages narrated in this domain" class="alipi"></div> '+
355 '<div id="share-box" class="alipi" title="Share this page in any following social network"></div>';
359356
360 var element_edit_overlay_template = '<div id="element_edit_overlay" class="alipi ui-widget-header ui-corner-all" >'+
361 '<button id="edit-text" class="alipi" onclick="a11ypi.displayEditor();" title="Help you to edit this element by providing an editor on right'+
362 ' & reference on left.">Edit Text</button>'+
363 '<button id="add-audio" class="alipi" onclick="a11ypi.addAudio();" title="Allow you to give an audio file(.ogg) link to add your audio '+
364 'to this element ">Add Audio</button>'+
365 '<button id="replace-image" class="alipi" onclick="a11ypi.imageReplacer();" title="Allow you to give an image file(jpeg/jpg/gif/png) '+
366 'link to replace with this image">Replace Image</button>'+
367 '<button id="delete-image" class="alipi" onclick="pageEditor.deleteImage();" title="Remove this image from page">Delete Image</button>'+
368 '<button id="close-element" class="alipi" onclick="pageEditor.cleanUp();" title="Close" ></button>'+
369 '<label id="cant-edit" class="alipi">No selection / Too large selection </label> '+
370 '</div>';
357 var pub_overlay_template = '<div id="pub_overlay" class="alipi ui-widget-header ui-corner-all">'+
358 '<button id="icon-up" class="alipi" down="true" onClick="a11ypi.hide_overlays();" title="Move this bar to top">Move</button>'+ //&#x25B2
359 '<button id="icon-down" class="alipi" onClick="a11ypi.hide_overlays();" title="Move this bar to bottom">Move</button>'+ //&#x25BC
360 '<button id="exit-mode" class="alipi" onclick="a11ypi.exitMode();" title="Do not want to save any changes, just take me out of this editing"> '+
361 'Exit</button>'+
362 '<button id="help-window" class="alipi" onclick="a11ypi.help_window();" title="How may I help you in editing this page?">Help</button>'+
363 '<button id="undo-button" class="alipi" onclick="util.undoChanges();"title="Undo previous change, one by one">Undo changes</button>'+
364 '<button id="publish-button" class="alipi" onclick="a11ypi.loginToSwtStore();"title="Publish your changes to blog">Publish</button></div>';
371365
372 $('body').append(overlay_template);
373 $('body').append(pub_overlay_template);
374 $('body').append(element_edit_overlay_template);
366 var element_edit_overlay_template = '<div id="element_edit_overlay" class="alipi ui-widget-header ui-corner-all" >'+
367 '<button id="edit-text" class="alipi" onclick="a11ypi.displayEditor();" title="Help you to edit this element by providing an editor on right'+
368 ' & reference on left.">Edit Text</button>'+
369 '<button id="add-audio" class="alipi" onclick="a11ypi.addAudio();" title="Allow you to give an audio file(.ogg) link to add your audio '+
370 'to this element ">Add Audio</button>'+
371 '<button id="replace-image" class="alipi" onclick="a11ypi.imageReplacer();" title="Allow you to give an image file(jpeg/jpg/gif/png) '+
372 'link to replace with this image">Replace Image</button>'+
373 '<button id="delete-image" class="alipi" onclick="pageEditor.deleteImage();" title="Remove this image from page">Delete Image</button>'+
374 '<button id="close-element" class="alipi" onclick="pageEditor.cleanUp();" title="Close" ></button>'+
375 '<label id="cant-edit" class="alipi">No selection / Too large selection </label> '+
376 '</div>';
375377
376 $('#outter-up-button').show();
377 $('#go').button({disabled : true});
378 $('#undo-button').button({ disabled: true});
379 $('#publish-button').button({ disabled: true});
380 $('input[class="alipi"], select[class="alipi"]').button();
378 $('body').append(overlay_template);
379 $('body').append(pub_overlay_template);
380 $('body').append(element_edit_overlay_template);
381381
382 $("#outter-down-button").button({icons:{primary:"ui-icon-circle-arrow-n"},text:false}); $('#outter-down-button').children().addClass('alipi');
383 $("#outter-up-button").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#outter-up-button').children().addClass('alipi');
384 $("#edit-current").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-current').children().addClass('alipi');
385 $("#see-narration").button({icons:{primary:"ui-icon-document-b"}}); $('#see-narration').children().addClass('alipi');
386 $("#see-comment").button({icons:{primary:"ui-icon-document-b"}}); $('#see-comment').children().addClass('alipi');
387 $("#see-links").button({icons:{primary:"ui-icon-link"}}); $('#see-links').children().addClass('alipi');
388 /*$("#blog-filter").button({icons:{secondary:"ui-icon-triangle-1-s"}}); */ $('#blog-filter').children().addClass('alipi');
389 $("#go").button({icons:{primary:"ui-icon-arrowthick-1-e"},text:false}); $('#go').children().addClass('alipi');
390 $("#share").button({icons:{primary:"ui-icon-signal-diag"}}); $('#share').children().addClass('alipi');
391 $("#orig-button").button({icons:{primary:"ui-icon-extlink"}}); $('#orig-button').children().addClass('alipi');
392 $("#info").button({icons:{primary:"ui-icon-info"}}); $('#info').children().addClass('alipi');
382 $('#outter-up-button').show();
383 $('#go').button({disabled : true});
384 $('#undo-button').button({ disabled: true});
385 $('#publish-button').button({ disabled: true});
393386
394 $("#icon-up").button({icons:{primary:"ui-icon-circle-arrow-n"},text:false}); $('#icon-up').children().addClass('alipi');
395 $("#icon-down").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#icon-down').children().addClass('alipi');
396 $("#exit-mode").button({icons:{primary:"ui-icon-power"}}); $('#exit-mode').children().addClass('alipi');
397 $("#help-window").button({icons:{primary:"ui-icon-help"}}); $('#help-window').children().addClass('alipi');
398 $("#undo-button").button({icons:{primary:"ui-icon-arrowreturnthick-1-w"}}); $('#undo-button').children().addClass('alipi');
399 $("#publish-button").button({icons:{primary:"ui-icon-circle-check"}}); $('#publish-button').children().addClass('alipi');
400387
401 $("#edit-text").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-text').children().addClass('alipi');
402 $("#add-audio").button({icons:{primary:"ui-icon-circle-plus"}}); $('#add-audio').children().addClass('alipi');
403 $("#replace-image").button({icons:{primary:"ui-icon-transferthick-e-w"}}); $('#replace-image').children().addClass('alipi');
404 $("#delete-image").button({icons:{primary:"ui-icon-trash"}}); $('#delete-image').children().addClass('alipi');
405 $("#close-element").button({icons:{primary:"ui-icon-circle-close"},text:false}); $("#close-element").children().addClass('alipi');
388 $("#outter-down-button").button({icons:{primary:"ui-icon-circle-arrow-n"},text:false}); $('#outter-down-button').children().addClass('alipi');
389 $("#outter-up-button").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#outter-up-button').children().addClass('alipi');
390 $("#edit-current").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-current').children().addClass('alipi');
391 $("#see-narration").button({icons:{primary:"ui-icon-document-b"}}); $('#see-narration').children().addClass('alipi');
392 $("#see-comment").button({icons:{primary:"ui-icon-document-b"}}); $('#see-comment').children().addClass('alipi');
393 $("#see-links").button({icons:{primary:"ui-icon-link"}}); $('#see-links').children().addClass('alipi');
394 /*$("#blog-filter").button({icons:{secondary:"ui-icon-triangle-1-s"}}); */ $('#blog-filter').children().addClass('alipi');
395 $("#go").button({icons:{primary:"ui-icon-arrowthick-1-e"},text:false}); $('#go').children().addClass('alipi');
396 $("#share").button({icons:{primary:"ui-icon-signal-diag"}}); $('#share').children().addClass('alipi');
397 $("#orig-button").button({icons:{primary:"ui-icon-extlink"}}); $('#orig-button').children().addClass('alipi');
398 $("#info").button({icons:{primary:"ui-icon-info"}}); $('#info').children().addClass('alipi');
406399
407 $("#edit-current").button();
408 $("#edit-current").on("click", a11ypi.editPage);
400 $("#icon-up").button({icons:{primary:"ui-icon-circle-arrow-n"},text:false}); $('#icon-up').children().addClass('alipi');
401 $("#icon-down").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#icon-down').children().addClass('alipi');
402 $("#exit-mode").button({icons:{primary:"ui-icon-power"}}); $('#exit-mode').children().addClass('alipi');
403 $("#help-window").button({icons:{primary:"ui-icon-help"}}); $('#help-window').children().addClass('alipi');
404 $("#undo-button").button({icons:{primary:"ui-icon-arrowreturnthick-1-w"}}); $('#undo-button').children().addClass('alipi');
405 $("#publish-button").button({icons:{primary:"ui-icon-circle-check"}}); $('#publish-button').children().addClass('alipi');
409406
410 $('#renarrated_overlay').addClass('barOnTop');
411 a11ypi.ajax();
412 a11ypi.ajaxLinks1();
413 $('#edit-current').show();
407 $("#edit-text").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-text').children().addClass('alipi');
408 $("#add-audio").button({icons:{primary:"ui-icon-circle-plus"}}); $('#add-audio').children().addClass('alipi');
409 $("#replace-image").button({icons:{primary:"ui-icon-transferthick-e-w"}}); $('#replace-image').children().addClass('alipi');
410 $("#delete-image").button({icons:{primary:"ui-icon-trash"}}); $('#delete-image').children().addClass('alipi');
411 $("#close-element").button({icons:{primary:"ui-icon-circle-close"},text:false}); $("#close-element").children().addClass('alipi');
414412
415 d = window.location.search.split('?')[1];
416 var a =[];
417 for (var i = 0;i<d.split('&').length;i++){
418 a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1];
419 }
420 if(a['blog'] != undefined ) {
421 $('#go').hide();
422 $('#blog-filter').hide();
423 } else {
424 }
413 $("#edit-current").button();
414 $("#see-narration").button();
415 $("#see-links").button();
425416
426 if($('#orig-button').text() == 'Original Page') {
427 $('#share').insertAfter($('#go')); $('#share').show();
428 $('#info').insertAfter($('#go')); $('#info').show();
429 $('#orig-button').insertAfter($('#go')); $('#orig-button').show();
430 $('#share-box').append($('#fb-like')); $('#share-box').append($('#tweet-root'));
431 }
432 }}]);
433 },
434 checkSelect: function()
435 {
436 if($('#blog-filter').val() != "Choose a blog") {
437 $('#go').button({disabled : false});
438 } else {
439 $('#go').button({disabled : true});
440 }
441 },
417// $('input[class="alipi"], select[class="alipi"]').button();
418 $("#edit-current").on("click", a11ypi.editPage);
419 $("#see-narration").on("click",a11ypi.showBox);
420 $("#see-links").on("click",a11ypi.showBox1);
442421
443 help_window: function() {
444 var help_template = '<div id="helpwindow" class="alipi ui-widget-header ui-corner-all">'+
445 '<label id="txtlab" class="alipi" style="color:#aaa;font-size:100%;">TEXT :- It will popup a '+
446 'window and allow you to modify/replace text of select element on editor(right) box.'+
447 '<p class="alipi">To delete - Empty the editor(right) box and press "Save changes".'+
448 '</p><p class="alipi" style="margin-left:50px";>Add Audio - It allows you to '+
449 'enter audio URL.</p>IMAGE:- <p class="alipi" style="margin-left:50px";> Replace - It allows you to enter '+
450 'image URL.</p> UNDO:- Use it when you want to revert back to '+
451 'previous change.'+
452 'PUBLISH:- To publish your crafted changes to database and blog (Alipi/Personal).'+
453 '<p class="alipi" style="margin-left:50px";>States - The place you are targetting to.</p><p class="alipi" '+
454 'style="margin-left:50px";>Languages - In language you publishing.</p><p class="alipi" style= '+
455 '"margin-left:50px";>Style - In what style you crafted?</p><p class="alipi" style="margin-left:50px";> '+
456 'Author - Who is a crafter?</p><p class="alipi" style="margin-left:50px";>'+
457 'Alipi blog - If you don\'t have blogspot ID then check this to post it to our blog.</p></div>';
422 $('#renarrated_overlay').addClass('barOnTop');
423 a11ypi.ajax();
424 a11ypi.ajaxLinks1();
425 $('#edit-current').show();
426 $("#see-narration").show();
427 d = window.location.search.split('?')[1];
428 var a =[];
429 for (var i = 0;i<d.split('&').length;i++){
430 a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1];
431 }
432 if(a['blog'] != undefined ) {
433 $('#go').hide();
434 $('#blog-filter').hide();
435 } else {
436 }
458437
459 $('body').append(help_template);
460 $(document).unbind('mouseover'); // Unbind the css on mouseover
461 $(document).unbind('mouseout'); // Unbind the css on mouseout
438 if($('#orig-button').text() == 'Original Page') {
439 $('#share').insertAfter($('#go')); $('#share').show();
440 $('#info').insertAfter($('#go')); $('#info').show();
441 $('#orig-button').insertAfter($('#go')); $('#orig-button').show();
442 $('#share-box').append($('#fb-like')); $('#share-box').append($('#tweet-root'));
443 }
462444
463 $(function() {
464 $( "#helpwindow" ).dialog({
465 width:800,
466 height:550,
467 modal: true,
468 close: function() {
469 $("#helpwindow").remove();
470 }
471 });
472 });
473 },
445 },
446 checkSelect: function()
447 {
448 if($('#blog-filter').val() != "Choose a blog") {
449 $('#go').button({disabled : false});
450 } else {
451 $('#go').button({disabled : true});
452 }
453 },
474454
475 exitMode: function() {
476 var exit = window.confirm("Do you really want to exit from edit mode?");
477 if (exit == true) {
478 window.location.reload();
479 }
480 },
455 help_window: function() {
456 var help_template = '<div id="helpwindow" class="alipi ui-widget-header ui-corner-all">'+
457 '<label id="txtlab" class="alipi" style="color:#aaa;font-size:100%;">TEXT :- It will popup a '+
458 'window and allow you to modify/replace text of select element on editor(right) box.'+
459 '<p class="alipi">To delete - Empty the editor(right) box and press "Save changes".'+
460 '</p><p class="alipi" style="margin-left:50px";>Add Audio - It allows you to '+
461 'enter audio URL.</p>IMAGE:- <p class="alipi" style="margin-left:50px";> Replace - It allows you to enter '+
462 'image URL.</p> UNDO:- Use it when you want to revert back to '+
463 'previous change.'+
464 'PUBLISH:- To publish your crafted changes to database and blog (Alipi/Personal).'+
465 '<p class="alipi" style="margin-left:50px";>States - The place you are targetting to.</p><p class="alipi" '+
466 'style="margin-left:50px";>Languages - In language you publishing.</p><p class="alipi" style= '+
467 '"margin-left:50px";>Style - In what style you crafted?</p><p class="alipi" style="margin-left:50px";> '+
468 'Author - Who is a crafter?</p><p class="alipi" style="margin-left:50px";>'+
469 'Alipi blog - If you don\'t have blogspot ID then check this to post it to our blog.</p></div>';
481470
482 hide_overlays: function() {
483 if($('#icon-up').attr('down') == 'true') {
484 $('#icon-up').attr('down', 'false');
485 $('#icon-up').show(); $('#icon-down').hide();
486 $('#pub_overlay').addClass('barOnBottom'); $('#pub_overlay').removeClass('barOnTop');
487 } else {
488 $('#icon-up').attr('down', 'true');
489 $('#icon-down').show(); $('#icon-up').hide();
490 $('#pub_overlay').addClass('barOnTop'); $('#pub_overlay').removeClass('barOnBottom');
471 $('body').append(help_template);
472 $(document).unbind('mouseover'); // Unbind the css on mouseover
473 $(document).unbind('mouseout'); // Unbind the css on mouseout
491474
492 }
493 },
475 $(function() {
476 $( "#helpwindow" ).dialog({
477 width:800,
478 height:550,
479 modal: true,
480 close: function() {
481 $("#helpwindow").remove();
482 }
483 });
484 });
485 },
494486
495 outterToggle: function() {
496 if($('#outter-down-button').attr('up') == 'true' ) {
497 $('#outter-down-button').attr('up', 'false');
498 $('#outter-up-button').hide(); $('#outter-down-button').show();
499 $('#renarrated_overlay').addClass('barOnBottom'); $('#renarrated_overlay').removeClass('barOnTop');
500 } else {
501 $('#outter-down-button').attr('up', 'true');
502 $('#outter-up-button').show(); $('#outter-down-button').hide();
503 $('#renarrated_overlay').addClass('barOnTop'); $('#renarrated_overlay').removeClass('barOnBottom');
504 }
505 },
487 exitMode: function() {
488 var exit = window.confirm("Do you really want to exit from edit mode?");
489 if (exit == true) {
490 window.location.reload();
491 }
492 },
506493
494 hide_overlays: function() {
495 if($('#icon-up').attr('down') == 'true') {
496 $('#icon-up').attr('down', 'false');
497 $('#icon-up').show(); $('#icon-down').hide();
498 $('#pub_overlay').addClass('barOnBottom'); $('#pub_overlay').removeClass('barOnTop');
499 } else {
500 $('#icon-up').attr('down', 'true');
501 $('#icon-down').show(); $('#icon-up').hide();
502 $('#pub_overlay').addClass('barOnTop'); $('#pub_overlay').removeClass('barOnBottom');
507503
508 getLoc: function() {
504 }
505 },
509506
510 $( "#loc-select" ).autocomplete({
511 source: function(req, add){
507 outterToggle: function() {
508 if($('#outter-down-button').attr('up') == 'true' ) {
509 $('#outter-down-button').attr('up', 'false');
510 $('#outter-up-button').hide(); $('#outter-down-button').show();
511 $('#renarrated_overlay').addClass('barOnBottom'); $('#renarrated_overlay').removeClass('barOnTop');
512 } else {
513 $('#outter-down-button').attr('up', 'true');
514 $('#outter-up-button').show(); $('#outter-down-button').hide();
515 $('#renarrated_overlay').addClass('barOnTop'); $('#renarrated_overlay').removeClass('barOnBottom');
516 }
517 },
512518
513 //pass request to server
514 $.getJSON(config.deploy+"/getLoc?", req, function(data) {
515 $('#loc-img').hide();
516519
517 //create array for response objects
518 var suggestions = [];
520 getLoc: function() {
519521
520 //process response
521 $.each(data['return'], function(i,val){
522 suggestions.push(val['name']+', '+val['country_name']);
523 });
524 //pass array to callback
525 add(suggestions);
526 });
527 $('#loc-img').show();
528 },
529 });
530 },
522 $( "#loc-select" ).autocomplete({
523 source: function(req, add){
531524
532 getLang: function() {
533 $( "#lang-select" ).autocomplete({
534 source: function(req, add){
525 //pass request to server
526 $.getJSON(config.deploy+"/getLoc?", req, function(data) {
527 $('#loc-img').hide();
535528
536 //pass request to server
537 $.getJSON(config.deploy+"/getLang?", req, function(data) {
538 $('#lang-img').hide();
529 //create array for response objects
530 var suggestions = [];
539531
540 //create array for response objects
541 var suggestions = [];
532 //process response
533 $.each(data['return'], function(i,val){
534 suggestions.push(val['name']+', '+val['country_name']);
535 });
536 //pass array to callback
537 add(suggestions);
538 });
539 $('#loc-img').show();
540 },
541 });
542 },
542543
543 //process response
544 $.each(data['return'], function(i, val){
545 //suggestions.push(val.country);
546 suggestions.push(val['name']);
547 });
548 //pass array to callback
549 add(suggestions);
550 });
551 $('#lang-img').show();
552 },
553 });
544 getLang: function() {
545 $( "#lang-select" ).autocomplete({
546 source: function(req, add){
554547
548 //pass request to server
549 $.getJSON(config.deploy+"/getLang?", req, function(data) {
550 $('#lang-img').hide();
555551
556 },
552 //create array for response objects
553 var suggestions = [];
557554
558 loginToSwtStore: function() {
559 var login_template = '<div id="login-template" style="display: none;" title="Please login" class="alipi ui-widget-header ui-corner-all">' +
560 '<div>' +
561 '<h3> Registered Users:</h3>' +
562 '<div style="text-align: left;">Please enter your username and password </div>' +
563 '<input id="tar-uname" type="text" placeholder=" username" size="30">'+
564 '<input id="tar-pass" class="" type="password" placeholder=" password" size="30">'+
565 '<h3 class="">Guest Users:</h3>' +
566 '<div>Please enter your name </div>' +
567 '<input id="tar-name" class="" type="text" placeholder=" Your name" /> '+
568 '</div>' +
569 '</div>';
555 //process response
556 $.each(data['return'], function(i, val){
557 //suggestions.push(val.country);
558 suggestions.push(val['name']);
559 });
560 //pass array to callback
561 add(suggestions);
562 });
563 $('#lang-img').show();
564 },
565 });
570566
571 if($('#login-template').length == 0) {
572 $('body').append(login_template);
573 }
574 $(document).unbind('mouseover'); // Unbind the css on mouseover
575 $(document).unbind('mouseout'); // Unbind the css on mouseout
576567
577 $('#login-template').dialog({
578 height: 400,
579 width: 400,
580 position: 'center',
581 modal: true,
582 buttons: [
583 {
584 text: 'Login',
585 click: function() {
586 console.log('login');
587 var uname = $('#tar-uname').val();
588 var pass = $('#tar-pass').val();
589 if(uname && pass) {
590 $('.login-button > .ui-button-text').text('Please wait..');
591 sweet.authenticate(config.sweet + '/authenticate', uname, pass, a11ypi.publish, function() {
592 $('.login-button > .ui-button-text').text('Login');
568 },
569
570 loginToSwtStore: function() {
571 var login_template = '<div id="login-template" style="display: none;" title="Please login" class="alipi ui-widget-header ui-corner-all">' +
572 '<div>' +
573 '<h3> Registered Users:</h3>' +
574 '<div style="text-align: left;">Please enter your username and password </div>' +
575 '<input id="tar-uname" type="text" placeholder=" username" size="30">'+
576 '<input id="tar-pass" class="" type="password" placeholder=" password" size="30">'+
577 '<h3 class="">Guest Users:</h3>' +
578 '<div>Please enter your name </div>' +
579 '<input id="tar-name" class="" type="text" placeholder=" Your name" /> '+
580 '</div>' +
581 '</div>';
582
583 if($('#login-template').length == 0) {
584 $('body').append(login_template);
585 }
586 $(document).unbind('mouseover'); // Unbind the css on mouseover
587 $(document).unbind('mouseout'); // Unbind the css on mouseout
588
589 $('#login-template').dialog({
590 height: 400,
591 width: 400,
592 position: 'center',
593 modal: true,
594 buttons: [
595 {
596 text: 'Login',
597 click: function() {
598 console.log('login');
599 var uname = $('#tar-uname').val();
600 var pass = $('#tar-pass').val();
601 if(uname && pass) {
602 $('.login-button > .ui-button-text').text('Please wait..');
603 sweet.authenticate(config.sweet + '/authenticate', uname, pass, a11ypi.publish, function() {
604 $('.login-button > .ui-button-text').text('Login');
605 });
606 }
607 else {
608 //console.log('no username and password');
609 //$('#login-error').show();
610 //TODO: have a proper UI
611 alert('No username or password provided! Please enter both and then click Login');
612 }
613 },
614 'class': 'login-button'
615 },
616 {
617 text: 'Guest Login',
618 click: function() {
619 console.log('guest login');
620 var name = $('#tar-name').val();
621 if(name) {
622 $(this).dialog('close');
623 a11ypi.publish();
624 }
625 else {
626 //console.log('no guest name');
627 //$('#guest-error').show();
628 alert('Please provide a name for Guest Login');
629 }
630 }
631 }
632 ],
633 close: function() {
634 console.log('close');
635 }
593636 });
637 },
638
639 publish: function() {
640 $('#login-template').dialog('close');
641 if(util.hasChangesPending())
642 {
643 $('#pub_overlay').slideUp();
644 $('#element_edit_overlay').slideUp();
645 $('#icon_on_overlay').slideUp();
646 if (a11ypi.target == false ) {
647 var publish_template = '<div id="targetoverlay" title="Who are you narrating to?" class="alipi ui-widget-header ui-corner-all"> '+
648 // '<div id="infovis" class="alipi"> </div>'+
649 '<label id="tar-lab1" class="alipi" >Enter few attributes of the target community </label>'+
650 '<label id="tar-lab2" class="alipi" >Location of the target community: </label> '+
651 '<input id="loc-select" class="alipi" placeholder="Type city/town name"/> '+
652 '<img id="loc-img" src="http://dev.a11y.in/wsgi/images/db_loading.gif" /> '+
653 '<label id="tar-lab3" class="alipi" >Language of re-narration: </label> '+
654 '<input id="lang-select" class="alipi" placeholder="Type language name"/>'+
655 '<img id="lang-img" src="http://dev.a11y.in/wsgi/images/db_loading.gif"/> '+
656 '<label id="tar-lab4" class="alipi" >Select a style of re-narration: </label> '+
657 '<select id="style-select" class="alipi" > '+
658 '<option>Translation</option><option>Technical</option><option>Fun</option><option>Simplification</option> '+
659 '<option>Correction</option><option>Evolution</option><option>Other</option></select>'+
660 '<div id="free-form"><label id="tar-lab8" class="alipi">Comments:</label><textarea id="tar-comment"></textarea></div>'+
661 '<div id="blogset" > We are having issues with posting to a personal Google blog. Please use demo.swtr.us to publish.</div> '+
662 '<p id="tar-p" ><input id="our-check" class="alipi" type="radio"name="blog" /> '+
663 '<label id="tar-lab6" class="alipi" > demo.swtr.us </label><input id="your-check" class="alipi" type="radio" name="blog" /> '+
664 '<label id="tar-lab7" class="alipi">Personal Blog</label></p></div>';
665
666 $('body').append(publish_template);
667 a11ypi.getLoc();
668 a11ypi.getLang();
669 a11ypi.target = true;
670 }
671
672 $(document).unbind('mouseover'); // Unbind the css on mouseover
673 $(document).unbind('mouseout'); // Unbind the css on mouseout
674
675 $('#pub_overlay').slideUp();
676 $('#element_edit_overlay').slideUp();
677 // $('#icon_on_overlay').slideUp();
678
679 $(function() {
680 $( "#targetoverlay" ).dialog({
681 height:550,
682 width:700,
683 modal: true,
684 buttons: {
685 Publish: function() {
686 util.publish();
687 },
688
689 },
690 close: function() {
691 $('#pub_overlay').slideDown();
692 // $('#element_edit_overlay').slideDown();
693 // $('#icon_on_overlay').slideDown();
694 $( "#targetoverlay" ).hide();
695 }
696 });
697 });
698 }
699 },
700
701 hideAll: function() {
702 var boxes = '#show-links, #show-box, #show-comment';
703 if($(boxes).dialog().dialog("isOpen"))
704 $(boxes).dialog().dialog('close');
705 },
706
707 showBox: function() {
708 a11ypi.hideAll();
709 $(document).unbind('mouseover'); // Unbind the css on mouseover
710 $(document).unbind('mouseout'); // Unbind the css on mouseout
711
712 $(function() {
713 // $( "#show-box" ).dialog( "destroy" );
714
715 $( "#show-box" ).dialog({
716 width: 300,
717 height: 300,
718 modal: true
719 });
720 });
721 d = window.location.search.split('?')[1];
722 var a = a11ypi.getParams();
723 if (a['blog'] === undefined ) {
724 a11ypi.createMenu('re-narration');
725 }
726 else {
727 $('#show-box').attr('title', 'Choose a re-narration from the blog you specified.');
728 a11ypi.ajax1();
729 }
730 },
731 showComment: function() {
732 a11ypi.hideAll();
733 $(document).unbind('mouseover'); // Unbind the css on mouseover
734 $(document).unbind('mouseout'); // Unbind the css on mouseout
735
736 $(function() {
737 $( "#show-comment" ).dialog( "destroy" );
738
739 $( "#show-comment" ).dialog({
740 width: 300,
741 height: 300,
742 modal: true
743 });
744 });
745 a11ypi.createMenu('5el');
746 },
747
748 ajaxLinks1: function() {
749 // var xhr = new XMLHttpRequest();
750 // xhr.onreadystatechange = function()
751 // {
752 // if(xhr.readyState == 4)
753 // {
754 // if(xhr.responseText == "empty")
755 // { }
756 // else
757 // {
758 // $('#see-links').show();
759 // a11ypi.showlinks = JSON.parse(xhr.responseText);
760 // }
761 // }
762 // }
763 // xhr.open("POST",config.deploy+"/domain",true);
764 // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
765 // d = window.location.search.split('?')[1];
766 // a = a11ypi.getParams();
767 // xhr.send('url='+a['foruri'])
768
769 $.get(config.deploy+"/domain", {"url":a['foruri']}, function(data){
770 if(data[0] != 'empty')
771 {
772 a11ypi.showlinks = data;
773 $('#see-links').show();
774 }
775 });
776 },
777 showBox1: function() {
778 a11ypi.hideAll();
779 $(document).unbind('mouseover'); // Unbind the css on mouseover
780 $(document).unbind('mouseout'); // Unbind the css on mouseout
781
782 $(function() {
783 // $( "#show-links" ).dialog( "destroy" );
784
785 $( "#show-links" ).dialog({
786 width: 500,
787 height: 300,
788 modal: true
789 });
790 });
791 a11ypi.createDomainMenu();
792 },
793 createDomainMenu: function() {
794 var xyz = $("#show-links");
795 xyz.html('');
796 for(var i in a11ypi.showlinks)
797 {
798 var para = document.createElement("p");
799 var newel = document.createElement("a");
800 newel.textContent = a11ypi.showlinks[i];
801 newel.setAttribute("href", config.deploy+"/?foruri="+encodeURIComponent(a11ypi.showlinks[i]));
802 newel.setAttribute("class","alipiShowLink");
803 para.appendChild(newel);
804 xyz.append(para);
805 }
806 $('.alipiShowLink').hover(
807 function() {
808 var xhr = new XMLHttpRequest();
809 xhr.onreadystatechange = function()
810 {
811 if(xhr.readyState == 4)
812 {
813 if(xhr.responseText == "empty")
814 { }
815 else
816 {
817 menu_list = JSON.parse(xhr.responseText);
818 x = '';
819 for(i=0; i<menu_list.length; i++) {
820 if (i == menu_list.length-1) {
821 x += menu_list[i];
822 } else {
823 x += menu_list[i] + ", ";
824 }
825 }
826 $('#show-links').title = x;
827 }
828 }
829 }
830 xhr.open("POST",config.root+"/menu",true);
831 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
832 xhr.send('url='+encodeURIComponent($(this).attr('href'))) ;
833 },
834 function () {$('#show-links').title= '';}
835 );
836 },
837 // blogFilter: function() {
838 // if (a11ypi.blog_flag == false) {
839 // a11ypi.blog_flag = true;
840 // // var xhr = new XMLHttpRequest();
841 // // xhr.onreadystatechange = function()
842 // // {
843 // // if(xhr.readyState == 4)
844 // // {
845 // // if(xhr.responseText == "empty")
846 // // { }
847 // // else
848 // // {
849 // // var sel = $("#blog-filter");
850 // // var menu_list = JSON.parse(xhr.responseText);
851 // // opt = document.createElement("option");
852 // // opt.textContent = "Choose a blog";
853 // // sel.append(opt);
854 // // for (var i=0; i < menu_list.length; i++)
855 // // {
856 // // opt = document.createElement("option");
857 // // opt.textContent = menu_list[i];
858 // // sel.append(opt);
859 // // }
860 // // }
861 // // }
862 // // }
863 // // xhr.open("POST",config.deploy+"/blog",true);
864 // // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
865 // // a = a11ypi.getParams();
866 // // xhr.send('url='+a['foruri']);
867 // $.get(config.deploy+"/blog", {"url":a['foruri']}, function(data){
868 // var sel = $("#blog-filter");
869 // var menu_list = JSON.parse(data);
870 // opt = document.createElement("option");
871 // opt.textContent = "Choose a blog";
872 // sel.append(opt);
873 // for (var i=0; i < menu_list.length; i++)
874 // {
875 // opt = document.createElement("option");
876 // opt.textContent = menu_list[i];
877 // sel.append(opt);
878 // }
879 // });
880 // }
881 // },
882 go: function() {
883 var a =[];
884 for (var i = 0;i<d.split('&').length;i++){
885 a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1];
886 }
887 if ($("#blog-filter").val() == null)
888 { }
889 else {
890 window.open(config.deploy+"/?foruri=" + a['foruri'] + "&blog=" + $("#blog-filter").val());
891 }
892 },
893 share: function() {
894 $('#fb-like').css('display', 'block');
895 $('#tweet-root').css('display', 'block');
896 $( "#share-box" ).dialog({
897 position: 'center',
898 width:450,
899 height:180,
900 modal: true,
901 });
902 },
903 editPage: function() {
904 //this.hideAll();
905 a11ypi.testContext();
906 $('#pub_overlay').show(); $('#pub_overlay').addClass('barOnTop');
907 $('#icon-down').show();
908 $('#renarrated_overlay').hide();
909 $('body *').not('iframe').contents().filter(function(){
910 {
911 try{
912 if(!($(this).hasClass('alipi')) && $(this).attr('m4pageedittype') )
913 return this;
914 }
915 catch(err)
916 {
917 //pass
918 }
919 }
920 }).click(pageEditor.startEdit);
921
922 $('body *').not('iframe').contents().filter(function(){
923 {
924 try{
925 if(!($(this).hasClass('alipi')) || $(this).attr('m4pageedittype'))
926 return this;
927 }
928 catch(err)
929 {
930 //pass
931 }
932 }
933 }).click(pageEditor.noEdit);
934
935 $(document).mouseover(a11ypi.highlightOnHover);
936 $(document).mouseout(a11ypi.unhighlightOnMouseOut);
937 },
938
939 displayEditor: function() {
940 var template = '<div id="editoroverlay" title="Editor" class="alipi ui-widget-header ui-corner-all">'+
941 '<button id="close-adv" class="alipi" onclick="a11ypi.closeAdv();" title="Want to close View Source & display without HTML code?"> '+
942 'Render source</button> '+
943 '<button id="adv-ref" class="alipi" onclick="a11ypi.showAdv();" title="Want to see HTML code? Then click me !!">View Source</button> '+
944 '<label id="ref-lab" class="alipi" style="left:3%;">Here is original piece (Reference)</label>'+
945 '<div id="reference" class="alipi" readonly="yes"></div>'+
946 '<textarea id="adv-reference" class="alipi" readonly="yes"></textarea> '+
947 '<label id="edit-lab" class="alipi" style="left:53%;">Where you should edit (Editor)</label>'+
948 '<div id="editor" class="alipi" contenteditable="true" '+
949 '</div>';
950 $('body').append(template);
951 $('#pub_overlay').slideUp();
952 $('#element_edit_overlay').hide();
953
954 var tag = pageEditor.event.target.nodeName;
955 $(pageEditor.event.target).removeAttr('m4pageedittype');
956 $(pageEditor.event.target).children().removeAttr('m4pageedittype');
957
958 $('#adv-reference').text('<'+tag+'>'+$(pageEditor.event.target).html()+'</'+tag+'>');
959 $('#reference').html($(pageEditor.event.target).html());
960 $('#editor').html($(pageEditor.event.target).html());
961 $("#adv-ref").button({icons:{primary:"ui-icon-script"},text:true}); $('#adv-ref').children().addClass('alipi');
962 $("#close-adv").button({icons:{primary:"ui-icon-bookmark"},text:true}); $('#close-adv').children().addClass('alipi');
963 $('#close-adv').hide();
964 $('#adv-ref').button();
965
966 $(document).unbind('mouseover'); // Unbind the css on mouseover
967 $(document).unbind('mouseout'); // Unbind the css on mouseout
968
969 $( "#editoroverlay" ).dialog({
970 position: 'center',
971 width:$(window).width()-10,
972 height:$(window).height()-50,
973 modal: true,
974 buttons: {
975 "+": function() {
976 if($('#editor').css('font-size') >= '30px') {
977 // passthrough
978 }
979 else {
980 var font = parseFloat($('#editor').css('font-size')) + 1;
981 $('#editor').css('font-size', font+'px');
982 font = parseFloat($('#reference').css('font-size')) + 1;
983 $('#reference').css('font-size', font+'px');
984 font = parseFloat($('#adv-reference').css('font-size')) + 1;
985 $('#adv-reference').css('font-size', font+'px');
986 }
987 },
988 "-": function() {
989 if($('#editor').css('font-size') <= '10px') {
990 //passthrough
991 }
992 else {
993 var font = parseFloat($('#editor').css('font-size')) - 1;
994 $('#editor').css('font-size', font+'px');
995 font = parseFloat($('#reference').css('font-size')) - 1;
996 $('#reference').css('font-size', font+'px');
997 font = parseFloat($('#adv-reference').css('font-size')) - 1;
998 $('#adv-reference').css('font-size', font+'px');
999 }
1000 },
1001 "Add Link": function() {
1002 pageEditor.handler();
1003 },
1004 "Save changes": function() {
1005 $('#pub_overlay').slideDown();
1006 $('#element_edit_overlay').slideDown();
1007 $('#icon_on_overlay').slideDown();
1008 manager.recordText(pageEditor.event.target);
1009 pageEditor.cleanUp(pageEditor.event.target);
1010 $( "#editoroverlay" ).remove();
1011 }
1012 },
1013 close: function() {
1014 pageEditor.cleanUp(pageEditor.event.target);
1015 $("#editoroverlay" ).remove();
1016 }
1017 });
1018
1019 $($($('<label>').insertAfter($('.ui-dialog-buttonset').children()[0])).html('Magnify or Demagnify')); // Element added externally with css
1020 $($('.ui-dialog-buttonset').children()[1]).attr('id','mag-demag');
1021 $($('.ui-dialog-buttonset').children()[0]).attr('id','mag'); // '+'
1022 $($('.ui-dialog-buttonset').children()[2]).attr('id','demag'); // '-'
1023 $($('.ui-dialog-buttonset').children()[3]).attr('id','add-link'); // 'Link'
1024 $($('.ui-dialog-buttonset').children()[4]).attr('id','save-changes'); // 'Save Changes'
1025
1026 $('#adv-reference').height($('#editor').height() + 40);
1027 $('#reference').height($('#editor').height());
1028 $('#mag').attr('title', 'To magnify letters/Increase font size');
1029 $('#demag').attr('title', 'To demagnify letters/Decrease font size');
1030 $('#add-link').attr('title', 'Add link(href) to the selected text portion (Before clicking this button, select some portion of text in "Editor")');
1031 $('#save-changes').attr('title', 'Save edited text onto the page')
1032 },
1033
1034 showAdv: function() {
1035 $('#reference').hide();
1036 $('#adv-reference').show();
1037 $('#adv-ref').hide();
1038 $('#close-adv').show();
1039 },
1040 closeAdv: function() {
1041 $('#reference').show();
1042 $('#adv-reference').hide();
1043 $('#close-adv').hide();
1044 $('#adv-ref').show();
1045 },
1046
1047 reflectInReference: function() {
1048 var tag = pageEditor.event.target.nodeName;
1049 $("#reference").html() = $("#editor").html();
1050 },
1051
1052 imageReplacer: function() {
1053 var imageInputTemplate = '<div id="imageInputElement" title="Enter url" class="alipi ui-widget-header ui-corner-all">'+
1054 '<input type="text" id="imageInput" placeholder="http://foo.com/baz.jpg" class="alipi" value=""/></div>';
1055
1056 $('body').append(imageInputTemplate);
1057 $(document).unbind('mouseover'); // Unbind the css on mouseover
1058 $(document).unbind('mouseout'); // Unbind the css on mouseout
1059
1060 $('#pub_overlay').slideUp();
1061 $('#element_edit_overlay').slideUp();
1062 $('#icon_on_overlay').slideUp();
1063
1064 $( "#imageInputElement" ).dialog({
1065 width:300,
1066 height:200,
1067 modal: true,
1068 buttons: {
1069 OK: function() {
1070 var formValue = $('#imageInput').val();
1071 if(formValue != '\/S/')
1072 {
1073 manager.recordImage(pageEditor.event.target, formValue);
1074 pageEditor.cleanUp(pageEditor.event.target);
1075 $( "#imageInputElement" ).remove();
1076 }
1077 }
1078 },
1079 close: function() {
1080 pageEditor.cleanUp(pageEditor.event.target);
1081 $("#imageInputElement" ).remove();
1082 }
1083 });
1084
1085 },
1086
1087 addAudio: function() {
1088 var audioInputTemplate = '<div id="audioInputElement" title="Enter url" class="alipi ui-widget-header ui-corner-all">'+
1089 '<input type="text" id="audioInput" placeholder="http://foo.com/baz.ogg" class="alipi" value=""/></div>';
1090
1091 $('body').append(audioInputTemplate);
1092 $(document).unbind('mouseover'); // Unbind the css on mouseover
1093 $(document).unbind('mouseout'); // Unbind the css on mouseout
1094
1095 $('#pub_overlay').slideUp();
1096 $('#element_edit_overlay').slideUp();
1097 $('#icon_on_overlay').slideUp();
1098
1099 $( "#audioInputElement" ).dialog({
1100 width:300,
1101 height:200,
1102 modal: true,
1103 buttons: {
1104 OK: function() {
1105 pageEditor.addAudio();
1106 pageEditor.cleanUp(pageEditor.event.target);
1107 $( "#audioInputElement" ).remove();
1108 }
1109 },
1110 close: function() {
1111 pageEditor.cleanUp(pageEditor.event.target);
1112 $("#audioInputElement" ).remove();
1113 }
1114 });
1115 },
1116
1117 highlightOnHover: function(event) {
1118 if( !($(event.target).hasClass('alipi')) ) {
1119 $(event.target).addClass('highlightElement');
1120 }
1121 },
1122
1123 unhighlightOnMouseOut: function(event) {
1124 $(event.target).removeClass('highlightElement');
1125 },
1126 showInfo: function(data) {
1127 infoWindow = window.open(config.deploy+'/blank','Info page');
1128 window.setTimeout(function(){a11ypi.pushInfo(infoWindow.document.getElementById('info_content'),infoWindow,data);},2500);
1129 },
1130 pushInfo: function(ele, win, data) //ele contains the info_content element from blank.html
1131 {
1132 win.infoFullJSON = a11ypi.responseJSON;
1133 win.onLoad();
1134 },
1135 getParams: function()
1136 {
1137 var a = [];
1138 if(window.location.hostname == config.hostname || "localhost" )
1139 {
1140 d = window.location.search.split('?')[1];
1141 for (var i = 0;i<d.split('&').length;i++){
1142 a[d.split('&')[i].split('=')[0]] = decodeURIComponent(d.split('&')[i].split('=')[1]);
1143 }
1144 return a;
1145 }
1146 else
1147 {
1148 a['foruri'] = window.location.href;
1149 return a;
1150 }
5941151 }
595 else {
596 //console.log('no username and password');
597 //$('#login-error').show();
598 //TODO: have a proper UI
599 alert('No username or password provided! Please enter both and then click Login');
600 }
1152 };
1153 window.a11ypi = a11ypi;
1154
1155
1156 });
1157 window.a11ypi.loadOverlay();
1158 var pageEditor = {
1159 event: 0 , //Use this var to store the event object, which will be passed for editor.
1160 m4pageedittype: '',
1161 savedHtml: '',
1162 url:'',
1163 selection:'',
1164 startEdit: function(event)
1165 {
1166 if(event.target.nodeName != 'AUDIO'){
1167 event.stopPropagation();
1168 event.preventDefault();
1169 }
1170 pageEditor.event = event;
1171 pageEditor.m4pageedittype = $(event.target).attr('m4pageedittype');
1172 $('*').removeClass('highlightOnSelect');
1173
1174 if (pageEditor.event) {
1175 xAxis = pageEditor.event.clientX;
1176 yAxis = pageEditor.event.clientY;
1177 $("#element_edit_overlay").css("top", yAxis);
1178 $("#element_edit_overlay").css("left", xAxis);
1179 }
1180
1181 if($(event.target).attr('m4pageedittype') == 'text') {
1182 $(event.target).addClass('highlightOnSelect'); // To show selected element
1183
1184 $('#edit-text').show();
1185 $('#add-audio').show();
1186 $('#close-element').show();
1187 $('#replace-image').hide();
1188 $('#delete-image').hide();
1189 $('#cant-edit').hide();
1190 $("body").css("overflow", "hidden");
1191 $('#pub_overlay').slideDown();
1192 $('#element_edit_overlay').slideDown();
1193 // At this point 'displayEditor' function will be performed on click of 'Edit Text' button
1194 // displayEditor function is in ui.js file
1195 }
1196 else if($(event.target).attr('m4pageedittype') == 'image') {
1197 $(event.target).addClass('highlightOnSelect'); // To show selected element
1198
1199 $('#replace-image').show();
1200 $('#delete-image').show();
1201 $('#close-element').show();
1202 $('#add-audio').hide();
1203 $('#edit-text').hide();
1204 $('#cant-edit').hide();
1205 $("body").css("overflow", "hidden");
1206 $('#element_edit_overlay').slideDown();
1207 $('#pub_overlay').slideDown();
1208 // At this point 'imageReplacer' function will be performed on click of 'Replace Image' button
1209 // imageReplacer function is in ui.js
1210 }
6011211 },
602 'class': 'login-button'
603 },
604 {
605 text: 'Guest Login',
606 click: function() {
607 console.log('guest login');
608 var name = $('#tar-name').val();
609 if(name) {
610 $(this).dialog('close');
611 a11ypi.publish();
612 }
613 else {
614 //console.log('no guest name');
615 //$('#guest-error').show();
616 alert('Please provide a name for Guest Login');
617 }
618 }
619 }
620 ],
621 close: function() {
622 console.log('close');
623 }
624 });
625 },
6261212
627 publish: function() {
628 $('#login-template').dialog('close');
629 if(util.hasChangesPending())
630 {
631 $('#pub_overlay').slideUp();
632 $('#element_edit_overlay').slideUp();
633 $('#icon_on_overlay').slideUp();
634 if (a11ypi.target == false ) {
635 var publish_template = '<div id="targetoverlay" title="Who are you narrating to?" class="alipi ui-widget-header ui-corner-all"> '+
636 // '<div id="infovis" class="alipi"> </div>'+
637 '<label id="tar-lab1" class="alipi" >Enter few attributes of the target community </label>'+
638 '<label id="tar-lab2" class="alipi" >Location of the target community: </label> '+
639 '<input id="loc-select" class="alipi" placeholder="Type city/town name"/> '+
640 '<img id="loc-img" src="http://dev.a11y.in/wsgi/images/db_loading.gif" /> '+
641 '<label id="tar-lab3" class="alipi" >Language of re-narration: </label> '+
642 '<input id="lang-select" class="alipi" placeholder="Type language name"/>'+
643 '<img id="lang-img" src="http://dev.a11y.in/wsgi/images/db_loading.gif"/> '+
644 '<label id="tar-lab4" class="alipi" >Select a style of re-narration: </label> '+
645 '<select id="style-select" class="alipi" > '+
646 '<option>Translation</option><option>Technical</option><option>Fun</option><option>Simplification</option> '+
647 '<option>Correction</option><option>Evolution</option><option>Other</option></select>'+
648 '<div id="free-form"><label id="tar-lab8" class="alipi">Comments:</label><textarea id="tar-comment"></textarea></div>'+
649 '<div id="blogset" > We are having issues with posting to a personal Google blog. Please use demo.swtr.us to publish.</div> '+
650 '<p id="tar-p" ><input id="our-check" class="alipi" type="radio"name="blog" /> '+
651 '<label id="tar-lab6" class="alipi" > demo.swtr.us </label><input id="your-check" class="alipi" type="radio" name="blog" /> '+
652 '<label id="tar-lab7" class="alipi">Personal Blog</label></p></div>';
1213 noEdit: function(event)
1214 {
1215 if (event) {
1216 xAxis = event.clientX;
1217 yAxis = event.clientY;
1218 $("#element_edit_overlay").css("top", yAxis);
1219 $("#element_edit_overlay").css("left", xAxis);
1220 }
1221 $('*').removeClass('highlightOnSelect');
1222 if(!($(event.target).attr('m4pageedittype'))) {
1223 $('#edit-text').hide();
1224 $('#add-audio').hide();
1225 $('#replace-image').hide();
1226 $('#delete-image').hide();
1227 $('#close-element').hide();
1228 $('#cant-edit').show();
1229 window.setTimeout("$('#cant-edit').hide();", 3000);
1230 $("body").css("overflow", "auto");
1231 $('#pub_overlay').slideDown();
1232 $('#element_edit_overlay').slideDown();
1233 }
1234 },
6531235
654 $('body').append(publish_template);
655 a11ypi.getLoc();
656 a11ypi.getLang();
657 a11ypi.target = true;
658 }
1236 handler: function()
1237 {
1238 var sel = window.getSelection();
1239 y = sel.anchorOffset;
1240 z = sel.focusOffset;
1241 if(y != z)
1242 {
1243 pageEditor.savedHtml = $('#editor').html();
1244 var url = prompt("Enter url");
1245 if(url)
1246 {
1247 sel.anchorNode.textContent = sel.anchorNode.textContent.substr(0,y)+'<a href="'+url+'">'+sel.anchorNode.textContent.substr(y,z-y)+"</a>"+sel.anchorNode.textContent.substr(z);
1248 abc = $('#editor').html();
1249 abc = abc.replace(/(&lt;)/g,'<');
1250 abc = abc.replace(/(&gt;)/g,'>');
1251 $('#editor').html(abc);
1252 }
1253 else
1254 {
1255 $('#dialog-message').html('<p>Please enter a valid url</p>');
1256 $('#dialog-message').dialog({
1257 modal: true,
1258 buttons:{
1259 OK:function(){
1260 $(this).dialog("close");
1261 $(this).html('');
1262 }
1263 }});
1264 }
1265 }
1266 else{
1267 $('#dialog-message').html('<p>Please choose a portion of text and then click <b>Add link</b>.</p>');
1268 $('#dialog-message').dialog({
1269 modal: true,
1270 buttons:{
1271 OK:function(){
1272 $(this).dialog("close");
1273 $(this).html('');
1274 }
1275 }});
1276 }
1277 },
6591278
660 $(document).unbind('mouseover'); // Unbind the css on mouseover
661 $(document).unbind('mouseout'); // Unbind the css on mouseout
1279 addAudio: function(){
1280 url = $('#audioInput').val();
1281 if(url.substr(-4) =='.ogg'){
1282 manager.recordAudio(pageEditor.event.target);
1283 }
1284 // else{
1285 // $('#dialog-message').html('<p>Please enter a valid url</p>');
1286 // $('#dialog-message').dialog({
1287 // modal: true,
1288 // buttons:{
1289 // OK:function(){
1290 // $(this).dialog("close");
1291 // $(this).html('');
1292 // }
1293 // }});
1294 // }
1295 },
6621296
663 $('#pub_overlay').slideUp();
664 $('#element_edit_overlay').slideUp();
665 // $('#icon_on_overlay').slideUp();
1297 deleteImage: function(){
1298 manager.deleteImage(pageEditor.event.target);
1299 pageEditor.cleanUp(pageEditor.event.target);
1300 },
6661301
667 $(function() {
668 $( "#targetoverlay" ).dialog({
669 height:550,
670 width:700,
671 modal: true,
672 buttons: {
673 Publish: function() {
674 util.publish();
675 },
1302 cleanUp: function(element)
1303 {
1304 if(util.hasChangesPending()) {
1305 $('#undo-button').button('option', 'disabled', false); // Another way of enabling UI-JQUERY button
1306 $('#publish-button').button({ disabled: false}); // Enabling UI-JQUERY button
1307 } else {
1308 $('#undo-button').button({ disabled: true}); // Disabling button
1309 $('#publish-button').button({ disabled: true}); // Disabling button
1310 }
6761311
677 },
678 close: function() {
679 $('#pub_overlay').slideDown();
680 // $('#element_edit_overlay').slideDown();
681 // $('#icon_on_overlay').slideDown();
682 $( "#targetoverlay" ).hide();
683 }
684 });
685 });
686 }
687 },
1312 $(element).attr('m4pageedittype', pageEditor.m4pageedittype);
1313 $(element).children().attr('m4pageedittype', pageEditor.m4pageedittype);
1314 // $('#icon_on_overlay').slideDown();
1315 $('#pub_overlay').slideDown();
1316 $('#element_edit_overlay').hide();
1317 $("body").css("overflow", "auto");
1318 $('*').removeClass('highlightOnSelect');
1319 // $('#element_edit_overlay').slideDown();
1320 $(document).mouseover(a11ypi.highlightOnHover);
1321 $(document).mouseout(a11ypi.unhighlightOnMouseOut);
1322 // $(pageEditor.event.target).removeClass('highlightOnSelect'); // Remove hightlight of selected element
1323 },
1324 };
6881325
689 hideAll: function() {
690 var boxes = '#show-links, #show-box, #show-comment';
691 $(boxes).dialog('close');
692 },
1326 var DOM = {
1327 getXpath : function (element)
1328 {
1329 var str = '';
1330 var currentNode = element;
1331 var path = '';
1332 var index = -1;
6931333
694 showBox: function() {
695 this.hideAll();
696 $(document).unbind('mouseover'); // Unbind the css on mouseover
697 $(document).unbind('mouseout'); // Unbind the css on mouseout
1334 if (currentNode.nodeName != "#text")
1335 {
1336 path = DOM.makePath(currentNode);
1337 }
1338 else
1339 {
1340 path = DOM.makePath(currentNode.parentNode);
1341 }
6981342
699 $(function() {
700 $( "#show-box" ).dialog( "destroy" );
7011343
702 $( "#show-box" ).dialog({
703 width: 300,
704 height: 300,
705 modal: true
706 });
707 });
708 d = window.location.search.split('?')[1];
709 var a = a11ypi.getParams();
710 if (a['blog'] === undefined ) {
711 a11ypi.createMenu('re-narration');
712 }
713 else {
714 $('#show-box').attr('title', 'Choose a re-narration from the blog you specified.');
715 a11ypi.ajax1();
716 }
717 },
718 showComment: function() {
719 this.hideAll();
720 $(document).unbind('mouseover'); // Unbind the css on mouseover
721 $(document).unbind('mouseout'); // Unbind the css on mouseout
1344 return path;
1345 },
1346 getElementIdx : function getElementIdx(elt)
1347 {
1348 var count = 1;
1349 for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling)
1350 {
1351 if(sib.nodeType == 1 && sib.tagName == elt.tagName)count++
1352 }
7221353
723 $(function() {
724 $( "#show-comment" ).dialog( "destroy" );
1354 return count;
1355 },
7251356
726 $( "#show-comment" ).dialog({
727 width: 300,
728 height: 300,
729 modal: true
730 });
731 });
732 a11ypi.createMenu('5el');
733 },
1357 makePath : function makePath(elt){
1358 var path = '';
1359 for (; elt && elt.nodeType == 1; elt = elt.parentNode)
1360 {
1361 if(elt.id == "")
1362 {
1363 idx = DOM.getElementIdx(elt);
1364 xname = elt.tagName;
1365 if (idx > 1)
1366 xname += "[" + idx + "]";
1367 path = "/" + xname + path;
1368 }
1369 else
1370 {
1371 path = "//*[@id='"+elt.id+"']"+path;
1372 break;
1373 }
1374 }
1375 return path;
1376 },
1377 settextContent : function(element, content){
1378 $(element).html(content);
1379 },
1380 gettextContent:function(element)
1381 {
1382 return $(element).html();
1383 },
1384 };
7341385
735 ajaxLinks1: function() {
736 // var xhr = new XMLHttpRequest();
737 // xhr.onreadystatechange = function()
738 // {
739 // if(xhr.readyState == 4)
740 // {
741 // if(xhr.responseText == "empty")
742 // { }
743 // else
744 // {
745 // $('#see-links').show();
746 // a11ypi.showlinks = JSON.parse(xhr.responseText);
747 // }
748 // }
749 // }
750 // xhr.open("POST",config.deploy+"/domain",true);
751 // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
752 // d = window.location.search.split('?')[1];
753 // a = a11ypi.getParams();
754 // xhr.send('url='+a['foruri'])
1386 var util = {
1387 history: [],
1388 command: [],
7551389
756 $.get(config.deploy+"/domain", {"url":a['foruri']}, function(data){
757 if(data[0] != 'empty')
758 {
759 a11ypi.showlinks = data;
760 $('#see-links').show();
761 }
762 });
763 },
764 showBox1: function() {
765 this.hideAll();
766 $(document).unbind('mouseover'); // Unbind the css on mouseover
767 $(document).unbind('mouseout'); // Unbind the css on mouseout
1390 forEach : function(array, callback) {
1391 var i = 0, length = array.length, value;
7681392
769 $(function() {
770 $( "#show-links" ).dialog( "destroy" );
1393 if (length) {
1394 for (value = array[0]; i < length && callback.call(value, i, value) !== false; value = array[++i]) {
1395 }
1396 }
1397 },
1398 hasChangesPending : function(){
1399 return util.history.length > 0;
1400 },
1401 formUncomplete : function formUnomplete(){
1402 return (locName == '' && langName=='' && styleName == '' );
1403 },
7711404
772 $( "#show-links" ).dialog({
773 width: 500,
774 height: 300,
775 modal: true
776 });
777 });
778 a11ypi.createDomainMenu();
779 },
780 createDomainMenu: function() {
781 var xyz = $("#show-links");
782 xyz.html('');
783 for(var i in a11ypi.showlinks)
784 {
785 var para = document.createElement("p");
786 var newel = document.createElement("a");
787 newel.textContent = a11ypi.showlinks[i];
788 newel.setAttribute("href", config.deploy+"/?foruri="+encodeURIComponent(a11ypi.showlinks[i]));
789 newel.setAttribute("class","alipiShowLink");
790 para.appendChild(newel);
791 xyz.append(para);
792 }
793 $('.alipiShowLink').hover(
794 function() {
795 var xhr = new XMLHttpRequest();
796 xhr.onreadystatechange = function()
797 {
798 if(xhr.readyState == 4)
799 {
800 if(xhr.responseText == "empty")
801 { }
802 else
803 {
804 menu_list = JSON.parse(xhr.responseText);
805 x = '';
806 for(i=0; i<menu_list.length; i++) {
807 if (i == menu_list.length-1) {
808 x += menu_list[i];
809 } else {
810 x += menu_list[i] + ", ";
811 }
812 }
813 $('#show-links').title = x;
814 }
815 }
816 }
817 xhr.open("POST",config.root+"/menu",true);
818 xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
819 xhr.send('url='+encodeURIComponent($(this).attr('href'))) ;
820 },
821 function () {$('#show-links').title= '';}
822 );
823 },
824 // blogFilter: function() {
825 // if (a11ypi.blog_flag == false) {
826 // a11ypi.blog_flag = true;
827 // // var xhr = new XMLHttpRequest();
828 // // xhr.onreadystatechange = function()
829 // // {
830 // // if(xhr.readyState == 4)
831 // // {
832 // // if(xhr.responseText == "empty")
833 // // { }
834 // // else
835 // // {
836 // // var sel = $("#blog-filter");
837 // // var menu_list = JSON.parse(xhr.responseText);
838 // // opt = document.createElement("option");
839 // // opt.textContent = "Choose a blog";
840 // // sel.append(opt);
841 // // for (var i=0; i < menu_list.length; i++)
842 // // {
843 // // opt = document.createElement("option");
844 // // opt.textContent = menu_list[i];
845 // // sel.append(opt);
846 // // }
847 // // }
848 // // }
849 // // }
850 // // xhr.open("POST",config.deploy+"/blog",true);
851 // // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
852 // // a = a11ypi.getParams();
853 // // xhr.send('url='+a['foruri']);
854 // $.get(config.deploy+"/blog", {"url":a['foruri']}, function(data){
855 // var sel = $("#blog-filter");
856 // var menu_list = JSON.parse(data);
857 // opt = document.createElement("option");
858 // opt.textContent = "Choose a blog";
859 // sel.append(opt);
860 // for (var i=0; i < menu_list.length; i++)
861 // {
862 // opt = document.createElement("option");
863 // opt.textContent = menu_list[i];
864 // sel.append(opt);
865 // }
866 // });
867 // }
868 // },
869 go: function() {
870 var a =[];
871 for (var i = 0;i<d.split('&').length;i++){
872 a[d.split('&')[i].split('=')[0]] = d.split('&')[i].split('=')[1];
873 }
874 if ($("#blog-filter").val() == null)
875 { }
876 else {
877 window.open(config.deploy+"/?foruri=" + a['foruri'] + "&blog=" + $("#blog-filter").val());
878 }
879 },
880 share: function() {
881 $('#fb-like').css('display', 'block');
882 $('#tweet-root').css('display', 'block');
883 $( "#share-box" ).dialog({
884 position: 'center',
885 width:450,
886 height:180,
887 modal: true,
888 });
889 },
890 editPage: function() {
891 //this.hideAll();
892 a11ypi.testContext();
893 $('#pub_overlay').show(); $('#pub_overlay').addClass('barOnTop');
894 $('#icon-down').show();
895 $('#renarrated_overlay').hide();
896 $('body *').not('iframe').contents().filter(function(){
897 {
898 try{
899 if(!($(this).hasClass('alipi')) && $(this).attr('m4pageedittype') )
900 return this;
901 }
902 catch(err)
903 {
904 //pass
905 }
906 }
907 }).click(pageEditor.startEdit);
1405 makeChanges: function (command, selectedElement) {
1406 var poofPosition, poofDiv;
1407 util.command = command;
1408 switch (util.command.command) {
1409 case 'TEXT_UPDATE':
1410 DOM.settextContent(util.command.element, util.command.data);
1411 break;
1412 case 'IMAGE_DELETE':
1413 $(selectedElement).hide();
1414 break;
1415 case 'IMAGE_SRC_UPDATE':
1416 imageMatcher = new RegExp("(\\d+)x(\\d+),(.+)").exec(util.command.data);
1417 imageWidth = imageMatcher[1];
1418 imageHeight = imageMatcher[2];
1419 imageSrc = imageMatcher[3];
9081420
909 $('body *').not('iframe').contents().filter(function(){
910 {
911 try{
912 if(!($(this).hasClass('alipi')) || $(this).attr('m4pageedittype'))
913 return this;
914 }
915 catch(err)
916 {
917 //pass
918 }
919 }
920 }).click(pageEditor.noEdit);
1421 if (imageSrc && util.command.element.src != imageSrc) {
1422 util.command.element.src = imageSrc;
1423 }
1424 if (imageWidth == 0) {
1425 util.command.element.removeAttribute('width');
1426 } else {
1427 util.command.element.width = imageWidth;
1428 }
9211429
922 $(document).mouseover(a11ypi.highlightOnHover);
923 $(document).mouseout(a11ypi.unhighlightOnMouseOut);
924 },
1430 if (imageHeight == 0) {
1431 util.command.element.removeAttribute('height');
1432 } else {
1433 util.command.element.height = imageHeight;
1434 }
1435 break;
9251436
926 displayEditor: function() {
927 var template = '<div id="editoroverlay" title="Editor" class="alipi ui-widget-header ui-corner-all">'+
928 '<button id="close-adv" class="alipi" onclick="a11ypi.closeAdv();" title="Want to close View Source & display without HTML code?"> '+
929 'Render source</button> '+
930 '<button id="adv-ref" class="alipi" onclick="a11ypi.showAdv();" title="Want to see HTML code? Then click me !!">View Source</button> '+
931 '<label id="ref-lab" class="alipi" style="left:3%;">Here is original piece (Reference)</label>'+
932 '<div id="reference" class="alipi" readonly="yes"></div>'+
933 '<textarea id="adv-reference" class="alipi" readonly="yes"></textarea> '+
934 '<label id="edit-lab" class="alipi" style="left:53%;">Where you should edit (Editor)</label>'+
935 '<div id="editor" class="alipi" contenteditable="true" '+
936 '</div>';
937 $('body').append(template);
938 $('#pub_overlay').slideUp();
939 $('#element_edit_overlay').hide();
1437 case 'ANCHOR_UPDATE':
1438 $(util.command.element).attr('href', util.command.data);
1439 break;
9401440
941 var tag = pageEditor.event.target.nodeName;
942 $(pageEditor.event.target).removeAttr('m4pageedittype');
943 $(pageEditor.event.target).children().removeAttr('m4pageedittype');
1441 case 'ANCHOR_CREATE':
1442 anchorElement = DOM.BUILDER.A({ 'href' : util.command.data });
1443 util.command.element.parentNode.replaceChild(anchorElement, util.command.element);
1444 anchorElement.appendChild(util.command.element);
1445 util.command.previousData = anchorElement;
1446 break;
9441447
945 $('#adv-reference').text('<'+tag+'>'+$(pageEditor.event.target).html()+'</'+tag+'>');
946 $('#reference').html($(pageEditor.event.target).html());
947 $('#editor').html($(pageEditor.event.target).html());
948 $("#adv-ref").button({icons:{primary:"ui-icon-script"},text:true}); $('#adv-ref').children().addClass('alipi');
949 $("#close-adv").button({icons:{primary:"ui-icon-bookmark"},text:true}); $('#close-adv').children().addClass('alipi');
950 $('#close-adv').hide();
951 $('#adv-ref').button();
1448 case 'AUDIO_UPDATE':
1449 util.command.element.setAttribute('src', util.command.data);
1450 //pageEditor.showMessage('Audio changed');
1451 break;
9521452
953 $(document).unbind('mouseover'); // Unbind the css on mouseover
954 $(document).unbind('mouseout'); // Unbind the css on mouseout
1453 case 'AUDIO_CREATE':
1454 audioElement = document.createElement('audio');
1455 audioElement.setAttribute("class", "alipi");
1456 audioElement.setAttribute('src',util.command.data);
1457 audioElement.setAttribute('controls','controls');
1458 audioElement.setAttribute('mime-type','audio/ogg');
1459 $(audioElement).insertBefore($(selectedElement));
1460 util.command.element = audioElement;
1461 break;
9551462
956 $( "#editoroverlay" ).dialog({
957 position: 'center',
958 width:$(window).width()-10,
959 height:$(window).height()-50,
960 modal: true,
961 buttons: {
962 "+": function() {
963 if($('#editor').css('font-size') >= '30px') {
964 // passthrough
965 }
966 else {
967 var font = parseFloat($('#editor').css('font-size')) + 1;
968 $('#editor').css('font-size', font+'px');
969 font = parseFloat($('#reference').css('font-size')) + 1;
970 $('#reference').css('font-size', font+'px');
971 font = parseFloat($('#adv-reference').css('font-size')) + 1;
972 $('#adv-reference').css('font-size', font+'px');
973 }
974 },
975 "-": function() {
976 if($('#editor').css('font-size') <= '10px') {
977 //passthrough
978 }
979 else {
980 var font = parseFloat($('#editor').css('font-size')) - 1;
981 $('#editor').css('font-size', font+'px');
982 font = parseFloat($('#reference').css('font-size')) - 1;
983 $('#reference').css('font-size', font+'px');
984 font = parseFloat($('#adv-reference').css('font-size')) - 1;
985 $('#adv-reference').css('font-size', font+'px');
986 }
987 },
988 "Add Link": function() {
989 pageEditor.handler();
990 },
991 "Save changes": function() {
992 $('#pub_overlay').slideDown();
993 $('#element_edit_overlay').slideDown();
994 $('#icon_on_overlay').slideDown();
995 manager.recordText(pageEditor.event.target);
996 pageEditor.cleanUp(pageEditor.event.target);
997 $( "#editoroverlay" ).remove();
998 }
999 },
1000 close: function() {
1001 pageEditor.cleanUp(pageEditor.event.target);
1002 $("#editoroverlay" ).remove();
1003 }
1004 });
1463 default:
1464 console.error('Unknown util.command:', util.command);
1465 }
10051466
1006 $($($('<label>').insertAfter($('.ui-dialog-buttonset').children()[0])).html('Magnify or Demagnify')); // Element added externally with css
1007 $($('.ui-dialog-buttonset').children()[1]).attr('id','mag-demag');
1008 $($('.ui-dialog-buttonset').children()[0]).attr('id','mag'); // '+'
1009 $($('.ui-dialog-buttonset').children()[2]).attr('id','demag'); // '-'
1010 $($('.ui-dialog-buttonset').children()[3]).attr('id','add-link'); // 'Link'
1011 $($('.ui-dialog-buttonset').children()[4]).attr('id','save-changes'); // 'Save Changes'
1467 util.history.push(util.command);
1468 },
10121469
1013 $('#adv-reference').height($('#editor').height() + 40);
1014 $('#reference').height($('#editor').height());
1015 $('#mag').attr('title', 'To magnify letters/Increase font size');
1016 $('#demag').attr('title', 'To demagnify letters/Decrease font size');
1017 $('#add-link').attr('title', 'Add link(href) to the selected text portion (Before clicking this button, select some portion of text in "Editor")');
1018 $('#save-changes').attr('title', 'Save edited text onto the page')
1019 },
1470 undoChanges:function () {
1471 var imageElement, command=util.command;
10201472
1021 showAdv: function() {
1022 $('#reference').hide();
1023 $('#adv-reference').show();
1024 $('#adv-ref').hide();
1025 $('#close-adv').show();
1026 },
1027 closeAdv: function() {
1028 $('#reference').show();
1029 $('#adv-reference').hide();
1030 $('#close-adv').hide();
1031 $('#adv-ref').show();
1032 },
1473 if (util.hasChangesPending()) {
1474 command = util.history.pop();
1475 switch (command.command) {
1476 case 'TEXT_UPDATE':
1477 command.element.innerHTML = command.previousData;
1478 break;
10331479
1034 reflectInReference: function() {
1035 var tag = pageEditor.event.target.nodeName;
1036 $("#reference").html() = $("#editor").html();
1037 },
1480 case 'DELETE':
1481 DOM.restoreStyleProperty(command.element, 'display', '');
1482 break;
10381483
1039 imageReplacer: function() {
1040 var imageInputTemplate = '<div id="imageInputElement" title="Enter url" class="alipi ui-widget-header ui-corner-all">'+
1041 '<input type="text" id="imageInput" placeholder="http://foo.com/baz.jpg" class="alipi" value=""/></div>';
1484 case 'IMAGE_SRC_UPDATE':
1485 command.element.src = command.previousData.src;
1486 if (command.previousData.size.width) {
1487 command.element.width = command.previousData.size.width;
1488 } else {
1489 command.element.removeAttribute('width');
1490 }
1491 if (command.previousData.size.height) {
1492 command.element.height = command.previousData.size.height;
1493 } else {
1494 command.element.removeAttribute('height');
1495 }
1496 break;
10421497
1043 $('body').append(imageInputTemplate);
1044 $(document).unbind('mouseover'); // Unbind the css on mouseover
1045 $(document).unbind('mouseout'); // Unbind the css on mouseout
1498 case 'AUDIO_CREATE':
1499 $(command.element).remove();
1500 break;
1501 case 'ANCHOR_UPDATE':
1502 command.element.setAttribute('href', command.previousData);
1503 break;
10461504
1047 $('#pub_overlay').slideUp();
1048 $('#element_edit_overlay').slideUp();
1049 $('#icon_on_overlay').slideUp();
1505 case 'ANCHOR_CREATE':
1506 command.previousData.parentNode.replaceChild(command.element, command.previousData);
1507 break;
1508 case 'IMAGE_DELETE':
1509 $(command.element).show();
1510 break;
1511 default:
1512 console.error('Unknown command:', command);
1513 }
1514 pageEditor.cleanUp(pageEditor.event.target);
1515 } else {
1516 }
1517 },
1518 checkHistoryChanges: function()
1519 {
1520 if(util.hasChangesPending())
1521 {
1522 $('#undo-button').attr('disabled',false);
1523 $('#publish-button').attr('disabled',false);
1524 }
1525 else{
1526 $('#undo-button').attr('disabled',true);
1527 $('#publish-button').attr('disabled',true);
1528 }
1529 },
10501530
1051 $( "#imageInputElement" ).dialog({
1052 width:300,
1053 height:200,
1054 modal: true,
1055 buttons: {
1056 OK: function() {
1057 var formValue = $('#imageInput').val();
1058 if(formValue != '\/S/')
1059 {
1060 manager.recordImage(pageEditor.event.target, formValue);
1061 pageEditor.cleanUp(pageEditor.event.target);
1062 $( "#imageInputElement" ).remove();
1063 }
1064 }
1065 },
1066 close: function() {
1067 pageEditor.cleanUp(pageEditor.event.target);
1068 $("#imageInputElement" ).remove();
1069 }
1070 });
1531 publish:function (){
1532 var result;
1533 if ($('#loc-select').val() == '' || $('#lang-select').val() == '' || $('input:checked') == undefined) {
1534 alert("please furnish all the details");
1535 } else {
1536 if($('input:checked') == $("#your-check"))
1537 {
1538 localStorage.myContent = util.buildDataString();
1539 window.location.href = "http://dev.a11y.in/test.html";
1540 }
1541 else{
1542 $(function(){
1543 $( "#targetoverlay" ).dialog('close');
1544 $('#pub_overlay').slideUp();
1545 $('#element_edit_overlay').hide();
1546 // $('#icon_on_overlay').slideUp();
1547 // $( "#success-dialog" ).dialog({
1548 // modal: true,
1549 // });
1550 var success_template = '<div id="success-dialog" title="Posting your changes" class="alipi ui-widget-header ui-corner-all" '+
1551 '<p style="color:#aaa"><b>Please wait !!!</b></p><p style="color:#aaa">Your contribution is being posted</p></div>';
1552 $('body').append(success_template);
1553 $(function() {
1554 $( "#success-dialog" ).dialog({
1555 modal: true,
1556 });
1557 });
1558 });
1559 $.post(config.deploy+'/publish', {"data" : JSON.stringify(util.buildDataString())},
1560 function(data){
1561 window.location.reload();
1562 });
10711563
1072 },
1564 //+'&title='+encodeURIComponent(document.title)
1565 // }).done(function(){
1566 // console.log("test");
1567 //window.location.reload();
1568 // });
1569 }
1570 }
1571 },
10731572
1074 addAudio: function() {
1075 var audioInputTemplate = '<div id="audioInputElement" title="Enter url" class="alipi ui-widget-header ui-corner-all">'+
1076 '<input type="text" id="audioInput" placeholder="http://foo.com/baz.ogg" class="alipi" value=""/></div>';
1573 buildDataString : function (){
1574 var check_xpath = [], temp_history = [], index = [];
1575 for(x=0; x<util.history.length; x++) {
1576 check_xpath.push(util.history[x].xpath);
1577 }
1578 for(i=0; i<check_xpath.length-1; i++) {
1579 for(j=i+1; j<check_xpath.length; j++) {
1580 if ((check_xpath[i] == check_xpath[j]) && (util.history[i].elementType == util.history[j].elementType)) {
1581 index.push(i);
1582 }
1583 }
1584 }
1585 if (index.length > 0) {
1586 for (var z=0; z<index.length; z++) {
1587 delete util.history[index[z]];
1588 }
1589 }
10771590
1078 $('body').append(audioInputTemplate);
1079 $(document).unbind('mouseover'); // Unbind the css on mouseover
1080 $(document).unbind('mouseout'); // Unbind the css on mouseout
1591 for (var x=0; x<util.history.length; x++) {
1592 if (util.history[x] != undefined) {
1593 temp_history.push(util.history[x]);
1594 }
1595 }
10811596
1082 $('#pub_overlay').slideUp();
1083 $('#element_edit_overlay').slideUp();
1084 $('#icon_on_overlay').slideUp();
1597 util.history = temp_history;
1598 var command = util.command, buffer;
1599 // buffer = new StringUtil.StringBuffer();
10851600
1086 $( "#audioInputElement" ).dialog({
1087 width:300,
1088 height:200,
1089 modal: true,
1090 buttons: {
1091 OK: function() {
1092 pageEditor.addAudio();
1093 pageEditor.cleanUp(pageEditor.event.target);
1094 $( "#audioInputElement" ).remove();
1095 }
1096 },
1097 close: function() {
1098 pageEditor.cleanUp(pageEditor.event.target);
1099 $("#audioInputElement" ).remove();
1100 }
1101 });
1102 },
1601 var buff = [];
1602 util.forEach(util.history, function(index, command) {
1603 var dict = {};
1604 dict['type'] = "re-narration"; //TYPE
1605 dict['about'] = decodeURIComponent(window.location.search.split('=')[1]);
1606 dict['lang'] = $('#lang-select').val();
1607 dict["location"] = $('#loc-select').val();
1608 dict["style"] = $('#style-select').val();
1609 dict["blog"] = config.sweet;
1610 dict["elementtype"] = command.elementType;
1611 dict["xpath"] = command.xpath;
1612 dict["data"] = command.data;
1613 /*if ($('#auth-select').val() == '' || $('#auth-select').val() == /\S/) {
1614 dict["author"] = "Anonymous";
1615 } else {
1616 dict["author"] = $('#auth-select').val();
1617 }*/
1618 dict['author'] = $('#tar-uname').val() || $('#tar-name').val() || 'Anonymous';
1619 buff.push(dict);
11031620
1104 highlightOnHover: function(event) {
1105 if( !($(event.target).hasClass('alipi')) ) {
1106 $(event.target).addClass('highlightElement');
1107 }
1108 },
1621 // buffer.append('###'); //separates the commands
1622 // buffer.append('about='); //url=about //removed '&' on purpose
1623 // buffer.append(window.location.search.split('=')[1]);
1624 // buffer.append('&lang=');//lang
1625 // buffer.append(encodeURIComponent($('#lang-select').val()));
1626 // buffer.append('&location=');//location
1627 // buffer.append(encodeURIComponent($('#loc-select').val()));
1628 // buffer.append('&style=');//style
1629 // buffer.append(encodeURIComponent($('#style-select').val()));
1630 // buffer.append('&blog='); //blog where to post
1631 // buffer.append(encodeURIComponent("blog"));
1632 // buffer.append('&elementtype='); // text, audio, img
1633 // buffer.append(encodeURIComponent(command.elementType));
1634 // buffer.append('&xpath=');//xpath
1635 // buffer.append(encodeURIComponent(command.xpath));
1636 // buffer.append('&data='); //data
1637 // buffer.append(encodeURIComponent(command.data));
1638 // buffer.append('&author='); //author
1639 // if ($('#auth-select').val() == '' || $('#auth-select').val() == /\S/) {
1640 // buffer.append(encodeURIComponent('Anonymous'));
1641 // } else {
1642 // buffer.append(encodeURIComponent($('#auth-select').val()));
1643 // }
1644 });
1645 // return buffer.toString().substring(3);
1646 buff.push({'comments': $("#tar-comment").val()});
1647 console.log(buff);
1648 return buff;
1649 },
1650 };
11091651
1110 unhighlightOnMouseOut: function(event) {
1111 $(event.target).removeClass('highlightElement');
1112 },
1113 showInfo: function(data) {
1114 infoWindow = window.open(config.deploy+'/blank','Info page');
1115 window.setTimeout(function(){a11ypi.pushInfo(infoWindow.document.getElementById('info_content'),infoWindow,data);},2500);
1116 },
1117 pushInfo: function(ele, win, data) //ele contains the info_content element from blank.html
1118 {
1119 win.infoFullJSON = a11ypi.responseJSON;
1120 win.onLoad();
1121 },
1122 getParams: function()
1123 {
1124 var a = [];
1125 if(window.location.hostname == config.hostname || "localhost" )
1126 {
1127 d = window.location.search.split('?')[1];
1128 for (var i = 0;i<d.split('&').length;i++){
1129 a[d.split('&')[i].split('=')[0]] = decodeURIComponent(d.split('&')[i].split('=')[1]);
1130 }
1131 return a;
1132 }
1133 else
1134 {
1135 a['foruri'] = window.location.href;
1136 return a;
1137 }
1138 }
1139};
1652 var manager = {
1653 recordText:function (selectedElement) {
1654 var prevData = $(selectedElement).html();
1655 var command = {
1656 command : 'TEXT_UPDATE',
1657 element : selectedElement,
1658 url : window.location.href,
1659 xpath : DOM.getXpath(selectedElement),
1660 elementType : 'text',
1661 data : DOM.gettextContent($('#editor')),
1662 previousData : prevData
1663 };
1664 util.makeChanges(command, selectedElement);
1665 },
1666 recordAudio:function(selectedElement){
1667 var command = {
1668 command : 'AUDIO_CREATE',
1669 element : selectedElement,
1670 url : window.location.href,
1671 xpath : DOM.getXpath(selectedElement),
1672 elementType: 'audio/ogg',
1673 data : url,
1674 previousData : ''
1675
1676 };
1677 util.makeChanges(command,selectedElement);
1678 },
1679 deleteElement : function(selectedElement) {
1680 var command = {
1681 command : 'DELETE',
1682 element : selectedElement,
1683 url : '',
1684 elementType : 'text',
1685 data : '',
1686 xpath : '',
1687 data : '',
1688 previousData : ''
1689 };
1690 util.makeChanges(command, selectedElement);
1691 },
1692 recordImage: function(selectedElement, url)
1693 {
1694 var command = {
1695 command : 'IMAGE_SRC_UPDATE',
1696 element : selectedElement,
1697 elementType : 'image',
1698 xpath : DOM.getXpath(selectedElement),
1699 url : window.location.href,
1700 data : new StringUtil.StringBuffer().append(selectedElement.width).append('x').append(selectedElement.height).append(',').append(url).toString(),
1701 previousData : {
1702 'src' : selectedElement.src,
1703 'size' : { width: selectedElement.width, height: selectedElement.height }
1704 }
1705 };
1706 util.makeChanges(command, selectedElement);
1707 },
1708 deleteImage : function(selectedElement) {
1709 var command = {
1710 command : 'IMAGE_DELETE',
1711 element : selectedElement,
1712 url : window.location.href,
1713 elementType : 'image',
1714 data : '',
1715 xpath : '',
1716 data : '',
1717 previousData : {
1718 'src' : selectedElement.src,
1719 'size' : { width: selectedElement.width, height: selectedElement.height }
1720 }
1721 };
1722 util.makeChanges(command, selectedElement);
1723 },
1724
1725 };
1726 //Implementing the class for doing StringBuffer.
1727 var StringUtil = StringUtil || {};
1728 (function(StringUtil){
1729 StringUtil.StringBuffer = function StringBuffer() {
1730 var buffer = [];
1731 this.append = function append(string) {
1732 buffer.push(string);
1733 return this;
1734 };
1735
1736 this.toString = function toString() {
1737 return buffer.join('');
1738 };
1739 };
1740 })(StringUtil);
1741 window.pageEditor = pageEditor;
1742 })(jQuery);
1743 }}]);};
  
1212 common:
1313 - yepnope.js
1414 - alipi/ui.js
15 - alipi/wsgi/pageEditor.js
1615 - alipi/config.js
1716 # utils:
1817 # # paths are relative to the current directory