--- a/alipi/ui.js +++ b/alipi/ui.js @@ -1,1140 +1,1744 @@ //-*-coding: utf-8 -*- -var a11ypi = { - auth : " ", - loc:" ", - elementTagName: " ", - elementId: " ", - flag : 0, - fflag : 0, - showbox : 0, - showlinks : 0, - blog_flag: false, - target : false, - pageHtml:'', - d: {}, - responseJSON:'', - testContext : function() - { - if(document.getElementById('social_overlay') != null) - document.body.removeChild(document.getElementById('social_overlay')); - $(document).ready(function(){ - try{ - $('body *').not('iframe').contents().filter(function(){ - try{ +//window.jQuery = window.jQuery || {}; +window.onload = function() { + yepnope([{ + test: window.jQuery, + nope:['//code.jquery.com/jquery-1.10.2.min.js'], + load:['//code.jquery.com/ui/1.10.3/jquery-ui.js'], + complete:function(){ + jQuery.noConflict(); + (function($) { - if(this.nodeType == 3 && !($(this).hasClass('alipi'))){ - return (this.nodeType == 3) && this.nodeValue.match(/\S/);}} - catch(err){ - console.log(err); - } - }).parent().attr('m4pageedittype','text'); - } - catch(e){ - console.log(this); - } - }); + $(function() { + var a11ypi = { + auth : " ", + loc:" ", + elementTagName: " ", + elementId: " ", + flag : 0, + fflag : 0, + showbox : 0, + showlinks : 0, + blog_flag: false, + target : false, + pageHtml:'', + d: {}, + responseJSON:'', + testContext : function() + { + if(document.getElementById('social_overlay') != null) + document.body.removeChild(document.getElementById('social_overlay')); + $(document).ready(function(){ + try{ + $('body *').not('iframe').contents().filter(function(){ + try{ - vimg = document.getElementsByTagName('img'); - for(i=0; i'; - $(result).before(audio); - result.setAttribute('class','blink'); - } - else{ - result.innerHTML = a['data']; - result.setAttribute('class','blink'); - } - result=nodes.iterateNext(); - } - } - catch (e) - { - // dump( 'error: Document tree modified during iteration ' + e ); - } - } - else if(a['type']=='5el') - { + a11ypi.evaluate(data['r'][i]['narration'][x]); + } + } + }); + }, + evaluate: function(a) + { + try{ + var nodes = document.evaluate(a['xpath'], document, null, XPathResult.ANY_TYPE,null); - try{ - var result = nodes.iterateNext(); - while (result) - { - $(result).html($(result).html()+a['data']); - $(result).get(0).scrollIntoView(); - result=nodes.iterateNext(); - } - } - catch (e) - { - //dump( 'error: Document tree modified during iteration ' + e ); - } - } - }, - filter: function() - { - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() - { - if(xhr.readyState == 4) - { - if(xhr.responseText =='empty') - { - // a11ypi.clearMenu(); - // alert("An internal server error occured, please try later."); - } - else - { + } + catch(e) + { + console.log(e); + } + if(a['type'] == 're-narration') + { + try{ + var result = nodes.iterateNext(); + while (result) + { + if (a['elementtype'] == 'image') + { + if(a['data'] != '') + { + result.setAttribute('src',a['data'].split(',')[1]); //A hack to display images properly, the size has been saved in the database. + width = a['data'].split(',')[0].split('x')[0]; + height = a['data'].split(',')[0].split('x')[1]; + result.setAttribute('width',width); + result.setAttribute('height', height); + result.setAttribute('class','blink'); + } + else + $(result).hide(); + } + else if(a['elementtype'] == 'audio/ogg') + { + a['data'] = decodeURIComponent(a['data']); + audio = ''; + $(result).before(audio); + result.setAttribute('class','blink'); + } + else{ + result.innerHTML = a['data']; + result.setAttribute('class','blink'); + } + result=nodes.iterateNext(); + } + } + catch (e) + { + // dump( 'error: Document tree modified during iteration ' + e ); + } + } + else if(a['type']=='5el') + { - d ={}; - var response=xhr.responseText.substring(3).split('###'); - for (var j= 0; j< response.length ; j++){ - chunk = response[j].substring(1).split('&'); + try{ + var result = nodes.iterateNext(); + while (result) + { + $(result).html($(result).html()+a['data']); + $(result).get(0).scrollIntoView(); + result=nodes.iterateNext(); + } + } + catch (e) + { + //dump( 'error: Document tree modified during iteration ' + e ); + } + } + }, + filter: function() + { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() + { + if(xhr.readyState == 4) + { + if(xhr.responseText =='empty') + { + // a11ypi.clearMenu(); + // alert("An internal server error occured, please try later."); + } + else + { - for (var i= 0; i< chunk.length ; i++){ - pair =chunk[i].split("::"); - key = pair[0]; - value = pair[1]; - d[key] = value; - } - path = d['xpath']; - newContent = d['data']; - elementType = d['elementtype']; - a11ypi.evaluate(path,newContent,elementType); - } - } - } - } - a = a11ypi.getParams(); - var url = a['foruri']; - var lang= a['lang']; - var blog= a['blog']; - var data="url="+url+"&lang="+encodeURIComponent(lang)+"&blog="+encodeURIComponent(blog); + d ={}; + var response=xhr.responseText.substring(3).split('###'); + for (var j= 0; j< response.length ; j++){ + chunk = response[j].substring(1).split('&'); - xhr.open("POST",config.root+"/filter",true); - xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); - xhr.send(data);// - }, - createMenuFilter: function(menu_list) { - var xyz = document.getElementById("show-box"); - xyz.innerHTML = ''; - d = window.location.search.split('?')[1]; - a = a11ypi.getParams(); - var page = a['foruri']; - var blog = a['blog']; - for(var i=0;iMove '+ - ' '+ - ' '+ - ''+ - // ''+ - ''+ - // ''+ - ''+ - '
'+ - '
'+ - ' '+ - '
'; + for (var i= 0; i< chunk.length ; i++){ + pair =chunk[i].split("::"); + key = pair[0]; + value = pair[1]; + d[key] = value; + } + path = d['xpath']; + newContent = d['data']; + elementType = d['elementtype']; + a11ypi.evaluate(path,newContent,elementType); + } + } + } + } + a = a11ypi.getParams(); + var url = a['foruri']; + var lang= a['lang']; + var blog= a['blog']; + var data="url="+url+"&lang="+encodeURIComponent(lang)+"&blog="+encodeURIComponent(blog); - var pub_overlay_template = '
'+ - ''+ //▲ - ''+ //▼ - ''+ - ''+ - ''+ - '
'; + xhr.open("POST",config.root+"/filter",true); + xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); + xhr.send(data);// + }, + createMenuFilter: function(menu_list) { + var xyz = document.getElementById("show-box"); + xyz.innerHTML = ''; + d = window.location.search.split('?')[1]; + a = a11ypi.getParams(); + var page = a['foruri']; + var blog = a['blog']; + for(var i=0;iMove '+ + ' '+ + ' '+ + ''+ + // ''+ + ''+ + // ''+ + ''+ + '
'+ + '
'+ + ' '+ + '
'; - var element_edit_overlay_template = '
'+ - ''+ - ''+ - ''+ - ''+ - ''+ - ' '+ - '
'; + var pub_overlay_template = '
'+ + ''+ //▲ + ''+ //▼ + ''+ + ''+ + ''+ + '
'; - $('body').append(overlay_template); - $('body').append(pub_overlay_template); - $('body').append(element_edit_overlay_template); + var element_edit_overlay_template = '
'+ + ''+ + ''+ + ''+ + ''+ + ''+ + ' '+ + '
'; - $('#outter-up-button').show(); - $('#go').button({disabled : true}); - $('#undo-button').button({ disabled: true}); - $('#publish-button').button({ disabled: true}); - $('input[class="alipi"], select[class="alipi"]').button(); + $('body').append(overlay_template); + $('body').append(pub_overlay_template); + $('body').append(element_edit_overlay_template); - $("#outter-down-button").button({icons:{primary:"ui-icon-circle-arrow-n"},text:false}); $('#outter-down-button').children().addClass('alipi'); - $("#outter-up-button").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#outter-up-button').children().addClass('alipi'); - $("#edit-current").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-current').children().addClass('alipi'); - $("#see-narration").button({icons:{primary:"ui-icon-document-b"}}); $('#see-narration').children().addClass('alipi'); - $("#see-comment").button({icons:{primary:"ui-icon-document-b"}}); $('#see-comment').children().addClass('alipi'); - $("#see-links").button({icons:{primary:"ui-icon-link"}}); $('#see-links').children().addClass('alipi'); - /*$("#blog-filter").button({icons:{secondary:"ui-icon-triangle-1-s"}}); */ $('#blog-filter').children().addClass('alipi'); - $("#go").button({icons:{primary:"ui-icon-arrowthick-1-e"},text:false}); $('#go').children().addClass('alipi'); - $("#share").button({icons:{primary:"ui-icon-signal-diag"}}); $('#share').children().addClass('alipi'); - $("#orig-button").button({icons:{primary:"ui-icon-extlink"}}); $('#orig-button').children().addClass('alipi'); - $("#info").button({icons:{primary:"ui-icon-info"}}); $('#info').children().addClass('alipi'); + $('#outter-up-button').show(); + $('#go').button({disabled : true}); + $('#undo-button').button({ disabled: true}); + $('#publish-button').button({ disabled: true}); - $("#icon-up").button({icons:{primary:"ui-icon-circle-arrow-n"},text:false}); $('#icon-up').children().addClass('alipi'); - $("#icon-down").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#icon-down').children().addClass('alipi'); - $("#exit-mode").button({icons:{primary:"ui-icon-power"}}); $('#exit-mode').children().addClass('alipi'); - $("#help-window").button({icons:{primary:"ui-icon-help"}}); $('#help-window').children().addClass('alipi'); - $("#undo-button").button({icons:{primary:"ui-icon-arrowreturnthick-1-w"}}); $('#undo-button').children().addClass('alipi'); - $("#publish-button").button({icons:{primary:"ui-icon-circle-check"}}); $('#publish-button').children().addClass('alipi'); - $("#edit-text").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-text').children().addClass('alipi'); - $("#add-audio").button({icons:{primary:"ui-icon-circle-plus"}}); $('#add-audio').children().addClass('alipi'); - $("#replace-image").button({icons:{primary:"ui-icon-transferthick-e-w"}}); $('#replace-image').children().addClass('alipi'); - $("#delete-image").button({icons:{primary:"ui-icon-trash"}}); $('#delete-image').children().addClass('alipi'); - $("#close-element").button({icons:{primary:"ui-icon-circle-close"},text:false}); $("#close-element").children().addClass('alipi'); + $("#outter-down-button").button({icons:{primary:"ui-icon-circle-arrow-n"},text:false}); $('#outter-down-button').children().addClass('alipi'); + $("#outter-up-button").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#outter-up-button').children().addClass('alipi'); + $("#edit-current").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-current').children().addClass('alipi'); + $("#see-narration").button({icons:{primary:"ui-icon-document-b"}}); $('#see-narration').children().addClass('alipi'); + $("#see-comment").button({icons:{primary:"ui-icon-document-b"}}); $('#see-comment').children().addClass('alipi'); + $("#see-links").button({icons:{primary:"ui-icon-link"}}); $('#see-links').children().addClass('alipi'); + /*$("#blog-filter").button({icons:{secondary:"ui-icon-triangle-1-s"}}); */ $('#blog-filter').children().addClass('alipi'); + $("#go").button({icons:{primary:"ui-icon-arrowthick-1-e"},text:false}); $('#go').children().addClass('alipi'); + $("#share").button({icons:{primary:"ui-icon-signal-diag"}}); $('#share').children().addClass('alipi'); + $("#orig-button").button({icons:{primary:"ui-icon-extlink"}}); $('#orig-button').children().addClass('alipi'); + $("#info").button({icons:{primary:"ui-icon-info"}}); $('#info').children().addClass('alipi'); - $("#edit-current").button(); - $("#edit-current").on("click", a11ypi.editPage); + $("#icon-up").button({icons:{primary:"ui-icon-circle-arrow-n"},text:false}); $('#icon-up').children().addClass('alipi'); + $("#icon-down").button({icons:{primary:"ui-icon-circle-arrow-s"},text:false}); $('#icon-down').children().addClass('alipi'); + $("#exit-mode").button({icons:{primary:"ui-icon-power"}}); $('#exit-mode').children().addClass('alipi'); + $("#help-window").button({icons:{primary:"ui-icon-help"}}); $('#help-window').children().addClass('alipi'); + $("#undo-button").button({icons:{primary:"ui-icon-arrowreturnthick-1-w"}}); $('#undo-button').children().addClass('alipi'); + $("#publish-button").button({icons:{primary:"ui-icon-circle-check"}}); $('#publish-button').children().addClass('alipi'); - $('#renarrated_overlay').addClass('barOnTop'); - a11ypi.ajax(); - a11ypi.ajaxLinks1(); - $('#edit-current').show(); + $("#edit-text").button({icons:{primary:"ui-icon-pencil"}}); $('#edit-text').children().addClass('alipi'); + $("#add-audio").button({icons:{primary:"ui-icon-circle-plus"}}); $('#add-audio').children().addClass('alipi'); + $("#replace-image").button({icons:{primary:"ui-icon-transferthick-e-w"}}); $('#replace-image').children().addClass('alipi'); + $("#delete-image").button({icons:{primary:"ui-icon-trash"}}); $('#delete-image').children().addClass('alipi'); + $("#close-element").button({icons:{primary:"ui-icon-circle-close"},text:false}); $("#close-element").children().addClass('alipi'); - d = window.location.search.split('?')[1]; - var a =[]; - for (var i = 0;iTEXT :- It will popup a '+ - 'window and allow you to modify/replace text of select element on editor(right) box.'+ - '

