@@ -1044,10 +1044,10 @@ MdPanelService.prototype._closeFirstOpenedPanel = function(groupName) {
1044
1044
1045
1045
1046
1046
/**
1047
- * Wraps the users template in two elements, md-panel-outer-wrapper, which
1048
- * covers the entire attachTo element, and md-panel, which contains only the
1049
- * template. This allows the panel control over positioning, animations,
1050
- * and similar properties .
1047
+ * Wraps the user's template in three elements:
1048
+ * - md-panel-outer-wrapper - covers the entire ` attachTo` element.
1049
+ * - md- panel-inner-wrapper - handles the positioning.
1050
+ * - md-panel - contains the user's content and deals with the animations .
1051
1051
* @param {string } origTemplate The original template.
1052
1052
* @returns {string } The wrapped template.
1053
1053
* @private
@@ -1059,26 +1059,32 @@ MdPanelService.prototype._wrapTemplate = function(origTemplate) {
1059
1059
// height and width for positioning.
1060
1060
return '' +
1061
1061
'<div class="md-panel-outer-wrapper">' +
1062
- ' <div class="md-panel" style="left: -9999px;">' + template + '</div>' +
1062
+ '<div class="md-panel-inner-wrapper" style="left: -9999px;">' +
1063
+ '<div class="md-panel">' + template + '</div>' +
1064
+ '</div>' +
1063
1065
'</div>' ;
1064
1066
} ;
1065
1067
1066
1068
1067
1069
/**
1068
- * Wraps a content element in a md-panel-outer wrapper and
1069
- * positions it off-screen. Allows for proper control over positoning
1070
- * and animations.
1070
+ * Wraps a content element in a ` md-panel-outer- wrapper`, as well as
1071
+ * a `md-panel-inner-wrapper`, and positions it off-screen. Allows for
1072
+ * proper control over positoning and animations.
1071
1073
* @param {!angular.JQLite } contentElement Element to be wrapped.
1072
1074
* @return {!angular.JQLite } Wrapper element.
1073
1075
* @private
1074
1076
*/
1075
1077
MdPanelService . prototype . _wrapContentElement = function ( contentElement ) {
1076
- var wrapper = angular . element ( '<div class="md-panel-outer-wrapper">' ) ;
1078
+ var outerWrapper = angular . element (
1079
+ '<div class="md-panel-outer-wrapper">' +
1080
+ '<div class="md-panel-inner-wrapper" style="left: -9999px;"></div>' +
1081
+ '</div>'
1082
+ ) ;
1077
1083
1078
- contentElement . addClass ( 'md-panel' ) . css ( 'left' , '-9999px' ) ;
1079
- wrapper . append ( contentElement ) ;
1084
+ contentElement . addClass ( 'md-panel' ) ;
1085
+ outerWrapper . children ( ) . eq ( 0 ) . append ( contentElement ) ;
1080
1086
1081
- return wrapper ;
1087
+ return outerWrapper ;
1082
1088
} ;
1083
1089
1084
1090
@@ -1145,6 +1151,9 @@ function MdPanelRef(config, $injector) {
1145
1151
/** @type {!angular.JQLite|undefined } */
1146
1152
this . panelEl ;
1147
1153
1154
+ /** @type {!angular.JQLite|undefined } */
1155
+ this . innerWrapper ;
1156
+
1148
1157
/**
1149
1158
* Whether the panel is attached. This is synchronous. When attach is called,
1150
1159
* isAttached is set to true. When detach is called, isAttached is set to
@@ -1587,6 +1596,11 @@ MdPanelRef.prototype._compile = function() {
1587
1596
) ;
1588
1597
}
1589
1598
1599
+ // Save a reference to the inner wrapper.
1600
+ self . innerWrapper = angular . element (
1601
+ self . panelContainer [ 0 ] . querySelector ( '.md-panel-inner-wrapper' )
1602
+ ) ;
1603
+
1590
1604
// Save a reference to the cleanup function from the compiler.
1591
1605
self . _compilerCleanup = compileData . cleanup ;
1592
1606
@@ -1662,14 +1676,14 @@ MdPanelRef.prototype._addStyles = function() {
1662
1676
var self = this ;
1663
1677
return this . _$q ( function ( resolve ) {
1664
1678
self . panelContainer . css ( 'z-index' , self . config [ 'zIndex' ] ) ;
1665
- self . panelEl . css ( 'z-index' , self . config [ 'zIndex' ] + 1 ) ;
1679
+ self . innerWrapper . css ( 'z-index' , self . config [ 'zIndex' ] + 1 ) ;
1666
1680
1667
1681
var hideAndResolve = function ( ) {
1668
1682
// Theme the element and container.
1669
1683
self . _setTheming ( ) ;
1670
1684
1671
1685
// Remove left: -9999px and add hidden class.
1672
- self . panelEl . css ( 'left' , '' ) ;
1686
+ self . innerWrapper . css ( 'left' , '' ) ;
1673
1687
self . panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
1674
1688
1675
1689
resolve ( self ) ;
@@ -1736,26 +1750,26 @@ MdPanelRef.prototype._updatePosition = function(init) {
1736
1750
var positionConfig = this . config [ 'position' ] ;
1737
1751
1738
1752
if ( positionConfig ) {
1739
- positionConfig . _setPanelPosition ( this . panelEl ) ;
1753
+ positionConfig . _setPanelPosition ( this . innerWrapper ) ;
1740
1754
1741
1755
// Hide the panel now that position is known.
1742
1756
if ( init ) {
1743
1757
this . panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
1744
1758
}
1745
1759
1746
- this . panelEl . css (
1760
+ this . innerWrapper . css (
1747
1761
MdPanelPosition . absPosition . TOP ,
1748
1762
positionConfig . getTop ( )
1749
1763
) ;
1750
- this . panelEl . css (
1764
+ this . innerWrapper . css (
1751
1765
MdPanelPosition . absPosition . BOTTOM ,
1752
1766
positionConfig . getBottom ( )
1753
1767
) ;
1754
- this . panelEl . css (
1768
+ this . innerWrapper . css (
1755
1769
MdPanelPosition . absPosition . LEFT ,
1756
1770
positionConfig . getLeft ( )
1757
1771
) ;
1758
- this . panelEl . css (
1772
+ this . innerWrapper . css (
1759
1773
MdPanelPosition . absPosition . RIGHT ,
1760
1774
positionConfig . getRight ( )
1761
1775
) ;
@@ -2662,38 +2676,38 @@ MdPanelPosition.prototype.getTransform = function() {
2662
2676
2663
2677
2664
2678
/**
2665
- * Sets the `transform` value for a panel element.
2666
- * @param {!angular.JQLite } panelEl
2679
+ * Sets the `transform` value for an element.
2680
+ * @param {!angular.JQLite } el
2667
2681
* @returns {!angular.JQLite }
2668
2682
* @private
2669
2683
*/
2670
- MdPanelPosition . prototype . _setTransform = function ( panelEl ) {
2671
- return panelEl . css ( this . _$mdConstant . CSS . TRANSFORM , this . getTransform ( ) ) ;
2684
+ MdPanelPosition . prototype . _setTransform = function ( el ) {
2685
+ return el . css ( this . _$mdConstant . CSS . TRANSFORM , this . getTransform ( ) ) ;
2672
2686
} ;
2673
2687
2674
2688
2675
2689
/**
2676
2690
* True if the panel is completely on-screen with this positioning; false
2677
2691
* otherwise.
2678
- * @param {!angular.JQLite } panelEl
2692
+ * @param {!angular.JQLite } el
2679
2693
* @return {boolean }
2680
2694
* @private
2681
2695
*/
2682
- MdPanelPosition . prototype . _isOnscreen = function ( panelEl ) {
2696
+ MdPanelPosition . prototype . _isOnscreen = function ( el ) {
2683
2697
// this works because we always use fixed positioning for the panel,
2684
2698
// which is relative to the viewport.
2685
2699
var left = parseInt ( this . getLeft ( ) ) ;
2686
2700
var top = parseInt ( this . getTop ( ) ) ;
2687
2701
2688
2702
if ( this . _translateX . length || this . _translateY . length ) {
2689
2703
var prefixedTransform = this . _$mdConstant . CSS . TRANSFORM ;
2690
- var offsets = getComputedTranslations ( panelEl , prefixedTransform ) ;
2704
+ var offsets = getComputedTranslations ( el , prefixedTransform ) ;
2691
2705
left += offsets . x ;
2692
2706
top += offsets . y ;
2693
2707
}
2694
2708
2695
- var right = left + panelEl [ 0 ] . offsetWidth ;
2696
- var bottom = top + panelEl [ 0 ] . offsetHeight ;
2709
+ var right = left + el [ 0 ] . offsetWidth ;
2710
+ var bottom = top + el [ 0 ] . offsetHeight ;
2697
2711
2698
2712
return ( left >= 0 ) &&
2699
2713
( top >= 0 ) &&
@@ -2733,53 +2747,53 @@ MdPanelPosition.prototype._reduceTranslateValues =
2733
2747
/**
2734
2748
* Sets the panel position based on the created panel element and best x/y
2735
2749
* positioning.
2736
- * @param {!angular.JQLite } panelEl
2750
+ * @param {!angular.JQLite } el
2737
2751
* @private
2738
2752
*/
2739
- MdPanelPosition . prototype . _setPanelPosition = function ( panelEl ) {
2740
- // Remove the "position adjusted" class in case it has been added before.
2741
- panelEl . removeClass ( '_md-panel-position-adjusted' ) ;
2753
+ MdPanelPosition . prototype . _setPanelPosition = function ( el ) {
2754
+ // Remove the class in case it has been added before.
2755
+ el . removeClass ( '_md-panel-position-adjusted' ) ;
2742
2756
2743
2757
// Only calculate the position if necessary.
2744
2758
if ( this . _absolute ) {
2745
- this . _setTransform ( panelEl ) ;
2759
+ this . _setTransform ( el ) ;
2746
2760
return ;
2747
2761
}
2748
2762
2749
2763
if ( this . _actualPosition ) {
2750
- this . _calculatePanelPosition ( panelEl , this . _actualPosition ) ;
2751
- this . _setTransform ( panelEl ) ;
2752
- this . _constrainToViewport ( panelEl ) ;
2764
+ this . _calculatePanelPosition ( el , this . _actualPosition ) ;
2765
+ this . _setTransform ( el ) ;
2766
+ this . _constrainToViewport ( el ) ;
2753
2767
return ;
2754
2768
}
2755
2769
2756
2770
for ( var i = 0 ; i < this . _positions . length ; i ++ ) {
2757
2771
this . _actualPosition = this . _positions [ i ] ;
2758
- this . _calculatePanelPosition ( panelEl , this . _actualPosition ) ;
2759
- this . _setTransform ( panelEl ) ;
2772
+ this . _calculatePanelPosition ( el , this . _actualPosition ) ;
2773
+ this . _setTransform ( el ) ;
2760
2774
2761
- if ( this . _isOnscreen ( panelEl ) ) {
2775
+ if ( this . _isOnscreen ( el ) ) {
2762
2776
return ;
2763
2777
}
2764
2778
}
2765
2779
2766
- this . _constrainToViewport ( panelEl ) ;
2780
+ this . _constrainToViewport ( el ) ;
2767
2781
} ;
2768
2782
2769
2783
2770
2784
/**
2771
2785
* Constrains a panel's position to the viewport.
2772
- * @param {!angular.JQLite } panelEl
2786
+ * @param {!angular.JQLite } el
2773
2787
* @private
2774
2788
*/
2775
- MdPanelPosition . prototype . _constrainToViewport = function ( panelEl ) {
2789
+ MdPanelPosition . prototype . _constrainToViewport = function ( el ) {
2776
2790
var margin = MdPanelPosition . viewportMargin ;
2777
2791
var initialTop = this . _top ;
2778
2792
var initialLeft = this . _left ;
2779
2793
2780
2794
if ( this . getTop ( ) ) {
2781
2795
var top = parseInt ( this . getTop ( ) ) ;
2782
- var bottom = panelEl [ 0 ] . offsetHeight + top ;
2796
+ var bottom = el [ 0 ] . offsetHeight + top ;
2783
2797
var viewportHeight = this . _$window . innerHeight ;
2784
2798
2785
2799
if ( top < margin ) {
@@ -2791,7 +2805,7 @@ MdPanelPosition.prototype._constrainToViewport = function(panelEl) {
2791
2805
2792
2806
if ( this . getLeft ( ) ) {
2793
2807
var left = parseInt ( this . getLeft ( ) ) ;
2794
- var right = panelEl [ 0 ] . offsetWidth + left ;
2808
+ var right = el [ 0 ] . offsetWidth + left ;
2795
2809
var viewportWidth = this . _$window . innerWidth ;
2796
2810
2797
2811
if ( left < margin ) {
@@ -2802,7 +2816,7 @@ MdPanelPosition.prototype._constrainToViewport = function(panelEl) {
2802
2816
}
2803
2817
2804
2818
// Class that can be used to re-style the panel if it was repositioned.
2805
- panelEl . toggleClass (
2819
+ el . toggleClass (
2806
2820
'_md-panel-position-adjusted' ,
2807
2821
this . _top !== initialTop || this . _left !== initialLeft
2808
2822
) ;
@@ -2841,13 +2855,13 @@ MdPanelPosition.prototype._bidi = function(position) {
2841
2855
/**
2842
2856
* Calculates the panel position based on the created panel element and the
2843
2857
* provided positioning.
2844
- * @param {!angular.JQLite } panelEl
2858
+ * @param {!angular.JQLite } el
2845
2859
* @param {!{x:string, y:string} } position
2846
2860
* @private
2847
2861
*/
2848
- MdPanelPosition . prototype . _calculatePanelPosition = function ( panelEl , position ) {
2862
+ MdPanelPosition . prototype . _calculatePanelPosition = function ( el , position ) {
2849
2863
2850
- var panelBounds = panelEl [ 0 ] . getBoundingClientRect ( ) ;
2864
+ var panelBounds = el [ 0 ] . getBoundingClientRect ( ) ;
2851
2865
var panelWidth = panelBounds . width ;
2852
2866
var panelHeight = panelBounds . height ;
2853
2867
0 commit comments