Commit 6be342231c1cb68bae1a84832f5ec64e13263771
- Diff rendering mode:
- inline
- side by side
server/stylesheet.css
(6 / 0)
  | |||
153 | 153 | z-index:2147483645; | |
154 | 154 | } | |
155 | 155 | ||
156 | .highlightElement { | ||
157 | /* color:#fff; */ | ||
158 | /* background-color:#777; */ | ||
159 | border-style:dotted; | ||
160 | } | ||
161 | |||
156 | 162 | #blog-filter { | |
157 | 163 | min-width:200px;max-width:200px; | |
158 | 164 | } |
server/ui.js
(66 / 52)
  | |||
14 | 14 | $(document).ready(function(){$('body *').contents().filter(function() | |
15 | 15 | { | |
16 | 16 | try{ | |
17 | if(this.nodeType == 3) | ||
17 | if(this.nodeType == 3 && !($(this).hasClass('alipi'))) | ||
18 | 18 | { | |
19 | 19 | return (this.nodeType == 3) && this.nodeValue.match(/\S/);}} | |
20 | 20 | catch(err) | |
21 | 21 | { | |
22 | // console.log(err.message); | ||
23 | // console.log(this); | ||
24 | 22 | }}).parent().attr('m4pageedittype','text')}); | |
23 | |||
25 | 24 | ||
26 | |||
27 | 25 | vimg = document.getElementsByTagName('img'); | |
28 | 26 | for(i=0; i<vimg.length; i++) | |
29 | 27 | { | |
… | … | ||
351 | 351 | }, | |
352 | 352 | loadOverlay: function() | |
353 | 353 | { | |
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%;" '+ | ||
356 | 356 | 'src="http://y.a11y.in/alipi.gif" /></input></div>'; | |
357 | 357 | ||
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>'; | ||
365 | 365 | ||
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">'; | ||
371 | 371 | ||
372 | 372 | var element_edit_overlay_template = '<div id="element_edit_overlay" class="alipi ui-widget-header ui-corner-all">'+ | |
373 | 373 | '<input id="edit-text" class="alipi" type="submit" onclick="a11ypi.displayEditor();" value="Edit Text" disabled=true>'+ | |
… | … | ||
376 | 376 | '<input id="replace-image" type="submit" onclick="a11ypi.imageReplacer();" class="alipi" value="Replace Image" disabled=true>'; | |
377 | 377 | ||
378 | 378 | 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>'; | ||
381 | 380 | ||
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 | |||
382 | 398 | $('body').append(icon_template); | |
383 | 399 | $('body').append(overlay_template); | |
384 | 400 | $('body').append(pub_overlay_template); | |
385 | 401 | $('body').append(element_edit_overlay_template); | |
386 | 402 | $('body').append(imageInputTemplate); | |
403 | $('body').append(publish_template); | ||
404 | |||
405 | $(document).addEventListener("DOMActivate", init, false); | ||
387 | 406 | a11ypi.ajax(); | |
388 | 407 | a11ypi.ajaxLinks1(); | |
389 | 408 | go.disabled = true; | |
390 | 409 | }, | |
391 | 410 | ||
392 | 411 | 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 '+ | ||
401 | 420 | '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>'+ | ||
403 | 422 | '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";>'+ | ||
407 | 427 | 'Our blog - If you don\'t have blogspot ID then check this to post it to our blog.</p></div>'; | |
408 | 428 | ||
409 | 429 | $('body').append(help_template); | |
… | … | ||
452 | 452 | $('#element_edit_overlay').slideToggle(); | |
453 | 453 | }, | |
454 | 454 | 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); | ||
474 | 455 | ||
475 | 456 | $(function() { | |
457 | $( "#targetoverlay" ).dialog( "destroy" ); | ||
476 | 458 | $( "#targetoverlay" ).dialog({ | |
477 | 459 | height:500, | |
478 | 460 | width:800, | |
… | … | ||
632 | 632 | $('#icon_on_overlay').show(); | |
633 | 633 | $('#pub_overlay').show(); | |
634 | 634 | $('#element_edit_overlay').show(); | |
635 | |||
635 | 636 | $('body *').contents().filter(function(){ | |
636 | 637 | { | |
637 | 638 | try{ | |
… | … | ||
643 | 643 | { | |
644 | 644 | //pass | |
645 | 645 | }}}).click(pageEditor.startEdit); | |
646 | $(document).click(pageEditor.startEdit); | ||
647 | $(document).mouseover(a11ypi.highlightOnHover); | ||
648 | $(document).mouseout(a11ypi.unhighlightOnMouseOut); | ||
646 | 649 | }, | |
647 | 650 | ||
648 | 651 | displayEditor: function() { | |
… | … | ||
719 | 719 | }); | |
720 | 720 | ||
721 | 721 | }, | |
722 | |||
723 | highlightOnHover: function() { | ||
724 | if( !$(event.target).hasClass('alipi') ) { | ||
725 | $(event.target).addClass('highlightElement'); | ||
726 | } | ||
727 | }, | ||
722 | 728 | ||
729 | unhighlightOnMouseOut: function() { | ||
730 | $(event.target).removeClass('highlightElement'); | ||
731 | }, | ||
732 | |||
723 | 733 | showTopBar: function() { | |
724 | 734 | ||
725 | } | ||
735 | }, | ||
726 | 736 | }; | |
727 | 737 | ||
728 | 738 | // $('html').bind('keypress', function(e) |
server/wsgi/pageEditor.js
(266 / 266)
  | |||
