Commit 6be342231c1cb68bae1a84832f5ec64e13263771

  • avatar
  • Arun Kulkarni <arun @ar…n.(none)>
  • Mon Apr 02 19:01:37 IST 2012
pushing changes for Arvind
  
153153 z-index:2147483645;
154154}
155155
156.highlightElement {
157 /* color:#fff; */
158 /* background-color:#777; */
159 border-style:dotted;
160}
161
156162#blog-filter {
157163 min-width:200px;max-width:200px;
158164}
server/ui.js
(66 / 52)
  
1414 $(document).ready(function(){$('body *').contents().filter(function()
1515 {
1616 try{
17 if(this.nodeType == 3)
17 if(this.nodeType == 3 && !($(this).hasClass('alipi')))
1818 {
1919 return (this.nodeType == 3) && this.nodeValue.match(/\S/);}}
2020 catch(err)
2121 {
22 // console.log(err.message);
23 // console.log(this);
2422 }}).parent().attr('m4pageedittype','text')});
23
2524
26
2725 vimg = document.getElementsByTagName('img');
2826 for(i=0; i<vimg.length; i++)
2927 {
351351 },
352352 loadOverlay: function()
353353 {
354 var icon_template = '<div id="icon_on_overlay" class="ui-widget-header ui-corner-all" '+
355 'onClick="a11ypi.hide_overlays();"> <input type="image" <img style="width:100%;height:100%;" '+
354 var icon_template = '<div id="icon_on_overlay" class="alipi ui-widget-header ui-corner-all" '+
355 'onClick="a11ypi.hide_overlays();"> <input class="alipi" type="image" <img style="width:100%;height:100%;" '+
356356 'src="http://y.a11y.in/alipi.gif" /></input></div>';
357357
358 var overlay_template = '<div id="renarrated_overlay" class="ui-widget-header ui-corner-all">'+
359 '<input id="edit-current" type="submit" onclick="a11ypi.editPage();" value="Renarrate this page">'+
360 '<input id="see-narration" type="submit" onclick="a11ypi.showBox();" value="See Narrations">'+
361 '<input id="see-links" type="submit" onclick="a11ypi.showBox1();" value="List of Pages Narrated">'+
362 '<select id="blog-filter" onclick="a11ypi.blogFilter();"><option>Choose a blog</option></select>'+
363 '<input id="go" type="submit" onclick="a11ypi.go();" value="Go">'+
364 '</div><div id="show-box"></div><div id="show-links"></div>';
358 var overlay_template = '<div id="renarrated_overlay" class="alipi ui-widget-header ui-corner-all">'+
359 '<input id="edit-current" class="alipi" type="submit" onclick="a11ypi.editPage();" value="Renarrate this page">'+
360 '<input id="see-narration" class="alipi" type="submit" onclick="a11ypi.showBox();" value="See Narrations">'+
361 '<input id="see-links" class="alipi" type="submit" onclick="a11ypi.showBox1();" value="List of Pages Narrated">'+
362 '<select id="blog-filter" class="alipi" onclick="a11ypi.blogFilter();"><option>Choose a blog</option></select>'+
363 '<input id="go" class="alipi" type="submit" onclick="a11ypi.go();" value="Go">'+
364 '</div><div id="show-box"></div><div id="show-links" class="alipi"></div>';
365365
366 var pub_overlay_template = '<div id="pub_overlay" class="ui-widget-header ui-corner-all">'+
367 '<input id="exit-mode" type="submit" onclick="a11ypi.exitMode();" value="EXIT">'+
368 '<input id="edit-current" type="submit" onclick="a11ypi.help_window();" value="Help">'+
369 '<input id="see-narration" type="submit" onclick="a11ypi." value="Undo">'+
370 '<input id="see-links" type="submit" onclick="a11ypi.publish();" value="Publish">';
366 var pub_overlay_template = '<div id="pub_overlay" class="alipi ui-widget-header ui-corner-all">'+
367 '<input id="exit-mode" class="alipi" type="submit" onclick="a11ypi.exitMode();" value="EXIT">'+
368 '<input id="edit-current" class="alipi" type="submit" onclick="a11ypi.help_window();" value="Help">'+
369 '<input id="see-narration" class="alipi" type="submit" onclick="a11ypi." value="Undo">'+
370 '<input id="see-links" class="alipi" type="submit" onclick="a11ypi.publish();" value="Publish">';
371371
372372 var element_edit_overlay_template = '<div id="element_edit_overlay" class="alipi ui-widget-header ui-corner-all">'+
373373 '<input id="edit-text" class="alipi" type="submit" onclick="a11ypi.displayEditor();" value="Edit Text" disabled=true>'+
376376 '<input id="replace-image" type="submit" onclick="a11ypi.imageReplacer();" class="alipi" value="Replace Image" disabled=true>';
377377
378378 var imageInputTemplate = '<div id="imageInputElement" title="Enter url" class="alipi ui-widget-header ui-corner-all">'+
379 '<input type="text" id="imageInput" placeholder="http://foo.com/baz.jpg" class="alipi" value=""/>'+
380 '</div>';
379 '<input type="text" id="imageInput" placeholder="http://foo.com/baz.jpg" class="alipi" value=""/></div>';
381380
381 var publish_template = '<div id="targetoverlay" class="alipi ui-widget-header ui-corner-all">Target'+
382 '<div id="infovis" class="alipi"></div><label class="alipi" style="position:absolute;top:12%; '+
383 'left:72%;color:#000;"> TARGET</label> '+
384 '<label class="alipi" style="position:absolute;top:25%;left:62%;color:#000;">Location :</label> '+
385 '<label class="alipi" id="loc-select" style="position:absolute;top:25%;left:75%;color:#000;"></label>'+
386 '<label class="alipi" style="position:absolute;top:40%;left:62%;color:#000;">Language :</label> '+
387 '<label id="lang-select" class="alipi" style="position:absolute;top:40%;left:75%;color:#000;"></label>'+
388 '<label class="alipi" style="position:absolute;top:55%;left:62%;color:#000;">Style :</label> '+
389 '<label id="style-select" class="alipi" style="position:absolute;top:55%;left:75%;color:#000;"></label>'+
390 '<label class="alipi" style="position:absolute;top:70%;left:62%;color:#000;">Author :</label> '+
391 '<input id="auth-select" class="alipi" type="text" style="position:absolute;top:70%;left:75%; '+
392 'width:160px;"></input><input id="our-check" class="alipi" type="radio"name="blog"style= '+
393 '"position:absolute;top:85%;left:52%;width:160px;"></input><label class="alipi" style="position:absolute; '+
394 'top:85%;left:64%;color:#000;">Our Blog</label><input id="your-check" class="alipi" type="radio" '+
395 'name="blog" style="position:absolute;top:85%;left:75%;"></input><label class="alipi" style= '+
396 '"position:absolute;top:85%;left:78%;color:#000;">Your Blog</label></div>';
397
382398 $('body').append(icon_template);
383399 $('body').append(overlay_template);
384400 $('body').append(pub_overlay_template);
385401 $('body').append(element_edit_overlay_template);
386402 $('body').append(imageInputTemplate);
403 $('body').append(publish_template);
404
405 $(document).addEventListener("DOMActivate", init, false);
387406 a11ypi.ajax();
388407 a11ypi.ajaxLinks1();
389408 go.disabled = true;
390409 },
391410
392411 help_window: function() {
393 var help_template = '<div id="helpwindow" class="ui-widget-header ui-corner-all">'+
394 '<label id="txtlab" style="color:#000;font-weight:normal;">TEXT :- It will popup a window and allow you to'+
395 'modify/replace text of select element on editor(right) box.'+
396 '<p>To delete - Empty the editor(right) box and press "OK".'+
397 '</p><p style="margin-left:50px";>See narrations - If the selected element has other narrations '+
398 'then it will list, on click.</p><p style="margin-left:50px";>Audio - It allows you to enter audio URL.</p>'+
399 'IMAGE:- <p style="margin-left:50px";> Replace - It allows you to enter image URL.'+
400 '</p><p style="margin-left:50px";> See narrations - If the selected element has other '+
412 var help_template = '<div id="helpwindow" class="alipi ui-widget-header ui-corner-all">'+
413 '<label id="txtlab" class="alipi" style="color:#000;font-weight:normal;">TEXT :- It will popup a '+
414 'window and allow you to modify/replace text of select element on editor(right) box.'+
415 '<p class="alipi">To delete - Empty the editor(right) box and press "OK".'+
416 '</p><p class="alipi" style="margin-left:50px";>See narrations - If the selected element has other narrations '+
417 'then it will list, on click.</p><p class="alipi" style="margin-left:50px";>Audio - It allows you to '+
418 'enter audio URL.</p>IMAGE:- <p class="alipi" style="margin-left:50px";> Replace - It allows you to enter '+
419 'image URL.</p><p class="alipi" style="margin-left:50px";> See narrations - If the selected element has other '+
401420 'image narration then it will show, on click.</p> UNDO:- Use it when you want to revert back to '+
402 'previous change.<p style="margin-left:50px";> Revert deleted - Press \'Undo\' button twice. </p>'+
421 'previous change.<p class="alipi" style="margin-left:50px";> Revert deleted - Press \'Undo\' button twice.</p>'+
403422 'PUBLISH:- To publish your crafted changes to database and blog (our/your).'+
404 '<p style="margin-left:50px";>States - To the place you are targetting.</p><p style="margin-left:50px";>'+
405 'Languages - In language you publishing.</p><p style="margin-left:50px";>Style - In what style you crafted?'+
406 '</p><p style="margin-left:50px";> Author - Who is a crafter?</p><p style="margin-left:50px";>'+
423 '<p class="alipi" style="margin-left:50px";>States - To the place you are targetting.</p><p class="alipi" '+
424 'style="margin-left:50px";>Languages - In language you publishing.</p><p class="alipi" style= '+
425 '"margin-left:50px";>Style - In what style you crafted?</p><p class="alipi" style="margin-left:50px";> '+
426 'Author - Who is a crafter?</p><p class="alipi" style="margin-left:50px";>'+
407427 'Our blog - If you don\'t have blogspot ID then check this to post it to our blog.</p></div>';
408428
409429 $('body').append(help_template);
452452 $('#element_edit_overlay').slideToggle();
453453 },
454454 publish: function() {
455
456 var publish_template = '<div id="targetoverlay" class="ui-widget-header ui-corner-all">Target'+
457 '<div id="infovis"></div><label style="position:absolute;top:12%;left:72%;color:#000;">TARGET</label> '+
458 '<label style="position:absolute;top:25%;left:62%;color:#000;">Location :</label> '+
459 '<label id="loc-select" style="position:absolute;top:25%;left:75%;color:#000;"></label>'+
460 '<label style="position:absolute;top:40%;left:62%;color:#000;">Language :</label> '+
461 '<label id="lang-select" style="position:absolute;top:40%;left:75%;color:#000;"></label>'+
462 '<label style="position:absolute;top:55%;left:62%;color:#000;">Style :</label> '+
463 '<label id="style-select" style="position:absolute;top:55%;left:75%;color:#000;"></label>'+
464 '<label style="position:absolute;top:70%;left:62%;color:#000;">Author :</label> '+
465 '<input id="auth-select" type="text" style="position:absolute;top:70%;left:75%;width:160px;"></input>'+
466 '<input id="our-check" type="radio"name="blog"style="position:absolute;top:85%;left:52%;width:160px;"></input>'+
467 '<label style="position:absolute;top:85%;left:64%;color:#000;">Our Blog</label>'+
468 '<input id="your-check" type="radio" name="blog" style="position:absolute;top:85%;left:75%;"></input>'+
469 '<label style="position:absolute;top:85%;left:78%;color:#000;">Your Blog</label>'+
470 '</div>';
471
472 $('body').append(publish_template);
473 document.addEventListener("DOMActivate", init, false);
474455
475456 $(function() {
457 $( "#targetoverlay" ).dialog( "destroy" );
476458 $( "#targetoverlay" ).dialog({
477459 height:500,
478460 width:800,
632632 $('#icon_on_overlay').show();
633633 $('#pub_overlay').show();
634634 $('#element_edit_overlay').show();
635
635636 $('body *').contents().filter(function(){
636637 {
637638 try{
643643 {
644644 //pass
645645 }}}).click(pageEditor.startEdit);
646 $(document).click(pageEditor.startEdit);
647 $(document).mouseover(a11ypi.highlightOnHover);
648 $(document).mouseout(a11ypi.unhighlightOnMouseOut);
646649 },
647650
648651 displayEditor: function() {
719719 });
720720
721721 },
722
723 highlightOnHover: function() {
724 if( !$(event.target).hasClass('alipi') ) {
725 $(event.target).addClass('highlightElement');
726 }
727 },
722728
729 unhighlightOnMouseOut: function() {
730 $(event.target).removeClass('highlightElement');
731 },
732
723733 showTopBar: function() {
724734
725 }
735 },
726736};
727737
728738// $('html').bind('keypress', function(e)
  
11var pageEditor = {
2 template : '<div id="editoroverlay" title="Editor" alipielements="alipi" class="ui-widget-header ui-corner-all">'+
3 '<label style="left: 20%;">Reference</label>'+
4 '<div id="reference" readonly="yes"></div>'+
5 '<label style="left: 70%;">Editor</label>'+
6 '<div id="editor" alipielements="alipi" contenteditable="true"></div>'+
7 '<div id="forPrevData"></div>'+
2 template : '<div id="editoroverlay" title="Editor" class="alipi ui-widget-header ui-corner-all">'+
3 '<label class="alipi" style="left: 20%;">Reference</label>'+
4 '<div id="reference" class="alipi" readonly="yes"></div>'+
5 '<label class="alipi" style="left: 70%;">Editor</label>'+
6 '<div id="editor" class="alipi" contenteditable="true"></div>'+
7 '<div id="forPrevData" class="alipi"></div>'+
88 '</div>',
99 event: 0 , //Use this var to store the event object, which will be passed for editor.
1010 m4pageedittype: '',
1414 pageEditor.m4pageedittype = $(event.target).attr('m4pageedittype');
1515 if($(event.target).attr('m4pageedittype') == 'text')
1616 {
17
1817 $('#pub_overlay').slideDown();
1918 $('#element_edit_overlay').slideDown();
20
19
2120 _this = pageEditor;
2221 $(event.target).removeAttr('m4pageedittype');
2322 $(event.target).children().removeAttr('m4pageedittype');
2423 $('body').append(_this.template);
2524 var tag = event.target.nodeName;
26// $(event.target).css('border-style', 'dotted');
27
25
2826 $('#reference').text('<'+tag+'>'+$(event.target).html()+'</'+tag+'>');
29
27
3028 $('#editor').html($(event.target).html());
3129
3230 $('#edit-text').attr('disabled', false);
3331 $('#add-audio').attr('disabled', false);
3432 $('#add-link').attr('disabled', false);
3533 $('#replace-image').attr('disabled', true);
34 // At this point 'displayEditor' function will be performed on click of 'Edit Text' button
35 // displayEditor function is in ui.js file
3636 }
3737 else if($(event.target).attr('m4pageedittype') == 'image')
3838 {
4141 $('#add-audio').attr('disabled', true);
4242 $('#add-link').attr('disabled', true);
4343 $('#edit-text').attr('disabled', true);
44
44 // At this point 'imageReplacer' function will be performed on click of 'Replace Image' button
45 // imageReplacer function is in ui.js
4546 }
46
4747 },
4848 cleanUp: function(element)
4949 {
113113 return $(element).html();
114114 },
115115
116// (function() { Re-wrote this portion in simpler terms. TO BE CLEANED.
117// if (document.all) {
118// // IE specific
119// return function textContent(element, content) {
120// if (content) {
121// element.innerText = content;
122// }
123// return element.innerText;
124// }
125// } else {
126// return function textContent(element, content) {
127// if (element == undefined) {
128// element = document.getElementById("alipiSelectedElement");
129// content = document.getElementById("alipiSelectedElement").innerHTML;
130// element.innerHTML = content;
131// } else if (content) {
132// element.innerHTML = content;
133// }
134// return element.innerHTML;
135// }
136// }
137// })(),
116 // (function() { Re-wrote this portion in simpler terms. TO BE CLEANED.
117 // if (document.all) {
118 // // IE specific
119 // return function textContent(element, content) {
120 // if (content) {
121 // element.innerText = content;
122 // }
123 // return element.innerText;
124 // }
125 // } else {
126 // return function textContent(element, content) {
127 // if (element == undefined) {
128 // element = document.getElementById("alipiSelectedElement");
129 // content = document.getElementById("alipiSelectedElement").innerHTML;
130 // element.innerHTML = content;
131 // } else if (content) {
132 // element.innerHTML = content;
133 // }
134 // return element.innerHTML;
135 // }
136 // }
137 // })(),
138138};
139139
140140var util = {
143143 history: [],
144144
145145 forEach : function(array, callback) {
146 var i = 0, length = array.length, value;
146 var i = 0, length = array.length, value;
147147
148 if (length) {
149 for (value = array[0]; i < length && callback.call(value, i, value) !== false; value = array[++i]) {
150 }
148 if (length) {
149 for (value = array[0]; i < length && callback.call(value, i, value) !== false; value = array[++i]) {
151150 }
151 }
152152 },
153153 hasChangesPending : function(){
154 return util.history.length > 0;
155 },
156 formUncomplete : function formUnomplete(){
157 return (locName == '' && langName=='' && styleName == '' );
158 },
159
154 return util.history.length > 0;
155 },
156 formUncomplete : function formUnomplete(){
157 return (locName == '' && langName=='' && styleName == '' );
158 },
159
160160 recordHistory: function (command, selectedElement) {
161 var poofPosition, poofDiv;
161 var poofPosition, poofDiv;
162162
163 switch (command.command) {
164 case 'TEXT_UPDATE':
165 command.element = selectedElement;
166 command.previousData = $(selectedElement).html();
167 command.data = $("#editor").html();
168 DOM.settextContent(command.element, command.data);
169 //pageEditor.showMessage('Text changed');
170 break;
171 case 'AUDIO_SRC_UPDATE':
172 textElementPopup.hasAudio = true;
173 command.previousData = "";
174 //pageEditor.showMessage('Audio updated');
175 break;
163 switch (command.command) {
164 case 'TEXT_UPDATE':
165 command.element = selectedElement;
166 command.previousData = $(selectedElement).html();
167 command.data = $("#editor").html();
168 DOM.settextContent(command.element, command.data);
169 //pageEditor.showMessage('Text changed');
170 break;
171 case 'AUDIO_SRC_UPDATE':
172 textElementPopup.hasAudio = true;
173 command.previousData = "";
174 //pageEditor.showMessage('Audio updated');
175 break;
176176
177177 // case 'DELETE':
178178 // poofPosition = DOM.findPosition(command.element);
192192 // pageEditor.showMessage('Section deleted');
193193 // break;
194194
195 case 'IMAGE_SRC_UPDATE':
196 console.log(command.data);
197 imageMatcher = new RegExp("(\\d+)x(\\d+),(.+)").exec(command.data);
198 imageWidth = imageMatcher[1];
199 imageHeight = imageMatcher[2];
200 imageSrc = imageMatcher[3];
195 case 'IMAGE_SRC_UPDATE':
196 console.log(command.data);
197 imageMatcher = new RegExp("(\\d+)x(\\d+),(.+)").exec(command.data);
198 imageWidth = imageMatcher[1];
199 imageHeight = imageMatcher[2];
200 imageSrc = imageMatcher[3];
201201
202 if (imageSrc && command.element.src != imageSrc) {
203 command.element.src = imageSrc;
204 //pageEditor.showMessage('Image changed');
205 }
206 if (imageWidth == 0) {
207 command.element.removeAttribute('width');
208 } else {
209 command.element.width = imageWidth;
210 }
202 if (imageSrc && command.element.src != imageSrc) {
203 command.element.src = imageSrc;
204 //pageEditor.showMessage('Image changed');
205 }
206 if (imageWidth == 0) {
207 command.element.removeAttribute('width');
208 } else {
209 command.element.width = imageWidth;
210 }
211211
212 if (imageHeight == 0) {
213 command.element.removeAttribute('height');
214 } else {
215 command.element.height = imageHeight;
216 }
217 break;
212 if (imageHeight == 0) {
213 command.element.removeAttribute('height');
214 } else {
215 command.element.height = imageHeight;
216 }
217 break;
218218
219 case 'ANCHOR_UPDATE':
220 command.element.setAttribute('href', command.data);
221 pageEditor.showMessage('Link changed');
222 break;
219 case 'ANCHOR_UPDATE':
220 command.element.setAttribute('href', command.data);
221 pageEditor.showMessage('Link changed');
222 break;
223223
224 case 'ANCHOR_CREATE':
225 anchorElement = DOM.BUILDER.A({ 'href' : command.data });
226 console.log(command.element);
227 command.element.parentNode.replaceChild(anchorElement, command.element);
228 anchorElement.appendChild(command.element);
229 command.previousData = anchorElement;
230 pageEditor.showMessage('Link added');
231 break;
224 case 'ANCHOR_CREATE':
225 anchorElement = DOM.BUILDER.A({ 'href' : command.data });
226 console.log(command.element);
227 command.element.parentNode.replaceChild(anchorElement, command.element);
228 anchorElement.appendChild(command.element);
229 command.previousData = anchorElement;
230 pageEditor.showMessage('Link added');
231 break;
232232
233 case 'AUDIO_UPDATE':
234 command.element.setAttribute('src', command.data);
235 pageEditor.showMessage('Audio changed');
236 break;
237
238 case 'AUDIO_CREATE':
239 audioElement = document.createElement('audio');
240 audioElement.setAttribute("id", "audiotag");
241 audioElement.setAttribute('src',command.data);
242 audioElement.setAttribute('controls','controls');
243 audioElement.setAttribute('style', 'display:table;');
244 $(audioElement).insertBefore($(selectedElement));
245 pageEditor.showMessage('Audio added');
246 break;
233 case 'AUDIO_UPDATE':
234 command.element.setAttribute('src', command.data);
235 pageEditor.showMessage('Audio changed');
236 break;
237
238 case 'AUDIO_CREATE':
239 audioElement = document.createElement('audio');
240 audioElement.setAttribute("id", "audiotag");
241 audioElement.setAttribute('src',command.data);
242 audioElement.setAttribute('controls','controls');
243 audioElement.setAttribute('style', 'display:table;');
244 $(audioElement).insertBefore($(selectedElement));
245 pageEditor.showMessage('Audio added');
246 break;
247247
248 default:
249 console.error('Unknown command:', command);
250 }
248 default:
249 console.error('Unknown command:', command);
250 }
251251
252 util.history.push(command);
253 },
252 util.history.push(command);
253 },
254254
255255 undoChanges:function (command) {
256 var imageElement, command;
256 var imageElement, command;
257257
258 if (self.hasChangesPending()) {
259 command = util.history.pop();
260 switch (command.command) {
261 case 'TEXT_UPDATE':
262 console.log(command.element.innerHTML);
263 console.log(command.previousData.innerHTML);
264 command.element.innerHTML = command.previousData;
265 pageEditor.showMessage('Text change undone');
266 break;
258 if (self.hasChangesPending()) {
259 command = util.history.pop();
260 switch (command.command) {
261 case 'TEXT_UPDATE':
262 console.log(command.element.innerHTML);
263 console.log(command.previousData.innerHTML);
264 command.element.innerHTML = command.previousData;
265 pageEditor.showMessage('Text change undone');
266 break;
267267
268 case 'DELETE':
269 DOM.restoreStyleProperty(command.element, 'display', '');
270 pageEditor.showMessage('Delete undone');
271 break;
268 case 'DELETE':
269 DOM.restoreStyleProperty(command.element, 'display', '');
270 pageEditor.showMessage('Delete undone');
271 break;
272272
273 case 'IMAGE_SRC_UPDATE':
274 imageElement = new M4ImageElement(command.element);
273 case 'IMAGE_SRC_UPDATE':
274 imageElement = new M4ImageElement(command.element);
275275
276 command.element.src = command.previousData.src;
277 if (command.previousData.size.width) {
278 command.element.width = command.previousData.size.width;
279 } else {
280 command.element.removeAttribute('width');
281 }
282 if (command.previousData.size.height) {
283 command.element.height = command.previousData.size.height;
284 } else {
285 command.element.removeAttribute('height');
286 }
287 imageElement.setRawImageSize(command.previousData.rawImageSize)
276 command.element.src = command.previousData.src;
277 if (command.previousData.size.width) {
278 command.element.width = command.previousData.size.width;
279 } else {
280 command.element.removeAttribute('width');
281 }
282 if (command.previousData.size.height) {
283 command.element.height = command.previousData.size.height;
284 } else {
285 command.element.removeAttribute('height');
286 }
287 imageElement.setRawImageSize(command.previousData.rawImageSize)
288288
289 pageEditor.showMessage('Image change undone');
290 break;
291
292 case 'AUDIO_SRC_UPDATE':
293 command.element.remove();
294 pageEditor.showMessage('Link removed');
295 break;
296 case 'ANCHOR_UPDATE':
297 command.element.setAttribute('href', command.previousData);
298 pageEditor.showMessage('Link change undone');
299 break;
289 pageEditor.showMessage('Image change undone');
290 break;
291
292 case 'AUDIO_SRC_UPDATE':
293 command.element.remove();
294 pageEditor.showMessage('Link removed');
295 break;
296 case 'ANCHOR_UPDATE':
297 command.element.setAttribute('href', command.previousData);
298 pageEditor.showMessage('Link change undone');
299 break;
300300
301 case 'ANCHOR_CREATE':
302 command.previousData.parentNode.replaceChild(command.element, command.previousData);
303 pageEditor.showMessage('Link removed');
304 break;
301 case 'ANCHOR_CREATE':
302 command.previousData.parentNode.replaceChild(command.element, command.previousData);
303 pageEditor.showMessage('Link removed');
304 break;
305305
306 default:
307 console.error('Unknown command:', command);
308 }
309 } else {
310 pageEditor.showMessage('Nothing to undo');
306 default:
307 console.error('Unknown command:', command);
311308 }
312 },
309 } else {
310 pageEditor.showMessage('Nothing to undo');
311 }
312 },
313313
314314 publish:function (){
315 var result;
316 if(document.getElementById('your-check').checked)
317 {
318 localStorage.myContent = buildDataString();
319 window.location.href = "http://dev.a11y.in/test.html";
320 window.reload();
321 }
322 else{
323
324 AJAX.post('http://dev.a11y.in/test', buildDataString(), function(result) {
325 ajaxResultProcessor.processPublishedResponse(result);
326 });
327 }
328 },
329
315 var result;
316 if(document.getElementById('your-check').checked)
317 {
318 localStorage.myContent = buildDataString();
319 window.location.href = "http://dev.a11y.in/test.html";
320 window.reload();
321 }
322 else{
323
324 AJAX.post('http://dev.a11y.in/test', buildDataString(), function(result) {
325 ajaxResultProcessor.processPublishedResponse(result);
326 });
327 }
328 },
329
330330 buildDataString : function (){
331 var check_xpath = [], temp_history = [], index = [];
332 for(x=0; x<util.history.length; x++) {
333 check_xpath.push(util.history[x].xpath);
331 var check_xpath = [], temp_history = [], index = [];
332 for(x=0; x<util.history.length; x++) {
333 check_xpath.push(util.history[x].xpath);
334 }
335 for(i=0; i<check_xpath.length-1; i++) {
336 for(j=i+1; j<check_xpath.length; j++) {
337 if ((check_xpath[i] == check_xpath[j]) && (util.history[i].elementType == util.history[j].elementType)) {
338 index.push(i);
339 }
334340 }
335 for(i=0; i<check_xpath.length-1; i++) {
336 for(j=i+1; j<check_xpath.length; j++) {
337 if ((check_xpath[i] == check_xpath[j]) && (util.history[i].elementType == util.history[j].elementType)) {
338 index.push(i);
339 }
340 }
341 }
342 if (index.length > 0) {
343 for (var z=0; z<index.length; z++) {
344 delete util.history[index[z]];
341345 }
342 if (index.length > 0) {
343 for (var z=0; z<index.length; z++) {
344 delete util.history[index[z]];
345 }
346 }
347
348 for (var x=0; x<util.history.length; x++) {
349 if (util.history[x] != undefined) {
350 temp_history.push(util.history[x]);
346351 }
347
348 for (var x=0; x<util.history.length; x++) {
349 if (util.history[x] != undefined) {
350 temp_history.push(util.history[x]);
351 }
352 }
352 }
353353
354 util.history = temp_history;
355 console.log("hello" + styleSelect.innerHTML);
356 var command, buffer;
357 buffer = new UTIL.StringBuffer();
358 util.forEach(util.history, function(index, command) {
359 buffer.append('###'); //separates the commands
360 buffer.append('about='); //url=about //removed '&' on purpose
361 buffer.append(window.location.search.split('=')[1]);
362 buffer.append('&lang=');//lang
363 buffer.append(encodeURIComponent(langName.innerHTML));
364 buffer.append('&location=');//location
365 buffer.append(encodeURIComponent(locName.innerHTML));
366 buffer.append('&style=');//style
367 buffer.append(encodeURIComponent(styleSelect.innerHTML));
368 buffer.append('&blog='); //blog where to post
369 buffer.append(encodeURIComponent("blog"));
370 buffer.append('&elementtype='); // text, audio, img
371 buffer.append(encodeURIComponent(command.elementType));
372 buffer.append('&xpath=');//xpath
373 buffer.append(encodeURIComponent(command.xpath));
374 buffer.append('&data='); //data
375 buffer.append(encodeURIComponent(command.data));
376 buffer.append('&author='); //author
377 if (author.value == '') {
378 buffer.append(encodeURIComponent('Anonymous'));
379 } else {
380 buffer.append(encodeURIComponent(author.value));
381 }
382 }); console.log(buffer.toString());
383 return buffer.toString().substring(3);
384 },
354 util.history = temp_history;
355 console.log("hello" + styleSelect.innerHTML);
356 var command, buffer;
357 buffer = new UTIL.StringBuffer();
358 util.forEach(util.history, function(index, command) {
359 buffer.append('###'); //separates the commands
360 buffer.append('about='); //url=about //removed '&' on purpose
361 buffer.append(window.location.search.split('=')[1]);
362 buffer.append('&lang=');//lang
363 buffer.append(encodeURIComponent(langName.innerHTML));
364 buffer.append('&location=');//location
365 buffer.append(encodeURIComponent(locName.innerHTML));
366 buffer.append('&style=');//style
367 buffer.append(encodeURIComponent(styleSelect.innerHTML));
368 buffer.append('&blog='); //blog where to post
369 buffer.append(encodeURIComponent("blog"));
370 buffer.append('&elementtype='); // text, audio, img
371 buffer.append(encodeURIComponent(command.elementType));
372 buffer.append('&xpath=');//xpath
373 buffer.append(encodeURIComponent(command.xpath));
374 buffer.append('&data='); //data
375 buffer.append(encodeURIComponent(command.data));
376 buffer.append('&author='); //author
377 if (author.value == '') {
378 buffer.append(encodeURIComponent('Anonymous'));
379 } else {
380 buffer.append(encodeURIComponent(author.value));
381 }
382 }); console.log(buffer.toString());
383 return buffer.toString().substring(3);
384 },
385385};
386386
387387var manager = {
388388 updateText:function (selectedElement) {
389 var command = {
390 command : 'TEXT_UPDATE',
391 element : selectedElement,
392 url : window.location.href,
393 xpath : DOM.getXpath(selectedElement),
394 elementType : 'text',
395 data : DOM.gettextContent(selectedElement),
396 previousData : $("editor").html()
397 };
389 var command = {
390 command : 'TEXT_UPDATE',
391 element : selectedElement,
392 url : window.location.href,
393 xpath : DOM.getXpath(selectedElement),
394 elementType : 'text',
395 data : DOM.gettextContent(selectedElement),
396 previousData : $("editor").html()
397 };
398398 util.recordHistory(command, selectedElement);
399 if (DOM.gettextContent(selectedElement).length == 0) {
400 manager.deleteElement(selectedElement);
401 }
399 if (DOM.gettextContent(selectedElement).length == 0) {
400 manager.deleteElement(selectedElement);
401 }
402402 },
403403 deleteElement : function(selectedElement) {
404 var command = {
405 command : 'DELETE',
406 element : selectedElement,
407 url : '',
408 elementType : 'text',
409 data : '',
410 xpath : '',
411 data : '',
412 previousData : ''
413 };
404 var command = {
405 command : 'DELETE',
406 element : selectedElement,
407 url : '',
408 elementType : 'text',
409 data : '',
410 xpath : '',
411 data : '',
412 previousData : ''
413 };
414414 util.recordHistory(command, selectedElement);
415415 },
416416 updateImage: function(selectedElement, url)
417417 {
418418 console.log(url);
419419 var command = {
420 command : 'IMAGE_SRC_UPDATE',
421 element : selectedElement,
422 elementType : 'image',
423 xpath : DOM.getXpath(selectedElement),
424 url : window.location.href,
425 data : new StringUtil.StringBuffer().append(selectedElement.width).append('x').append(selectedElement.height).append(',').append(url).toString(),
426 previousData : {
427 'src' : selectedElement.src,
428 'size' : { width: selectedElement.width, height: selectedElement.height }
429 //'rawImageSize' : image.getRawImageSize()
430 }
420 command : 'IMAGE_SRC_UPDATE',
421 element : selectedElement,
422 elementType : 'image',
423 xpath : DOM.getXpath(selectedElement),
424 url : window.location.href,
425 data : new StringUtil.StringBuffer().append(selectedElement.width).append('x').append(selectedElement.height).append(',').append(url).toString(),
426 previousData : {
427 'src' : selectedElement.src,
428 'size' : { width: selectedElement.width, height: selectedElement.height }
429 //'rawImageSize' : image.getRawImageSize()
430 }
431431 }
432432 util.recordHistory(command, selectedElement);
433433 },
436436var StringUtil = StringUtil || {};
437437(function(StringUtil){
438438 StringUtil.StringBuffer = function StringBuffer() {
439 var buffer = [];
440 this.append = function append(string) {
441 buffer.push(string);
442 return this;
443 };
439 var buffer = [];
440 this.append = function append(string) {
441 buffer.push(string);
442 return this;
443 };
444444
445 this.toString = function toString() {
446 return buffer.join('');
447 };
445 this.toString = function toString() {
446 return buffer.join('');
447 };
448448 };
449449})(StringUtil);