//>>built
define("dgrid/Keyboard","dojo/_base/declare dojo/aspect dojo/dom-class dojo/on dojo/_base/lang dojo/has ./util/misc dojo/_base/sniff".split(" "),function(t,p,u,q,r,D,E){function v(a){a.preventDefault()}var F={checkbox:1,radio:1,button:1},w=/\bdgrid-cell\b/,x=/\bdgrid-row\b/,c=t(null,{pageSkip:10,tabIndex:0,keyMap:null,headerKeyMap:null,postMixInProperties:function(){this.inherited(arguments);this.keyMap||(this.keyMap=r.mixin({},c.defaultKeyMap));this.headerKeyMap||(this.headerKeyMap=r.mixin({},c.defaultHeaderKeyMap))},
postCreate:function(){function a(a){var b=a.target;return b.type&&(!F[b.type]||32===a.keyCode)}function d(d){function e(){b._focusedHeaderNode&&(b._focusedHeaderNode.tabIndex=-1);if(b.showHeader){if(c)for(var a=b.headerNode.getElementsByTagName("th"),d=0,e;e=a[d];++d){if(k.test(e.className)){b._focusedHeaderNode=l=e;break}}else b._focusedHeaderNode=l=b.headerNode;l&&(l.tabIndex=b.tabIndex)}}function h(){var a=b._focusedNode||l;if(!k.test(a.className)||!d.contains(a)){for(var e=d.getElementsByTagName("*"),
f=0,c;c=e[f];++f)if(k.test(c.className)){a=b._focusedNode=c;break}l.tabIndex=-1;a.tabIndex=b.tabIndex}}var c=b.cellNavigation,k=c?w:x,m=d===b.headerNode,l=d;m?(e(),p.after(b,"renderHeader",e,!0)):(p.after(b,"renderArray",h,!0),p.after(b,"_onNotification",function(a,b){0===b.totalLength?d.tabIndex=0:1===b.totalLength&&"add"===b.type&&h()},!0));b._listeners.push(q(d,"mousedown",function(d){a(d)||b._focusOnNode(d.target,m,d)}));b._listeners.push(q(d,"keydown",function(d){if(!d.metaKey&&!d.altKey){var e=
b[m?"headerKeyMap":"keyMap"][d.keyCode];e&&!a(d)&&e.call(b,d)}}))}this.inherited(arguments);var b=this;this.tabableHeader&&(d(this.headerNode),q(this.headerNode,"dgrid-cellfocusin",function(){b.scrollTo({x:this.scrollLeft})}));d(this.contentNode);this._debouncedEnsureScroll=E.debounce(this._ensureScroll,this)},removeRow:function(a){if(!this._focusedNode)return this.inherited(arguments);var d=this,b=document.activeElement===this._focusedNode,e=this[this.cellNavigation?"cell":"row"](this._focusedNode),
f=e.row||e,c;a=a.element||a;a===f.element&&((c=this.down(f,!0))&&c.element!==a||(c=this.up(f,!0)),this._removedFocus={active:b,rowId:f.id,columnId:e.column&&e.column.id,siblingId:c&&c.element!==a?c.id:void 0},setTimeout(function(){d._removedFocus&&d._restoreFocus(f.id)},0),this._focusedNode=null);this.inherited(arguments)},insertRow:function(){var a=this.inherited(arguments);this._removedFocus&&!this._removedFocus.wait&&this._restoreFocus(a);return a},_restoreFocus:function(a){var d=this._removedFocus,
b;if((a=(a=a&&this.row(a))&&a.element&&a.id===d.rowId?a:"undefined"!==typeof d.siblingId&&this.row(d.siblingId))&&a.element){if(!a.element.parentNode.parentNode){d.wait=!0;return}"undefined"!==typeof d.columnId&&(b=this.cell(a,d.columnId))&&b.element&&(a=b);d.active&&0!==a.element.offsetHeight?this._focusOnNode(a,!1,null):(u.add(a.element,"dgrid-focus"),a.element.tabIndex=this.tabIndex,this._focusedNode=a.element)}delete this._removedFocus},addKeyHandler:function(a,d,b){return p.after(this[b?"headerKeyMap":
"keyMap"],a,d,!0)},_ensureRowScroll:function(a){var d=this.getScrollPosition().y;d>a.offsetTop?this.scrollTo({y:a.offsetTop}):d+this.contentNode.offsetHeight<a.offsetTop+a.offsetHeight&&this.scrollTo({y:a.offsetTop-this.contentNode.offsetHeight+a.offsetHeight})},_ensureColumnScroll:function(a){var d=this.getScrollPosition().x,b=a.offsetLeft;if(d>b)this.scrollTo({x:b});else{var e=this.bodyNode.clientWidth;a=a.offsetWidth;var c=b+a;d+e<c&&this.scrollTo({x:e>a?c-e:b})}},_ensureScroll:function(a,d){this.cellNavigation&&
(this.columnSets||1<this.subRows.length)&&!d&&this._ensureRowScroll(a.row.element);this.bodyNode.clientWidth<this.contentNode.offsetWidth&&this._ensureColumnScroll(a.element)},_focusOnNode:function(a,d,b){var e="_focused"+(d?"Header":"")+"Node",c=this[e],h=this.cellNavigation?"cell":"row",g=this[h](a),k,m,l,p,n;if(a=g&&g.element){if(this.cellNavigation)for(k=a.getElementsByTagName("input"),n=0,l=k.length;n<l;n++)if(m=k[n],(-1!==m.tabIndex||"_dgridLastValue"in m)&&!m.disabled){m.focus();p=!0;break}null!==
b&&(b=r.mixin({grid:this},b),b.type&&(b.parentType=b.type),b.bubbles||(b.bubbles=!0));c&&(u.remove(c,"dgrid-focus"),c.removeAttribute("tabindex"),b&&(b[h]=this[h](c),q.emit(c,"dgrid-cellfocusout",b)));c=this[e]=a;b&&(b[h]=g);e=this.cellNavigation?w:x;!p&&e.test(a.className)&&(a.tabIndex=this.tabIndex,a.focus());u.add(a,"dgrid-focus");b&&q.emit(c,"dgrid-cellfocusin",b);this._debouncedEnsureScroll(g,d)}},focusHeader:function(a){this._focusOnNode(a||this._focusedHeaderNode,!0)},focus:function(a){(a=
a||this._focusedNode)?this._focusOnNode(a,!1):(this._removedFocus&&(this._removedFocus.active=!0),this.contentNode.focus())}}),n=c.moveFocusVertical=function(a,d){var b=this.cellNavigation,c=this[b?"cell":"row"](a),c=b&&c.column.id,f=this.down(this._focusedNode,d,!0);b&&(f=this.cell(f,c));this._focusOnNode(f,!1,a);a.preventDefault()};t=c.moveFocusUp=function(a){n.call(this,a,-1)};var G=c.moveFocusDown=function(a){n.call(this,a,1)},H=c.moveFocusPageUp=function(a){n.call(this,a,-this.pageSkip)},I=c.moveFocusPageDown=
function(a){n.call(this,a,this.pageSkip)},y=c.moveFocusHorizontal=function(a,d){if(this.cellNavigation){var b=!this.row(a);this._focusOnNode(this.right(this["_focused"+(b?"Header":"")+"Node"],d),b,a);a.preventDefault()}},z=c.moveFocusLeft=function(a){y.call(this,a,-1)},A=c.moveFocusRight=function(a){y.call(this,a,1)},B=c.moveHeaderFocusEnd=function(a,d){var b;this.cellNavigation&&(b=this.headerNode.getElementsByTagName("th"),this._focusOnNode(b[d?0:b.length-1],!0,a));a.preventDefault()},J=c.moveHeaderFocusHome=
function(a){B.call(this,a,!0)},C=c.moveFocusEnd=function(a,d){var b=this.cellNavigation,c=this.contentNode,f=c.scrollTop+(d?0:c.scrollHeight),c=c[d?"firstChild":"lastChild"],h=-1<c.className.indexOf("dgrid-preload"),g=h?c[(d?"next":"previous")+"Sibling"]:c,k;a.preventDefault();this.scrollTo({y:f});if(h){for(;g&&0>g.className.indexOf("dgrid-row");)g=g[(d?"next":"previous")+"Sibling"];if(!g)return}!h||1>c.offsetHeight?(b&&(g=this.cell(g,this.cell(a).column.id)),this._focusOnNode(g,!1,a)):(D("dom-addeventlistener")||
(a=r.mixin({},a)),k=p.after(this,"renderArray",function(c){var e=c[d?0:c.length-1];b&&(e=this.cell(e,this.cell(a).column.id));this._focusOnNode(e,!1,a);k.remove();return c}))},K=c.moveFocusHome=function(a){C.call(this,a,!0)};c.defaultKeyMap={32:v,33:H,34:I,35:C,36:K,37:z,38:t,39:A,40:G};c.defaultHeaderKeyMap={32:v,35:B,36:J,37:z,39:A};return c});
//# sourceMappingURL=Keyboard.js.map