md2
Version:
Angular2 based Material Design components, directives and services are Accordion, Autocomplete, Chips(Tags), Collapse, Colorpicker, Data Table, Datepicker, Dialog(Modal), Menu, Multiselect, Select, Tabs, Tags(Chips), Toast and Tooltip.
169 lines • 6 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { throwNullPortalHostError, throwPortalAlreadyAttachedError, throwNoPortalAttachedError, throwNullPortalError, throwPortalHostAlreadyDisposedError, throwUnknownPortalTypeError } from './portal-errors';
/**
* A `Portal` is something that you want to render somewhere else.
* It can be attach to / detached from a `PortalHost`.
*/
var Portal = (function () {
function Portal() {
}
/** Attach this portal to a host. */
Portal.prototype.attach = function (host) {
if (host == null) {
throwNullPortalHostError();
}
if (host.hasAttached()) {
throwPortalAlreadyAttachedError();
}
this._attachedHost = host;
return host.attach(this);
};
/** Detach this portal from its host */
Portal.prototype.detach = function () {
var host = this._attachedHost;
if (host == null) {
throwNoPortalAttachedError();
}
this._attachedHost = null;
return host.detach();
};
Object.defineProperty(Portal.prototype, "isAttached", {
/** Whether this portal is attached to a host. */
get: function () {
return this._attachedHost != null;
},
enumerable: true,
configurable: true
});
/**
* Sets the PortalHost reference without performing `attach()`. This is used directly by
* the PortalHost when it is performing an `attach()` or `detach()`.
*/
Portal.prototype.setAttachedHost = function (host) {
this._attachedHost = host;
};
return Portal;
}());
export { Portal };
/**
* A `ComponentPortal` is a portal that instantiates some Component upon attachment.
*/
var ComponentPortal = (function (_super) {
__extends(ComponentPortal, _super);
function ComponentPortal(component, viewContainerRef, injector) {
if (viewContainerRef === void 0) { viewContainerRef = null; }
if (injector === void 0) { injector = null; }
var _this = _super.call(this) || this;
_this.component = component;
_this.viewContainerRef = viewContainerRef;
_this.injector = injector;
return _this;
}
return ComponentPortal;
}(Portal));
export { ComponentPortal };
/**
* A `TemplatePortal` is a portal that represents some embedded template (TemplateRef).
*/
var TemplatePortal = (function (_super) {
__extends(TemplatePortal, _super);
function TemplatePortal(template, viewContainerRef) {
var _this = _super.call(this) || this;
/**
* Additional locals for the instantiated embedded view.
* These locals can be seen as "exports" for the template, such as how ngFor has
* index / event / odd.
* See https://angular.io/docs/ts/latest/api/core/EmbeddedViewRef-class.html
*/
_this.locals = new Map();
_this.templateRef = template;
_this.viewContainerRef = viewContainerRef;
return _this;
}
Object.defineProperty(TemplatePortal.prototype, "origin", {
get: function () {
return this.templateRef.elementRef;
},
enumerable: true,
configurable: true
});
TemplatePortal.prototype.attach = function (host, locals) {
this.locals = locals == null ? new Map() : locals;
return _super.prototype.attach.call(this, host);
};
TemplatePortal.prototype.detach = function () {
this.locals = new Map();
return _super.prototype.detach.call(this);
};
return TemplatePortal;
}(Portal));
export { TemplatePortal };
/**
* Partial implementation of PortalHost that only deals with attaching either a
* ComponentPortal or a TemplatePortal.
*/
var BasePortalHost = (function () {
function BasePortalHost() {
/** Whether this host has already been permanently disposed. */
this._isDisposed = false;
}
/** Whether this host has an attached portal. */
BasePortalHost.prototype.hasAttached = function () {
return !!this._attachedPortal;
};
BasePortalHost.prototype.attach = function (portal) {
if (!portal) {
throwNullPortalError();
}
if (this.hasAttached()) {
throwPortalAlreadyAttachedError();
}
if (this._isDisposed) {
throwPortalHostAlreadyDisposedError();
}
if (portal instanceof ComponentPortal) {
this._attachedPortal = portal;
return this.attachComponentPortal(portal);
}
else if (portal instanceof TemplatePortal) {
this._attachedPortal = portal;
return this.attachTemplatePortal(portal);
}
throwUnknownPortalTypeError();
};
BasePortalHost.prototype.detach = function () {
if (this._attachedPortal) {
this._attachedPortal.setAttachedHost(null);
this._attachedPortal = null;
}
this._invokeDisposeFn();
};
BasePortalHost.prototype.dispose = function () {
if (this.hasAttached()) {
this.detach();
}
this._invokeDisposeFn();
this._isDisposed = true;
};
BasePortalHost.prototype.setDisposeFn = function (fn) {
this._disposeFn = fn;
};
BasePortalHost.prototype._invokeDisposeFn = function () {
if (this._disposeFn) {
this._disposeFn();
this._disposeFn = null;
}
};
return BasePortalHost;
}());
export { BasePortalHost };
//# sourceMappingURL=portal.js.map