@@ -155,7 +155,8 @@ angular
155
155
* @param {Object= } opt_config Specific configuration object that may contain
156
156
* the properties defined in `$mdPanel.create`.
157
157
*
158
- * @returns {MdPanelRef } panelRef
158
+ * @returns {angular.$q.Promise<MdPanelRef> } panelRef A promise that resolves
159
+ * to an instance of the panel.
159
160
*/
160
161
161
162
@@ -245,7 +246,7 @@ angular
245
246
246
247
/**
247
248
* @ngdoc method
248
- * @name MdPanelRef#attachOnly
249
+ * @name MdPanelRef#attach
249
250
* @description
250
251
* Create the panel elements and attach them to the DOM. The panel will be
251
252
* hidden by default.
@@ -258,7 +259,7 @@ angular
258
259
* @ngdoc method
259
260
* @name MdPanelRef#detach
260
261
* @description
261
- * Removes the panel from the DOM. This will hide the panel before removing it.
262
+ * Removes the panel from the DOM. This will NOT hide the panel before removing it.
262
263
*
263
264
* @returns {!angular.$q.Promise } A promise that is resolved when the panel is
264
265
* detached.
@@ -612,26 +613,23 @@ function MdPanelService($rootElement, $rootScope, $injector) {
612
613
focusOnOpen : true ,
613
614
fullscreen : false ,
614
615
hasBackdrop : false ,
615
- transformTemplate : angular . bind ( this , this . wrapTemplate_ ) ,
616
+ transformTemplate : angular . bind ( this , this . _wrapTemplate ) ,
616
617
trapFocus : false ,
617
618
zIndex : defaultZIndex
618
619
} ;
619
620
620
- /** @private {!angular.Scope} */
621
- this . _$rootScope = $rootScope ;
622
-
623
621
/** @private {!Object} */
624
622
this . _config = { } ;
625
623
626
- /** @private {!angular.$injector} */
627
- this . _$injector = $injector ;
628
-
629
- /** @private {!angular.$injector} */
624
+ /** @private @const */
630
625
this . _$rootScope = $rootScope ;
631
626
632
- /** @private {!angular.JQLite} */
627
+ /** @private @const */
633
628
this . _$rootElement = $rootElement ;
634
629
630
+ /** @private @const */
631
+ this . _$injector = $injector ;
632
+
635
633
/**
636
634
* Default animations that can be used within the panel.
637
635
* @type {enum }
@@ -678,33 +676,13 @@ MdPanelService.prototype.create = function(opt_config) {
678
676
/**
679
677
* Creates and opens a panel with the specified options.
680
678
* @param {!Object= } opt_config Configuration object for the panel.
681
- * @returns {!MdPanelRef } The panel created from create.
679
+ * @returns {!angular.$q.Promise< MdPanelRef> } The panel created from create.
682
680
*/
683
681
MdPanelService . prototype . open = function ( opt_config ) {
684
682
var panelRef = this . create ( opt_config ) ;
685
- panelRef . open ( ) ;
686
- return panelRef ;
687
- } ;
688
-
689
-
690
- /**
691
- * Wraps the users template in two elements, md-panel-container, which covers
692
- * the entire attachTo element, and md-panel, which contains only the
693
- * template. This allows the panel control over positioning, animations,
694
- * and similar properties.
695
- *
696
- * @param {string } origTemplate The original template.
697
- * @returns {string } The wrapped template.
698
- * @private
699
- */
700
- MdPanelService . prototype . wrapTemplate_ = function ( origTemplate ) {
701
- var template = origTemplate || '' ;
702
-
703
- return '<div class="md-panel-outer-wrapper">' +
704
- '<div class="md-panel">' +
705
- template +
706
- '</div>' +
707
- '</div>' ;
683
+ return panelRef . open ( ) . then ( function ( ) {
684
+ return panelRef ;
685
+ } ) ;
708
686
} ;
709
687
710
688
@@ -730,6 +708,25 @@ MdPanelService.prototype.newPanelAnimation = function() {
730
708
} ;
731
709
732
710
711
+ /**
712
+ * Wraps the users template in two elements, md-panel-outer-wrapper, which
713
+ * covers the entire attachTo element, and md-panel, which contains only the
714
+ * template. This allows the panel control over positioning, animations,
715
+ * and similar properties.
716
+ *
717
+ * @param {string } origTemplate The original template.
718
+ * @returns {string } The wrapped template.
719
+ * @private
720
+ */
721
+ MdPanelService . prototype . _wrapTemplate = function ( origTemplate ) {
722
+ var template = origTemplate || '' ;
723
+
724
+ return '' +
725
+ '<div class="md-panel-outer-wrapper">' +
726
+ ' <div class="md-panel">' + template + '</div>' +
727
+ '</div>' ;
728
+ } ;
729
+
733
730
/*****************************************************************************
734
731
* MdPanelRef *
735
732
*****************************************************************************/
@@ -828,8 +825,8 @@ function MdPanelRef(config, $injector) {
828
825
* Opens an already created and configured panel. If the panel is already
829
826
* visible, does nothing.
830
827
*
831
- * @returns {!angular.$q.Promise } A promise that is resolved when the panel
832
- * is opened and animations finish.
828
+ * @returns {!angular.$q.Promise<MdPanelRef> } A promise that is resolved when
829
+ * the panel is opened and animations finish.
833
830
*/
834
831
MdPanelRef . prototype . open = function ( ) {
835
832
if ( this . _openPromise ) {
@@ -841,9 +838,12 @@ MdPanelRef.prototype.open = function() {
841
838
// TODO(ErinCoughlan) - Cancel any in-progress actions.
842
839
843
840
var self = this ;
844
- this . _openPromise = this . attachOnly ( )
841
+ this . _openPromise = this . attach ( )
845
842
. then ( function ( ) {
846
843
return self . show ( ) ;
844
+ } , this . _$q . reject )
845
+ . then ( function ( ) {
846
+ return self ; // Return a reference to the MdPanelRef.
847
847
} , this . _$q . reject ) ;
848
848
849
849
return this . _openPromise ;
@@ -877,10 +877,10 @@ MdPanelRef.prototype.close = function() {
877
877
/**
878
878
* Attaches the panel. The panel will be hidden afterwards.
879
879
*
880
- * @returns {!angular.$q.Promise } A promise that is resolved when the panel is
881
- * attached.
880
+ * @returns {!angular.$q.Promise<MdPanelRef> } A promise that is resolved when
881
+ * the panel is attached.
882
882
*/
883
- MdPanelRef . prototype . attachOnly = function ( ) {
883
+ MdPanelRef . prototype . attach = function ( ) {
884
884
if ( this . isAttached ) {
885
885
return this . _attachPromise ;
886
886
}
@@ -903,7 +903,7 @@ MdPanelRef.prototype.attachOnly = function() {
903
903
904
904
905
905
/**
906
- * Detaches the panel. Will hide the panel first if visible .
906
+ * Only detaches the panel. Will NOT hide the panel first.
907
907
*
908
908
* @returns {!angular.$q.Promise } A promise that is resolved when the panel is
909
909
* detached.
@@ -935,12 +935,10 @@ MdPanelRef.prototype.detach = function() {
935
935
return self . _$q . resolve ( self ) ;
936
936
} ;
937
937
938
- this . _detachPromise = this . hide ( ) . then ( function ( ) {
939
- return self . _$q . all ( [
940
- detachFn ( ) ,
941
- self . _backdropRef ? self . _backdropRef . detach ( ) : self . _$q . resolve ( self )
942
- ] ) ;
943
- } , this . _$q . reject ) ;
938
+ this . _detachPromise = self . _$q . all ( [
939
+ detachFn ( ) ,
940
+ self . _backdropRef ? self . _backdropRef . detach ( ) : self . _$q . resolve ( self )
941
+ ] ) ;
944
942
945
943
return this . _detachPromise ;
946
944
} ;
@@ -969,7 +967,7 @@ MdPanelRef.prototype.show = function() {
969
967
var animatePromise = function ( ) {
970
968
self . removeClass ( MD_PANEL_HIDDEN ) ;
971
969
return self . _animateOpen ( ) ;
972
- }
970
+ } ;
973
971
974
972
this . _showPromise = this . _$q . all ( [
975
973
this . _backdropRef ? this . _backdropRef . show ( ) : this . _$q . resolve ( self ) ,
@@ -1084,7 +1082,7 @@ MdPanelRef.prototype._createPanel = function() {
1084
1082
self . _config . locals = { } ;
1085
1083
}
1086
1084
self . _config . locals . mdPanelRef = self ;
1087
- self . _$mdCompiler . compile ( self . _config )
1085
+ return self . _$mdCompiler . compile ( self . _config )
1088
1086
. then ( function ( compileData ) {
1089
1087
self . _panelContainer = compileData . link ( self . _config [ 'scope' ] ) ;
1090
1088
getElement ( self . _config [ 'attachTo' ] ) . append ( self . _panelContainer ) ;
@@ -1104,16 +1102,19 @@ MdPanelRef.prototype._createPanel = function() {
1104
1102
getElement ( self . _config [ 'attachTo' ] ) ) ;
1105
1103
}
1106
1104
1107
- self . _addStyles ( ) ;
1108
1105
self . _configureTrapFocus ( ) ;
1109
- return resolve ( self ) ;
1106
+ return self . _addStyles ( ) . then ( function ( ) {
1107
+ self . _panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
1108
+ resolve ( self ) ;
1109
+ } , reject ) ;
1110
1110
} , reject ) ;
1111
1111
} ) ;
1112
1112
} ;
1113
1113
1114
1114
1115
1115
/**
1116
1116
* Adds the styles for the panel, such as positioning and z-index.
1117
+ * @return {!angular.$q.Promise }
1117
1118
* @private
1118
1119
*/
1119
1120
MdPanelRef . prototype . _addStyles = function ( ) {
@@ -1123,34 +1124,42 @@ MdPanelRef.prototype._addStyles = function() {
1123
1124
1124
1125
if ( this . _config [ 'fullscreen' ] ) {
1125
1126
this . _panelEl . addClass ( '_md-panel-fullscreen' ) ;
1126
- return ; // Don't setup positioning.
1127
+ return this . _$q . resolve ( this ) ; // Don't setup positioning.
1127
1128
}
1128
1129
1129
- // Wait for angular to finish processing the template, then position it
1130
- // correctly. This is necessary so that the panel will have a defined height
1131
- // and width.
1132
- this . _$rootScope [ '$$postDigest' ] ( angular . bind ( this , this . _configurePosition ) ) ;
1133
- this . _panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
1130
+ return this . _configurePosition ( ) ;
1134
1131
} ;
1135
1132
1136
1133
1137
1134
/**
1138
1135
* Configure the position of the panel.
1136
+ * @return {!angular.$q.Promise }
1139
1137
* @private
1140
1138
*/
1141
1139
MdPanelRef . prototype . _configurePosition = function ( ) {
1142
1140
var positionConfig = this . _config [ 'position' ] ;
1141
+ if ( ! positionConfig ) {
1142
+ return this . _$q . resolve ( this ) ;
1143
+ }
1143
1144
1144
- if ( ! positionConfig ) { return ; }
1145
-
1146
- this . _panelEl . css ( 'top' , positionConfig . getTop ( this . _panelEl ) ) ;
1147
- this . _panelEl . css ( 'bottom' , positionConfig . getBottom ( this . _panelEl ) ) ;
1148
- this . _panelEl . css ( 'left' , positionConfig . getLeft ( this . _panelEl ) ) ;
1149
- this . _panelEl . css ( 'right' , positionConfig . getRight ( this . _panelEl ) ) ;
1145
+ var self = this ;
1146
+ return this . _$q ( function ( resolve ) {
1147
+ // Wait for angular to finish processing the template, then position it
1148
+ // correctly. This is necessary so that the panel will have a defined
1149
+ // height and width.
1150
+ return self . _$rootScope [ '$$postDigest' ] ( function ( ) {
1151
+ self . _panelEl . css ( 'top' , positionConfig . getTop ( self . _panelEl ) ) ;
1152
+ self . _panelEl . css ( 'bottom' , positionConfig . getBottom ( self . _panelEl ) ) ;
1153
+ self . _panelEl . css ( 'left' , positionConfig . getLeft ( self . _panelEl ) ) ;
1154
+ self . _panelEl . css ( 'right' , positionConfig . getRight ( self . _panelEl ) ) ;
1155
+
1156
+ // Use the vendor prefixed version of transform.
1157
+ var prefixedTransform = self . _$mdConstant . CSS . TRANSFORM ;
1158
+ self . _panelEl . css ( prefixedTransform , positionConfig . getTransform ( ) ) ;
1150
1159
1151
- // Use the vendor prefixed version of transform.
1152
- var prefixedTransform = this . _$mdConstant . CSS . TRANSFORM ;
1153
- this . _panelEl . css ( prefixedTransform , positionConfig . getTransform ( ) ) ;
1160
+ return resolve ( self ) ;
1161
+ } ) ;
1162
+ } ) ;
1154
1163
} ;
1155
1164
1156
1165
@@ -1195,7 +1204,7 @@ MdPanelRef.prototype._createBackdrop = function() {
1195
1204
zIndex : this . _config . zIndex - 1
1196
1205
}
1197
1206
this . _backdropRef = this . _$mdPanel . create ( backdropConfig ) ;
1198
- return this . _backdropRef . attachOnly ( ) ;
1207
+ return this . _backdropRef . attach ( ) ;
1199
1208
}
1200
1209
return this . _$q . resolve ( ) ;
1201
1210
} ;
@@ -1362,7 +1371,7 @@ MdPanelRef.prototype._animateClose = function() {
1362
1371
1363
1372
var self = this ;
1364
1373
return this . _$q ( function ( resolve , reject ) {
1365
- animationConfig . animateClose ( self . _$q ) . then ( function ( ) {
1374
+ animationConfig . animateClose ( self . _$q ) . then ( function ( ) {
1366
1375
self . removeClass ( 'md-panel-is-showing' ) ;
1367
1376
return resolve ( self ) ;
1368
1377
} , reject ) ;
@@ -2014,7 +2023,7 @@ MdPanelAnimation.prototype.animateOpen = function(panelEl, animator) {
2014
2023
2015
2024
/**
2016
2025
* Animate the panel close.
2017
- * @param $q
2026
+ * @param { !angular.$q } $q
2018
2027
* @returns {!angular.$q.Promise }
2019
2028
*/
2020
2029
MdPanelAnimation . prototype . animateClose = function ( $q ) {
0 commit comments