define(["dom"],function(dom){"use strict";functionpushScope(elem){scopes.push(elem)}functionpopScope(elem){scopes.length&&(scopes.length-=1)}functionautoFocus(view,defaultToFirst,findAutoFocusElement){varelement;returnfindAutoFocusElement!==!1&&(element=view.querySelector("*[autofocus]"))?(focus(element),element):defaultToFirst!==!1&&(element=getFocusableElements(view,1,"noautofocus")[0])?(focus(element),element):null}functionfocus(element){try{element.focus()}catch(err){console.log("Error in focusManager.autoFocus: "+err)}}functionisFocusable(elem){returnfocusableTagNames.indexOf(elem.tagName)!==-1||!(!elem.classList||!elem.classList.contains("focusable"))}functionfocusableParent(elem){for(;!isFocusable(elem);)if(elem=elem.parentNode,!elem)returnnull;returnelem}functionisCurrentlyFocusableInternal(elem){returnnull!==elem.offsetParent}functionisCurrentlyFocusable(elem){if(elem.disabled)return!1;if("-1"===elem.getAttribute("tabindex"))return!1;if("INPUT"===elem.tagName){vartype=elem.type;if("range"===type)return!1}returnisCurrentlyFocusableInternal(elem)}functiongetDefaultScope(){returnscopes[0]||document.body}functiongetFocusableElements(parent,limit,excludeClass){for(varelems=(parent||getDefaultScope()).querySelectorAll(focusableQuery),focusableElements=[],i=0,length=elems.length;i<length;i++){varelem=elems[i];if((!excludeClass||!elem.classList.contains(excludeClass))&&isCurrentlyFocusableInternal(elem)&&(focusableElements.push(elem),limit&&focusableElements.length>=limit))break}returnfocusableElements}functionisFocusContainer(elem,direction){if(focusableContainerTagNames.indexOf(elem.tagName)!==-1)return!0;varclassList=elem.classList;if(classList.contains("focuscontainer"))return!0;if(0===direction){if(classList.contains("focuscontainer-x"))return!0;if(classList.contains("focuscontainer-left"))return!0}elseif(1===direction){if(classList.contains("focuscontainer-x"))return!0;if(classList.contains("focuscontainer-right"))return!0}elseif(2===direction){if(classList.contains("focuscontainer-y"))return!0}elseif(3===direction){if(classList.contains("focuscontainer-y"))return!0;if(classList.contains("focuscontainer-down"))return!0}return!1}functiongetFocusContainer(elem,direction){for(;!isFocusContainer(elem,direction);)if(elem=elem.parentNode,!elem)returngetDefaultScope();returnelem}functiongetOffset(elem){varbox;if(box=elem.getBoundingClientRect?elem.getBoundingClientRect():{top:0,left:0,width:0,height:0},null===box.right){varnewBox={top:box.top,left:box.left,width:box.width,height:box.height};box=newBox,box.right=box.left+box.width,box.bottom=box.top+box.height}returnbox}functionnav(activeElement,direction){activeElement=activeElement||document.activeElement,activeElement&&(activeElement=focusableParent(activeElement));varcontainer=activeElement?getFocusContainer(activeElement,direction):getDefaultScope();if(!activeElement)returnvoidautoFocus(container,!0,!1);for(varnearestElement,focusableContainer=dom.parentWithClass(activeElement,"focusable"),rect=getOffset(activeElement),point1x=parseFloat(rect.left)||0,point1y=parseFloat(rect.top)||0,point2x=parseFloat(point1x+rect.width-1)||point1x,point2y=parseFloat(point1y+rect.height-1)||point1y,sourceMidX=(Math.min,Math.max,rect.left+rect.width/2),sourceMidY=rect.top+rect.height/2,focusable=container.querySelectorAll(focusableQuery),maxDistance=1/0,minDistance=maxDistance,i=0,length=focusable.length;i<length;i++){varcurr=focusable[i];if(curr!==activeElement&&curr!==focusableContainer){varelementRect=getOffset(curr);if(elementRect.width||elementRect.height){switch(direction){case0:if(elementRect.left>=rect.left)continue;if(elementRect.right===rect.right)continue;break;case1:if(elementRect.right<=rect.right)continue;if(elementRect.left===rect.left)continue;break;case2:if(elementRect.top>=rect.top)continue;if(elementRect.bottom>=rect.bottom)continue;break;case3:if(elementRect.bottom<=rect.bottom)continue;if(elementRect.top<=rect.top)continue}vardistX,distY,x=elementRect.left,y=elementRect.top,x2=x+elementRect.width-1,y2=y+elementRect.he