@@ -1306,10 +1306,10 @@ MdPanelService.prototype._closeFirstOpenedPanel = function(groupName) {
1306
1306
1307
1307
1308
1308
/**
1309
- * Wraps the users template in two elements, md-panel-outer-wrapper, which
1310
- * covers the entire attachTo element, and md-panel, which contains only the
1311
- * template. This allows the panel control over positioning, animations,
1312
- * and similar properties .
1309
+ * Wraps the user's template in three elements:
1310
+ * - md-panel-outer-wrapper - covers the entire ` attachTo` element.
1311
+ * - md- panel-inner-wrapper - handles the positioning.
1312
+ * - md-panel - contains the user's content and deals with the animations .
1313
1313
* @param {string } origTemplate The original template.
1314
1314
* @returns {string } The wrapped template.
1315
1315
* @private
@@ -1321,26 +1321,32 @@ MdPanelService.prototype._wrapTemplate = function(origTemplate) {
1321
1321
// height and width for positioning.
1322
1322
return '' +
1323
1323
'<div class="md-panel-outer-wrapper">' +
1324
- ' <div class="md-panel _md-panel-offscreen">' + template + '</div>' +
1324
+ '<div class="md-panel-inner-wrapper" style="left: -9999px;">' +
1325
+ '<div class="md-panel _md-panel-offscreen">' + template + '</div>' +
1326
+ '</div>' +
1325
1327
'</div>' ;
1326
1328
} ;
1327
1329
1328
1330
1329
1331
/**
1330
- * Wraps a content element in a md-panel-outer wrapper and
1331
- * positions it off-screen. Allows for proper control over positoning
1332
- * and animations.
1332
+ * Wraps a content element in a ` md-panel-outer- wrapper`, as well as
1333
+ * a `md-panel-inner-wrapper`, and positions it off-screen. Allows for
1334
+ * proper control over positoning and animations.
1333
1335
* @param {!angular.JQLite } contentElement Element to be wrapped.
1334
1336
* @return {!angular.JQLite } Wrapper element.
1335
1337
* @private
1336
1338
*/
1337
1339
MdPanelService . prototype . _wrapContentElement = function ( contentElement ) {
1338
- var wrapper = angular . element ( '<div class="md-panel-outer-wrapper">' ) ;
1340
+ var outerWrapper = angular . element (
1341
+ '<div class="md-panel-outer-wrapper">' +
1342
+ '<div class="md-panel-inner-wrapper" style="left: -9999px;"></div>' +
1343
+ '</div>'
1344
+ ) ;
1339
1345
1340
1346
contentElement . addClass ( 'md-panel _md-panel-offscreen' ) ;
1341
- wrapper . append ( contentElement ) ;
1347
+ outerWrapper . children ( ) . eq ( 0 ) . append ( contentElement ) ;
1342
1348
1343
- return wrapper ;
1349
+ return outerWrapper ;
1344
1350
} ;
1345
1351
1346
1352
@@ -1407,6 +1413,9 @@ function MdPanelRef(config, $injector) {
1407
1413
/** @type {!angular.JQLite|undefined } */
1408
1414
this . panelEl ;
1409
1415
1416
+ /** @type {!angular.JQLite|undefined } */
1417
+ this . innerWrapper ;
1418
+
1410
1419
/**
1411
1420
* Whether the panel is attached. This is synchronous. When attach is called,
1412
1421
* isAttached is set to true. When detach is called, isAttached is set to
@@ -1853,6 +1862,11 @@ MdPanelRef.prototype._compile = function() {
1853
1862
) ;
1854
1863
}
1855
1864
1865
+ // Save a reference to the inner wrapper.
1866
+ self . innerWrapper = angular . element (
1867
+ self . panelContainer [ 0 ] . querySelector ( '.md-panel-inner-wrapper' )
1868
+ ) ;
1869
+
1856
1870
// Save a reference to the cleanup function from the compiler.
1857
1871
self . _compilerCleanup = compileData . cleanup ;
1858
1872
@@ -1929,14 +1943,17 @@ MdPanelRef.prototype._addStyles = function() {
1929
1943
var self = this ;
1930
1944
return this . _$q ( function ( resolve ) {
1931
1945
self . panelContainer . css ( 'z-index' , self . config [ 'zIndex' ] ) ;
1932
- self . panelEl . css ( 'z-index' , self . config [ 'zIndex' ] + 1 ) ;
1946
+ self . innerWrapper . css ( 'z-index' , self . config [ 'zIndex' ] + 1 ) ;
1933
1947
1934
1948
var hideAndResolve = function ( ) {
1935
1949
// Theme the element and container.
1936
1950
self . _setTheming ( ) ;
1937
1951
1938
1952
// Remove offscreen class and add hidden class.
1939
1953
self . panelEl . removeClass ( '_md-panel-offscreen' ) ;
1954
+
1955
+ // Remove left: -9999px and add hidden class.
1956
+ self . innerWrapper . css ( 'left' , '' ) ;
1940
1957
self . panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
1941
1958
1942
1959
resolve ( self ) ;
@@ -2003,27 +2020,27 @@ MdPanelRef.prototype._updatePosition = function(init) {
2003
2020
var positionConfig = this . config [ 'position' ] ;
2004
2021
2005
2022
if ( positionConfig ) {
2006
- positionConfig . _setPanelPosition ( this . panelEl ) ;
2023
+ positionConfig . _setPanelPosition ( this . innerWrapper ) ;
2007
2024
2008
2025
// Hide the panel now that position is known.
2009
2026
if ( init ) {
2010
2027
this . panelEl . removeClass ( '_md-panel-offscreen' ) ;
2011
2028
this . panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
2012
2029
}
2013
2030
2014
- this . panelEl . css (
2031
+ this . innerWrapper . css (
2015
2032
MdPanelPosition . absPosition . TOP ,
2016
2033
positionConfig . getTop ( )
2017
2034
) ;
2018
- this . panelEl . css (
2035
+ this . innerWrapper . css (
2019
2036
MdPanelPosition . absPosition . BOTTOM ,
2020
2037
positionConfig . getBottom ( )
2021
2038
) ;
2022
- this . panelEl . css (
2039
+ this . innerWrapper . css (
2023
2040
MdPanelPosition . absPosition . LEFT ,
2024
2041
positionConfig . getLeft ( )
2025
2042
) ;
2026
- this . panelEl . css (
2043
+ this . innerWrapper . css (
2027
2044
MdPanelPosition . absPosition . RIGHT ,
2028
2045
positionConfig . getRight ( )
2029
2046
) ;
@@ -2880,38 +2897,38 @@ MdPanelPosition.prototype.getTransform = function() {
2880
2897
2881
2898
2882
2899
/**
2883
- * Sets the `transform` value for a panel element.
2884
- * @param {!angular.JQLite } panelEl
2900
+ * Sets the `transform` value for an element.
2901
+ * @param {!angular.JQLite } el
2885
2902
* @returns {!angular.JQLite }
2886
2903
* @private
2887
2904
*/
2888
- MdPanelPosition . prototype . _setTransform = function ( panelEl ) {
2889
- return panelEl . css ( this . _$mdConstant . CSS . TRANSFORM , this . getTransform ( ) ) ;
2905
+ MdPanelPosition . prototype . _setTransform = function ( el ) {
2906
+ return el . css ( this . _$mdConstant . CSS . TRANSFORM , this . getTransform ( ) ) ;
2890
2907
} ;
2891
2908
2892
2909
2893
2910
/**
2894
2911
* True if the panel is completely on-screen with this positioning; false
2895
2912
* otherwise.
2896
- * @param {!angular.JQLite } panelEl
2913
+ * @param {!angular.JQLite } el
2897
2914
* @return {boolean }
2898
2915
* @private
2899
2916
*/
2900
- MdPanelPosition . prototype . _isOnscreen = function ( panelEl ) {
2917
+ MdPanelPosition . prototype . _isOnscreen = function ( el ) {
2901
2918
// this works because we always use fixed positioning for the panel,
2902
2919
// which is relative to the viewport.
2903
2920
var left = parseInt ( this . getLeft ( ) ) ;
2904
2921
var top = parseInt ( this . getTop ( ) ) ;
2905
2922
2906
2923
if ( this . _translateX . length || this . _translateY . length ) {
2907
2924
var prefixedTransform = this . _$mdConstant . CSS . TRANSFORM ;
2908
- var offsets = getComputedTranslations ( panelEl , prefixedTransform ) ;
2925
+ var offsets = getComputedTranslations ( el , prefixedTransform ) ;
2909
2926
left += offsets . x ;
2910
2927
top += offsets . y ;
2911
2928
}
2912
2929
2913
- var right = left + panelEl [ 0 ] . offsetWidth ;
2914
- var bottom = top + panelEl [ 0 ] . offsetHeight ;
2930
+ var right = left + el [ 0 ] . offsetWidth ;
2931
+ var bottom = top + el [ 0 ] . offsetHeight ;
2915
2932
2916
2933
return ( left >= 0 ) &&
2917
2934
( top >= 0 ) &&
@@ -2950,53 +2967,53 @@ MdPanelPosition.prototype._reduceTranslateValues =
2950
2967
/**
2951
2968
* Sets the panel position based on the created panel element and best x/y
2952
2969
* positioning.
2953
- * @param {!angular.JQLite } panelEl
2970
+ * @param {!angular.JQLite } el
2954
2971
* @private
2955
2972
*/
2956
- MdPanelPosition . prototype . _setPanelPosition = function ( panelEl ) {
2957
- // Remove the "position adjusted" class in case it has been added before.
2958
- panelEl . removeClass ( '_md-panel-position-adjusted' ) ;
2973
+ MdPanelPosition . prototype . _setPanelPosition = function ( el ) {
2974
+ // Remove the class in case it has been added before.
2975
+ el . removeClass ( '_md-panel-position-adjusted' ) ;
2959
2976
2960
2977
// Only calculate the position if necessary.
2961
2978
if ( this . _absolute ) {
2962
- this . _setTransform ( panelEl ) ;
2979
+ this . _setTransform ( el ) ;
2963
2980
return ;
2964
2981
}
2965
2982
2966
2983
if ( this . _actualPosition ) {
2967
- this . _calculatePanelPosition ( panelEl , this . _actualPosition ) ;
2968
- this . _setTransform ( panelEl ) ;
2969
- this . _constrainToViewport ( panelEl ) ;
2984
+ this . _calculatePanelPosition ( el , this . _actualPosition ) ;
2985
+ this . _setTransform ( el ) ;
2986
+ this . _constrainToViewport ( el ) ;
2970
2987
return ;
2971
2988
}
2972
2989
2973
2990
for ( var i = 0 ; i < this . _positions . length ; i ++ ) {
2974
2991
this . _actualPosition = this . _positions [ i ] ;
2975
- this . _calculatePanelPosition ( panelEl , this . _actualPosition ) ;
2976
- this . _setTransform ( panelEl ) ;
2992
+ this . _calculatePanelPosition ( el , this . _actualPosition ) ;
2993
+ this . _setTransform ( el ) ;
2977
2994
2978
- if ( this . _isOnscreen ( panelEl ) ) {
2995
+ if ( this . _isOnscreen ( el ) ) {
2979
2996
return ;
2980
2997
}
2981
2998
}
2982
2999
2983
- this . _constrainToViewport ( panelEl ) ;
3000
+ this . _constrainToViewport ( el ) ;
2984
3001
} ;
2985
3002
2986
3003
2987
3004
/**
2988
3005
* Constrains a panel's position to the viewport.
2989
- * @param {!angular.JQLite } panelEl
3006
+ * @param {!angular.JQLite } el
2990
3007
* @private
2991
3008
*/
2992
- MdPanelPosition . prototype . _constrainToViewport = function ( panelEl ) {
3009
+ MdPanelPosition . prototype . _constrainToViewport = function ( el ) {
2993
3010
var margin = MdPanelPosition . viewportMargin ;
2994
3011
var initialTop = this . _top ;
2995
3012
var initialLeft = this . _left ;
2996
3013
2997
3014
if ( this . getTop ( ) ) {
2998
3015
var top = parseInt ( this . getTop ( ) ) ;
2999
- var bottom = panelEl [ 0 ] . offsetHeight + top ;
3016
+ var bottom = el [ 0 ] . offsetHeight + top ;
3000
3017
var viewportHeight = this . _$window . innerHeight ;
3001
3018
3002
3019
if ( top < margin ) {
@@ -3008,7 +3025,7 @@ MdPanelPosition.prototype._constrainToViewport = function(panelEl) {
3008
3025
3009
3026
if ( this . getLeft ( ) ) {
3010
3027
var left = parseInt ( this . getLeft ( ) ) ;
3011
- var right = panelEl [ 0 ] . offsetWidth + left ;
3028
+ var right = el [ 0 ] . offsetWidth + left ;
3012
3029
var viewportWidth = this . _$window . innerWidth ;
3013
3030
3014
3031
if ( left < margin ) {
@@ -3019,7 +3036,7 @@ MdPanelPosition.prototype._constrainToViewport = function(panelEl) {
3019
3036
}
3020
3037
3021
3038
// Class that can be used to re-style the panel if it was repositioned.
3022
- panelEl . toggleClass (
3039
+ el . toggleClass (
3023
3040
'_md-panel-position-adjusted' ,
3024
3041
this . _top !== initialTop || this . _left !== initialLeft
3025
3042
) ;
@@ -3058,15 +3075,15 @@ MdPanelPosition.prototype._bidi = function(position) {
3058
3075
/**
3059
3076
* Calculates the panel position based on the created panel element and the
3060
3077
* provided positioning.
3061
- * @param {!angular.JQLite } panelEl
3078
+ * @param {!angular.JQLite } el
3062
3079
* @param {!{x:string, y:string} } position
3063
3080
* @private
3064
3081
*/
3065
- MdPanelPosition . prototype . _calculatePanelPosition = function ( panelEl , position ) {
3082
+ MdPanelPosition . prototype . _calculatePanelPosition = function ( el , position ) {
3066
3083
3067
- var panelBounds = panelEl [ 0 ] . getBoundingClientRect ( ) ;
3068
- var panelWidth = Math . max ( panelBounds . width , panelEl [ 0 ] . clientWidth ) ;
3069
- var panelHeight = Math . max ( panelBounds . height , panelEl [ 0 ] . clientHeight ) ;
3084
+ var panelBounds = el [ 0 ] . getBoundingClientRect ( ) ;
3085
+ var panelWidth = Math . max ( panelBounds . width , el [ 0 ] . clientWidth ) ;
3086
+ var panelHeight = Math . max ( panelBounds . height , el [ 0 ] . clientHeight ) ;
3070
3087
3071
3088
var targetBounds = this . _relativeToEl [ 0 ] . getBoundingClientRect ( ) ;
3072
3089
0 commit comments