To delete - Empty the editor(right) box and press "Save changes".'+ - '

Add Audio - It allows you to '+ - 'enter audio URL.

IMAGE:-

Replace - It allows you to enter '+ - 'image URL.

UNDO:- Use it when you want to revert back to '+ - 'previous change.'+ - 'PUBLISH:- To publish your crafted changes to database and blog (Alipi/Personal).'+ - '

States - The place you are targetting to.

Languages - In language you publishing.

Style - In what style you crafted?

'+ - 'Author - Who is a crafter?

'+ - 'Alipi blog - If you don\'t have blogspot ID then check this to post it to our blog.

'; + $('#renarrated_overlay').addClass('barOnTop'); + a11ypi.ajax(); + a11ypi.ajaxLinks1(); + $('#edit-current').show(); + $("#see-narration").show(); + d = window.location.search.split('?')[1]; + var a =[]; + for (var i = 0;iTEXT :- It will popup a '+ + 'window and allow you to modify/replace text of select element on editor(right) box.'+ + '

To delete - Empty the editor(right) box and press "Save changes".'+ + '

Add Audio - It allows you to '+ + 'enter audio URL.

IMAGE:-

Replace - It allows you to enter '+ + 'image URL.

UNDO:- Use it when you want to revert back to '+ + 'previous change.'+ + 'PUBLISH:- To publish your crafted changes to database and blog (Alipi/Personal).'+ + '

