UNPKG

2.85 kBJavaScriptView Raw
1import { Component, Input, ElementRef, forwardRef, Renderer, Inject, ViewEncapsulation } from '@angular/core';
2import { MdlMenuComponent } from './mdl-menu.component';
3import { toBoolean } from '../common/boolean-property';
4export var MdlMenuItemComponent = (function () {
5 // forwardRef is needed because of he circular dependency menu queries menuitems; menuitem needs the parent
6 function MdlMenuItemComponent(elementRef, renderer, mdlMenu) {
7 this.elementRef = elementRef;
8 this.renderer = renderer;
9 this.mdlMenu = mdlMenu;
10 this._disabled = false;
11 this.element = elementRef.nativeElement;
12 }
13 Object.defineProperty(MdlMenuItemComponent.prototype, "disabled", {
14 get: function () { return this._disabled; },
15 set: function (value) { this._disabled = toBoolean(value); },
16 enumerable: true,
17 configurable: true
18 });
19 MdlMenuItemComponent.prototype.onClick = function ($event) {
20 $event.stopPropagation();
21 if (this.disabled) {
22 this.mdlMenu.hide();
23 return;
24 }
25 this.mdlMenu.hideOnItemClicked();
26 };
27 // we need to register a touchstart at the window to get informed if the user taps outside the menu.
28 // But if we register a touchstart event - safari will no longer convert touch events to click events.
29 // So we need to convert touch to click and the user still needs to register a (click) listener to be
30 // informed if the menu item has clicked.
31 MdlMenuItemComponent.prototype.onTouch = function ($event) {
32 // ensure that this event is totally consumed
33 $event.stopPropagation();
34 $event.preventDefault();
35 var event = new MouseEvent('click', { bubbles: true });
36 this.renderer.invokeElementMethod(this.element, 'dispatchEvent', [event]);
37 };
38 MdlMenuItemComponent.decorators = [
39 { type: Component, args: [{
40 selector: 'mdl-menu-item',
41 host: {
42 '[class.mdl-menu__item]': 'true',
43 'tabindex': '-1',
44 '(click)': 'onClick($event)',
45 '(touchstart)': 'onTouch($event)'
46 },
47 template: '<ng-content></ng-content>',
48 encapsulation: ViewEncapsulation.None
49 },] },
50 ];
51 /** @nocollapse */
52 MdlMenuItemComponent.ctorParameters = function () { return [
53 { type: ElementRef, },
54 { type: Renderer, },
55 { type: MdlMenuComponent, decorators: [{ type: Inject, args: [forwardRef(function () { return MdlMenuComponent; }),] },] },
56 ]; };
57 MdlMenuItemComponent.propDecorators = {
58 'disabled': [{ type: Input },],
59 };
60 return MdlMenuItemComponent;
61}());
62//# sourceMappingURL=mdl-menu-item.component.js.map
\No newline at end of file