-
Notifications
You must be signed in to change notification settings - Fork 0
/
GreekTyper.min.js
1 lines (1 loc) · 5.22 KB
/
GreekTyper.min.js
1
window.onload=function(){'use strict';const a=$('textarea'),b=a[0],c=$('#options');c.shownText='\u23F7options',c.hiddenText='\u23F5options';const d=$('#options-button'),e=$('#description');e.shownText='\u23F7description',e.hiddenText='\u23F5description';const f=$('#description-button'),g=$('#compose-toggle'),h=$('#backspace-toggle'),j=$('#reorder-diacritics-toggle'),k=$('#validate-diacritics-toggle'),l=$('#replace-diacritics-toggle'),m=$('#macron-and-breve-toggle'),n={39:'\u2019',40:'\u0314',41:'\u0313',43:'\u0308',47:'\u0301',58:'\xB7',59:'\xB7',61:'\u0342',63:';',65:'\u0391',66:'\u0392',67:'\u039E',68:'\u0394',69:'\u0395',70:'\u03A6',71:'\u0393',72:'\u0397',73:'\u0399',74:'\u03A3',75:'\u039A',76:'\u039B',77:'\u039C',78:'\u039D',79:'\u039F',80:'\u03A0',81:'\u0398',82:'\u03A1',83:'\u03A3',84:'\u03A4',85:'\u03A5',86:'\u03BD',87:'\u03A9',88:'\u03A7',89:'\u03A8',90:'\u0396',92:'\u0300',94:'\u0306',95:'\u0304',97:'\u03B1',98:'\u03B2',99:'\u03BE',100:'\u03B4',101:'\u03B5',102:'\u03C6',103:'\u03B3',104:'\u03B7',105:'\u03B9',106:'\u03C3',107:'\u03BA',108:'\u03BB',109:'\u03BC',110:'\u03BD',111:'\u03BF',112:'\u03C0',113:'\u03B8',114:'\u03C1',115:'\u03C3',116:'\u03C4',117:'\u03C5',118:'\u03DD',119:'\u03C9',120:'\u03C7',121:'\u03C8',122:'\u03B6',124:'\u0345'},p={'\u0304':1,'\u0306':2,'\u0314':3,'\u0313':3,'\u0308':3,'\u0301':4,'\u0300':4,'\u0342':4,'\u0345':5},q=function(I,J){return p[I]-p[J]},r=function(I){for(let K,L,M,J=0;K=I[J];)L=p[K],L==M?I.splice(J-1,1):++J,M=L;return I},s=function(I){return k.prop('checked')?r(I.split('').sort(q)).join(''):I.split('').sort(q).join('')},t=function(I,J,K,L){J=u(J),L?(I.value=J+L+K,I.setSelectionRange(J.length,J.length+L.length)):(I.value=J+K,I.setSelectionRange(J.length,J.length))},u=function(I){return g.prop('checked')?j.prop('checked')?I.replace(/[^\u0300-\u0345][\u0300-\u0345]+$/,function(J){return J.normalize('NFD').replace(/[\u0300-\u0345]{2,}$/,s).normalize('NFC')}):I.replace(/[^\u0300-\u0345][\u0300-\u0345]+$/,function(J){return J.normalize('NFC')}):I},v=/[\u0300-\u0345]{2,}/g,w=function(){b.value=g.prop('checked')?b.value.normalize('NFD').replace(v,s).normalize('NFC'):b.value.replace(v,s)},x=function(I,J){return function(K){J.innerHTML=I.hidden?(I.hide(K?200:void 0),I.hiddenText):(I.show(K?200:void 0),I.shownText)}},y=function(I){return function(){I.hidden=!I.hidden,I.setButtonText(!0)}};c.setButtonText=x(c,d[0]),e.setButtonText=x(e,f[0]),d.click(y(c)),f.click(y(e));const D=function(){try{const I=window.localStorage;return I.setItem('test','1'),I.removeItem('test'),!0}catch(I){return!1}}();$(window).on('beforeunload',function(){if(D){const I=window.localStorage;I.setItem('textBox',a.val()),I.setItem('selectionStart',b.selectionStart),I.setItem('selectionEnd',b.selectionEnd),I.setItem('scrollTop',b.scrollTop),$('input[type=checkbox]').each(function(J,K){K=$(K),I.setItem(K.attr('id'),+K.prop('checked'))}),I.setItem('optionsHidden',+('none'===c.css('display'))),I.setItem('descriptionHidden',+('none'===e.css('display')))}}),g.change(function(){const I=g.prop('checked')?'NFC':'NFD';let{value:J,selectionStart:K,selectionEnd:L}=b;t(b,J.slice(0,K).normalize(I),J.slice(L).normalize(I),J.slice(K,L).normalize(I)),a.focus()}),k.change(function(){k.prop('checked')?(w(),l.removeAttr('disabled'),m.removeAttr('disabled')):(l.attr('disabled',!0),m.attr('disabled',!0))}),j.change(function(){j.prop('checked')?k.removeAttr('disabled'):k.attr('disabled',!0)}),m.change(function(){if(m.prop('checked'))p['\u0306']=2;else{p['\u0306']=1;let I=b.value;const J=g.prop('checked');J&&(I=I.normalize('NFD')),I=I.replace(/\u0304\u0306/g,'\u0304'),J&&(I=I.normalize('NFC')),b.value=I}}),function(){if(D){const I=window.localStorage,J=I.getItem('textBox'),K=I.getItem('selectionStart'),L=I.getItem('selectionEnd'),M=I.getItem('scrollTop');J&&a.val(J),M&&(b.scrollTop=M),K&&L&&(a.focus(),b.setSelectionRange(+K,+L)),$('input[type=checkbox]').each(function(N,O){O=$(O),O.prop('checked','1'===I.getItem(O.attr('id')))}),c.hidden='1'===I.getItem('optionsHidden'),c.setButtonText(),e.hidden='1'===I.getItem('descriptionHidden'),e.setButtonText()}}();const F=['\u03C2','\u03C3'],G=function(I,J){return F.includes(I)?''===J||/^[\s–—,.·:;'’")\]|}\u0300-\u0345]/.test(J)?'\u03C2':/^[-\u0370-\u03FF\u1F00-\u1FFF]/.test(J)?'\u03C3':I:I},H=function(I,J){const{selectionStart:K,selectionEnd:L,value:M}=I,N=M.slice(L);J=G(J,N.charAt(0));const O=0===K?'':1===K?G(M.charAt(K-1),J):M.slice(0,K-1)+G(M.charAt(K-1),J);t(I,O+J,N)};a.keydown(function(J){if(8===J.which){const{selectionStart:K,selectionEnd:L}=this;if(K!==L||J.ctrlKey)return;J.preventDefault();const M=this.value;let N,O;J.shiftKey?(N=M.slice(0,K).normalize('NFD').replace(/(?:[\u0300-\u0345]+|.)$/,''),O=M.slice(L)):h.prop('checked')?g.prop('checked')?(N=0===K?'':M.slice(0,K-1)+M.charAt(K-1).normalize('NFD').slice(0,-1),O=M.slice(L)):(N=0===K?'':M.slice(0,K-1),O=M.slice(L)):(N=0===K?'':M.slice(0,K).replace(/[^\u0300-\u0345][\u0300-\u0345]*$/,''),O=M.slice(L)),N=N.slice(0,-1)+G(N.slice(-1),O.charAt(0)),t(this,N,O)}}),a.keypress(function(J){const K=J.which;if(!(8===K||J.ctrlKey||J.altKey||J.metaKey))if(n[K])J.preventDefault(),H(this,n[K]);else if(1===J.key.length){const{selectionStart:L,selectionEnd:M,value:N}=this;t(this,0===L?'':1===L?G(N.charAt(L-1),J.key):N.slice(0,L-1)+G(N.charAt(L-1),J.key),N.slice(M))}})};