UNPKG

@angular2-material/core

Version:
121 lines (119 loc) 5.18 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { NgModule, Directive, TemplateRef, ViewContainerRef, Input, ElementRef } from '@angular/core'; import { Overlay, OVERLAY_PROVIDERS } from './overlay'; import { TemplatePortal } from '../portal/portal'; import { OverlayState } from './overlay-state'; import { ConnectionPositionPair } from './position/connected-position'; import { PortalModule } from '../portal/portal-directives'; /** Default set of positions for the overlay. Follows the behavior of a dropdown. */ var defaultPositionList = [ new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' }), new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' }), ]; /** * Directive applied to an element to make it usable as an origin for an Overlay using a * ConnectedPositionStrategy. */ export var OverlayOrigin = (function () { function OverlayOrigin(_elementRef) { this._elementRef = _elementRef; } Object.defineProperty(OverlayOrigin.prototype, "elementRef", { get: function () { return this._elementRef; }, enumerable: true, configurable: true }); OverlayOrigin = __decorate([ Directive({ selector: '[overlay-origin]', exportAs: 'overlayOrigin', }), __metadata('design:paramtypes', [ElementRef]) ], OverlayOrigin); return OverlayOrigin; }()); /** * Directive to facilitate declarative creation of an Overlay using a ConnectedPositionStrategy. */ export var ConnectedOverlayDirective = (function () { // TODO(jelbourn): inputs for size, scroll behavior, animation, etc. function ConnectedOverlayDirective(_overlay, templateRef, viewContainerRef) { this._overlay = _overlay; this._templatePortal = new TemplatePortal(templateRef, viewContainerRef); } Object.defineProperty(ConnectedOverlayDirective.prototype, "overlayRef", { get: function () { return this._overlayRef; }, enumerable: true, configurable: true }); /** TODO: internal */ ConnectedOverlayDirective.prototype.ngOnInit = function () { this._createOverlay(); }; /** TODO: internal */ ConnectedOverlayDirective.prototype.ngOnDestroy = function () { this._destroyOverlay(); }; /** Creates an overlay and attaches this directive's template to it. */ ConnectedOverlayDirective.prototype._createOverlay = function () { if (!this.positions || !this.positions.length) { this.positions = defaultPositionList; } var overlayConfig = new OverlayState(); overlayConfig.positionStrategy = this._overlay.position().connectedTo(this.origin.elementRef, { originX: this.positions[0].overlayX, originY: this.positions[0].originY }, { overlayX: this.positions[0].overlayX, overlayY: this.positions[0].overlayY }); this._overlayRef = this._overlay.create(overlayConfig); this._overlayRef.attach(this._templatePortal); }; /** Destroys the overlay created by this directive. */ ConnectedOverlayDirective.prototype._destroyOverlay = function () { this._overlayRef.dispose(); }; __decorate([ Input(), __metadata('design:type', OverlayOrigin) ], ConnectedOverlayDirective.prototype, "origin", void 0); __decorate([ Input(), __metadata('design:type', Array) ], ConnectedOverlayDirective.prototype, "positions", void 0); ConnectedOverlayDirective = __decorate([ Directive({ selector: '[connected-overlay]' }), __metadata('design:paramtypes', [Overlay, TemplateRef, ViewContainerRef]) ], ConnectedOverlayDirective); return ConnectedOverlayDirective; }()); export var OverlayModule = (function () { function OverlayModule() { } OverlayModule.forRoot = function () { return { ngModule: OverlayModule, providers: OVERLAY_PROVIDERS, }; }; OverlayModule = __decorate([ NgModule({ imports: [PortalModule], exports: [ConnectedOverlayDirective, OverlayOrigin], declarations: [ConnectedOverlayDirective, OverlayOrigin], }), __metadata('design:paramtypes', []) ], OverlayModule); return OverlayModule; }()); //# sourceMappingURL=overlay-directives.js.map