加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.js 7.42 KB
一键复制 编辑 原始数据 按行查看 历史
Bd999 提交于 2019-10-17 17:18 . update v1.0.0-beta.1
!function(e){var o={};function n(t){if(o[t])return o[t].exports;var r=o[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=o,n.d=function(e,o,t){n.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,o){if(1&o&&(e=n(e)),8&o)return e;if(4&o&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&o&&"string"!=typeof e)for(var r in e)n.d(t,r,function(o){return e[o]}.bind(null,r));return t},n.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(o,"a",o),o},n.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},n.p="",n(n.s=0)}([function(e,o,n){const t=n(1),r=n(2);window.aKeyboard={keyboard:t,numberKeyboard:r}},function(e,o){e.exports=class{constructor(e){if("object"!=typeof e)return void console.error('aKeyboard: The obj parameter needs to be an object <In "new aKeyboard()">');this.obj=e;const o=document.querySelector(e.el);let n="";if("object"==typeof e.style)for(let o in e.style)n+=o+": "+e.style[o]+";";let t='<div class="akeyboard-keyboard'+(e.fixedBottomCenter?" akeyboard-keyboard-fixedBottomCenter":"")+'" style="'+n+'">',r=[];for(let e=1;e<10;e++)r.push(e.toString());r.push("0");const a=[["`"].concat(r).concat(["-","=","Delete"]),["Tab","q","w","e","r","t","y","u","i","o","p","[","]","\\"],["Caps","a","s","d","f","g","h","j","k","l",";","'","Enter"],["Shift","z","x","c","v","b","n","m",",",".","/","Shift"],["Space"]];let i;const s=[],c=[];for(let e=0;e<a.length;e++){s.push([]),c.push([]),i=a[e];for(let o=0;o<i.length;o++)if(1!==i[o].length)s[e].push(i[o]),c[e].push(i[o]);else{switch(c[e].push(i[o].toUpperCase()),i[o]){case"`":s[e].push("~");continue;case"1":s[e].push("!");continue;case"2":s[e].push("@");continue;case"3":s[e].push("#");continue;case"4":s[e].push("$");continue;case"5":s[e].push("%");continue;case"6":s[e].push("^");continue;case"7":s[e].push("&");continue;case"8":s[e].push("*");continue;case"9":s[e].push("(");continue;case"0":s[e].push(")");continue;case"-":s[e].push("_");continue;case"=":s[e].push("+");continue;case"[":s[e].push("{");continue;case"]":s[e].push("}");continue;case"\\":s[e].push("|");continue;case";":s[e].push(":");continue;case"'":s[e].push('"');continue;case",":s[e].push("<");continue;case".":s[e].push(">");continue;case"/":s[e].push("?");continue}s[e].push(i[o].toUpperCase())}}for(let e=0;e<a.length;e++){i=a[e],t+='<div class="akeyboard-keyboard-innerKeys">';for(let e=0;e<i.length;e++)t+='<div class="akeyboard-keyboard-keys akeyboard-keyboard-keys-'+i[e]+'">'+i[e]+"</div>";t+="</div>"}t+="</div>",o.innerHTML=t;const d=document.querySelectorAll(e.el+" .akeyboard-keyboard-keys-Shift");function l(){if(!this.isShift){if(document.querySelector(e.el+" .akeyboard-keyboard-keys-Caps").isCaps)return;d[0].isShift=!0,d[1].isShift=!0,d[0].innerHTML="SHIFT",d[1].innerHTML="SHIFT";const o=document.querySelectorAll(e.el+" .akeyboard-keyboard-innerKeys");let n;for(let e=0;e<o.length;e++){n=o[e];for(let o=0;o<n.childNodes.length;o++)"Shift"!==s[e][o]&&(n.childNodes[o].innerHTML=s[e][o])}return}d[0].isShift=!1,d[1].isShift=!1,d[0].innerHTML="Shift",d[1].innerHTML="Shift";const o=document.querySelectorAll(e.el+" .akeyboard-keyboard-innerKeys");let n;for(let e=0;e<o.length;e++){n=o[e];for(let o=0;o<n.childNodes.length;o++)n.childNodes[o].innerHTML=a[e][o]}}d[0].onclick=l,d[0].isShift=!1,d[1].onclick=l,d[1].isShift=!1;const u=document.querySelector(e.el+" .akeyboard-keyboard-keys-Caps");u.onclick=function(){if(!this.isCaps){if(document.querySelector(e.el+" .akeyboard-keyboard-keys-Shift").isShift)return;this.isCaps=!0,this.classList.add("keyboard-keyboard-keys-focus");const o=document.querySelectorAll(e.el+" .akeyboard-keyboard-innerKeys");let n;for(let e=0;e<o.length;e++){n=o[e];for(let o=0;o<n.childNodes.length;o++)n.childNodes[o].innerHTML=c[e][o]}return}this.isCaps=!1,this.classList.remove("keyboard-keyboard-keys-focus");const o=document.querySelectorAll(e.el+" .akeyboard-keyboard-innerKeys");let n;for(let e=0;e<o.length;e++){n=o[e];for(let o=0;o<n.childNodes.length;o++)n.childNodes[o].innerHTML=a[e][o]}},u.isCaps=!1}inputOn(e,o){if("string"!=typeof e)return void console.error('aKeyboard: The inputEle parameter needs to be a string <In "aKeyboard.inputOn()">');if("string"!=typeof o)return void console.error('aKeyboard: The type parameter needs to be a string <In "aKeyboard.inputOn()">');document.querySelector(this.obj.el);const n=document.querySelector(e),t=document.querySelectorAll(this.obj.el+" .akeyboard-keyboard-keys");for(let e=0;e<t.length;e++)"Shift"!==t[e].innerHTML&&"Caps"!==t[e].innerHTML&&("Delete"!==t[e].innerHTML?"Tab"!==t[e].innerHTML?"Enter"!==t[e].innerHTML?"Space"!==t[e].innerHTML?t[e].onclick=function(){n[o]+=this.innerText}:t[e].onclick=function(){n[o]+=" "}:t[e].onclick=function(){n[o]+="\n"}:t[e].onclick=function(){n[o]+=" "}:t[e].onclick=function(){n[o]=n[o].substr(0,n[o].length-1)})}onclick(e,o){if("string"!=typeof e)return void console.error('aKeyboard: The btn parameter needs to be a string <In "aKeyboard.onclick()">');if("function"!=typeof o)return void console.error('aKeyboard: The fn parameter needs to be a function <In "aKeyboard.onclick()">');document.querySelector(this.obj.el+" .akeyboard-keyboard-keys-"+e).onclick=o}}},function(e,o){e.exports=class{constructor(e){if("object"!=typeof e)return void console.error('aKeyboard: The obj parameter needs to be an object <In "new aKeyboard()">');this.obj=e;const o=document.querySelector(e.el);let n="";if("object"==typeof e.style)for(let o in e.style)n+=o+": "+e.style[o]+";";let t='<div class="akeyboard-numberKeyboard'+(e.fixedBottomCenter?" akeyboard-keyboard-fixedBottomCenter":"")+'" style="'+n+'">';t+='<div class="akeyboard-keyboard-innerKeys">';for(let e=1;e<10;e++)t+='<div class="akeyboard-keyboard-keys akeyboard-keyboard-keys-'+e+'">'+e+"</div>",e%3==0&&(t+='</div><div class="akeyboard-keyboard-innerKeys">');t+='<div class="akeyboard-keyboard-keys akeyboard-keyboard-keys-0">0</div><div class="akeyboard-keyboard-keys akeyboard-keyboard-keys-Delete">Delete</div></div><div class="akeyboard-keyboard-innerKeys"><div class="akeyboard-keyboard-keys akeyboard-numberKeyboard-keys-Enter">Enter</div></div>',t+="</div>",o.innerHTML=t}inputOn(e,o){if("string"!=typeof e)return void console.error('aKeyboard: The inputEle parameter needs to be a string <In "aKeyboard.inputOn()">');if("string"!=typeof o)return void console.error('aKeyboard: The type parameter needs to be a string <In "aKeyboard.inputOn()">');document.querySelector(this.obj.el);const n=document.querySelector(e),t=document.querySelectorAll(this.obj.el+" .akeyboard-keyboard-keys");for(let e=0;e<t.length;e++)"Delete"!==t[e].innerHTML?"Enter"!==t[e].innerHTML?t[e].onclick=function(){n[o]+=this.innerText}:t[e].onclick=function(){n[o]+="\n"}:t[e].onclick=function(){n[o]=n[o].substr(0,n[o].length-1)}}onclick(e,o){if("string"!=typeof e)return void console.error('aKeyboard: The btn parameter needs to be a string <In "aKeyboard.onclick()">');if("function"!=typeof o)return void console.error('aKeyboard: The fn parameter needs to be a function <In "aKeyboard.onclick()">');let n=document.querySelector(this.obj.el+" .akeyboard-keyboard-keys-"+e);null===n&&(n=document.querySelector(this.obj.el+" .akeyboard-numberKeyboard-keys-"+e)),n.onclick=o}}}]);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化