import { Menu , MenuType } from './menu-interface' ; import { Platform } from '../../platform/platform' ; import { assert , removeArrayItem } from '../../util/util' ; name description usage Component demo see {@link /docs/components#menus Menu Component Docs} see {@link /docs/api/components/menu/Menu/ Menu API Docs} export class MenuController { private _menus : Array < Menu > = [ ] ; param { string } menuId return { Promise } open ( menuId ? ) { const menu = this . get ( menuId ) ; if ( menu && ! this . isAnimating ( ) ) { let openedMenu = this . getOpen ( ) ; if ( openedMenu && menu !== openedMenu ) { openedMenu . setOpen ( false , false ) ; } return menu . open ( ) ; } return Promise . resolve ( false ) ; } param { string } menuId return { Promise } close ( menuId ? ) { let menu ; if ( menuId ) { menu = this . get ( menuId ) ; } else { menu = this . getOpen ( ) ; } if ( menu ) { return menu . close ( ) ; } return Promise . resolve ( false ) ; } param { string } menuId return { Promise } toggle ( menuId ? ) { const menu = this . get ( menuId ) ; if ( menu && ! this . isAnimating ( ) ) { var openedMenu = this . getOpen ( ) ; if ( openedMenu && menu !== openedMenu ) { openedMenu . setOpen ( false , false ) ; } return menu . toggle ( ) ; } return Promise . resolve ( false ) ; } param { string } menuId return { Menu } enable ( shouldEnable , menuId ? ) { const menu = this . get ( menuId ) ; if ( menu ) { return menu . enable ( shouldEnable ) ; } } param { boolean } shouldEnable param { string } menuId return { Menu } swipeEnable ( shouldEnable , menuId ? ) { const menu = this . get ( menuId ) ; if ( menu ) { return menu . swipeEnable ( shouldEnable ) ; } } param { string } menuId return { boolean } isOpen ( menuId ? ) { if ( menuId ) { var menu = this . get ( menuId ) ; return menu && menu . isOpen || false ; } else { return ! ! this . getOpen ( ) ; } } param { string } menuId return { boolean } isEnabled ( menuId ? ) { const menu = this . get ( menuId ) ; return menu && menu . enabled || false ; } param { string } menuId return { Menu } get ( menuId ? ) { var menu ; if ( menuId === 'left' || menuId === 'right' ) { menu = this . _menus . find ( m => m . side === menuId && m . enabled ) ; if ( menu ) { return menu ; } return this . _menus . find ( m => m . side === menuId ) || null ; } else if ( menuId ) { return this . _menus . find ( m => m . id === menuId ) || null ; } menu = this . _menus . find ( m => m . enabled ) ; if ( menu ) { return menu ; } return ( this . _menus . length ? this . _menus [ 0 ] : null ) ; } return { Menu } getOpen ( ) { return this . _menus . find ( m => m . isOpen ) ; } return { Array < Menu > } getMenus ( ) { return this . _menus ; } hidden return { boolean } isAnimating ( ) { return this . _menus . some ( menu => menu . isAnimating ( ) ) ; } hidden _register ( menu ) { assert ( this . _menus . indexOf ( menu ) < 0 , 'menu was already registered' ) ; this . _menus . push ( menu ) ; } hidden _unregister ( menu ) { assert ( this . _menus . indexOf ( menu ) >= 0 , 'menu is not registered' ) ; removeArrayItem ( this . _menus , menu ) ; } hidden _setActiveMenu ( menu ) { assert ( menu . enabled , 'menu must be enabled' ) ; assert ( this . _menus . indexOf ( menu ) >= 0 , 'menu is not registered' ) ; const side = menu . side ; this . _menus . filter ( m => m . side === side && m !== menu ) . map ( m => m . enable ( false ) ) ; } hidden static registerType ( name , cls ) { menuTypes [ name ] = cls ; } hidden static create ( type , menuCmp , plt ) { return new menuTypes [ type ] ( menuCmp , plt ) ; } } let menuTypes = { } ;