|
!function(e,t,n){"use strict";function r(e,r,o,i,a,l,s,u,d){var c,m,f=a.prefixer(),p=this;this.nestLevel=parseInt(r.mdNestLevel,10)||0,this.init=function(n,r){r=r||{},c=n,m=o[0].querySelector(f.buildSelector(["ng-click","ng-mouseenter"])),m.setAttribute("aria-expanded","false"),this.isInMenuBar=r.isInMenuBar,this.nestedMenus=a.nodesToArray(c[0].querySelectorAll(".md-nested-menu")),c.on("$mdInterimElementRemove",function(){p.isOpen=!1,a.nextTick(function(){p.onIsOpenChanged(p.isOpen)})}),a.nextTick(function(){p.onIsOpenChanged(p.isOpen)});var l="menu_container_"+a.nextUid();c.attr("id",l),t.element(m).attr({"aria-owns":l,"aria-haspopup":"true"}),i.$on("$destroy",t.bind(this,function(){this.disableHoverListener(),e.destroy()})),c.on("$destroy",function(){e.destroy()})};var h,g,v=[];this.enableHoverListener=function(){v.push(s.$on("$mdMenuOpen",function(e,t){c[0].contains(t[0])&&(p.currentlyOpenMenu=t.controller("mdMenu"),p.isAlreadyOpening=!1,p.currentlyOpenMenu.registerContainerProxy(p.triggerContainerProxy.bind(p)))})),v.push(s.$on("$mdMenuClose",function(e,t){c[0].contains(t[0])&&(p.currentlyOpenMenu=n)})),g=t.element(a.nodesToArray(c[0].children[0].children)),g.on("mouseenter",p.handleMenuItemHover),g.on("mouseleave",p.handleMenuItemMouseLeave)},this.disableHoverListener=function(){for(;v.length;)v.shift()();g&&g.off("mouseenter",p.handleMenuItemHover),g&&g.off("mouseleave",p.handleMenuItemMouseLeave)},this.handleMenuItemHover=function(e){if(!p.isAlreadyOpening){var n=e.target.querySelector("md-menu")||a.getClosest(e.target,"MD-MENU");h=l(function(){if(n&&(n=t.element(n).controller("mdMenu")),p.currentlyOpenMenu&&p.currentlyOpenMenu!=n){var e=p.nestLevel+1;p.currentlyOpenMenu.close(!0,{closeTo:e}),p.isAlreadyOpening=!!n,n&&n.open()}else n&&!n.isOpen&&n.open&&(p.isAlreadyOpening=!!n,n&&n.open())},n?100:250);var r=e.currentTarget.querySelector(".md-button:not([disabled])");r&&r.focus()}},this.handleMenuItemMouseLeave=function(){h&&(l.cancel(h),h=n)},this.open=function(t){t&&t.stopPropagation(),t&&t.preventDefault(),p.isOpen||(p.enableHoverListener(),p.isOpen=!0,a.nextTick(function(){p.onIsOpenChanged(p.isOpen)}),m=m||(t?t.target:o[0]),m.setAttribute("aria-expanded","true"),i.$emit("$mdMenuOpen",o),e.show({scope:i,mdMenuCtrl:p,nestLevel:p.nestLevel,element:c,target:m,preserveElement:!0,parent:"body"})["finally"](function(){m.setAttribute("aria-expanded","false"),p.disableHoverListener()}))},this.onIsOpenChanged=function(e){e?(c.attr("aria-hidden","false"),o[0].classList.add("md-open"),t.forEach(p.nestedMenus,function(e){e.classList.remove("md-open")})):(c.attr("aria-hidden","true"),o[0].classList.remove("md-open")),i.$mdMenuIsOpen=p.isOpen},this.focusMenuContainer=function(){var e=c[0].querySelector(f.buildSelector(["md-menu-focus-target","md-autofocus"]));e||(e=c[0].querySelector(".md-button:not([disabled])")),e.focus()},this.registerContainerProxy=function(e){this.containerProxy=e},this.triggerContainerProxy=function(e){this.containerProxy&&this.containerProxy(e)},this.destroy=function(){return p.isOpen?e.destroy():u.when(!1)},this.close=function(n,r){if(p.isOpen){p.isOpen=!1,a.nextTick(function(){p.onIsOpenChanged(p.isOpen)});var l=t.extend({},r,{skipFocus:n});if(i.$emit("$mdMenuClose",o,l),e.hide(null,r),!n){var s=p.restoreFocusTo||o.find("button")[0];s instanceof t.element&&(s=s[0]),s&&s.focus()}}},this.positionMode=function(){var e=(r.mdPositionMode||"target").split(" ");return 1==e.length&&e.push(e[0]),{left:e[0],top:e[1]}},this.offsets=function(){var e=(r.mdOffset||"0 0").split(" ").map(parseFloat);if(2==e.length)return{left:e[0],top:e[1]};if(1==e.length)return{top:e[0],left:e[0]};throw Error("Invalid offsets specified. Please follow format <x, y> or <n>")},i.$mdMenu={open:this.open,close:this.close},i.$mdOpenMenu=t.bind(this,function(){return d.warn("mdMenu: The $mdOpenMenu method is deprecated. Please use `$mdMenu.open`."),this.open.apply(this,arguments)})}function o(e){function n(n){n.addClass("md-menu");var i=n.children()[0],a=n.children()[1],l=e.prefixer();l.hasAttribute(i,"ng-click")||(i=i.querySelector(l.buildSelector(["ng-click","ng-mouseenter"]))||i);var s="MD-BUTTON"===i.nodeName||"BUTTON"===i.nodeName;if(i&&s&&!i.hasAttribute("type")&&i.setAttribute("type","button"),!i)throw Error(o+"Expected the menu to have a trigger element.");if(!a||"MD-MENU-CONTENT"!==a.nodeName)throw Error(o+"Expected the menu to contain a `md-menu-content` element.");i&&i.setAttribute("aria-haspopup","true");var u=n[0].querySelectorAll("md-menu"),d=parseInt(n[0].getAttribute("md-nest-level"),10)||0;return u&&t.forEach(e.nodesToArray(u),function(e){e.hasAttribute("md-position-mode")||e.setAttribute("md-position-mode","cascade"),e.classList.add("_md-nested-menu"),e.setAttribute("md-nest-level",d+1)}),r}function r(e,n,r,o){var i=o[0],a=!!o[1],l=t.element('<div class="_md md-open-menu-container md-whiteframe-z2"></div>'),s=n.children()[1];n.addClass("_md"),s.hasAttribute("role")||s.setAttribute("role","menu"),l.append(s),n.on("$destroy",function(){l.remove()}),n.append(l),l[0].style.display="none",i.init(l,{isInMenuBar:a})}var o="Invalid HTML for md-menu: ";return{restrict:"E",require:["mdMenu","?^mdMenuBar"],controller:"mdMenuCtrl",scope:!0,compile:n}}function i(e){function r(e,r,a,l,s,u,d,c,m,f){function p(n,r,o){return o.nestLevel?t.noop:(o.disableParentScroll&&!e.getClosest(o.target,"MD-DIALOG")?o.restoreScroll=e.disableScrollAround(o.element,o.parent):o.disableParentScroll=!1,o.hasBackdrop&&(o.backdrop=e.createBackdrop(n,"md-menu-backdrop md-click-catcher"),m.enter(o.backdrop,l[0].body)),function(){o.backdrop&&o.backdrop.remove(),o.disableParentScroll&&o.restoreScroll()})}function h(e,t,n){function r(){return c(t,{addClass:"md-leave"}).start()}function o(){t.removeClass("md-active"),M(t,n),n.alreadyOpen=!1}return n.cleanupInteraction(),n.cleanupBackdrop(),n.cleanupResizing(),n.hideBackdrop(),t.removeClass("md-clickable"),n.$destroy===!0?o():r().then(o)}function g(n,o,i){function l(){return i.parent.append(o),o[0].style.display="",u(function(e){var t=y(o,i);o.removeClass("md-leave"),c(o,{addClass:"md-active",from:E.toCss(t),to:E.toCss({transform:""})}).start().then(e)})}function m(){if(!i.target)throw Error("$mdMenu.show() expected a target to animate from in options.target");t.extend(i,{alreadyOpen:!1,isRemoved:!1,target:t.element(i.target),parent:t.element(i.parent),menuContentEl:t.element(o[0].querySelector("md-menu-content"))})}function h(){var e=function(e,t){return d.throttle(function(){if(!i.isRemoved){var n=y(e,t);e.css(E.toCss(n))}})}(o,i);return s.addEventListener("resize",e),s.addEventListener("orientationchange",e),function(){s.removeEventListener("resize",e),s.removeEventListener("orientationchange",e)}}function g(){return i.backdrop?(i.backdrop.on("click",b),function(){i.backdrop.off("click",b)}):t.noop}function b(e){e.preventDefault(),e.stopPropagation(),n.$apply(function(){i.mdMenuCtrl.close(!0,{closeAll:!0})})}function M(){function r(t){var n;switch(t.keyCode){case a.KEY_CODE.ESCAPE:i.mdMenuCtrl.close(!1,{closeAll:!0}),n=!0;break;case a.KEY_CODE.UP_ARROW:v(t,i.menuContentEl,i,-1)||i.nestLevel||i.mdMenuCtrl.triggerContainerProxy(t),n=!0;break;case a.KEY_CODE.DOWN_ARROW:v(t,i.menuContentEl,i,1)||i.nestLevel||i.mdMenuCtrl.triggerContainerProxy(t),n=!0;break;case a.KEY_CODE.LEFT_ARROW:i.nestLevel?i.mdMenuCtrl.close():i.mdMenuCtrl.triggerContainerProxy(t),n=!0;break;case a.KEY_CODE.RIGHT_ARROW:var r=e.getClosest(t.target,"MD-MENU");r&&r!=i.parent[0]?t.target.click():i.mdMenuCtrl.triggerContainerProxy(t),n=!0}n&&(t.preventDefault(),t.stopImmediatePropagation())}function o(t){function r(){n.$apply(function(){i.mdMenuCtrl.close(!0,{closeAll:!0})})}function o(e,t){if(!e)return!1;for(var n,r=0;n=t[r];++r)if(C.hasAttribute(e,n))return!0;return!1}var a=t.target;do{if(a==i.menuContentEl[0])return;if((o(a,["ng-click","ng-href","ui-sref"])||"BUTTON"==a.nodeName||"MD-BUTTON"==a.nodeName)&&!o(a,["md-prevent-menu-close"])){var l=e.getClosest(a,"MD-MENU");a.hasAttribute("disabled")||l&&l!=i.parent[0]||r();break}}while(a=a.parentNode)}if(!i.menuContentEl[0])return t.noop;i.menuContentEl.on("keydown",r),i.menuContentEl[0].addEventListener("click",o,!0);var l=i.menuContentEl[0].querySelector(C.buildSelector(["md-menu-focus-target","md-autofocus"]));if(!l)for(var s=i.menuContentEl[0].children.length,u=0;u<s;u++){var d=i.menuContentEl[0].children[u];if(l=d.querySelector(".md-button:not([disabled])"))break;if(d.firstElementChild&&!d.firstElementChild.disabled){l=d.firstElementChild;break}}return l&&l.focus(),function(){i.menuContentEl.off("keydown",r),i.menuContentEl[0].removeEventListener("click",o,!0)}}return m(i),i.menuContentEl[0]?r.inherit(i.menuContentEl,i.target):f.warn("$mdMenu: Menu elements should always contain a `md-menu-content` element,otherwise interactivity features will not work properly.",o),i.cleanupResizing=h(),i.hideBackdrop=p(n,o,i),l().then(function(e){return i.alreadyOpen=!0,i.cleanupInteraction=M(),i.cleanupBackdrop=g(),o.addClass("md-clickable"),e})}function v(t,n,r,o){for(var i,a=e.getClosest(t.target,"MD-MENU-ITEM"),l=e.nodesToArray(n[0].children),s=l.indexOf(a),u=s+o;u>=0&&u<l.length;u+=o){var d=l[u].querySelector(".md-button");if(i=b(d))break}return i}function b(e){if(e&&e.getAttribute("tabindex")!=-1)return e.focus(),l[0].activeElement==e}function M(e,t){t.preserveElement?o(e).style.display="none":o(e).parentNode===o(t.parent)&&o(t.parent).removeChild(o(e))}function y(t,r){function o(e){e.top=Math.max(Math.min(e.top,b.bottom-d.offsetHeight),b.top),e.left=Math.max(Math.min(e.left,b.right-d.offsetWidth),b.left)}function a(){for(var e=0;e<c.children.length;++e)if("none"!=s.getComputedStyle(c.children[e]).display)return c.children[e]}var u,d=t[0],c=t[0].firstElementChild,m=c.getBoundingClientRect(),f=l[0].body,p=f.getBoundingClientRect(),h=s.getComputedStyle(c),g=r.target[0].querySelector(C.buildSelector("md-menu-origin"))||r.target[0],v=g.getBoundingClientRect(),b={left:p.left+i,top:Math.max(p.top,0)+i,bottom:Math.max(p.bottom,Math.max(p.top,0)+p.height)-i,right:p.right-i},M={top:0,left:0,right:0,bottom:0},y={top:0,left:0,right:0,bottom:0},E=r.mdMenuCtrl.positionMode();"target"!=E.top&&"target"!=E.left&&"target-right"!=E.left||(u=a(),u&&(u=u.firstElementChild||u,u=u.querySelector(C.buildSelector("md-menu-align-target"))||u,M=u.getBoundingClientRect(),y={top:parseFloat(d.style.top||0),left:parseFloat(d.style.left||0)}));var k={},O="top ";switch(E.top){case"target":k.top=y.top+v.top-M.top;break;case"cascade":k.top=v.top-parseFloat(h.paddingTop)-g.style.top;break;case"bottom":k.top=v.top+v.height;break;default:throw new Error('Invalid target mode "'+E.top+'" specified for md-menu on Y axis.')}var $="rtl"==e.bidi();switch(E.left){case"target":k.left=y.left+v.left-M.left,O+=$?"right":"left";break;case"target-left":k.left=v.left,O+="left";break;case"target-right":k.left=v.right-m.width+(m.right-M.right),O+="right";break;case"cascade":var w=$?v.left-m.width<b.left:v.right+m.width<b.right;k.left=w?v.right-g.style.left:v.left-g.style.left-m.width,O+=w?"left":"right";break;case"right":$?(k.left=v.right-v.width,O+="left"):(k.left=v.right-m.width,O+="right");break;case"left":$?(k.left=v.right-m.width,O+="right"):(k.left=v.left,O+="left");break;default:throw new Error('Invalid target mode "'+E.left+'" specified for md-menu on X axis.')}var x=r.mdMenuCtrl.offsets();k.top+=x.top,k.left+=x.left,o(k);var A=Math.round(100*Math.min(v.width/d.offsetWidth,1))/100,S=Math.round(100*Math.min(v.height/d.offsetHeight,1))/100;return{top:Math.round(k.top),left:Math.round(k.left),transform:r.alreadyOpen?n:e.supplant("scale({0},{1})",[A,S]),transformOrigin:O}}var C=e.prefixer(),E=e.dom.animator;return{parent:"body",onShow:g,onRemove:h,hasBackdrop:!0,disableParentScroll:!0,skipCompile:!0,preserveScope:!0,multiple:!0,themable:!0}}function o(e){return e instanceof t.element&&(e=e[0]),e}r.$inject=["$mdUtil","$mdTheming","$mdConstant","$document","$window","$q","$$rAF","$animateCss","$animate","$log"];var i=8;return e("$mdMenu").setDefaults({methods:["target"],options:r})}t.module("material.components.menu",["material.core","material.components.backdrop"]),r.$inject=["$mdMenu","$attrs","$element","$scope","$mdUtil","$timeout","$rootScope","$q","$log"],t.module("material.components.menu").controller("mdMenuCtrl",r),o.$inject=["$mdUtil"],t.module("material.components.menu").directive("mdMenu",o),i.$inject=["$$interimElementProvider"],t.module("material.components.menu").provider("$mdMenu",i)}(window,window.angular);
|