@@ -2471,11 +2471,15 @@ MdPanelPosition.prototype.getTransform = function() {
24712471MdPanelPosition . prototype . _isOnscreen = function ( panelEl ) {
24722472 // this works because we always use fixed positioning for the panel,
24732473 // which is relative to the viewport.
2474- // TODO(gmoothart): take into account _translateX and _translateY to the
2475- // extent feasible.
2476-
24772474 var left = parseInt ( this . getLeft ( ) ) ;
24782475 var top = parseInt ( this . getTop ( ) ) ;
2476+
2477+ if ( this . _translateX . length || this . _translateY . length ) {
2478+ var offsets = getComputedTranslations ( panelEl ) ;
2479+ left += offsets . x ;
2480+ top += offsets . y ;
2481+ }
2482+
24792483 var right = left + panelEl [ 0 ] . offsetWidth ;
24802484 var bottom = top + panelEl [ 0 ] . offsetHeight ;
24812485
@@ -2982,3 +2986,30 @@ function getElement(el) {
29822986 document . querySelector ( el ) : el ;
29832987 return angular . element ( queryResult ) ;
29842988}
2989+
2990+ /**
2991+ * Gets the computed values for an element's translateX and translateY in px.
2992+ * @param {!angular.JQLite|!Element } el
2993+ * @return {{x: number, y: number} }
2994+ */
2995+ function getComputedTranslations ( el ) {
2996+ // The transform being returned by `getComputedStyle` is in the format:
2997+ // `matrix(a, b, c, d, translateX, translateY)` if defined and `none`
2998+ // if the element doesn't have a transform.
2999+ var transform = getComputedStyle ( el [ 0 ] || el ) . transform ;
3000+ var openIndex = transform . indexOf ( '(' ) ;
3001+ var closeIndex = transform . lastIndexOf ( ')' ) ;
3002+ var output = { x : 0 , y : 0 } ;
3003+
3004+ if ( openIndex > - 1 && closeIndex > - 1 ) {
3005+ var parsedValues = transform
3006+ . substring ( openIndex + 1 , closeIndex )
3007+ . split ( ', ' )
3008+ . slice ( - 2 ) ;
3009+
3010+ output . x = parseInt ( parsedValues [ 0 ] ) ;
3011+ output . y = parseInt ( parsedValues [ 1 ] ) ;
3012+ }
3013+
3014+ return output ;
3015+ }
0 commit comments