UNPKG

@material-git/all

Version:
83 lines (81 loc) 3.42 kB
import { Subject } from 'rxjs/Subject'; /** * Reference to an overlay that has been created with the Overlay service. * Used to manipulate or dispose of said overlay. */ export var OverlayRef = (function () { function OverlayRef(_portalHost, _pane, _state) { this._portalHost = _portalHost; this._pane = _pane; this._state = _state; this._backdropElement = null; this._backdropClick = new Subject(); } OverlayRef.prototype.attach = function (portal) { if (this._state.hasBackdrop) { this._attachBackdrop(); } var attachResult = this._portalHost.attach(portal); this.updatePosition(); return attachResult; }; OverlayRef.prototype.detach = function () { this._detatchBackdrop(); return this._portalHost.detach(); }; OverlayRef.prototype.dispose = function () { this._detatchBackdrop(); this._portalHost.dispose(); }; OverlayRef.prototype.hasAttached = function () { return this._portalHost.hasAttached(); }; OverlayRef.prototype.backdropClick = function () { return this._backdropClick.asObservable(); }; /** Gets the current state config of the overlay. */ OverlayRef.prototype.getState = function () { return this._state; }; /** Updates the position of the overlay based on the position strategy. */ OverlayRef.prototype.updatePosition = function () { if (this._state.positionStrategy) { this._state.positionStrategy.apply(this._pane); } }; /** Attaches a backdrop for this overlay. */ OverlayRef.prototype._attachBackdrop = function () { var _this = this; this._backdropElement = document.createElement('div'); this._backdropElement.classList.add('md-overlay-backdrop'); this._pane.parentElement.appendChild(this._backdropElement); // Forward backdrop clicks such that the consumer of the overlay can perform whatever // action desired when such a click occurs (usually closing the overlay). this._backdropElement.addEventListener('click', function () { _this._backdropClick.next(null); }); // Add class to fade-in the backdrop after one frame. requestAnimationFrame(function () { _this._backdropElement.classList.add('md-overlay-backdrop-showing'); }); }; /** Detaches the backdrop (if any) associated with the overlay. */ OverlayRef.prototype._detatchBackdrop = function () { var _this = this; var backdropToDetach = this._backdropElement; if (backdropToDetach) { backdropToDetach.classList.remove('md-overlay-backdrop-showing'); backdropToDetach.addEventListener('transitionend', function () { backdropToDetach.parentNode.removeChild(backdropToDetach); // It is possible that a new portal has been attached to this overlay since we started // removing the backdrop. If that is the case, only clear the backdrop reference if it // is still the same instance that we started to remove. if (_this._backdropElement == backdropToDetach) { _this._backdropElement = null; } }); } }; return OverlayRef; }()); //# sourceMappingURL=overlay-ref.js.map