From 2c270b372226785a8fa10366aa61aaed3b4b43f7 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sat, 31 Oct 2015 14:41:27 -0500 Subject: [PATCH] feat(menu): enable/disable side menus --- ionic/components/menu/menu-toggle.ts | 3 +- ionic/components/menu/menu.ts | 26 ++++++++++++-- ionic/components/menu/test/multiple/index.ts | 33 +++++++++++++++++ ionic/components/menu/test/multiple/main.html | 36 +++++++++++++++++++ .../components/menu/test/multiple/page1.html | 30 ++++++++++++++++ 5 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 ionic/components/menu/test/multiple/index.ts create mode 100644 ionic/components/menu/test/multiple/main.html create mode 100644 ionic/components/menu/test/multiple/page1.html diff --git a/ionic/components/menu/menu-toggle.ts b/ionic/components/menu/menu-toggle.ts index 2de876178a..48e5da262e 100644 --- a/ionic/components/menu/menu-toggle.ts +++ b/ionic/components/menu/menu-toggle.ts @@ -16,7 +16,8 @@ import {Navbar} from '../nav-bar/nav-bar'; ], host: { '(click)': 'toggle()', - '[hidden]': 'isHidden' + '[hidden]': 'isHidden', + 'menu-toggle': '' //ensures the attr is there for css when using [menu-toggle] } }) export class MenuToggle extends Ion { diff --git a/ionic/components/menu/menu.ts b/ionic/components/menu/menu.ts index 7c59d37a8b..4fbd50fe4d 100644 --- a/ionic/components/menu/menu.ts +++ b/ionic/components/menu/menu.ts @@ -79,6 +79,7 @@ export class Menu extends Ion { this.opening = new EventEmitter('opening'); this.isOpen = false; this._disableTime = 0; + this.isEnabled = true; } /** @@ -107,9 +108,11 @@ export class Menu extends Ion { let self = this; this.onContentClick = function(ev) { - ev.preventDefault(); - ev.stopPropagation(); - self.close(); + if (self.isEnabled) { + ev.preventDefault(); + ev.stopPropagation(); + self.close(); + } }; } @@ -253,6 +256,23 @@ export class Menu extends Ion { return this.setOpen(!this.isOpen); } + enabled(isEnabled) { + if (!this.isEnabled && isEnabled && !this._gesture) { + // was previously disabled, and is being enabled again + // re-add the gestures + this._initGesture(); + + } else if (this.isEnabled && !isEnabled) { + // is currently enabled, and is being disabled + // remove the gestures + this._gesture && this._gesture.destroy(); + this._targetGesture && this._targetGesture.destroy(); + this._gesture = this._targetGesture = null; + } + + this.isEnabled = isEnabled; + } + /** * TODO * @return {Element} The Menu element. diff --git a/ionic/components/menu/test/multiple/index.ts b/ionic/components/menu/test/multiple/index.ts new file mode 100644 index 0000000000..62d167162d --- /dev/null +++ b/ionic/components/menu/test/multiple/index.ts @@ -0,0 +1,33 @@ +import {App, IonicApp, Page, NavController} from 'ionic/ionic'; + + +@Page({ + templateUrl: 'page1.html' +}) +class Page1 { + constructor(app: IonicApp) { + this.app = app; + this.menu1Active(); + } + menu1Active() { + this.activeMenu = 'menu1'; + this.app.getComponent('menu1').enabled(true); + this.app.getComponent('menu2').enabled(false); + } + menu2Active() { + this.activeMenu = 'menu2'; + this.app.getComponent('menu1').enabled(false); + this.app.getComponent('menu2').enabled(true); + } +} + + +@App({ + templateUrl: 'main.html' +}) +class E2EApp { + constructor(app: IonicApp) { + this.app = app; + this.rootPage = Page1; + } +} diff --git a/ionic/components/menu/test/multiple/main.html b/ionic/components/menu/test/multiple/main.html new file mode 100644 index 0000000000..07beb0315e --- /dev/null +++ b/ionic/components/menu/test/multiple/main.html @@ -0,0 +1,36 @@ + + + + + Menu 1 + + + + + + + + + + + + + + + Menu 2 + + + + + + + + + + + + diff --git a/ionic/components/menu/test/multiple/page1.html b/ionic/components/menu/test/multiple/page1.html new file mode 100644 index 0000000000..a8e989f07c --- /dev/null +++ b/ionic/components/menu/test/multiple/page1.html @@ -0,0 +1,30 @@ + + + + + + + Multiple Menus + + + + + + +

Active Menu: {{ activeMenu }}

+ +

+ +

+ +

+ +

+ +

+ +

+ +

This page has two left menus, but only one is active at a time.

+ +