UNPKG

easy-typing-input-tool

Version:

A tool utilizing google input tool for the use of easy typing repositories such as ENT, EHt & EBT

1 lines 9.26 kB
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var i=t[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){const o=n(1);function i(e,t,n,o,i,l){const r=u(e.currentTarget),c=e.target.value,p=c.length;let g="",f=r.end;const h=c.substr(0,r.end);if(g=c.substr(r.end,p),void 0!==i){let n=h.split(" "),r=0;if(r=n.includes("")?n[n.length-2]:n[n.length-1],t[i]=t[r],void 0===r)return void console.log("last word before cursor end is not defined");f-=r.length;let c=!1;n.includes("")?n[n.length-2]=i:(c=!0,n[n.length-1]=i),n=n.join(" "),f+=i.length,n+=g,c&&(f++,n+=" "),o.val(d(n)),a(e.currentTarget,f),$(l+" .btn, #InputSuggestions .suggestion-btn").removeClass("btn-success"),$(this).addClass("btn-success"),s()}}function s(){null!==document.getElementById("InputSuggestions")&&document.getElementById("InputSuggestions").remove()}function l(e,t){for(let n in e){const o=e[n];void 0!==o.classList&&o.classList.contains(t)&&o.classList.remove(t)}}function r(e,t){void 0!==e&&e.classList.add(t)}function c(e,t,n,o,i){n.innerHTML="";let s=0,c=0;e.forEach(function(e){c++,s+=25;const t=document.createElement("button");t.setAttribute("value",e[0]),t.innerHTML=e[1],t.classList.add("suggestion-btn"),t.style.height="25px",t.style.display="block",t.style.backgroundColor="#fefefe",t.style.border="0px",t.style.width="100%",t.style.fontSize="15px",t.style.textAlign="left",1===c&&t.classList.add("selected"),n.append(t),n.style.height=s+"px"}),n.remove();const u=t[0],a=function(e){let t={x:0,y:0};const n=function(e,t,n){let o=document.createElement("div");o.id="input-textarea-caret-position-mirror-div",document.body.appendChild(o);let i=o.style,s=window.getComputedStyle?getComputedStyle(e):e.currentStyle;i.whiteSpace="pre-wrap","INPUT"!==e.nodeName&&(i.wordWrap="break-word");i.position="absolute",i.visibility="hidden",p.forEach(function(e){i[e]=s[e]}),g?(i.width=parseInt(s.width)-2+"px",e.scrollHeight>parseInt(s.height)&&(i.overflowY="scroll")):i.overflow="hidden";o.textContent=e.value.substring(0,t),"INPUT"===e.nodeName&&(o.textContent=o.textContent.replace(/\s/g," "));let l=document.createElement("span");l.textContent=e.value.substring(t)||".",o.appendChild(l);const r={top:l.offsetTop+parseInt(s.borderTopWidth),left:l.offsetLeft+parseInt(s.borderLeftWidth)};return document.body.removeChild(o),r}(e,e.selectionEnd),o=e.style.fontSize.replace("px",""),i=function(e){let t={height:0,width:0};return t.height=e.clientHeight+1,t.width=e.clientWidth+1,t}(e);100*n.left/i.width<70?t.x=n.left:t.x=n.left-50;return t.y=n.top+2*o,t}(u);!function(e,t,n,o,i,s){t.style.position="absolute",t.style.left=o+"px",t.style.top=s+i+"px",t.style.display="block",t.style.border="1px solid #999";const l=e.parentNode;l.style.position="relative",l.appendChild(t)}(u,n,0,a.x,a.y,i);let d=0;$(document).keydown(function(e){const t=document.getElementById("InputSuggestions");if(null===t)return;const n=t.getElementsByTagName("button"),o=n.length,i=document.getElementById("InputSuggestions");if(null!==i&&"block"===i.style.display)switch(e.which){case 39:case 38:e.preventDefault(),-1===--d&&(d=o-1),l(n,"selected"),r(n[d],"selected");break;case 37:case 40:e.preventDefault(),++d===o&&(d=0),l(n,"selected"),r(n[d],"selected")}})}function u(e){let t,n,o,i,s,l=0,r=0;return"number"==typeof e.selectionStart&&"number"==typeof e.selectionEnd?(l=e.selectionStart,r=e.selectionEnd):(n=document.selection.createRange())&&n.parentElement()==e&&(i=e.value.length,t=e.value.replace(/\r\n/g,"\n"),(o=e.createTextRange()).moveToBookmark(n.getBookmark()),(s=e.createTextRange()).collapse(!1),o.compareEndPoints("StartToEnd",s)>-1?l=r=i:(l=-o.moveStart("character",-i),l+=t.slice(0,l).split("\n").length-1,o.compareEndPoints("EndToEnd",s)>-1?r=i:(r=-o.moveEnd("character",-i),r+=t.slice(0,r).split("\n").length-1))),{start:l,end:r}}function a(e,t){let n;e.createTextRange?((n=e.createTextRange()).move("character",t),n.select()):(e.focus(),void 0!==e.selectionStart&&e.setSelectionRange(t,t))}function d(e){let t=document.createElement("div");return t.innerHTML=e,0===t.childNodes.length?"":t.childNodes[0].nodeValue}e.exports={transliterate:function(e){const t=(e=e||{}).inputTextareaIds||"#input_tool, #languageTextarea, #emailContents, #translationTextarea",n=e.inputHelperTool||"#input_tool_helper",l=e.additionalPopUpTopMargin||0;e.debug&&console.log("google transliteration tool",e);const r=e.suggestionPopupAfterSpace||!1,p=e.suggestionPopupOnClick||!1;let g=e.googleInputKeyCode||$("input[name=googleInputKeyCode]").val(),f=$(t);const h=$(n),m=e.maxResult||6;let y=new XMLHttpRequest,v=!1;const b=document.createElement("div");b.id="InputSuggestions";const E=document.createTextNode("Option");f.on("input",function(e){b.remove()}),g||(g="ne-t-i0-und",console.error('Google Input Key Code not defined. So defaulting to Nepali (ne-t-i0-und). Please specify hidden input: <input type="hidden" name="googleInputKeyCode" value="inputKeyCode(ne-t-i0-und)">'));f.on("keydown",function(e){(function(e){if(71===e.which&&e.ctrlKey)return e.preventDefault(),!0;return!1})(e)&&(v=!v)});let x={};f.on("keyup",function(e){8===e.which&&(h.empty(),v?h.append("<em>English mode enabled. Press (CTRL + G) to switch back.</em>"):h.append("<em>Additional options appears here!</em>"))}),f.click(function(e){console.log("1. Backup Google Input 1..."),s();const t=[" ","\n","\r","\t"],i=$(this).val();let r=$(this)[0].selectionStart,u=$(this)[0].selectionEnd;for(;r>0&&-1==t.indexOf(i[r]);)--r;for(++r;u<i.length&&-1==t.indexOf(i[u]);)++u;const a=i.substr(r,u-r);if(a){let e=x[a];void 0===e&&(e=a),o(y,e,g,m).then(function(t){t.forEach(function(t){x[t[0]]=e});const o=e.match(/[A-Za-z0-9\u00C0-\u024F\u1E00-\u1EFF]+/)[0];t.push([e,o]),h.empty(),t.forEach(function(e){const t=document.createElement("button");t.setAttribute("value",e[0]),t.innerHTML=e[1],t.classList.add("btn"),h.append(t)}),!0===p&&c(t,f,b,E,l),$(n+" .btn, #InputSuggestions .suggestion-btn").on("click",function(t){let n=void 0!==this.value?this.value:this.innerHTML;x[n]=e;const o=i.slice(0,r)+n+i.slice(u);f.val(d(o)),s()})})}}),f.on("keyup",function(e){if(v)return h.empty(),void h.append("<em>English mode enabled. Press (CTRL + G) to switch back.</em>");if(32===e.which||229===e.which||8===e.which){let t=$(this).val().split(" "),p=!1,v="",w=0;const T=u(e.currentTarget),S=e.target.value,I=S.length;let C=null;if(8===e.which){T.end;let e=t[t.length-1];return void(C=x[e])}if(null===(C=t[t.length-2]))return;if(T.end!==I){w=T.end;const e=S.substr(0,T.end);v=S.substr(T.end,I),p=!0,t=e.split(" "),C=t[t.length-2],w-=C.length}o(y,C,g,m).then(function(o){o.forEach(function(e){x[e[0]]=C});const u=C.match(/[A-Za-z0-9\u00C0-\u024F\u1E00-\u1EFF]+/)[0];o.push([C,u]),h.empty();let g=0;o.forEach(function(e){g++;const t=document.createElement("button");t.setAttribute("value",e[0]),t.innerHTML=e[1],t.classList.add("btn"),1===g&&t.classList.add("btn-success"),h.append(t)}),!0===r&&c(o,f,b,E,l),f.on("keydown",function(t){if($("#InputSuggestions .selected")&&"Enter"===t.key){const o=document.getElementById("InputSuggestions");null!==o&&"block"===o.style.display&&t.preventDefault();const l=document.getElementById("InputSuggestions");if(null===l)return;const r=l.getElementsByClassName("selected");if(void 0===r||void 0===r[0])return;const c=r[0];i(e,x,C,f,void 0!==c.value?c.value:c.innerHTML,n),s()}}),$(n+" .btn, #InputSuggestions .suggestion-btn").on("click",function(t){i(e,x,C,f,""!==this.value?this.value:this.innerHTML,n)}),8===e.which?t[t.length-1]=o[0][0]:t[t.length-2]=o[0][0],t=t.join(" "),!0===p&&(w+=o[0][0].length,t+=v),x[o[0][0]]=C,f.val(d(t)),!0===p&&a(e.currentTarget,w)})}else h.empty(),v?h.append("<em>English mode enabled. Press (CTRL + G) to switch back.</em>"):h.append("<em>Additional options appears here!</em>")})}};let p=["direction","boxSizing","width","height","overflowX","overflowY","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","paddingTop","paddingRight","paddingBottom","paddingLeft","fontStyle","fontVariant","fontWeight","fontStretch","fontSize","fontSizeAdjust","lineHeight","fontFamily","textAlign","textTransform","textIndent","textDecoration","letterSpacing","wordSpacing"],g=!(null==window.mozInnerScreenX)},function(e,t,n){"use strict";e.exports=function(e,t,n,o){return new Promise(function(i,s){const l=t.match(/[A-Za-z0-9\u00C0-\u024F\u1E00-\u1EFF]+/);if(null===l)return;const r=l[0],c=t.split(r),u=c[0],a=c[1];let d=encodeURI("https://inputtools.google.com/request?text="+r+"&itc="+n+"&num="+o+"&cp=0&cs=1&ie=utf-8&oe=utf-8&app=demopage");e.open("GET",d),e.onreadystatechange=function(){if(e.readyState===e.DONE)if(200===e.status){const e=JSON.parse(this.responseText);if(void 0===e[1]||void 0===e[1][0])return;const t=e[1][0][1];i(t.map(e=>[u+e+a,e]))}else s("Rejected status code: "+e.status)},e.onerror=function(){s(Error("Network Error"))},e.send()})}},function(e,t,n){e.exports=n(0)}]);