-
Notifications
You must be signed in to change notification settings - Fork 1
/
jkeyboard.min.js
1 lines (1 loc) · 3.14 KB
/
jkeyboard.min.js
1
!function(a){var t={init:function(t){var e=a.extend({slidetime:200,onKeyDown:function(){},onShow:function(){},onHide:function(){},onKeyPress:function(){}},t);return this.each(function(){var t=a(this),n=(a("#jKeyboard").length>0||($container=a('<div id="jKeyboard" class="jkeyboard"></div>'),a("body").append($container),$container.on("keydown",function(a){e.onKeyDown(a,t)}),1),a("#jKeyboard")),i="",o={abnt2:["' 1 2 3 4 5 6 7 8 9 0 - = {bksp}","{tab} q w e r t y u i o p \xb4 [ ]","a s d f g h j k l \xe7 ~ {enter}","{shift} \\ z x c v b n m , . ; /","{accept} {space} {cancel}"],shift:['" ! @ # $ % \xa8 & * ( ) _ + {bksp}',"{tab} Q W E R T Y U I O P ` { }","A S D F G H J K L \xc7 ^ {enter}","{shift} | Z X C V B N M < > : ?","{accept} {space} {cancel}"]},s={"{bksp}":'<i class="fa-regular fa-arrow-left-long"></i> Bksp',"{tab}":'<i class="fa-regular fa-arrow-right-arrow-left"></i> Tab',"{enter}":'<i class="fa-light fa-arrow-turn-down-left"></i> Enter',"{shift}":'<i class="fa-solid fa-up-long"></i> Shift',"{space}":'<i class="fa-regular fa-dash"></i>',"{accept}":'<i class="fa-light fa-check"></i> Concluir',"{cancel}":'<i class="fa-light fa-xmark"></i> Cancelar'},c={"{bksp}":"bksp","{tab}":"tab","{enter}":"enter","{shift}":"shift","{space}":"space","{accept}":"accept","{cancel}":"cancel"},l={"~":{a:"\xe3",o:"\xf5",A:"\xc3",O:"\xd5"},"^":{a:"\xe2",e:"\xea",i:"\xee",o:"\xf4",u:"\xfb",A:"\xc2",E:"\xca",I:"\xce",O:"\xd4",U:"\xdb"},"`":{a:"\xe0",e:"\xe8",i:"\xec",o:"\xf2",u:"\xf9",A:"\xc0",E:"\xc8",I:"\xcc",O:"\xd2",U:"\xd9"},"\xb4":{a:"\xe1",e:"\xe9",i:"\xed",o:"\xf3",u:"\xfa",c:"\xe7",A:"\xc1",E:"\xc9",I:"\xcd",O:"\xd3",U:"\xda",C:"\xc7"},'"':{a:"\xe4",e:"\xeb",i:"\xef",o:"\xf6",u:"\xfc",y:"\xff",A:"\xc4",E:"\xcb",I:"\xcf",O:"\xd6",U:"\xdc",Y:"Ÿ"}};function r(t,e){for(var n=0;n<t.length;n++){for(var i=a('<div class="keyboard-row"></div>'),o=t[n].split(" "),l=0;l<o.length;l++){var r=o[l],d=a('<div class="navi key '+(c[r]||r)+'"></div>').html(s[r]||r).attr("data-key",r);d.on("click",function(){f(a(this).attr("data-key"))}),i.append(d)}e.append(i)}}function f(n){n in l?(i=n,t.val(t.val()+n)):i&&l[i][n]?(t.val(t.val().slice(0,-1)+l[i][n]),i=""):("{bksp}"===n?t.val(t.val().slice(0,-1)):"{space}"===n?t.val(t.val()+" "):"{enter}"===n?t.val(t.val()+"\n"):"{tab}"===n?t.val(t.val()+" "):"{accept}"===n?d():"{cancel}"===n?(t.val(""),d()):"{shift}"===n?(a(".abnt2-layout").toggleClass("d-none"),a(".shift-layout").toggleClass("d-none")):t.val(t.val()+n),i=""),e.onKeyPress(n,t)}function d(){n.animate({bottom:"-25%"},e.slidetime,function(){n.hide()}),e.onHide()}t.data("keyboard",{show:function t(){var i,s;n.empty(),i=a('<div class="keyboard-layout abnt2-layout"></div>'),s=a('<div class="keyboard-layout shift-layout d-none"></div>'),r(o.abnt2,i),r(o.shift,s),n.append(i),n.append(s),n.show(),e.onShow(),n.animate({bottom:0},e.slidetime)},hide:d})})},show:function(){return this.each(function(){var t=a(this).data("keyboard");t&&t.show()})},hide:function(){return this.each(function(){var t=a(this).data("keyboard");t&&t.hide()})}};a.fn.jKeyboard=function(a){return t[a]?t[a].apply(this,Array.prototype.slice.call(arguments,1)):("object"==typeof a||!a)&&t.init.apply(this,arguments)}}(jQuery);