-
Notifications
You must be signed in to change notification settings - Fork 6.7k
/
dialog-demo.ts
185 lines (158 loc) · 4.73 KB
/
dialog-demo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import {Component, Inject, ViewChild, TemplateRef} from '@angular/core';
import {DOCUMENT} from '@angular/platform-browser';
import {MdDialog, MdDialogRef, MD_DIALOG_DATA} from '@angular/material';
@Component({
moduleId: module.id,
selector: 'dialog-demo',
templateUrl: 'dialog-demo.html',
styleUrls: ['dialog-demo.css'],
})
export class DialogDemo {
dialogRef: MdDialogRef<JazzDialog> | null;
lastCloseResult: string;
actionsAlignment: string;
config = {
disableClose: false,
panelClass: 'custom-overlay-pane-class',
hasBackdrop: true,
backdropClass: '',
width: '',
height: '',
position: {
top: '',
bottom: '',
left: '',
right: ''
},
data: {
message: 'Jazzy jazz jazz'
}
};
numTemplateOpens = 0;
@ViewChild(TemplateRef) template: TemplateRef<any>;
constructor(public dialog: MdDialog, @Inject(DOCUMENT) doc: any) {
// Possible useful example for the open and closeAll events.
// Adding a class to the body if a dialog opens and
// removing it after all open dialogs are closed
dialog.afterOpen.subscribe(() => {
if (!doc.body.classList.contains('no-scroll')) {
doc.body.classList.add('no-scroll');
}
});
dialog.afterAllClosed.subscribe(() => {
doc.body.classList.remove('no-scroll');
});
}
openJazz() {
this.dialogRef = this.dialog.open(JazzDialog, this.config);
this.dialogRef.afterClosed().subscribe((result: string) => {
this.lastCloseResult = result;
this.dialogRef = null;
});
}
openContentElement() {
let dialogRef = this.dialog.open(ContentElementDialog, this.config);
dialogRef.componentInstance.actionsAlignment = this.actionsAlignment;
}
openTemplate() {
this.numTemplateOpens++;
this.dialog.open(this.template, this.config);
}
}
@Component({
selector: 'demo-jazz-dialog',
template: `
<p>It's Jazz!</p>
<md-input-container>
<input mdInput placeholder="How much?" #howMuch>
</md-input-container>
<p> {{ data.message }} </p>
<button type="button" (click)="dialogRef.close(howMuch.value)">Close dialog</button>
<button (click)="togglePosition()">Change dimensions</button>`
})
export class JazzDialog {
private _dimesionToggle = false;
constructor(
public dialogRef: MdDialogRef<JazzDialog>,
@Inject(MD_DIALOG_DATA) public data: any) { }
togglePosition(): void {
this._dimesionToggle = !this._dimesionToggle;
if (this._dimesionToggle) {
this.dialogRef
.updateSize('500px', '500px')
.updatePosition({ top: '25px', left: '25px' });
} else {
this.dialogRef
.updateSize()
.updatePosition();
}
}
}
@Component({
selector: 'demo-content-element-dialog',
styles: [
`img {
max-width: 100%;
}`
],
template: `
<h2 md-dialog-title>Neptune</h2>
<md-dialog-content>
<img src="https://upload.wikimedia.org/wikipedia/commons/5/56/Neptune_Full.jpg"/>
<p>
Neptune is the eighth and farthest known planet from the Sun in the Solar System. In the
Solar System, it is the fourth-largest planet by diameter, the third-most-massive planet,
and the densest giant planet. Neptune is 17 times the mass of Earth and is slightly more
massive than its near-twin Uranus, which is 15 times the mass of Earth and slightly larger
than Neptune. Neptune orbits the Sun once every 164.8 years at an average distance of 30.1
astronomical units (4.50×109 km). It is named after the Roman god of the sea and has the
astronomical symbol ♆, a stylised version of the god Neptune's trident.
</p>
</md-dialog-content>
<md-dialog-actions [attr.align]="actionsAlignment">
<button
md-raised-button
color="primary"
md-dialog-close>Close</button>
<a
md-button
color="primary"
href="https://en.wikipedia.org/wiki/Neptune"
target="_blank">Read more on Wikipedia</a>
<button
md-button
color="secondary"
(click)="showInStackedDialog()">
Show in Dialog</button>
</md-dialog-actions>
`
})
export class ContentElementDialog {
actionsAlignment: string;
constructor(public dialog: MdDialog) { }
showInStackedDialog() {
this.dialog.open(IFrameDialog);
}
}
@Component({
selector: 'demo-iframe-dialog',
styles: [
`iframe {
width: 800px;
}`
],
template: `
<h2 md-dialog-title>Neptune</h2>
<md-dialog-content>
<iframe frameborder="0" src="https://en.wikipedia.org/wiki/Neptune"></iframe>
</md-dialog-content>
<md-dialog-actions>
<button
md-raised-button
color="primary"
md-dialog-close>Close</button>
</md-dialog-actions>
`
})
export class IFrameDialog {
}