12 |
- /*! jQuery UI Virtual Keyboard Typing Simulator v1.11.1 */
- !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(d){d.fn.addTyping=function(e){var t={showTyping:!0,lockTypeIn:!1,delay:250,hoverDelay:250},f=d.keyboard;return this.each(function(){var g,l=d(this).data("keyboard");l&&(g=l.typing_options=d.extend({},t,e),l.typing_keymap={" ":"space",'"':"34","'":"39"," ":"space","\b":"bksp","{b}":"bksp","{d}":"del","{l}":"left","{r}":"right","\n":"enter","\r":"enter","{e}":"enter","\t":"tab","{t}":"tab"},l.typing_xref={8:"bksp",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"del"},l.typing_event=!1,l.typing_namespace=l.namespace+"typing",l.extensionNamespace.push(l.typing_namespace),g.savedLockInput=l.options.lockInput,l.typing_setup_reset=function(){var e=f.events,t=l.typing_namespace,n=[e.kbHidden,e.kbInactive,""].join(t+" ");l.$el.unbind(t).bind(n,function(){l.typing_reset()}),l.unbindButton(t).bindButton("mousedown"+t,function(){l.typing_reset()})},l.typing_setup=function(){var e=l.typing_namespace;l.typing_setup_reset(),l.$el.bind(f.events.kbBeforeVisible+e,function(){l.typing_setup()}),l.$preview.unbind(e).bind("keyup"+e,function(e){return!(g.init&&g.lockTypeIn||!g.showTyping)&&(37<=e.which&&e.which<=40?void 0:(16===e.which&&(l.shiftActive=!1),18===e.which&&(l.altActive=!1),16===e.which||18===e.which?(l.showSet(),void setTimeout(function(){l.$preview&&l.$preview.focus()},200)):void 0))}).bind("keydown"+e,function(e){if(g.init&&g.lockTypeIn||!g.showTyping)return!1;e.temp=!1,16===e.which&&(e.temp=!l.shiftActive,l.shiftActive=!0),18===e.which&&(e.temp=!l.altActive,l.altActive=!0),e.temp&&(l.showSet(),l.$preview.focus()),l.typing_event=!0,l.typing_xref[e.which]&&l.typing_findKey("",e)}).bind("keypress"+e,function(e){if(g.init&&g.lockTypeIn)return!1;l.typing_event&&!l.options.lockInput&&(l.typing_reset(),l.typing_event=!0,l.typing_findKey("",e))})},l.typing_reset=function(){l.typing_event=g.init=!1,g.text="",g.len=g.current=0,l.options.lockInput=g.savedLockInput},l.typeIn=function(e,t,n,i){if(!l.isVisible())return clearTimeout(l.typing_timer),void l.typing_reset();if(l.typing_event){if(void 0===e)return l.typing_event=!1,void(l.options.lockInput=g.savedLockInput)}else!0!==g.init&&(g.init=!0,l.options.lockInput=g.lockTypeIn,g.text=e||g.text||"",g.len=g.text.length,g.delay=t||g.delay,g.current=0,n&&(g.callback=n)),"{"===(e=g.text.substring(g.current,++g.current))&&"}"===g.text.substring(g.current+1,g.current+2)&&(e+=g.text.substring(g.current,g.current+=2)),l.typing_findKey(e,i)},l.typing_findKey=function(e,t){var n,i,p,s,y,o,r,a,c=f.css,u=f.builtLayouts[l.layout].mappedKeys;if(l.isOpen&&l.$keyboard.length)if(o=l.$keyboard.find("."+c.keySet),s=e in l.typing_keymap?l.typing_keymap[e]:e,n="."+c.keyButton+'[data-action="'+s+'"]',l.typing_event&&t&&(n="keypress"!==t.type&&l.typing_xref.hasOwnProperty(t.keyCode||t.which)?"."+c.keyPrefix+l.processName(l.typing_xref[t.keyCode||t.which]):(i=String.fromCharCode(t.charCode||t.which),u.hasOwnProperty(i)?"."+c.keyButton+'[data-value="'+u[i].replace(/"/g,'\\"')+'"]':"."+c.keyPrefix+l.processName(i))),(y=o.filter(":visible").find(n)).length?l.typing_simulateKey(y,e,t):(a=(y=l.typing_event?o.find(n):(p=e in l.typing_keymap?l.typing_keymap[e]:l.processName(e),o.find("."+c.keyPrefix+p))).closest("."+c.keySet)).attr("name")?(g.showTyping&&(r=a.attr("name"),l.shiftActive=/shift/.test(r),l.altActive=/alt/.test(r),l.metaActive=l.last.keyset[2]=!!/\bmeta/.test(r)&&r.match(/meta[\w-]+/)[0],l.showSet(l.metaActive)),l.typing_simulateKey(y,e,t)):l.typing_event||(e in l.typing_keymap&&l.typing_keymap[e]in f.keyaction?f.keyaction[l.typing_keymap[e]](l,y,t):l.insertText(e),l.checkCombos(),l.$el.trigger(f.events.kbChange,[l,l.el])),g.current<=g.len&&0!==g.len){if(!l.isVisible())return;l.typing_timer=setTimeout(function(){l.typeIn()},g.delay)}else{if(0!==g.len)return l.typing_reset(),void(d.isFunction(g.callback)&&(l.typing_timer=setTimeout(function(){d.isFunction(g.callback)&&g.callback(l)},g.delay)));l.typing_reset()}},l.typing_simulateKey=function(e,t,n){var i=e.length;l.isVisible()&&(g.showTyping&&i&&(e.filter(":visible").trigger("mouseenter"+l.namespace),g.showTyping&&i&&setTimeout(function(){e.trigger("mouseleave"+l.namespace)},Math.min(g.hoverDelay,g.delay))),l.typing_event||setTimeout(function(){t in l.typing_keymap&&l.typing_keymap[t]in f.keyaction?((n=n||d.Event("keypress")).target=e,f.keyaction[l.typing_keymap[t]](l,e,n)):l.insertText(t),l.checkCombos(),l.$el.trigger(f.events.kbChange,[l,l.el])},g.delay/3))},g.showTyping&&l.options.alwaysOpen&&l.isVisible()?l.typing_setup():l.$el.unbind(f.events.kbBeforeVisible+l.typing_namespace).bind(f.events.kbBeforeVisible+l.typing_namespace,function(){g.showTyping?l.typing_setup():l.typing_setup_reset()}))})}});
|