States - The place you are targetting to.

Languages - In language you publishing.

Style - In what style you crafted?

'+ + 'Author - Who is a crafter?

'+ + 'Alipi blog - If you don\'t have blogspot ID then check this to post it to our blog.

'; - hide_overlays: function() { - if($('#icon-up').attr('down') == 'true') { - $('#icon-up').attr('down', 'false'); - $('#icon-up').show(); $('#icon-down').hide(); - $('#pub_overlay').addClass('barOnBottom'); $('#pub_overlay').removeClass('barOnTop'); - } else { - $('#icon-up').attr('down', 'true'); - $('#icon-down').show(); $('#icon-up').hide(); - $('#pub_overlay').addClass('barOnTop'); $('#pub_overlay').removeClass('barOnBottom'); + $('body').append(help_template); + $(document).unbind('mouseover'); // Unbind the css on mouseover + $(document).unbind('mouseout'); // Unbind the css on mouseout - } - }, + $(function() { + $( "#helpwindow" ).dialog({ + width:800, + height:550, + modal: true, + close: function() { + $("#helpwindow").remove(); + } + }); + }); + }, - outterToggle: function() { - if($('#outter-down-button').attr('up') == 'true' ) { - $('#outter-down-button').attr('up', 'false'); - $('#outter-up-button').hide(); $('#outter-down-button').show(); - $('#renarrated_overlay').addClass('barOnBottom'); $('#renarrated_overlay').removeClass('barOnTop'); - } else { - $('#outter-down-button').attr('up', 'true'); - $('#outter-up-button').show(); $('#outter-down-button').hide(); - $('#renarrated_overlay').addClass('barOnTop'); $('#renarrated_overlay').removeClass('barOnBottom'); - } - }, + exitMode: function() { + var exit = window.confirm("Do you really want to exit from edit mode?"); + if (exit == true) { + window.location.reload(); + } + }, + hide_overlays: function() { + if($('#icon-up').attr('down') == 'true') { + $('#icon-up').attr('down', 'false'); + $('#icon-up').show(); $('#icon-down').hide(); + $('#pub_overlay').addClass('barOnBottom'); $('#pub_overlay').removeClass('barOnTop'); + } else { + $('#icon-up').attr('down', 'true'); + $('#icon-down').show(); $('#icon-up').hide(); + $('#pub_overlay').addClass('barOnTop'); $('#pub_overlay').removeClass('barOnBottom'); - getLoc: function() { + } + }, - $( "#loc-select" ).autocomplete({ - source: function(req, add){ + outterToggle: function() { + if($('#outter-down-button').attr('up') == 'true' ) { + $('#outter-down-button').attr('up', 'false'); + $('#outter-up-button').hide(); $('#outter-down-button').show(); + $('#renarrated_overlay').addClass('barOnBottom'); $('#renarrated_overlay').removeClass('barOnTop'); + } else { + $('#outter-down-button').attr('up', 'true'); + $('#outter-up-button').show(); $('#outter-down-button').hide(); + $('#renarrated_overlay').addClass('barOnTop'); $('#renarrated_overlay').removeClass('barOnBottom'); + } + }, - //pass request to server - $.getJSON(config.deploy+"/getLoc?", req, function(data) { - $('#loc-img').hide(); - //create array for response objects - var suggestions = []; + getLoc: function() { - //process response - $.each(data['return'], function(i,val){ - suggestions.push(val['name']+', '+val['country_name']); - }); - //pass array to callback - add(suggestions); - }); - $('#loc-img').show(); - }, - }); - }, + $( "#loc-select" ).autocomplete({ + source: function(req, add){ - getLang: function() { - $( "#lang-select" ).autocomplete({ - source: function(req, add){ + //pass request to server + $.getJSON(config.deploy+"/getLoc?", req, function(data) { + $('#loc-img').hide(); - //pass request to server - $.getJSON(config.deploy+"/getLang?", req, function(data) { - $('#lang-img').hide(); + //create array for response objects + var suggestions = []; - //create array for response objects - var suggestions = []; + //process response + $.each(data['return'], function(i,val){ + suggestions.push(val['name']+', '+val['country_name']); + }); + //pass array to callback + add(suggestions); + }); + $('#loc-img').show(); + }, + }); + }, - //process response - $.each(data['return'], function(i, val){ - //suggestions.push(val.country); - suggestions.push(val['name']); - }); - //pass array to callback - add(suggestions); - }); - $('#lang-img').show(); - }, - }); + getLang: function() { + $( "#lang-select" ).autocomplete({ + source: function(req, add){ + //pass request to server + $.getJSON(config.deploy+"/getLang?", req, function(data) { + $('#lang-img').hide(); - }, + //create array for response objects + var suggestions = []; - loginToSwtStore: function() { - var login_template = ''; + //process response + $.each(data['return'], function(i, val){ + //suggestions.push(val.country); + suggestions.push(val['name']); + }); + //pass array to callback + add(suggestions); + }); + $('#lang-img').show(); + }, + }); - if($('#login-template').length == 0) { - $('body').append(login_template); - } - $(document).unbind('mouseover'); // Unbind the css on mouseover - $(document).unbind('mouseout'); // Unbind the css on mouseout - $('#login-template').dialog({ - height: 400, - width: 400, - position: 'center', - modal: true, - buttons: [ - { - text: 'Login', - click: function() { - console.log('login'); - var uname = $('#tar-uname').val(); - var pass = $('#tar-pass').val(); - if(uname && pass) { - $('.login-button > .ui-button-text').text('Please wait..'); - sweet.authenticate(config.sweet + '/authenticate', uname, pass, a11ypi.publish, function() { - $('.login-button > .ui-button-text').text('Login'); + }, + + loginToSwtStore: function() { + var login_template = ''; + + if($('#login-template').length == 0) { + $('body').append(login_template); + } + $(document).unbind('mouseover'); // Unbind the css on mouseover + $(document).unbind('mouseout'); // Unbind the css on mouseout + + $('#login-template').dialog({ + height: 400, + width: 400, + position: 'center', + modal: true, + buttons: [ + { + text: 'Login', + click: function() { + console.log('login'); + var uname = $('#tar-uname').val(); + var pass = $('#tar-pass').val(); + if(uname && pass) { + $('.login-button > .ui-button-text').text('Please wait..'); + sweet.authenticate(config.sweet + '/authenticate', uname, pass, a11ypi.publish, function() { + $('.login-button > .ui-button-text').text('Login'); + }); + } + else { + //console.log('no username and password'); + //$('#login-error').show(); + //TODO: have a proper UI + alert('No username or password provided! Please enter both and then click Login'); + } + }, + 'class': 'login-button' + }, + { + text: 'Guest Login', + click: function() { + console.log('guest login'); + var name = $('#tar-name').val(); + if(name) { + $(this).dialog('close'); + a11ypi.publish(); + } + else { + //console.log('no guest name'); + //$('#guest-error').show(); + alert('Please provide a name for Guest Login'); + } + } + } + ], + close: function() { + console.log('close'); + } }); + }, + + publish: function() { + $('#login-template').dialog('close'); + if(util.hasChangesPending()) + { + $('#pub_overlay').slideUp(); + $('#element_edit_overlay').slideUp(); + $('#icon_on_overlay').slideUp(); + if (a11ypi.target == false ) { + var publish_template = '
'+ + // '
'+ + ''+ + ' '+ + ' '+ + ' '+ + ' '+ + ''+ + ' '+ + ' '+ + ''+ + '
'+ + '
We are having issues with posting to a personal Google blog. Please use demo.swtr.us to publish.
'+ + '

