1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
5 | };
|
6 | import { MdNullPortalHostError, MdPortalAlreadyAttachedError, MdNoPortalAttachedError, MdNullPortalError, MdPortalHostAlreadyDisposedError, MdUnknownPortalTypeError } from './portal-errors';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export var Portal = (function () {
|
12 | function Portal() {
|
13 | }
|
14 |
|
15 | Portal.prototype.attach = function (host) {
|
16 | if (host == null) {
|
17 | throw new MdNullPortalHostError();
|
18 | }
|
19 | if (host.hasAttached()) {
|
20 | throw new MdPortalAlreadyAttachedError();
|
21 | }
|
22 | this._attachedHost = host;
|
23 | return host.attach(this);
|
24 | };
|
25 |
|
26 | Portal.prototype.detach = function () {
|
27 | var host = this._attachedHost;
|
28 | if (host == null) {
|
29 | throw new MdNoPortalAttachedError();
|
30 | }
|
31 | this._attachedHost = null;
|
32 | return host.detach();
|
33 | };
|
34 | Object.defineProperty(Portal.prototype, "isAttached", {
|
35 |
|
36 | get: function () {
|
37 | return this._attachedHost != null;
|
38 | },
|
39 | enumerable: true,
|
40 | configurable: true
|
41 | });
|
42 | |
43 |
|
44 |
|
45 |
|
46 | Portal.prototype.setAttachedHost = function (host) {
|
47 | this._attachedHost = host;
|
48 | };
|
49 | return Portal;
|
50 | }());
|
51 |
|
52 |
|
53 |
|
54 | export var ComponentPortal = (function (_super) {
|
55 | __extends(ComponentPortal, _super);
|
56 | function ComponentPortal(component, viewContainerRef, injector) {
|
57 | if (viewContainerRef === void 0) { viewContainerRef = null; }
|
58 | if (injector === void 0) { injector = null; }
|
59 | _super.call(this);
|
60 | this.component = component;
|
61 | this.viewContainerRef = viewContainerRef;
|
62 | this.injector = injector;
|
63 | }
|
64 | return ComponentPortal;
|
65 | }(Portal));
|
66 |
|
67 |
|
68 |
|
69 | export var TemplatePortal = (function (_super) {
|
70 | __extends(TemplatePortal, _super);
|
71 | function TemplatePortal(template, viewContainerRef) {
|
72 | _super.call(this);
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | this.locals = new Map();
|
80 | this.templateRef = template;
|
81 | this.viewContainerRef = viewContainerRef;
|
82 | }
|
83 | Object.defineProperty(TemplatePortal.prototype, "origin", {
|
84 | get: function () {
|
85 | return this.templateRef.elementRef;
|
86 | },
|
87 | enumerable: true,
|
88 | configurable: true
|
89 | });
|
90 | TemplatePortal.prototype.attach = function (host, locals) {
|
91 | this.locals = locals == null ? new Map() : locals;
|
92 | return _super.prototype.attach.call(this, host);
|
93 | };
|
94 | TemplatePortal.prototype.detach = function () {
|
95 | this.locals = new Map();
|
96 | return _super.prototype.detach.call(this);
|
97 | };
|
98 | return TemplatePortal;
|
99 | }(Portal));
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | export var BasePortalHost = (function () {
|
105 | function BasePortalHost() {
|
106 |
|
107 | this._isDisposed = false;
|
108 | }
|
109 |
|
110 | BasePortalHost.prototype.hasAttached = function () {
|
111 | return this._attachedPortal != null;
|
112 | };
|
113 | BasePortalHost.prototype.attach = function (portal) {
|
114 | if (portal == null) {
|
115 | throw new MdNullPortalError();
|
116 | }
|
117 | if (this.hasAttached()) {
|
118 | throw new MdPortalAlreadyAttachedError();
|
119 | }
|
120 | if (this._isDisposed) {
|
121 | throw new MdPortalHostAlreadyDisposedError();
|
122 | }
|
123 | if (portal instanceof ComponentPortal) {
|
124 | this._attachedPortal = portal;
|
125 | return this.attachComponentPortal(portal);
|
126 | }
|
127 | else if (portal instanceof TemplatePortal) {
|
128 | this._attachedPortal = portal;
|
129 | return this.attachTemplatePortal(portal);
|
130 | }
|
131 | throw new MdUnknownPortalTypeError();
|
132 | };
|
133 | BasePortalHost.prototype.detach = function () {
|
134 | if (this._attachedPortal) {
|
135 | this._attachedPortal.setAttachedHost(null);
|
136 | }
|
137 | this._attachedPortal = null;
|
138 | if (this._disposeFn != null) {
|
139 | this._disposeFn();
|
140 | this._disposeFn = null;
|
141 | }
|
142 | };
|
143 | BasePortalHost.prototype.dispose = function () {
|
144 | if (this.hasAttached()) {
|
145 | this.detach();
|
146 | }
|
147 | this._isDisposed = true;
|
148 | };
|
149 | BasePortalHost.prototype.setDisposeFn = function (fn) {
|
150 | this._disposeFn = fn;
|
151 | };
|
152 | return BasePortalHost;
|
153 | }());
|
154 |
|
155 |
|