diff --git a/ionic/components/menu/menu-controller.ts b/ionic/components/menu/menu-controller.ts index f8a6a056fd..9acca3ebb2 100644 --- a/ionic/components/menu/menu-controller.ts +++ b/ionic/components/menu/menu-controller.ts @@ -132,26 +132,74 @@ import {MenuType} from './menu-types'; export class MenuController { private _menus: Array = []; + /** + * Progamatically open the Menu. + * @return {Promise} returns a promise when the menu is fully opened + */ open(menuId?: string) { let menu = this.get(menuId); - menu && menu.open(); + if (menu) { + return menu.open(); + } } + /** + * Progamatically close the Menu. + * @param {string} [menuId] Optionally get the menu by its id, or side. + * @return {Promise} returns a promise when the menu is fully closed + */ close(menuId?: string) { let menu = this.get(menuId); - menu && menu.close(); + if (menu) { + return menu.close(); + } } + /** + * Toggle the menu. If it's closed, it will open, and if opened, it will + * close. + * @param {string} [menuId] Optionally get the menu by its id, or side. + * @return {Promise} returns a promise when the menu has been toggled + */ + toggle(menuId?: string) { + let menu = this.get(menuId); + if (menu) { + return menu.toggle(); + } + } + + /** + * Used to enable or disable a menu. For example, there could be multiple + * left menus, but only one of them should be able to be dragged open. + * @param {boolean} shouldEnable True if it should be enabled, false if not. + * @param {string} [menuId] Optionally get the menu by its id, or side. + * @return {Menu} Returns the instance of the menu, which is useful for chaining. + */ enable(shouldEnable: boolean, menuId?: string) { let menu = this.get(menuId); - menu && menu.enable(shouldEnable); + if (menu) { + return menu.enable(shouldEnable); + } } + /** + * Used to enable or disable the ability to swipe open the menu. + * @param {boolean} shouldEnable True if it should be swipe-able, false if not. + * @param {string} [menuId] Optionally get the menu by its id, or side. + * @return {Menu} Returns the instance of the menu, which is useful for chaining. + */ swipeEnable(shouldEnable: boolean, menuId?: string) { let menu = this.get(menuId); - menu && menu.swipeEnable(shouldEnable); + if (menu) { + return menu.swipeEnable(shouldEnable); + } } + /** + * Used to get a menu instance. + * @param {string} [menuId] Optionally get the menu by its id, or side. + * @return {Menu} Returns the instance of the menu if found, otherwise `null`. + */ get(menuId?: string): Menu { if (menuId) { // first try by "id" diff --git a/ionic/components/menu/menu.ts b/ionic/components/menu/menu.ts index 63b9f77a97..e9a9f067fa 100644 --- a/ionic/components/menu/menu.ts +++ b/ionic/components/menu/menu.ts @@ -10,6 +10,9 @@ import {MenuController} from './menu-controller'; import {MenuType} from './menu-types'; +/** + * @private + */ @Component({ selector: 'ion-menu', host: {