'+ + ' '+ + '

'; + + $('body').append(publish_template); + a11ypi.getLoc(); + a11ypi.getLang(); + a11ypi.target = true; + } + + $(document).unbind('mouseover'); // Unbind the css on mouseover + $(document).unbind('mouseout'); // Unbind the css on mouseout + + $('#pub_overlay').slideUp(); + $('#element_edit_overlay').slideUp(); + // $('#icon_on_overlay').slideUp(); + + $(function() { + $( "#targetoverlay" ).dialog({ + height:550, + width:700, + modal: true, + buttons: { + Publish: function() { + util.publish(); + }, + + }, + close: function() { + $('#pub_overlay').slideDown(); + // $('#element_edit_overlay').slideDown(); + // $('#icon_on_overlay').slideDown(); + $( "#targetoverlay" ).hide(); + } + }); + }); + } + }, + + hideAll: function() { + var boxes = '#show-links, #show-box, #show-comment'; + if($(boxes).dialog().dialog("isOpen")) + $(boxes).dialog().dialog('close'); + }, + + showBox: function() { + a11ypi.hideAll(); + $(document).unbind('mouseover'); // Unbind the css on mouseover + $(document).unbind('mouseout'); // Unbind the css on mouseout + + $(function() { + // $( "#show-box" ).dialog( "destroy" ); + + $( "#show-box" ).dialog({ + width: 300, + height: 300, + modal: true + }); + }); + d = window.location.search.split('?')[1]; + var a = a11ypi.getParams(); + if (a['blog'] === undefined ) { + a11ypi.createMenu('re-narration'); + } + else { + $('#show-box').attr('title', 'Choose a re-narration from the blog you specified.'); + a11ypi.ajax1(); + } + }, + showComment: function() { + a11ypi.hideAll(); + $(document).unbind('mouseover'); // Unbind the css on mouseover + $(document).unbind('mouseout'); // Unbind the css on mouseout + + $(function() { + $( "#show-comment" ).dialog( "destroy" ); + + $( "#show-comment" ).dialog({ + width: 300, + height: 300, + modal: true + }); + }); + a11ypi.createMenu('5el'); + }, + + ajaxLinks1: function() { + // var xhr = new XMLHttpRequest(); + // xhr.onreadystatechange = function() + // { + // if(xhr.readyState == 4) + // { + // if(xhr.responseText == "empty") + // { } + // else + // { + // $('#see-links').show(); + // a11ypi.showlinks = JSON.parse(xhr.responseText); + // } + // } + // } + // xhr.open("POST",config.deploy+"/domain",true); + // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); + // d = window.location.search.split('?')[1]; + // a = a11ypi.getParams(); + // xhr.send('url='+a['foruri']) + + $.get(config.deploy+"/domain", {"url":a['foruri']}, function(data){ + if(data[0] != 'empty') + { + a11ypi.showlinks = data; + $('#see-links').show(); + } + }); + }, + showBox1: function() { + a11ypi.hideAll(); + $(document).unbind('mouseover'); // Unbind the css on mouseover + $(document).unbind('mouseout'); // Unbind the css on mouseout + + $(function() { + // $( "#show-links" ).dialog( "destroy" ); + + $( "#show-links" ).dialog({ + width: 500, + height: 300, + modal: true + }); + }); + a11ypi.createDomainMenu(); + }, + createDomainMenu: function() { + var xyz = $("#show-links"); + xyz.html(''); + for(var i in a11ypi.showlinks) + { + var para = document.createElement("p"); + var newel = document.createElement("a"); + newel.textContent = a11ypi.showlinks[i]; + newel.setAttribute("href", config.deploy+"/?foruri="+encodeURIComponent(a11ypi.showlinks[i])); + newel.setAttribute("class","alipiShowLink"); + para.appendChild(newel); + xyz.append(para); + } + $('.alipiShowLink').hover( + function() { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() + { + if(xhr.readyState == 4) + { + if(xhr.responseText == "empty") + { } + else + { + menu_list = JSON.parse(xhr.responseText); + x = ''; + for(i=0; i '+ + 'Render source '+ + ' '+ + ''+ + '
'+ + ' '+ + ''+ + '
'; + $('body').append(template); + $('#pub_overlay').slideUp(); + $('#element_edit_overlay').hide(); + + var tag = pageEditor.event.target.nodeName; + $(pageEditor.event.target).removeAttr('m4pageedittype'); + $(pageEditor.event.target).children().removeAttr('m4pageedittype'); + + $('#adv-reference').text('<'+tag+'>'+$(pageEditor.event.target).html()+''); + $('#reference').html($(pageEditor.event.target).html()); + $('#editor').html($(pageEditor.event.target).html()); + $("#adv-ref").button({icons:{primary:"ui-icon-script"},text:true}); $('#adv-ref').children().addClass('alipi'); + $("#close-adv").button({icons:{primary:"ui-icon-bookmark"},text:true}); $('#close-adv').children().addClass('alipi'); + $('#close-adv').hide(); + $('#adv-ref').button(); + + $(document).unbind('mouseover'); // Unbind the css on mouseover + $(document).unbind('mouseout'); // Unbind the css on mouseout + + $( "#editoroverlay" ).dialog({ + position: 'center', + width:$(window).width()-10, + height:$(window).height()-50, + modal: true, + buttons: { + "+": function() { + if($('#editor').css('font-size') >= '30px') { + // passthrough + } + else { + var font = parseFloat($('#editor').css('font-size')) + 1; + $('#editor').css('font-size', font+'px'); + font = parseFloat($('#reference').css('font-size')) + 1; + $('#reference').css('font-size', font+'px'); + font = parseFloat($('#adv-reference').css('font-size')) + 1; + $('#adv-reference').css('font-size', font+'px'); + } + }, + "-": function() { + if($('#editor').css('font-size') <= '10px') { + //passthrough + } + else { + var font = parseFloat($('#editor').css('font-size')) - 1; + $('#editor').css('font-size', font+'px'); + font = parseFloat($('#reference').css('font-size')) - 1; + $('#reference').css('font-size', font+'px'); + font = parseFloat($('#adv-reference').css('font-size')) - 1; + $('#adv-reference').css('font-size', font+'px'); + } + }, + "Add Link": function() { + pageEditor.handler(); + }, + "Save changes": function() { + $('#pub_overlay').slideDown(); + $('#element_edit_overlay').slideDown(); + $('#icon_on_overlay').slideDown(); + manager.recordText(pageEditor.event.target); + pageEditor.cleanUp(pageEditor.event.target); + $( "#editoroverlay" ).remove(); + } + }, + close: function() { + pageEditor.cleanUp(pageEditor.event.target); + $("#editoroverlay" ).remove(); + } + }); + + $($($('
'+ - ''+ - ' '+ - ' '+ - ' '+ - ' '+ - ''+ - ' '+ - ' '+ - ''+ - '
'+ - '
We are having issues with posting to a personal Google blog. Please use demo.swtr.us to publish.
'+ - '

