1- import  { DynamicComponentLoader ,  ElementRef ,  ComponentRef ,  onDestroy ,  DomRenderer }  from  'angular2/angular2' ; 
2- import  { bind ,  Injector }  from  'angular2/di' ; 
1+ import  { 
2+  Component , 
3+  Directive , 
4+  View , 
5+  Parent , 
6+  ElementRef , 
7+  DynamicComponentLoader , 
8+  ComponentRef , 
9+  DomRenderer 
10+ }  from  'angular2/angular2' ; 
11+ import  { bind ,  Injector ,  Injectable ,  FORWARD_REF }  from  'angular2/di' ; 
12+ 
313import  { ObservableWrapper ,  Promise ,  PromiseWrapper }  from  'angular2/src/facade/async' ; 
414import  { isPresent ,  Type }  from  'angular2/src/facade/lang' ; 
515import  { DOM }  from  'angular2/src/dom/dom_adapter' ; 
616import  { MouseEvent ,  KeyboardEvent }  from  'angular2/src/facade/browser' ; 
717import  { KEY_ESC }  from  'angular2_material/src/core/constants' ; 
818
9- // TODO(radokirov): Once the application is transpiled by TS instead of Traceur, 
10- // add those imports back into 'angular2/angular2'; 
11- import  { Component ,  Directive }  from  'angular2/src/core/annotations_impl/annotations' ; 
12- import  { Parent }  from  'angular2/src/core/annotations_impl/visibility' ; 
13- import  { View }  from  'angular2/src/core/annotations_impl/view' ; 
14- 
1519// TODO(jelbourn): Opener of dialog can control where it is rendered. 
1620// TODO(jelbourn): body scrolling is disabled while dialog is open. 
1721// TODO(jelbourn): Don't manually construct and configure a DOM element. See #1402 
@@ -21,11 +25,10 @@ import {View} from 'angular2/src/core/annotations_impl/view';
2125// TODO(jelbourn): Pre-built `alert` and `confirm` dialogs. 
2226// TODO(jelbourn): Animate dialog out of / into opening element. 
2327
24- var  _nextDialogId  =  0 ; 
25- 
2628/** 
2729 * Service for opening modal dialogs. 
2830 */ 
31+ @Injectable ( ) 
2932export  class  MdDialog  { 
3033 componentLoader : DynamicComponentLoader ; 
3134 domRenderer : DomRenderer ; 
@@ -39,13 +42,12 @@ export class MdDialog {
3942 * Opens a modal dialog. 
4043 * @param  type The component to open. 
4144 * @param  elementRef The logical location into which the component will be opened. 
45+  * @param  parentInjector 
46+  * @param  options 
4247 * @returns  Promise for a reference to the dialog. 
4348 */ 
44-  open ( 
45-  type : Type , 
46-  elementRef : ElementRef , 
47-  parentInjector : Injector , 
48-  options : MdDialogConfig  =  null ) : Promise < MdDialogRef >  { 
49+  open ( type : Type ,  elementRef : ElementRef ,  parentInjector : Injector , 
50+  options : MdDialogConfig  =  null ) : Promise < MdDialogRef >  { 
4951 var  config  =  isPresent ( options )  ? options  : new  MdDialogConfig ( ) ; 
5052
5153 // Create the dialogRef here so that it can be injected into the content component. 
@@ -57,61 +59,63 @@ export class MdDialog {
5759 var  backdropRefPromise  =  this . _openBackdrop ( elementRef ,  contentInjector ) ; 
5860
5961 // First, load the MdDialogContainer, into which the given component will be loaded. 
60-  return  this . componentLoader . loadIntoNewLocation ( 
61-  MdDialogContainer ,  elementRef ) . then ( containerRef  =>  { 
62-  // TODO(tbosch): clean this up when we have custom renderers (https://github.com/angular/angular/issues/1807) 
63-  // TODO(jelbourn): Don't use direct DOM access. Need abstraction to create an element 
64-  // directly on the document body (also needed for web workers stuff). 
65-  // Create a DOM node to serve as a physical host element for the dialog. 
66-  var  dialogElement  =  this . domRenderer . getHostElement ( containerRef . hostView . render ) ; 
67-  DOM . appendChild ( DOM . query ( 'body' ) ,  dialogElement ) ; 
68- 
69-  // TODO(jelbourn): Use hostProperties binding to set these once #1539 is fixed. 
70-  // Configure properties on the host element. 
71-  DOM . addClass ( dialogElement ,  'md-dialog' ) ; 
72-  DOM . setAttribute ( dialogElement ,  'tabindex' ,  '0' ) ; 
73- 
74-  // TODO(jelbourn): Do this with hostProperties (or another rendering abstraction) once ready. 
75-  if  ( isPresent ( config . width ) )  { 
76-  DOM . setStyle ( dialogElement ,  'width' ,  config . width ) ; 
77-  } 
78-  if  ( isPresent ( config . height ) )  { 
79-  DOM . setStyle ( dialogElement ,  'height' ,  config . height ) ; 
80-  } 
81- 
82-  dialogRef . containerRef  =  containerRef ; 
83- 
84-  // Now load the given component into the MdDialogContainer. 
85-  return  this . componentLoader . loadNextToExistingLocation ( 
86-  type ,  containerRef . instance . contentRef ,  contentInjector ) . then ( contentRef  =>  { 
87- 
88-  // Wrap both component refs for the container and the content so that we can return 
89-  // the `instance` of the content but the dispose method of the container back to the 
90-  // opener. 
91-  dialogRef . contentRef  =  contentRef ; 
92-  containerRef . instance . dialogRef  =  dialogRef ; 
93- 
94-  backdropRefPromise . then ( backdropRef  =>  { 
95-  dialogRef . whenClosed . then ( ( _ )  =>  { 
96-  backdropRef . dispose ( ) ; 
97-  } ) ; 
62+  return  this . componentLoader . loadIntoNewLocation ( MdDialogContainer ,  elementRef ) 
63+  . then ( containerRef  =>  { 
64+  // TODO(tbosch): clean this up when we have custom renderers 
65+  // (https://github.com/angular/angular/issues/1807) 
66+  // TODO(jelbourn): Don't use direct DOM access. Need abstraction to create an element 
67+  // directly on the document body (also needed for web workers stuff). 
68+  // Create a DOM node to serve as a physical host element for the dialog. 
69+  var  dialogElement  =  this . domRenderer . getHostElement ( containerRef . hostView . render ) ; 
70+  DOM . appendChild ( DOM . query ( 'body' ) ,  dialogElement ) ; 
71+ 
72+  // TODO(jelbourn): Use hostProperties binding to set these once #1539 is fixed. 
73+  // Configure properties on the host element. 
74+  DOM . addClass ( dialogElement ,  'md-dialog' ) ; 
75+  DOM . setAttribute ( dialogElement ,  'tabindex' ,  '0' ) ; 
76+ 
77+  // TODO(jelbourn): Do this with hostProperties (or another rendering abstraction) once 
78+  // ready. 
79+  if  ( isPresent ( config . width ) )  { 
80+  DOM . setStyle ( dialogElement ,  'width' ,  config . width ) ; 
81+  } 
82+  if  ( isPresent ( config . height ) )  { 
83+  DOM . setStyle ( dialogElement ,  'height' ,  config . height ) ; 
84+  } 
85+ 
86+  dialogRef . containerRef  =  containerRef ; 
87+ 
88+  // Now load the given component into the MdDialogContainer. 
89+  return  this . componentLoader . loadNextToExistingLocation ( 
90+  type ,  containerRef . instance . contentRef ,  contentInjector ) 
91+  . then ( contentRef  =>  { 
92+ 
93+  // Wrap both component refs for the container and the content so that we can return 
94+  // the `instance` of the content but the dispose method of the container back to the 
95+  // opener. 
96+  dialogRef . contentRef  =  contentRef ; 
97+  containerRef . instance . dialogRef  =  dialogRef ; 
98+ 
99+  backdropRefPromise . then ( backdropRef  =>  { 
100+  dialogRef . whenClosed . then ( ( _ )  =>  {  backdropRef . dispose ( ) ;  } ) ; 
101+  } ) ; 
102+ 
103+  return  dialogRef ; 
104+  } ) ; 
98105 } ) ; 
99- 
100-  return  dialogRef ; 
101-  } ) ; 
102-  } ) ; 
103106 } 
104107
105108 /** Loads the dialog backdrop (transparent overlay over the rest of the page). */ 
106-  _openBackdrop ( elementRef :ElementRef ,  injector : Injector ) : Promise < ComponentRef >  { 
107-  return  this . componentLoader . loadIntoNewLocation ( 
108-  MdBackdrop ,  elementRef ,  injector ) . then (  ( componentRef )  =>  { 
109-  // TODO(tbosch): clean this up when we have custom renderers (https://github.com/angular/angular/issues/1807) 
110-  var  backdropElement  =  this . domRenderer . getHostElement ( componentRef . hostView . render ) ; 
111-  DOM . addClass ( backdropElement ,  'md-backdrop' ) ; 
112-  DOM . appendChild ( DOM . query ( 'body' ) ,  backdropElement ) ; 
113-  return  componentRef ; 
114-  } ) ; 
109+  _openBackdrop ( elementRef : ElementRef ,  injector : Injector ) : Promise < ComponentRef >  { 
110+  return  this . componentLoader . loadIntoNewLocation ( MdBackdrop ,  elementRef ,  injector ) 
111+  . then ( ( componentRef )  =>  { 
112+  // TODO(tbosch): clean this up when we have custom renderers 
113+  // (https://github.com/angular/angular/issues/1807) 
114+  var  backdropElement  =  this . domRenderer . getHostElement ( componentRef . hostView . render ) ; 
115+  DOM . addClass ( backdropElement ,  'md-backdrop' ) ; 
116+  DOM . appendChild ( DOM . query ( 'body' ) ,  backdropElement ) ; 
117+  return  componentRef ; 
118+  } ) ; 
115119 } 
116120
117121 alert ( message : string ,  okMessage : string ) : Promise  { 
@@ -163,8 +167,10 @@ export class MdDialogRef {
163167 return  this . _contentRef . instance ; 
164168 } 
165169
166-  // The only time one could attempt to access this property before the value is set is if an access occurs during 
167-  // the constructor of the very instance they are trying to get (which is much more easily accessed as `this`). 
170+  // The only time one could attempt to access this property before the value is set is if an 
171+  // access occurs during 
172+  // the constructor of the very instance they are trying to get (which is much more easily 
173+  // accessed as `this`). 
168174 throw  "Cannot access dialog component instance *from* that component's constructor." ; 
169175 } 
170176
@@ -203,13 +209,11 @@ export class MdDialogConfig {
203209 */ 
204210@Component ( { 
205211 selector : 'md-dialog-container' , 
206-  hostListeners : { 
207-  'body:^keydown' : 'documentKeypress($event)' 
208-  } 
212+  hostListeners : { 'body:^keydown' : 'documentKeypress($event)' } , 
209213} ) 
210214@View ( { 
211215 templateUrl : 'angular2_material/src/components/dialog/dialog.html' , 
212-  directives : [ MdDialogContent ] 
216+  directives : [ FORWARD_REF ( ( )   =>   MdDialogContent ) ] 
213217} ) 
214218class  MdDialogContainer  { 
215219 // Ref to the dialog content. Used by the DynamicComponentLoader to load the dialog content. 
@@ -234,13 +238,22 @@ class MdDialogContainer {
234238 } 
235239} 
236240
241+ /** 
242+  * Simple decorator used only to communicate an ElementRef to the parent MdDialogContainer as the 
243+  * location 
244+  * for where the dialog content will be loaded. 
245+  */ 
246+ @Directive ( { selector : 'md-dialog-content' } ) 
247+ class  MdDialogContent  { 
248+  constructor ( @Parent ( )  dialogContainer : MdDialogContainer ,  elementRef : ElementRef )  { 
249+  dialogContainer . contentRef  =  elementRef ; 
250+  } 
251+ } 
237252
238253/** Component for the dialog "backdrop", a transparent overlay over the rest of the page. */ 
239254@Component ( { 
240255 selector : 'md-backdrop' , 
241-  hostListeners : { 
242-  'click' : 'onClick()' 
243-  } 
256+  hostListeners : { 'click' : 'onClick()' } , 
244257} ) 
245258@View ( { template : '' } ) 
246259class  MdBackdrop  { 
@@ -256,15 +269,3 @@ class MdBackdrop {
256269 this . dialogRef . close ( ) ; 
257270 } 
258271} 
259- 
260- 
261- /** 
262-  * Simple decorator used only to communicate an ElementRef to the parent MdDialogContainer as the location 
263-  * for where the dialog content will be loaded. 
264-  */ 
265- @Directive ( { selector : 'md-dialog-content' } ) 
266- class  MdDialogContent  { 
267-  constructor ( @Parent ( )  dialogContainer : MdDialogContainer ,  elementRef : ElementRef )  { 
268-  dialogContainer . contentRef  =  elementRef ; 
269-  } 
270- } 
0 commit comments