1 | 1 | var 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>'+ | ||
8 | 8 | '</div>', | |
9 | 9 | event: 0 , //Use this var to store the event object, which will be passed for editor. | |
10 | 10 | m4pageedittype: '', | |
… | … | ||
14 | 14 | pageEditor.m4pageedittype = $(event.target).attr('m4pageedittype'); | |
15 | 15 | if($(event.target).attr('m4pageedittype') == 'text') | |
16 | 16 | { | |
17 | |||
18 | 17 | $('#pub_overlay').slideDown(); | |
19 | 18 | $('#element_edit_overlay').slideDown(); | |
20 | |||
19 | |||
21 | 20 | _this = pageEditor; | |
22 | 21 | $(event.target).removeAttr('m4pageedittype'); | |
23 | 22 | $(event.target).children().removeAttr('m4pageedittype'); | |
24 | 23 | $('body').append(_this.template); | |
25 | 24 | var tag = event.target.nodeName; | |
26 | // $(event.target).css('border-style', 'dotted'); | ||
27 | |||
25 | |||
28 | 26 | $('#reference').text('<'+tag+'>'+$(event.target).html()+'</'+tag+'>'); | |
29 | |||
27 | |||
30 | 28 | $('#editor').html($(event.target).html()); | |
31 | 29 | ||
32 | 30 | $('#edit-text').attr('disabled', false); | |
33 | 31 | $('#add-audio').attr('disabled', false); | |
34 | 32 | $('#add-link').attr('disabled', false); | |
35 | 33 | $('#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 | ||
36 | 36 | } | |
37 | 37 | else if($(event.target).attr('m4pageedittype') == 'image') | |
38 | 38 | { | |
… | … | ||
41 | 41 | $('#add-audio').attr('disabled', true); | |
42 | 42 | $('#add-link').attr('disabled', true); | |
43 | 43 | $('#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 | ||
45 | 46 | } | |
46 | |||
47 | 47 | }, | |
48 | 48 | cleanUp: function(element) | |
49 | 49 | { | |
… | … | ||
113 | 113 | return $(element).html(); | |
114 | 114 | }, | |
115 | 115 | ||
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 | // })(), | ||
138 | 138 | }; | |
139 | 139 | ||
140 | 140 | var util = { | |
… | … | ||
143 | 143 | history: [], | |
144 | 144 | ||
145 | 145 | forEach : function(array, callback) { | |
146 | var i = 0, length = array.length, value; | ||
146 | var i = 0, length = array.length, value; | ||
147 | 147 | ||
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]) { | ||
151 | 150 | } | |
151 | } | ||
152 | 152 | }, | |
153 | 153 | 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 | |||
160 | 160 | recordHistory: function (command, selectedElement) { | |
161 | var poofPosition, poofDiv; | ||
161 | var poofPosition, poofDiv; | ||
162 | 162 | ||
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; | ||
176 | 176 | ||
177 | 177 | // case 'DELETE': | |
178 | 178 | // poofPosition = DOM.findPosition(command.element); | |
… | … | ||
192 | 192 | // pageEditor.showMessage('Section deleted'); | |
193 | 193 | // break; | |
194 | 194 | ||
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]; | ||
201 | 201 | ||
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 | } | ||
211 | 211 | ||
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; | ||
218 | 218 | ||
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; | ||
223 | 223 | ||
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; | ||
232 | 232 | ||
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; | ||
247 | 247 | ||
248 | default: | ||
249 | console.error('Unknown command:', command); | ||
250 | } | ||
248 | default: | ||
249 | console.error('Unknown command:', command); | ||
250 | } | ||
251 | 251 | ||
252 | util.history.push(command); | ||
253 | }, | ||
252 | util.history.push(command); | ||
253 | }, | ||
254 | 254 | ||
255 | 255 | undoChanges:function (command) { | |
256 | var imageElement, command; | ||
256 | var imageElement, command; | ||
257 | 257 | ||
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; | ||
267 | 267 | ||
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; | ||
272 | 272 | ||
273 | case 'IMAGE_SRC_UPDATE': | ||
274 | imageElement = new M4ImageElement(command.element); | ||
273 | case 'IMAGE_SRC_UPDATE': | ||
274 | imageElement = new M4ImageElement(command.element); | ||
275 | 275 | ||
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) | ||
288 | 288 | ||
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; | ||
300 | 300 | ||
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; | ||
305 | 305 | ||
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); | ||
311 | 308 | } | |
312 | }, | ||
309 | } else { | ||
310 | pageEditor.showMessage('Nothing to undo'); | ||
311 | } | ||
312 | }, | ||
313 | 313 | ||
314 | 314 | 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 | |||
330 | 330 | 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 | } | ||
334 | 340 | } | |
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]]; | ||
341 | 345 | } | |
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]); | ||
346 | 351 | } | |
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 | } | ||
353 | 353 | ||
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 | }, | ||
385 | 385 | }; | |
386 | 386 | ||
387 | 387 | var manager = { | |
388 | 388 | 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 | }; | ||
398 | 398 | 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 | } | ||
402 | 402 | }, | |
403 | 403 | 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 | }; | ||
414 | 414 | util.recordHistory(command, selectedElement); | |
415 | 415 | }, | |
416 | 416 | updateImage: function(selectedElement, url) | |
417 | 417 | { | |
418 | 418 | console.log(url); | |
419 | 419 | 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 | } | ||
431 | 431 | } | |
432 | 432 | util.recordHistory(command, selectedElement); | |
433 | 433 | }, | |
… | … | ||
436 | 436 | var StringUtil = StringUtil || {}; | |
437 | 437 | (function(StringUtil){ | |
438 | 438 | 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 | }; | ||
444 | 444 | ||
445 | this.toString = function toString() { | ||
446 | return buffer.join(''); | ||
447 | }; | ||
445 | this.toString = function toString() { | ||
446 | return buffer.join(''); | ||
447 | }; | ||
448 | 448 | }; | |
449 | 449 | })(StringUtil); |