Files
2015-12-14 08:14:05 -06:00

63 lines
1.3 KiB
TypeScript

import {Directive, ElementRef, Optional} from 'angular2/angular2';
import {IonicApp} from '../app/app';
import {ViewController} from '../nav/view-controller';
import {Navbar} from '../navbar/navbar';
import {Menu} from './menu';
/**
* TODO
* @demo /docs/v2/demos/menu/
* @see {@link /docs/v2/components#menus Menu Component Docs}
* @see {@link ../../menu/Menu Menu API Docs}
*/
@Directive({
selector: '[menu-toggle]',
inputs: [
'menuToggle'
],
host: {
'(click)': 'toggle()',
'[hidden]': 'isHidden',
'menu-toggle': '' //ensures the attr is there for css when using [menu-toggle]
}
})
export class MenuToggle {
constructor(
app: IonicApp,
elementRef: ElementRef,
@Optional() viewCtrl: ViewController,
@Optional() navbar: Navbar
) {
this.app = app;
this.viewCtrl = viewCtrl;
this.withinNavbar = !!navbar;
// Deprecation warning
if (this.withinNavbar && elementRef.nativeElement.tagName === 'A') {
console.warn('Menu toggles within a navbar should use <button menu-toggle> instead of <a toggle>')
}
}
/**
* @private
*/
toggle() {
let menu = Menu.getById(this.app, this.menuToggle);
menu && menu.toggle();
}
/**
* @private
*/
get isHidden() {
if (this.withinNavbar && this.viewCtrl) {
return !this.viewCtrl.isRoot();
}
return false;
}
}