_KeyNavMixin.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //>>built
  2. define("dijit/_KeyNavMixin",["dojo/_base/array","dojo/_base/declare","dojo/dom-attr","dojo/keys","dojo/_base/lang","dojo/on","dijit/registry","dijit/_FocusMixin"],function(_1,_2,_3,_4,_5,on,_6,_7){
  3. return _2("dijit._KeyNavMixin",_7,{tabIndex:"0",childSelector:null,postCreate:function(){
  4. this.inherited(arguments);
  5. _3.set(this.domNode,"tabIndex",this.tabIndex);
  6. if(!this._keyNavCodes){
  7. var _8=this._keyNavCodes={};
  8. _8[_4.HOME]=_5.hitch(this,"focusFirstChild");
  9. _8[_4.END]=_5.hitch(this,"focusLastChild");
  10. _8[this.isLeftToRight()?_4.LEFT_ARROW:_4.RIGHT_ARROW]=_5.hitch(this,"_onLeftArrow");
  11. _8[this.isLeftToRight()?_4.RIGHT_ARROW:_4.LEFT_ARROW]=_5.hitch(this,"_onRightArrow");
  12. _8[_4.UP_ARROW]=_5.hitch(this,"_onUpArrow");
  13. _8[_4.DOWN_ARROW]=_5.hitch(this,"_onDownArrow");
  14. }
  15. var _9=this,_a=typeof this.childSelector=="string"?this.childSelector:_5.hitch(this,"childSelector");
  16. this.own(on(this.domNode,"keypress",_5.hitch(this,"_onContainerKeypress")),on(this.domNode,"keydown",_5.hitch(this,"_onContainerKeydown")),on(this.domNode,"focus",_5.hitch(this,"_onContainerFocus")),on(this.containerNode,on.selector(_a,"focusin"),function(_b){
  17. _9._onChildFocus(_6.getEnclosingWidget(this),_b);
  18. }));
  19. },_onLeftArrow:function(){
  20. },_onRightArrow:function(){
  21. },_onUpArrow:function(){
  22. },_onDownArrow:function(){
  23. },focus:function(){
  24. this.focusFirstChild();
  25. },_getFirstFocusableChild:function(){
  26. return this._getNextFocusableChild(null,1);
  27. },_getLastFocusableChild:function(){
  28. return this._getNextFocusableChild(null,-1);
  29. },focusFirstChild:function(){
  30. this.focusChild(this._getFirstFocusableChild());
  31. },focusLastChild:function(){
  32. this.focusChild(this._getLastFocusableChild());
  33. },focusChild:function(_c,_d){
  34. if(!_c){
  35. return;
  36. }
  37. if(this.focusedChild&&_c!==this.focusedChild){
  38. this._onChildBlur(this.focusedChild);
  39. }
  40. _c.set("tabIndex",this.tabIndex);
  41. _c.focus(_d?"end":"start");
  42. },_onContainerFocus:function(_e){
  43. if(_e.target!==this.domNode||this.focusedChild){
  44. return;
  45. }
  46. this.focus();
  47. },_onFocus:function(){
  48. _3.set(this.domNode,"tabIndex","-1");
  49. this.inherited(arguments);
  50. },_onBlur:function(_f){
  51. _3.set(this.domNode,"tabIndex",this.tabIndex);
  52. if(this.focusedChild){
  53. this.focusedChild.set("tabIndex","-1");
  54. this.lastFocusedChild=this.focusedChild;
  55. this._set("focusedChild",null);
  56. }
  57. this.inherited(arguments);
  58. },_onChildFocus:function(_10){
  59. if(_10&&_10!=this.focusedChild){
  60. if(this.focusedChild&&!this.focusedChild._destroyed){
  61. this.focusedChild.set("tabIndex","-1");
  62. }
  63. _10.set("tabIndex",this.tabIndex);
  64. this.lastFocused=_10;
  65. this._set("focusedChild",_10);
  66. }
  67. },_searchString:"",multiCharSearchDuration:1000,onKeyboardSearch:function(_11,evt,_12,_13){
  68. if(_11){
  69. this.focusChild(_11);
  70. }
  71. },_keyboardSearchCompare:function(_14,_15){
  72. var _16=_14.domNode,_17=_14.label||(_16.focusNode?_16.focusNode.label:"")||_16.innerText||_16.textContent||"",_18=_17.replace(/^\s+/,"").substr(0,_15.length).toLowerCase();
  73. return (!!_15.length&&_18==_15)?-1:0;
  74. },_onContainerKeydown:function(evt){
  75. var _19=this._keyNavCodes[evt.keyCode];
  76. if(_19){
  77. _19(evt,this.focusedChild);
  78. evt.stopPropagation();
  79. evt.preventDefault();
  80. this._searchString="";
  81. }else{
  82. if(evt.keyCode==_4.SPACE&&this._searchTimer&&!(evt.ctrlKey||evt.altKey||evt.metaKey)){
  83. evt.stopImmediatePropagation();
  84. evt.preventDefault();
  85. this._keyboardSearch(evt," ");
  86. }
  87. }
  88. },_onContainerKeypress:function(evt){
  89. if(evt.charCode<_4.SPACE||evt.ctrlKey||evt.altKey||evt.metaKey||(evt.charCode==_4.SPACE&&this._searchTimer)){
  90. return;
  91. }
  92. evt.preventDefault();
  93. evt.stopPropagation();
  94. this._keyboardSearch(evt,String.fromCharCode(evt.charCode).toLowerCase());
  95. },_keyboardSearch:function(evt,_1a){
  96. var _1b=null,_1c,_1d=0,_1e=_5.hitch(this,function(){
  97. if(this._searchTimer){
  98. this._searchTimer.remove();
  99. }
  100. this._searchString+=_1a;
  101. var _1f=/^(.)\1*$/.test(this._searchString);
  102. var _20=_1f?1:this._searchString.length;
  103. _1c=this._searchString.substr(0,_20);
  104. this._searchTimer=this.defer(function(){
  105. this._searchTimer=null;
  106. this._searchString="";
  107. },this.multiCharSearchDuration);
  108. var _21=this.focusedChild||null;
  109. if(_20==1||!_21){
  110. _21=this._getNextFocusableChild(_21,1);
  111. if(!_21){
  112. return;
  113. }
  114. }
  115. var _22=_21;
  116. do{
  117. var rc=this._keyboardSearchCompare(_21,_1c);
  118. if(!!rc&&_1d++==0){
  119. _1b=_21;
  120. }
  121. if(rc==-1){
  122. _1d=-1;
  123. break;
  124. }
  125. _21=this._getNextFocusableChild(_21,1);
  126. }while(_21!=_22);
  127. });
  128. _1e();
  129. this.onKeyboardSearch(_1b,evt,_1c,_1d);
  130. },_onChildBlur:function(){
  131. },_getNextFocusableChild:function(_23,dir){
  132. var _24=_23;
  133. do{
  134. if(!_23){
  135. _23=this[dir>0?"_getFirst":"_getLast"]();
  136. if(!_23){
  137. break;
  138. }
  139. }else{
  140. _23=this._getNext(_23,dir);
  141. }
  142. if(_23!=null&&_23!=_24&&_23.isFocusable()){
  143. return _23;
  144. }
  145. }while(_23!=_24);
  146. return null;
  147. },_getFirst:function(){
  148. return null;
  149. },_getLast:function(){
  150. return null;
  151. },_getNext:function(_25,dir){
  152. if(_25){
  153. _25=_25.domNode;
  154. while(_25){
  155. _25=_25[dir<0?"previousSibling":"nextSibling"];
  156. if(_25&&"getAttribute" in _25){
  157. var w=_6.byNode(_25);
  158. if(w){
  159. return w;
  160. }
  161. }
  162. }
  163. }
  164. return null;
  165. }});
  166. });