2 lines
6.1 KiB
JavaScript
2 lines
6.1 KiB
JavaScript
/*! jQuery UI Virtual Keyboard Alt Key Popup v1.1.4 */
|
||
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&"object"==typeof module.exports?module.exports=e(require("jquery")):e(jQuery)}(function(e){"use strict";var p=e.keyboard;e.extend(p.css,{altKeyPopup:"ui-keyboard-popup",altKeyOverlay:"ui-keyboard-overlay"}),p.altKeys=e.extend({a:"å æ ā ă ą à á â ã ä",A:"Å Æ Ā Ă Ą À Á  à Ä",c:"ç ć ĉ ċ č",C:"Ç Ć Ĉ Ċ Č",d:"ď ð ď",D:"Ď Ð Ď",e:"ė ę ĕ ě ə è é ê ë ē",E:"Ė Ę Ĕ Ě Ǝ È É Ê Ë Ē",g:"ģ ğ ĝ ġ",G:"Ģ Ğ Ĝ Ġ",h:"ĥ ħ",H:"Ĥ Ħ",i:"ı į ī ï î í ì ĩ ĭ",I:"İ Į Ī Ï Î Í Ì Ĩ Ĭ",j:"ĵ",J:"Ĵ",k:"ķ",K:"Ķ",l:"Ł Ľ Ļ Ĺ Ŀ",L:"ł ľ ļ ĺ ŀ",n:"ʼn ň ņ ń ñ",N:"ʼn Ň Ņ Ń Ñ",o:"œ ő ø ö õ ô ó ò ō ŏ",O:"Œ Ő Ø Ö Õ Ô Ó Ò Ō Ŏ",r:"ŕ ř ŗ",R:"Ŕ Ř Ŗ",s:"ś š ş ß § ŝ",S:"Ś Š Ş ẞ § Ŝ",t:"þ ť ț ţ ŧ",T:"Þ Ť Ț Ţ Ŧ",u:"ų ű ů ū ü û ú ù ũ ŭ",U:"Ų Ű Ů Ū Ü Û Ú Ù Ũ Ŭ",w:"ŵ",W:"Ŵ",y:"ý",Y:"Ý",z:"ź ż ž",Z:"Ź Ż Ž","!":"¡",$:"€ £ ¤ ¥ ¢ ₡ ₱ ₩ ₹ ₪ ₭ ₮ ₦ ₤","?":"¿","'":"〈 「 『 “",'"':"〉 」 』 ”","(":"《 【 〔",")":"》 】 〕"},p.altKeys),p.navigationKeys=e.extend({enter:13,escape:27,end:35,home:36,left:37,right:39},p.navigationKeys),e.fn.addAltKeyPopup=function(o){var t={holdTime:500,popupVisible:"popup-visible",popupHidden:"popup-hidden",popupPosition:null};return this.each(function(){var a=e(this).data("keyboard");if(a){if(a.altkeypopup_options=e.extend({},t,a.altkeypopup_options,o),a.altkeypopup_namespace)return a.altkeypopup_setup();a.altkeypopup_namespace=a.namespace+"AltKeyPopup",a.extensionNamespace.push(a.altkeypopup_namespace),a.altkeypopup_setup=function(){var o,t="mousedown touchstart ".split(" ").join(a.altkeypopup_namespace+" "),i="mouseup touchend touchcancel ".split(" ").join(a.altkeypopup_namespace+" ");a.options.repeatRate=0,a.$allKeys.unbind(a.altkeypopup_namespace).bind(t,function(){clearTimeout(o);var t=e(this),i=t.attr("data-value")||"",n=a.altkeypopup_options.holdTime;i in p.altKeys&&(n?o=setTimeout(function(){a.altKeyPopup_popup(i,t)},n):a.altKeyPopup_popup(i,t))}).bind(i,function(){clearTimeout(o)}),a.altkeypopup_blockingFlag=!1,a.$preview.unbind("keypress keydown keyup ".split(" ").join(a.altkeypopup_namespace+" ").trim()).bind("keypress keydown keyup ".split(" ").join(a.altkeypopup_namespace+" "),function(t){if("keyup"===t.type)return clearTimeout(o),a.altkeypopup_blockingFlag=!1,t.which!==p.navigationKeys.escape;var i,n=p.builtLayouts[a.layout],u=p.keyCodes,s=e(t.target),l=t.charCode||t.which,y=String.fromCharCode(l);return"keydown"===t.type&&y in p.altKeys?(i=a.altkeypopup_blockingFlag,a.altkeypopup_blockingFlag=!0,!i):a.altkeypopup_blockingFlag?(l>=u.a&&l<=u.z&&!t.shiftKey&&(y=y.toLowerCase()),n.hasMappedKeys&&n.mappedKeys.hasOwnProperty(y)&&(y=n.mappedKeys[y]),y in p.altKeys&&(o=setTimeout(function(){a.altkeypopup_blockingFlag&&a.altKeyPopup_popup(y,s)},a.altkeypopup_options.holdTime)),!0):void 0})},a.altKeyPopup_close=function(){a.altkeypopup_blockingFlag=!1,a.altKeyPopup_$overlay=null,a.$keyboard.find("."+p.css.altKeyOverlay).remove(),e(document).unbind(a.altkeypopup_namespace),a.$preview.focus(),a.options.ignoreEsc=a.altKeyPopup_savedIgnoreEsc,a.$el.trigger(a.altkeypopup_options.popupHidden,[a])},a.altKeyPopup_popup=function(o,t){if(!a.$keyboard.find("."+p.css.altKeyOverlay).length){var i,n,u,s,l,y,r,c,d,k=p.css,h={$kb:a.$keyboard,kbWidth:a.$keyboard.outerWidth(),kbHeight:a.$keyboard.outerHeight(),$key:t};a.altKeyPopup_$overlay=e('<div class="'+k.altKeyOverlay+'" />').css({width:h.kbWidth,height:h.kbHeight}).appendTo(a.$keyboard).bind("click touchstart",function(){a.altKeyPopup_close()}),d="inactive hidden ".split(" ").join(a.altkeypopup_namespace+" "),a.$el.unbind(d).bind(d,function(){a.altKeyPopup_close()}),"bksp"!==o&&p.keyaction.bksp(a),n=e('<div class="'+k.altKeyPopup+" "+a.options.css.container+'" />'),i=p.altKeys[o].split(/\s+/),a.buildRow(n,0,i,[]),u=n.appendTo(a.altKeyPopup_$overlay).children().bind("mousedown touchstart",function(o){var t=e(this).attr("data-action");t in p.keyaction&&e.isFunction(p.keyaction[t])?p.keyaction[t](a,this,o):a.insertText(t),a.altKeyPopup_close()}).bind("mouseover mouseleave",function(p){u.removeClass(a.options.css.buttonHover),"mouseleave"!==p.type&&e(this).addClass(a.options.css.buttonHover)}),a.altKeyPopup_navigate(!0),a.altKeyPopup_savedIgnoreEsc=a.options.ignoreEsc,a.options.ignoreEsc=!0,e(document).unbind(a.altkeypopup_namespace).bind("keydown"+a.altkeypopup_namespace,function(e){return!1}).bind("keyup"+a.altkeypopup_namespace,function(e){return e.which===p.navigationKeys.escape?(e.which=0,a.altKeyPopup_close()):a.altKeyPopup_navigate(e),!1}),h.$popup=n,r=n.outerWidth(),(s=t.position().left-r/2)+r>h.kbWidth&&(s=h.kbWidth-r)<0&&n.css({width:h.kbWidth,height:"auto"}),l=t.position().top-t.outerHeight()-5,c=n.outerHeight(),y=a.$keyboard.find("."+k.keySet).position().top,l+c>h.kbHeight&&(l=h.kbHeight-c)<y&&n.css({height:h.popupHeight,width:"auto"}),h.popupWidth=n.outerWidth(),h.popupHeight=n.outerHeight(),h.popupLeft=s<0?0:s,h.popupTop=l<y?y:l,n.css({position:"absolute",left:h.popupLeft,top:h.popupTop}),"function"==typeof a.altkeypopup_options.popupPosition&&a.altkeypopup_options.popupPosition(a,h),a.$preview.blur(),a.$el.trigger(a.altkeypopup_options.popupVisible,[a])}},a.altKeyPopup_navigate=function(e){var o,t=p.css,i=p.navigationKeys,n=a.options.css.buttonHover,u=a.$keyboard.find("."+t.altKeyPopup).find("."+t.keyButton),s=u.length-1;if(!0===e)return u.eq(0).addClass(n),void(a.altKeyPopup_currentIndex=0);if(o=a.altKeyPopup_currentIndex,e.which===i.enter)return a.insertText(u.eq(o).attr("data-value")),a.altKeyPopup_close(),!0;switch(e.which){case i.end:o=s;break;case i.home:o=0;break;case i.left:o-=1;break;case i.right:o+=1}o<0&&(o=0),o>s&&(o=s),a.altKeyPopup_currentIndex=o,u.removeClass(n).eq(o).addClass(n)},a.options.alwaysOpen&&a.isVisible()&&a.altkeypopup_setup(),a.$el.unbind(p.events.kbBeforeVisible+a.altkeypopup_namespace).bind(p.events.kbBeforeVisible+a.altkeypopup_namespace,function(){a.altkeypopup_setup()})}})}}); |