'+ - ' '+ - '

'; + noEdit: function(event) + { + if (event) { + xAxis = event.clientX; + yAxis = event.clientY; + $("#element_edit_overlay").css("top", yAxis); + $("#element_edit_overlay").css("left", xAxis); + } + $('*').removeClass('highlightOnSelect'); + if(!($(event.target).attr('m4pageedittype'))) { + $('#edit-text').hide(); + $('#add-audio').hide(); + $('#replace-image').hide(); + $('#delete-image').hide(); + $('#close-element').hide(); + $('#cant-edit').show(); + window.setTimeout("$('#cant-edit').hide();", 3000); + $("body").css("overflow", "auto"); + $('#pub_overlay').slideDown(); + $('#element_edit_overlay').slideDown(); + } + }, - $('body').append(publish_template); - a11ypi.getLoc(); - a11ypi.getLang(); - a11ypi.target = true; - } + handler: function() + { + var sel = window.getSelection(); + y = sel.anchorOffset; + z = sel.focusOffset; + if(y != z) + { + pageEditor.savedHtml = $('#editor').html(); + var url = prompt("Enter url"); + if(url) + { + sel.anchorNode.textContent = sel.anchorNode.textContent.substr(0,y)+''+sel.anchorNode.textContent.substr(y,z-y)+""+sel.anchorNode.textContent.substr(z); + abc = $('#editor').html(); + abc = abc.replace(/(<)/g,'<'); + abc = abc.replace(/(>)/g,'>'); + $('#editor').html(abc); + } + else + { + $('#dialog-message').html('

