jquery.keyboard.extension-navigation.min.js 3.9 KB

12
  1. /*! jQuery UI Virtual Keyboard Navigation v1.6.2 */
  2. !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(u){"use strict";u.keyboard=u.keyboard||{},u.keyboard.navigationKeys={toggle:112,enter:13,pageup:33,pagedown:34,end:35,home:36,left:37,up:38,right:39,down:40,caretrt:45,caretlt:46,caretright:function(e){u.keyboard.keyaction.right(e)},caretleft:function(e){u.keyboard.keyaction.left(e)}},u.fn.addNavigation=function(t){return this.each(function(){var c,e,v=u(this).data("keyboard"),y=v.options,n=u.keyboard.events,l=u.keyboard.css;v&&(v.navigation_options=c=u.extend({},{position:[0,0],toggleMode:!1,focusClass:"hasFocus",toggleKey:null,rowLooping:!1},t),v.navigation_keys=e=u.extend({},u.keyboard.navigationKeys),v.navigation_namespace=v.namespace+"Nav",v.extensionNamespace.push(v.navigation_namespace),v.saveNav=[v.options.tabNavigation,v.options.enterNavigation],v.allNavKeys=u.map(e,function(e){return e}),v.navigation_init=function(){v.$keyboard.toggleClass(c.focusClass,c.toggleMode).find("."+l.keySet+":visible").find("."+l.keyButton+'[data-pos="'+c.position[0]+","+c.position[1]+'"]').addClass(y.css.buttonHover),v.$preview.unbind(v.navigation_namespace).bind("keydown"+v.navigation_namespace,function(e){return v.checkKeys(e.which)})},v.checkKeys=function(e,t){if(void 0!==e){var a=v.navigation_keys;return(e===(c.toggleKey||a.toggle)||t)&&(c.toggleMode=!t&&!c.toggleMode,v.options.tabNavigation=!c.toggleMode&&v.saveNav[0],v.options.enterNavigation=!c.toggleMode&&v.saveNav[1]),v.$keyboard.toggleClass(c.focusClass,c.toggleMode),c.toggleMode&&e===a.enter?(v.$keyboard.find("."+l.keySet+":visible").find("."+l.keyButton+'[data-pos="'+c.position[0]+","+c.position[1]+'"]').trigger(n.kbRepeater),!1):c.toggleMode&&0<=u.inArray(e,v.allNavKeys)?(v.navigateKeys(e),!1):void 0}},v.getMaxIndex=function(e,t){return e.find("."+l.keyButton+'[data-pos^="'+t+',"]').length-1},v.leftNavigateKey=function(e,t){var a=v.navigation_options.rowLooping,n=e-1;return 0<=n?n:a?t:0},v.rightNavigateKey=function(e,t){var a=v.navigation_options.rowLooping,n=e+1;return n<=t?n:a?0:t},v.navigateKeys=function(e,t,a){if(v.isVisible()){a="number"==typeof a?a:c.position[1],t="number"==typeof t?t:c.position[0];var n,o=v.$keyboard.find("."+l.keySet+":visible"),i=o.find("."+l.endRow).length-1,s=v.getMaxIndex(o,t),r=v.last,g=v.$preview.val().length,d=v.navigation_keys;switch(e){case d.pageup:t=0;break;case d.pagedown:t=i;break;case d.end:a=s;break;case d.home:a=0;break;case d.left:a=v.leftNavigateKey(a,s);break;case d.up:t+=0<t?-1:0,n=v.getMaxIndex(o,t),a=a===s?n:a;break;case d.right:a=v.rightNavigateKey(a,s);break;case d.down:t+=i<t+1?0:1,n=v.getMaxIndex(o,t),a=a===s?n:a;break;case d.caretrt:r.start++;break;case d.caretlt:r.start--}e!==d.caretrt&&e!==d.caretlt||(r.start=r.start<0?0:r.start>g?g:r.start,v.last.start=v.last.end=r.end=r.start,u.keyboard.caret(v.$preview,v.last)),(s=v.getMaxIndex(o,t))<a&&(a=s),o.find("."+y.css.buttonHover).removeClass(y.css.buttonHover),o.find("."+l.keyButton+'[data-pos="'+t+","+a+'"]').addClass(y.css.buttonHover),c.position=[t,a]}},v.options.alwaysOpen&&v.isVisible()&&(v.$keyboard.find("."+y.css.buttonHover).removeClass(y.css.buttonHover),v.navigation_init()),v.$el.unbind(v.navigation_namespace).bind(n.kbVisible,function(){v.$keyboard.find("."+y.css.buttonHover).removeClass(y.css.buttonHover),v.navigation_init()}).bind(n.kbInactive+" "+n.kbHidden,function(e){v.checkKeys(e.which,!0)}).bind(n.kbKeysetChange,function(){v.navigateKeys(null)}).bind("navigate navigateTo",function(e,t,a){var n;(t=isNaN(t)?t.toLowerCase():t)in v.navigation_keys?(n=v.navigation_keys[t],isNaN(n)&&n in u.keyboard.keyaction?u.keyboard.keyaction[n](v,this,e):u.isFunction(n)?n(v):v.checkKeys(n)):"string"==typeof t&&t in u.keyboard.keyaction?u.keyboard.keyaction[t](v,this,e):v.navigateKeys(null,t,a)}))})}});