|
|
/*! * Angular Material Design * https://github.com/angular/material
* @license MIT * v1.1.0-master-2b98560 */ function MenuBarController(e,n,t,r,o,i,a,l){this.$element=t,this.$attrs=r,this.$mdConstant=o,this.$mdUtil=a,this.$document=i,this.$scope=e,this.$rootScope=n,this.$timeout=l;var u=this;angular.forEach(BOUND_MENU_METHODS,function(e){u[e]=angular.bind(u,u[e])})}function MenuBarDirective(e,n){return{restrict:"E",require:"mdMenuBar",controller:"MenuBarController",compile:function(t,r){return r.ariaRole||t[0].setAttribute("role","menubar"),angular.forEach(t[0].children,function(n){if("MD-MENU"==n.nodeName){n.hasAttribute("md-position-mode")||(n.setAttribute("md-position-mode","left bottom"),n.querySelector("button, a, md-button").setAttribute("role","menuitem"));var t=e.nodesToArray(n.querySelectorAll("md-menu-content"));angular.forEach(t,function(e){e.classList.add("md-menu-bar-menu"),e.classList.add("md-dense"),e.hasAttribute("width")||e.setAttribute("width",5)})}}),t.find("md-menu-item").addClass("md-in-menu-bar"),function(e,t,r,o){t.addClass("_md"),n(e,t),o.init()}}}}function MenuDividerDirective(){return{restrict:"E",compile:function(e,n){n.role||e[0].setAttribute("role","separator")}}}function MenuItemController(e,n,t){this.$element=n,this.$attrs=t,this.$scope=e}function MenuItemDirective(e,n){return{controller:"MenuItemController",require:["mdMenuItem","?ngModel"],priority:210,compile:function(t,r){function o(e,n,r){r=r||t,r instanceof angular.element&&(r=r[0]),r.hasAttribute(e)||r.setAttribute(e,n)}function i(n){var r=e.prefixer(n);angular.forEach(r,function(e){if(t[0].hasAttribute(e)){var n=t[0].getAttribute(e);s[0].setAttribute(e,n),t[0].removeAttribute(e)}})}var a=r.type,l="md-in-menu-bar";if("checkbox"!=a&&"radio"!=a||!t.hasClass(l))o("role","menuitem",t[0].querySelector("md-button, button, a"));else{var u=t[0].textContent,s=angular.element('<md-button type="button"></md-button>'),c='<md-icon md-svg-src="'+n.mdChecked+'"></md-icon>';s.html(u),s.attr("tabindex","0"),t.html(""),t.append(angular.element(c)),t.append(s),t.addClass("md-indent").removeClass(l),o("role","checkbox"==a?"menuitemcheckbox":"menuitemradio",s),i("ng-disabled")}return function(e,n,t,r){var o=r[0],i=r[1];o.init(i)}}}}goog.provide("ngmaterial.components.menuBar"),goog.require("ngmaterial.components.icon"),goog.require("ngmaterial.components.menu"),goog.require("ngmaterial.core"),angular.module("material.components.menuBar",["material.core","material.components.icon","material.components.menu"]),MenuBarController.$inject=["$scope","$rootScope","$element","$attrs","$mdConstant","$document","$mdUtil","$timeout"],angular.module("material.components.menuBar").controller("MenuBarController",MenuBarController);var BOUND_MENU_METHODS=["handleKeyDown","handleMenuHover","scheduleOpenHoveredMenu","cancelScheduledOpen"];MenuBarController.prototype.init=function(){var e=this.$element,n=this.$mdUtil,t=this.$scope,r=this,o=[];e.on("keydown",this.handleKeyDown),this.parentToolbar=n.getClosest(e,"MD-TOOLBAR"),o.push(this.$rootScope.$on("$mdMenuOpen",function(n,t){r.getMenus().indexOf(t[0])!=-1&&(e[0].classList.add("md-open"),t[0].classList.add("md-open"),r.currentlyOpenMenu=t.controller("mdMenu"),r.currentlyOpenMenu.registerContainerProxy(r.handleKeyDown),r.enableOpenOnHover())})),o.push(this.$rootScope.$on("$mdMenuClose",function(t,o,i){var a=r.getMenus();if(a.indexOf(o[0])!=-1&&(e[0].classList.remove("md-open"),o[0].classList.remove("md-open")),e[0].contains(o[0])){for(var l=o[0];l&&a.indexOf(l)==-1;)l=n.getClosest(l,"MD-MENU",!0);l&&(i.skipFocus||l.querySelector("button:not([disabled])").focus(),r.currentlyOpenMenu=void 0,r.disableOpenOnHover(),r.setKeyboardMode(!0))}})),t.$on("$destroy",function(){for(r.disableOpenOnHover();o.length;)o.shift()()}),this.setKeyboardMode(!0)},MenuBarController.prototype.setKeyboardMode=function(e){e?this.$element[0].classList.add("md-keyboard-mode"):this.$element[0].classList.remove("md-keyboard-mode")},MenuBarController.prototype.enableOpenOnHover=function(){if(!this.openOnHoverEnabled){var e=this;e.openOnHoverEnabled=!0,e.parentToolbar&&(e.parentToolbar.classList.add("md-has-open-menu"),e.$mdUtil.nextTick(function(){angular.element(e.parentToolbar).on("click",e.handleParentClick)},!1)),angular.element(e.getMenus()).on("mouseenter",e.handleMenuHover)}},MenuBarController.prototype.handleMenuHover=function(e){this.setKeyboardMode(!1),this.openOnHoverEnabled&&this.scheduleOpenHoveredMenu(e)},MenuBarController.prototype.disableOpenOnHover=function(){this.openOnHoverEnabled&&(this.openOnHoverEnabled=!1,this.parentToolbar&&(this.parentToolbar.classList.remove("md-has-open-menu"),angular.element(this.parentToolbar).off("click",this.handleParentClick)),angular.element(this.getMenus()).off("mouseenter",this.handleMenuHover))},MenuBarController.prototype.scheduleOpenHoveredMenu=function(e){var n=angular.element(e.currentTarget),t=n.controller("mdMenu");this.setKeyboardMode(!1),this.scheduleOpenMenu(t)},MenuBarController.prototype.scheduleOpenMenu=function(e){var n=this,t=this.$timeout;e!=n.currentlyOpenMenu&&(t.cancel(n.pendingMenuOpen),n.pendingMenuOpen=t(function(){n.pendingMenuOpen=void 0,n.currentlyOpenMenu&&n.currentlyOpenMenu.close(!0,{closeAll:!0}),e.open()},200,!1))},MenuBarController.prototype.handleKeyDown=function(e){var n=this.$mdConstant.KEY_CODE,t=this.currentlyOpenMenu,r=t&&t.isOpen;this.setKeyboardMode(!0);var o,i,a;switch(e.keyCode){case n.DOWN_ARROW:t?t.focusMenuContainer():this.openFocusedMenu(),o=!0;break;case n.UP_ARROW:t&&t.close(),o=!0;break;case n.LEFT_ARROW:i=this.focusMenu(-1),r&&(a=angular.element(i).controller("mdMenu"),this.scheduleOpenMenu(a)),o=!0;break;case n.RIGHT_ARROW:i=this.focusMenu(1),r&&(a=angular.element(i).controller("mdMenu"),this.scheduleOpenMenu(a)),o=!0}o&&(e&&e.preventDefault&&e.preventDefault(),e&&e.stopImmediatePropagation&&e.stopImmediatePropagation())},MenuBarController.prototype.focusMenu=function(e){var n=this.getMenus(),t=this.getFocusedMenuIndex();t==-1&&(t=this.getOpenMenuIndex());var r=!1;if(t==-1?(t=0,r=!0):(e<0&&t>0||e>0&&t<n.length-e)&&(t+=e,r=!0),r)return n[t].querySelector("button").focus(),n[t]},MenuBarController.prototype.openFocusedMenu=function(){var e=this.getFocusedMenu();e&&angular.element(e).controller("mdMenu").open()},MenuBarController.prototype.getMenus=function(){var e=this.$element;return this.$mdUtil.nodesToArray(e[0].children).filter(function(e){return"MD-MENU"==e.nodeName})},MenuBarController.prototype.getFocusedMenu=function(){return this.getMenus()[this.getFocusedMenuIndex()]},MenuBarController.prototype.getFocusedMenuIndex=function(){var e=this.$mdUtil,n=e.getClosest(this.$document[0].activeElement,"MD-MENU");if(!n)return-1;var t=this.getMenus().indexOf(n);return t},MenuBarController.prototype.getOpenMenuIndex=function(){for(var e=this.getMenus(),n=0;n<e.length;++n)if(e[n].classList.contains("md-open"))return n;return-1},MenuBarController.prototype.handleParentClick=function(e){var n=this.querySelector("md-menu.md-open");n&&!n.contains(e.target)&&angular.element(n).controller("mdMenu").close()},MenuBarDirective.$inject=["$mdUtil","$mdTheming"],angular.module("material.components.menuBar").directive("mdMenuBar",MenuBarDirective),angular.module("material.components.menuBar").directive("mdMenuDivider",MenuDividerDirective),MenuItemController.$inject=["$scope","$element","$attrs"],angular.module("material.components.menuBar").controller("MenuItemController",MenuItemController),MenuItemController.prototype.init=function(e){var n=this.$element,t=this.$attrs;this.ngModel=e,"checkbox"!=t.type&&"radio"!=t.type||(this.mode=t.type,this.iconEl=n[0].children[0],this.buttonEl=n[0].children[1],e&&this.initClickListeners())},MenuItemController.prototype.clearNgAria=function(){var e=this.$element[0],n=["role","tabindex","aria-invalid","aria-checked"];angular.forEach(n,function(n){e.removeAttribute(n)})},MenuItemController.prototype.initClickListeners=function(){function e(){if("radio"==a){var e=i.ngValue?o.$eval(i.ngValue):i.value;return r.$modelValue==e}return r.$modelValue}function n(e){e?u.off("click",s):u.on("click",s)}var t=this,r=this.ngModel,o=this.$scope,i=this.$attrs,a=(this.$element,this.mode);this.handleClick=angular.bind(this,this.handleClick);var l=this.iconEl,u=angular.element(this.buttonEl),s=this.handleClick;i.$observe("disabled",n),n(i.disabled),r.$render=function(){t.clearNgAria(),e()?(l.style.display="",u.attr("aria-checked","true")):(l.style.display="none",u.attr("aria-checked","false"))},o.$$postDigest(r.$render)},MenuItemController.prototype.handleClick=function(e){var n,t=this.mode,r=this.ngModel,o=this.$attrs;"checkbox"==t?n=!r.$modelValue:"radio"==t&&(n=o.ngValue?this.$scope.$eval(o.ngValue):o.value),r.$setViewValue(n),r.$render()},MenuItemDirective.$inject=["$mdUtil","$$mdSvgRegistry"],angular.module("material.components.menuBar").directive("mdMenuItem",MenuItemDirective),ngmaterial.components.menuBar=angular.module("material.components.menuBar");
|