Please enter a valid url

'); + $('#dialog-message').dialog({ + modal: true, + buttons:{ + OK:function(){ + $(this).dialog("close"); + $(this).html(''); + } + }}); + } + } + else{ + $('#dialog-message').html('

Please choose a portion of text and then click Add link.

'); + $('#dialog-message').dialog({ + modal: true, + buttons:{ + OK:function(){ + $(this).dialog("close"); + $(this).html(''); + } + }}); + } + }, - $(document).unbind('mouseover'); // Unbind the css on mouseover - $(document).unbind('mouseout'); // Unbind the css on mouseout + addAudio: function(){ + url = $('#audioInput').val(); + if(url.substr(-4) =='.ogg'){ + manager.recordAudio(pageEditor.event.target); + } + // else{ + // $('#dialog-message').html('

Please enter a valid url

'); + // $('#dialog-message').dialog({ + // modal: true, + // buttons:{ + // OK:function(){ + // $(this).dialog("close"); + // $(this).html(''); + // } + // }}); + // } + }, - $('#pub_overlay').slideUp(); - $('#element_edit_overlay').slideUp(); - // $('#icon_on_overlay').slideUp(); + deleteImage: function(){ + manager.deleteImage(pageEditor.event.target); + pageEditor.cleanUp(pageEditor.event.target); + }, - $(function() { - $( "#targetoverlay" ).dialog({ - height:550, - width:700, - modal: true, - buttons: { - Publish: function() { - util.publish(); - }, + cleanUp: function(element) + { + if(util.hasChangesPending()) { + $('#undo-button').button('option', 'disabled', false); // Another way of enabling UI-JQUERY button + $('#publish-button').button({ disabled: false}); // Enabling UI-JQUERY button + } else { + $('#undo-button').button({ disabled: true}); // Disabling button + $('#publish-button').button({ disabled: true}); // Disabling button + } - }, - close: function() { - $('#pub_overlay').slideDown(); - // $('#element_edit_overlay').slideDown(); - // $('#icon_on_overlay').slideDown(); - $( "#targetoverlay" ).hide(); - } - }); - }); - } - }, + $(element).attr('m4pageedittype', pageEditor.m4pageedittype); + $(element).children().attr('m4pageedittype', pageEditor.m4pageedittype); + // $('#icon_on_overlay').slideDown(); + $('#pub_overlay').slideDown(); + $('#element_edit_overlay').hide(); + $("body").css("overflow", "auto"); + $('*').removeClass('highlightOnSelect'); + // $('#element_edit_overlay').slideDown(); + $(document).mouseover(a11ypi.highlightOnHover); + $(document).mouseout(a11ypi.unhighlightOnMouseOut); + // $(pageEditor.event.target).removeClass('highlightOnSelect'); // Remove hightlight of selected element + }, + }; - hideAll: function() { - var boxes = '#show-links, #show-box, #show-comment'; - $(boxes).dialog('close'); - }, + var DOM = { + getXpath : function (element) + { + var str = ''; + var currentNode = element; + var path = ''; + var index = -1; - showBox: function() { - this.hideAll(); - $(document).unbind('mouseover'); // Unbind the css on mouseover - $(document).unbind('mouseout'); // Unbind the css on mouseout + if (currentNode.nodeName != "#text") + { + path = DOM.makePath(currentNode); + } + else + { + path = DOM.makePath(currentNode.parentNode); + } - $(function() { - $( "#show-box" ).dialog( "destroy" ); - $( "#show-box" ).dialog({ - width: 300, - height: 300, - modal: true - }); - }); - d = window.location.search.split('?')[1]; - var a = a11ypi.getParams(); - if (a['blog'] === undefined ) { - a11ypi.createMenu('re-narration'); - } - else { - $('#show-box').attr('title', 'Choose a re-narration from the blog you specified.'); - a11ypi.ajax1(); - } - }, - showComment: function() { - this.hideAll(); - $(document).unbind('mouseover'); // Unbind the css on mouseover - $(document).unbind('mouseout'); // Unbind the css on mouseout + return path; + }, + getElementIdx : function getElementIdx(elt) + { + var count = 1; + for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling) + { + if(sib.nodeType == 1 && sib.tagName == elt.tagName)count++ + } - $(function() { - $( "#show-comment" ).dialog( "destroy" ); + return count; + }, - $( "#show-comment" ).dialog({ - width: 300, - height: 300, - modal: true - }); - }); - a11ypi.createMenu('5el'); - }, + makePath : function makePath(elt){ + var path = ''; + for (; elt && elt.nodeType == 1; elt = elt.parentNode) + { + if(elt.id == "") + { + idx = DOM.getElementIdx(elt); + xname = elt.tagName; + if (idx > 1) + xname += "[" + idx + "]"; + path = "/" + xname + path; + } + else + { + path = "//*[@id='"+elt.id+"']"+path; + break; + } + } + return path; + }, + settextContent : function(element, content){ + $(element).html(content); + }, + gettextContent:function(element) + { + return $(element).html(); + }, + }; - ajaxLinks1: function() { - // var xhr = new XMLHttpRequest(); - // xhr.onreadystatechange = function() - // { - // if(xhr.readyState == 4) - // { - // if(xhr.responseText == "empty") - // { } - // else - // { - // $('#see-links').show(); - // a11ypi.showlinks = JSON.parse(xhr.responseText); - // } - // } - // } - // xhr.open("POST",config.deploy+"/domain",true); - // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); - // d = window.location.search.split('?')[1]; - // a = a11ypi.getParams(); - // xhr.send('url='+a['foruri']) + var util = { + history: [], + command: [], - $.get(config.deploy+"/domain", {"url":a['foruri']}, function(data){ - if(data[0] != 'empty') - { - a11ypi.showlinks = data; - $('#see-links').show(); - } - }); - }, - showBox1: function() { - this.hideAll(); - $(document).unbind('mouseover'); // Unbind the css on mouseover - $(document).unbind('mouseout'); // Unbind the css on mouseout + forEach : function(array, callback) { + var i = 0, length = array.length, value; - $(function() { - $( "#show-links" ).dialog( "destroy" ); + if (length) { + for (value = array[0]; i < length && callback.call(value, i, value) !== false; value = array[++i]) { + } + } + }, + hasChangesPending : function(){ + return util.history.length > 0; + }, + formUncomplete : function formUnomplete(){ + return (locName == '' && langName=='' && styleName == '' ); + }, - $( "#show-links" ).dialog({ - width: 500, - height: 300, - modal: true - }); - }); - a11ypi.createDomainMenu(); - }, - createDomainMenu: function() { - var xyz = $("#show-links"); - xyz.html(''); - for(var i in a11ypi.showlinks) - { - var para = document.createElement("p"); - var newel = document.createElement("a"); - newel.textContent = a11ypi.showlinks[i]; - newel.setAttribute("href", config.deploy+"/?foruri="+encodeURIComponent(a11ypi.showlinks[i])); - newel.setAttribute("class","alipiShowLink"); - para.appendChild(newel); - xyz.append(para); - } - $('.alipiShowLink').hover( - function() { - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() - { - if(xhr.readyState == 4) - { - if(xhr.responseText == "empty") - { } - else - { - menu_list = JSON.parse(xhr.responseText); - x = ''; - for(i=0; i '+ - 'Render source '+ - ' '+ - ''+ - '
'+ - ' '+ - ''+ - '
'; - $('body').append(template); - $('#pub_overlay').slideUp(); - $('#element_edit_overlay').hide(); + case 'ANCHOR_UPDATE': + $(util.command.element).attr('href', util.command.data); + break; - var tag = pageEditor.event.target.nodeName; - $(pageEditor.event.target).removeAttr('m4pageedittype'); - $(pageEditor.event.target).children().removeAttr('m4pageedittype'); + case 'ANCHOR_CREATE': + anchorElement = DOM.BUILDER.A({ 'href' : util.command.data }); + util.command.element.parentNode.replaceChild(anchorElement, util.command.element); + anchorElement.appendChild(util.command.element); + util.command.previousData = anchorElement; + break; - $('#adv-reference').text('<'+tag+'>'+$(pageEditor.event.target).html()+''); - $('#reference').html($(pageEditor.event.target).html()); - $('#editor').html($(pageEditor.event.target).html()); - $("#adv-ref").button({icons:{primary:"ui-icon-script"},text:true}); $('#adv-ref').children().addClass('alipi'); - $("#close-adv").button({icons:{primary:"ui-icon-bookmark"},text:true}); $('#close-adv').children().addClass('alipi'); - $('#close-adv').hide(); - $('#adv-ref').button(); + case 'AUDIO_UPDATE': + util.command.element.setAttribute('src', util.command.data); + //pageEditor.showMessage('Audio changed'); + break; - $(document).unbind('mouseover'); // Unbind the css on mouseover - $(document).unbind('mouseout'); // Unbind the css on mouseout + case 'AUDIO_CREATE': + audioElement = document.createElement('audio'); + audioElement.setAttribute("class", "alipi"); + audioElement.setAttribute('src',util.command.data); + audioElement.setAttribute('controls','controls'); + audioElement.setAttribute('mime-type','audio/ogg'); + $(audioElement).insertBefore($(selectedElement)); + util.command.element = audioElement; + break; - $( "#editoroverlay" ).dialog({ - position: 'center', - width:$(window).width()-10, - height:$(window).height()-50, - modal: true, - buttons: { - "+": function() { - if($('#editor').css('font-size') >= '30px') { - // passthrough - } - else { - var font = parseFloat($('#editor').css('font-size')) + 1; - $('#editor').css('font-size', font+'px'); - font = parseFloat($('#reference').css('font-size')) + 1; - $('#reference').css('font-size', font+'px'); - font = parseFloat($('#adv-reference').css('font-size')) + 1; - $('#adv-reference').css('font-size', font+'px'); - } - }, - "-": function() { - if($('#editor').css('font-size') <= '10px') { - //passthrough - } - else { - var font = parseFloat($('#editor').css('font-size')) - 1; - $('#editor').css('font-size', font+'px'); - font = parseFloat($('#reference').css('font-size')) - 1; - $('#reference').css('font-size', font+'px'); - font = parseFloat($('#adv-reference').css('font-size')) - 1; - $('#adv-reference').css('font-size', font+'px'); - } - }, - "Add Link": function() { - pageEditor.handler(); - }, - "Save changes": function() { - $('#pub_overlay').slideDown(); - $('#element_edit_overlay').slideDown(); - $('#icon_on_overlay').slideDown(); - manager.recordText(pageEditor.event.target); - pageEditor.cleanUp(pageEditor.event.target); - $( "#editoroverlay" ).remove(); - } - }, - close: function() { - pageEditor.cleanUp(pageEditor.event.target); - $("#editoroverlay" ).remove(); - } - }); + default: + console.error('Unknown util.command:', util.command); + } - $($($('