@@ -1304,10 +1304,10 @@ MdPanelService.prototype._closeFirstOpenedPanel = function(groupName) {
1304
1304
1305
1305
1306
1306
/**
1307
- * Wraps the users template in two elements, md-panel-outer-wrapper, which
1308
- * covers the entire attachTo element, and md-panel, which contains only the
1309
- * template. This allows the panel control over positioning, animations,
1310
- * and similar properties .
1307
+ * Wraps the user's template in three elements:
1308
+ * - md-panel-outer-wrapper - covers the entire ` attachTo` element.
1309
+ * - md- panel-inner-wrapper - handles the positioning.
1310
+ * - md-panel - contains the user's content and deals with the animations .
1311
1311
* @param {string } origTemplate The original template.
1312
1312
* @returns {string } The wrapped template.
1313
1313
* @private
@@ -1319,26 +1319,32 @@ MdPanelService.prototype._wrapTemplate = function(origTemplate) {
1319
1319
// height and width for positioning.
1320
1320
return '' +
1321
1321
'<div class="md-panel-outer-wrapper">' +
1322
- ' <div class="md-panel _md-panel-offscreen">' + template + '</div>' +
1322
+ '<div class="md-panel-inner-wrapper" style="left: -9999px;">' +
1323
+ '<div class="md-panel _md-panel-offscreen">' + template + '</div>' +
1324
+ '</div>' +
1323
1325
'</div>' ;
1324
1326
} ;
1325
1327
1326
1328
1327
1329
/**
1328
- * Wraps a content element in a md-panel-outer wrapper and
1329
- * positions it off-screen. Allows for proper control over positoning
1330
- * and animations.
1330
+ * Wraps a content element in a ` md-panel-outer- wrapper`, as well as
1331
+ * a `md-panel-inner-wrapper`, and positions it off-screen. Allows for
1332
+ * proper control over positoning and animations.
1331
1333
* @param {!angular.JQLite } contentElement Element to be wrapped.
1332
1334
* @return {!angular.JQLite } Wrapper element.
1333
1335
* @private
1334
1336
*/
1335
1337
MdPanelService . prototype . _wrapContentElement = function ( contentElement ) {
1336
- var wrapper = angular . element ( '<div class="md-panel-outer-wrapper">' ) ;
1338
+ var outerWrapper = angular . element (
1339
+ '<div class="md-panel-outer-wrapper">' +
1340
+ '<div class="md-panel-inner-wrapper" style="left: -9999px;"></div>' +
1341
+ '</div>'
1342
+ ) ;
1337
1343
1338
1344
contentElement . addClass ( 'md-panel _md-panel-offscreen' ) ;
1339
- wrapper . append ( contentElement ) ;
1345
+ outerWrapper . children ( ) . eq ( 0 ) . append ( contentElement ) ;
1340
1346
1341
- return wrapper ;
1347
+ return outerWrapper ;
1342
1348
} ;
1343
1349
1344
1350
@@ -1405,6 +1411,9 @@ function MdPanelRef(config, $injector) {
1405
1411
/** @type {!angular.JQLite|undefined } */
1406
1412
this . panelEl ;
1407
1413
1414
+ /** @type {!angular.JQLite|undefined } */
1415
+ this . innerWrapper ;
1416
+
1408
1417
/**
1409
1418
* Whether the panel is attached. This is synchronous. When attach is called,
1410
1419
* isAttached is set to true. When detach is called, isAttached is set to
@@ -1851,6 +1860,11 @@ MdPanelRef.prototype._compile = function() {
1851
1860
) ;
1852
1861
}
1853
1862
1863
+ // Save a reference to the inner wrapper.
1864
+ self . innerWrapper = angular . element (
1865
+ self . panelContainer [ 0 ] . querySelector ( '.md-panel-inner-wrapper' )
1866
+ ) ;
1867
+
1854
1868
// Save a reference to the cleanup function from the compiler.
1855
1869
self . _compilerCleanup = compileData . cleanup ;
1856
1870
@@ -1927,14 +1941,17 @@ MdPanelRef.prototype._addStyles = function() {
1927
1941
var self = this ;
1928
1942
return this . _$q ( function ( resolve ) {
1929
1943
self . panelContainer . css ( 'z-index' , self . config [ 'zIndex' ] ) ;
1930
- self . panelEl . css ( 'z-index' , self . config [ 'zIndex' ] + 1 ) ;
1944
+ self . innerWrapper . css ( 'z-index' , self . config [ 'zIndex' ] + 1 ) ;
1931
1945
1932
1946
var hideAndResolve = function ( ) {
1933
1947
// Theme the element and container.
1934
1948
self . _setTheming ( ) ;
1935
1949
1936
1950
// Remove offscreen class and add hidden class.
1937
1951
self . panelEl . removeClass ( '_md-panel-offscreen' ) ;
1952
+
1953
+ // Remove left: -9999px and add hidden class.
1954
+ self . innerWrapper . css ( 'left' , '' ) ;
1938
1955
self . panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
1939
1956
1940
1957
resolve ( self ) ;
@@ -2001,27 +2018,27 @@ MdPanelRef.prototype._updatePosition = function(init) {
2001
2018
var positionConfig = this . config [ 'position' ] ;
2002
2019
2003
2020
if ( positionConfig ) {
2004
- positionConfig . _setPanelPosition ( this . panelEl ) ;
2021
+ positionConfig . _setPanelPosition ( this . innerWrapper ) ;
2005
2022
2006
2023
// Hide the panel now that position is known.
2007
2024
if ( init ) {
2008
2025
this . panelEl . removeClass ( '_md-panel-offscreen' ) ;
2009
2026
this . panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
2010
2027
}
2011
2028
2012
- this . panelEl . css (
2029
+ this . innerWrapper . css (
2013
2030
MdPanelPosition . absPosition . TOP ,
2014
2031
positionConfig . getTop ( )
2015
2032
) ;
2016
- this . panelEl . css (
2033
+ this . innerWrapper . css (
2017
2034
MdPanelPosition . absPosition . BOTTOM ,
2018
2035
positionConfig . getBottom ( )
2019
2036
) ;
2020
- this . panelEl . css (
2037
+ this . innerWrapper . css (
2021
2038
MdPanelPosition . absPosition . LEFT ,
2022
2039
positionConfig . getLeft ( )
2023
2040
) ;
2024
- this . panelEl . css (
2041
+ this . innerWrapper . css (
2025
2042
MdPanelPosition . absPosition . RIGHT ,
2026
2043
positionConfig . getRight ( )
2027
2044
) ;
@@ -2928,38 +2945,38 @@ MdPanelPosition.prototype.getTransform = function() {
2928
2945
2929
2946
2930
2947
/**
2931
- * Sets the `transform` value for a panel element.
2932
- * @param {!angular.JQLite } panelEl
2948
+ * Sets the `transform` value for an element.
2949
+ * @param {!angular.JQLite } el
2933
2950
* @returns {!angular.JQLite }
2934
2951
* @private
2935
2952
*/
2936
- MdPanelPosition . prototype . _setTransform = function ( panelEl ) {
2937
- return panelEl . css ( this . _$mdConstant . CSS . TRANSFORM , this . getTransform ( ) ) ;
2953
+ MdPanelPosition . prototype . _setTransform = function ( el ) {
2954
+ return el . css ( this . _$mdConstant . CSS . TRANSFORM , this . getTransform ( ) ) ;
2938
2955
} ;
2939
2956
2940
2957
2941
2958
/**
2942
2959
* True if the panel is completely on-screen with this positioning; false
2943
2960
* otherwise.
2944
- * @param {!angular.JQLite } panelEl
2961
+ * @param {!angular.JQLite } el
2945
2962
* @return {boolean }
2946
2963
* @private
2947
2964
*/
2948
- MdPanelPosition . prototype . _isOnscreen = function ( panelEl ) {
2965
+ MdPanelPosition . prototype . _isOnscreen = function ( el ) {
2949
2966
// this works because we always use fixed positioning for the panel,
2950
2967
// which is relative to the viewport.
2951
2968
var left = parseInt ( this . getLeft ( ) ) ;
2952
2969
var top = parseInt ( this . getTop ( ) ) ;
2953
2970
2954
2971
if ( this . _translateX . length || this . _translateY . length ) {
2955
2972
var prefixedTransform = this . _$mdConstant . CSS . TRANSFORM ;
2956
- var offsets = getComputedTranslations ( panelEl , prefixedTransform ) ;
2973
+ var offsets = getComputedTranslations ( el , prefixedTransform ) ;
2957
2974
left += offsets . x ;
2958
2975
top += offsets . y ;
2959
2976
}
2960
2977
2961
- var right = left + panelEl [ 0 ] . offsetWidth ;
2962
- var bottom = top + panelEl [ 0 ] . offsetHeight ;
2978
+ var right = left + el [ 0 ] . offsetWidth ;
2979
+ var bottom = top + el [ 0 ] . offsetHeight ;
2963
2980
2964
2981
return ( left >= 0 ) &&
2965
2982
( top >= 0 ) &&
@@ -2998,53 +3015,53 @@ MdPanelPosition.prototype._reduceTranslateValues =
2998
3015
/**
2999
3016
* Sets the panel position based on the created panel element and best x/y
3000
3017
* positioning.
3001
- * @param {!angular.JQLite } panelEl
3018
+ * @param {!angular.JQLite } el
3002
3019
* @private
3003
3020
*/
3004
- MdPanelPosition . prototype . _setPanelPosition = function ( panelEl ) {
3005
- // Remove the "position adjusted" class in case it has been added before.
3006
- panelEl . removeClass ( '_md-panel-position-adjusted' ) ;
3021
+ MdPanelPosition . prototype . _setPanelPosition = function ( el ) {
3022
+ // Remove the class in case it has been added before.
3023
+ el . removeClass ( '_md-panel-position-adjusted' ) ;
3007
3024
3008
3025
// Only calculate the position if necessary.
3009
3026
if ( this . _absolute ) {
3010
- this . _setTransform ( panelEl ) ;
3027
+ this . _setTransform ( el ) ;
3011
3028
return ;
3012
3029
}
3013
3030
3014
3031
if ( this . _actualPosition ) {
3015
- this . _calculatePanelPosition ( panelEl , this . _actualPosition ) ;
3016
- this . _setTransform ( panelEl ) ;
3017
- this . _constrainToViewport ( panelEl ) ;
3032
+ this . _calculatePanelPosition ( el , this . _actualPosition ) ;
3033
+ this . _setTransform ( el ) ;
3034
+ this . _constrainToViewport ( el ) ;
3018
3035
return ;
3019
3036
}
3020
3037
3021
3038
for ( var i = 0 ; i < this . _positions . length ; i ++ ) {
3022
3039
this . _actualPosition = this . _positions [ i ] ;
3023
- this . _calculatePanelPosition ( panelEl , this . _actualPosition ) ;
3024
- this . _setTransform ( panelEl ) ;
3040
+ this . _calculatePanelPosition ( el , this . _actualPosition ) ;
3041
+ this . _setTransform ( el ) ;
3025
3042
3026
- if ( this . _isOnscreen ( panelEl ) ) {
3043
+ if ( this . _isOnscreen ( el ) ) {
3027
3044
return ;
3028
3045
}
3029
3046
}
3030
3047
3031
- this . _constrainToViewport ( panelEl ) ;
3048
+ this . _constrainToViewport ( el ) ;
3032
3049
} ;
3033
3050
3034
3051
3035
3052
/**
3036
3053
* Constrains a panel's position to the viewport.
3037
- * @param {!angular.JQLite } panelEl
3054
+ * @param {!angular.JQLite } el
3038
3055
* @private
3039
3056
*/
3040
- MdPanelPosition . prototype . _constrainToViewport = function ( panelEl ) {
3057
+ MdPanelPosition . prototype . _constrainToViewport = function ( el ) {
3041
3058
var margin = MdPanelPosition . viewportMargin ;
3042
3059
var initialTop = this . _top ;
3043
3060
var initialLeft = this . _left ;
3044
3061
3045
3062
if ( this . getTop ( ) ) {
3046
3063
var top = parseInt ( this . getTop ( ) ) ;
3047
- var bottom = panelEl [ 0 ] . offsetHeight + top ;
3064
+ var bottom = el [ 0 ] . offsetHeight + top ;
3048
3065
var viewportHeight = this . _$window . innerHeight ;
3049
3066
3050
3067
if ( top < margin ) {
@@ -3056,7 +3073,7 @@ MdPanelPosition.prototype._constrainToViewport = function(panelEl) {
3056
3073
3057
3074
if ( this . getLeft ( ) ) {
3058
3075
var left = parseInt ( this . getLeft ( ) ) ;
3059
- var right = panelEl [ 0 ] . offsetWidth + left ;
3076
+ var right = el [ 0 ] . offsetWidth + left ;
3060
3077
var viewportWidth = this . _$window . innerWidth ;
3061
3078
3062
3079
if ( left < margin ) {
@@ -3067,7 +3084,7 @@ MdPanelPosition.prototype._constrainToViewport = function(panelEl) {
3067
3084
}
3068
3085
3069
3086
// Class that can be used to re-style the panel if it was repositioned.
3070
- panelEl . toggleClass (
3087
+ el . toggleClass (
3071
3088
'_md-panel-position-adjusted' ,
3072
3089
this . _top !== initialTop || this . _left !== initialLeft
3073
3090
) ;
@@ -3106,15 +3123,15 @@ MdPanelPosition.prototype._bidi = function(position) {
3106
3123
/**
3107
3124
* Calculates the panel position based on the created panel element and the
3108
3125
* provided positioning.
3109
- * @param {!angular.JQLite } panelEl
3126
+ * @param {!angular.JQLite } el
3110
3127
* @param {!{x:string, y:string} } position
3111
3128
* @private
3112
3129
*/
3113
- MdPanelPosition . prototype . _calculatePanelPosition = function ( panelEl , position ) {
3130
+ MdPanelPosition . prototype . _calculatePanelPosition = function ( el , position ) {
3114
3131
3115
- var panelBounds = panelEl [ 0 ] . getBoundingClientRect ( ) ;
3116
- var panelWidth = Math . max ( panelBounds . width , panelEl [ 0 ] . clientWidth ) ;
3117
- var panelHeight = Math . max ( panelBounds . height , panelEl [ 0 ] . clientHeight ) ;
3132
+ var panelBounds = el [ 0 ] . getBoundingClientRect ( ) ;
3133
+ var panelWidth = Math . max ( panelBounds . width , el [ 0 ] . clientWidth ) ;
3134
+ var panelHeight = Math . max ( panelBounds . height , el [ 0 ] . clientHeight ) ;
3118
3135
3119
3136
var targetBounds = this . _relativeToEl [ 0 ] . getBoundingClientRect ( ) ;
3120
3137
0 commit comments