Files
leanote/public/libs/ace/ck/ext-chromevox-min.js
2015-03-31 14:27:26 +08:00

1 line
6.1 KiB
JavaScript

ace.define("ace/ext/chromevox",["require","exports","module","ace/editor","ace/config"],function(e,o,n){function t(){return"undefined"!=typeof cvox&&cvox&&cvox.Api}function r(e){if(t())So(e);else{if(Eo++,Eo>=ko)return;window.setTimeout(r,500,e)}}var c={};c.SpeechProperty,c.Cursor,c.Token,c.Annotation;var i={rate:.8,pitch:.4,volume:.9},a={rate:1,pitch:.5,volume:.9},u={rate:.8,pitch:.8,volume:.9},s={rate:.8,pitch:.3,volume:.9},p={rate:.8,pitch:.7,volume:.9},d={rate:.8,pitch:.8,volume:.9},l={punctuationEcho:"none",relativePitch:-.6},f="ALERT_NONMODAL",v="ALERT_MODAL",m="INVALID_KEYPRESS",g="insertMode",A="start",h=[{substr:";",newSubstr:" semicolon "},{substr:":",newSubstr:" colon "}],S={SPEAK_ANNOT:"annots",SPEAK_ALL_ANNOTS:"all_annots",TOGGLE_LOCATION:"toggle_location",SPEAK_MODE:"mode",SPEAK_ROW_COL:"row_col",TOGGLE_DISPLACEMENT:"toggle_displacement",FOCUS_TEXT:"focus_text"},E="CONTROL + SHIFT ";c.editor=null;var k=null,x={},y=!1,w=!1,T=!1,C=null,b={},O={},_=function(e){return E+String.fromCharCode(e)},L=function(){var e=c.editor.keyBinding.getKeyboardHandler();return"ace/keyboard/vim"===e.$id},N=function(e){return c.editor.getSession().getTokenAt(e.row,e.column+1)},K=function(e){return c.editor.getSession().getLine(e.row)},P=function(e){x[e.row]&&cvox.Api.playEarcon(f),y?(cvox.Api.stop(),V(e),X(N(e)),q(e.row,1)):q(e.row,0)},I=function(e){var o=K(e),n=o.substr(e.column-1);0===e.column&&(n=" "+o);var t=/^\W(\w+)/,r=t.exec(n);return null!==r},M={constant:{prop:i},entity:{prop:u},keyword:{prop:s},storage:{prop:p},variable:{prop:d},meta:{prop:a,replace:[{substr:"</",newSubstr:" closing tag "},{substr:"/>",newSubstr:" close tag "},{substr:"<",newSubstr:" tag start "},{substr:">",newSubstr:" tag end "}]}},D={prop:D},G=function(e,o){for(var n=e,t=0;t<o.length;t++){var r=o[t],c=new RegExp(r.substr,"g");n=n.replace(c,r.newSubstr)}return n},R=function(e,o,n){var t={};t.value="",t.type=e[o].type;for(var r=o;n>r;r++)t.value+=e[r].value;return t},B=function(e){if(e.length<=1)return e;for(var o=[],n=0,t=1;t<e.length;t++){var r=e[n],c=e[t];H(r)!==H(c)&&(o.push(R(e,n,t)),n=t)}return o.push(R(e,n,e.length)),o},F=function(e){var o=c.editor.getSession().getLine(e),n=/^\s*$/;return null!==n.exec(o)},q=function(e,o){var n=c.editor.getSession().getTokens(e);if(0===n.length||F(e))return void cvox.Api.playEarcon("EDITABLE_TEXT");n=B(n);var t=n[0];n=n.filter(function(e){return e!==t}),U(t,o),n.forEach(X)},W=function(e){U(e,0)},X=function(e){U(e,1)},H=function(e){if(e&&e.type){var o=e.type.split(".");if(0!==o.length){var n=o[0],t=M[n];return t?t:D}}},U=function(e,o){var n=H(e),t=G(e.value,h);n.replace&&(t=G(t,n.replace)),cvox.Api.speak(t,o,n.prop)},V=function(e){var o=K(e);cvox.Api.speak(o[e.column],1)},J=function(e,o){var n=K(o),t=n.substring(e.column,o.column);t=t.replace(/ /g," space "),cvox.Api.speak(t)},Y=function(e,o){if(1!==Math.abs(e.column-o.column)){var n=K(o).length;if(0===o.column||o.column===n)return void q(o.row,0);if(I(o))return cvox.Api.stop(),void X(N(o))}V(o)},$=function(e,o){c.editor.selection.isEmpty()?w?J(e,o):Y(e,o):(J(e,o),cvox.Api.speak("selected",1))},j=function(e){if(T)return void(T=!1);var o=c.editor.selection.getCursor();o.row!==k.row?P(o):$(k,o),k=o},z=function(e){c.editor.selection.isEmpty()&&cvox.Api.speak("unselected")},Q=function(e){var o=e.data;switch(o.action){case"removeText":cvox.Api.speak(o.text,0,l),T=!0;break;case"insertText":cvox.Api.speak(o.text,0),T=!0}},Z=function(e){var o=e.row,n=e.column;return!x[o]||!x[o][n]},eo=function(e){x={};for(var o=0;o<e.length;o++){var n=e[o],t=n.row,r=n.column;x[t]||(x[t]={}),x[t][r]=n}},oo=function(e){var o=c.editor.getSession().getAnnotations(),n=o.filter(Z);n.length>0&&cvox.Api.playEarcon(f),eo(o)},no=function(e){var o=e.type+" "+e.text+" on "+ro(e.row,e.column);o=o.replace(";","semicolon"),cvox.Api.speak(o,1)},to=function(e){var o=x[e];for(var n in o)no(o[n])},ro=function(e,o){return"row "+(e+1)+" column "+(o+1)},co=function(){cvox.Api.speak(ro(k.row,k.column))},io=function(){for(var e in x)to(e)},ao=function(){if(L())switch(c.editor.keyBinding.$data.state){case g:cvox.Api.speak("Insert mode");break;case A:cvox.Api.speak("Command mode")}},uo=function(){y=!y,cvox.Api.speak(y?"Speak location on row change enabled.":"Speak location on row change disabled.")},so=function(){w=!w,cvox.Api.speak(w?"Speak displacement on column changes.":"Speak current character or word on column changes.")},po=function(e){if(e.ctrlKey&&e.shiftKey){var o=b[e.keyCode];o&&o.func()}},lo=function(e,o){if(L()){var n=o.keyBinding.$data.state;if(n!==C){switch(n){case g:cvox.Api.playEarcon(v),cvox.Api.setKeyEcho(!0);break;case A:cvox.Api.playEarcon(v),cvox.Api.setKeyEcho(!1)}C=n}}},fo=function(e){var o=e.detail.customCommand,n=O[o];n&&(n.func(),c.editor.focus())},vo=function(){var e=Ao.map(function(e){return{desc:e.desc+_(e.keyCode),cmd:e.cmd}}),o=document.querySelector("body");o.setAttribute("contextMenuActions",JSON.stringify(e)),o.addEventListener("ATCustomEvent",fo,!0)},mo=function(e){e.match?q(k.row,0):cvox.Api.playEarcon(m)},go=function(){c.editor.focus()},Ao=[{keyCode:49,func:function(){to(k.row)},cmd:S.SPEAK_ANNOT,desc:"Speak annotations on line"},{keyCode:50,func:io,cmd:S.SPEAK_ALL_ANNOTS,desc:"Speak all annotations"},{keyCode:51,func:ao,cmd:S.SPEAK_MODE,desc:"Speak Vim mode"},{keyCode:52,func:uo,cmd:S.TOGGLE_LOCATION,desc:"Toggle speak row location"},{keyCode:53,func:co,cmd:S.SPEAK_ROW_COL,desc:"Speak row and column"},{keyCode:54,func:so,cmd:S.TOGGLE_DISPLACEMENT,desc:"Toggle speak displacement"},{keyCode:55,func:go,cmd:S.FOCUS_TEXT,desc:"Focus text"}],ho=function(){c.editor=editor,editor.getSession().selection.on("changeCursor",j),editor.getSession().selection.on("changeSelection",z),editor.getSession().on("change",Q),editor.getSession().on("changeAnnotation",oo),editor.on("changeStatus",lo),editor.on("findSearchBox",mo),editor.container.addEventListener("keydown",po),k=editor.selection.getCursor()},So=function(e){ho(),Ao.forEach(function(e){b[e.keyCode]=e,O[e.cmd]=e}),e.on("focus",ho),L()&&cvox.Api.setKeyEcho(!1),vo()},Eo=0,ko=15,xo=e("../editor").Editor;e("../config").defineOptions(xo.prototype,"editor",{enableChromevoxEnhancements:{set:function(e){e&&r(this)},value:!0}})}),function(){ace.require(["ace/ext/chromevox"],function(){})}();