@@ -386,8 +386,8 @@ angular
386
386
* @ngdoc method
387
387
* @name MdPanelPosition#top
388
388
* @description
389
- * Sets the value of `top` for the panel. Clears any previously set
390
- * vertical position.
389
+ * Sets the value of `top` for the panel. Clears any previously set vertical
390
+ * position.
391
391
* @param {string= } top Value of `top`. Defaults to '0'.
392
392
* @returns {MdPanelPosition }
393
393
*/
@@ -396,12 +396,32 @@ angular
396
396
* @ngdoc method
397
397
* @name MdPanelPosition#bottom
398
398
* @description
399
- * Sets the value of `bottom` for the panel. Clears any previously set
400
- * vertical position.
399
+ * Sets the value of `bottom` for the panel. Clears any previously set vertical
400
+ * position.
401
401
* @param {string= } bottom Value of `bottom`. Defaults to '0'.
402
402
* @returns {MdPanelPosition }
403
403
*/
404
404
405
+ /**
406
+ * @ngdoc method
407
+ * @name MdPanelPosition#start
408
+ * @description
409
+ * Sets the panel to the start of the page - `left` if `ltr` or `right` for `rtl`. Clears any previously set
410
+ * horizontal position.
411
+ * @param {string= } start Value of position. Defaults to '0'.
412
+ * @returns {MdPanelPosition }
413
+ */
414
+
415
+ /**
416
+ * @ngdoc method
417
+ * @name MdPanelPosition#end
418
+ * @description
419
+ * Sets the panel to the end of the page - `right` if `ltr` or `left` for `rtl`. Clears any previously set
420
+ * horizontal position.
421
+ * @param {string= } end Value of position. Defaults to '0'.
422
+ * @returns {MdPanelPosition }
423
+ */
424
+
405
425
/**
406
426
* @ngdoc method
407
427
* @name MdPanelPosition#left
@@ -713,7 +733,7 @@ MdPanelService.prototype.open = function(config) {
713
733
* @returns {MdPanelPosition }
714
734
*/
715
735
MdPanelService . prototype . newPanelPosition = function ( ) {
716
- return new MdPanelPosition ( this . _$window ) ;
736
+ return new MdPanelPosition ( this . _$injector ) ;
717
737
} ;
718
738
719
739
@@ -1243,10 +1263,10 @@ MdPanelRef.prototype._updatePosition = function(init) {
1243
1263
this . _panelContainer . addClass ( MD_PANEL_HIDDEN ) ;
1244
1264
}
1245
1265
1246
- this . _panelEl . css ( 'top' , positionConfig . getTop ( ) ) ;
1247
- this . _panelEl . css ( 'bottom' , positionConfig . getBottom ( ) ) ;
1248
- this . _panelEl . css ( 'left' , positionConfig . getLeft ( ) ) ;
1249
- this . _panelEl . css ( 'right' , positionConfig . getRight ( ) ) ;
1266
+ this . _panelEl . css ( MdPanelPosition . absPosition . TOP , positionConfig . getTop ( ) ) ;
1267
+ this . _panelEl . css ( MdPanelPosition . absPosition . BOTTOM , positionConfig . getBottom ( ) ) ;
1268
+ this . _panelEl . css ( MdPanelPosition . absPosition . LEFT , positionConfig . getLeft ( ) ) ;
1269
+ this . _panelEl . css ( MdPanelPosition . absPosition . RIGHT , positionConfig . getRight ( ) ) ;
1250
1270
1251
1271
// Use the vendor prefixed version of transform.
1252
1272
var prefixedTransform = this . _$mdConstant . CSS . TRANSFORM ;
@@ -1570,12 +1590,15 @@ MdPanelRef.prototype._done = function(callback, self) {
1570
1590
* position: panelPosition
1571
1591
* });
1572
1592
*
1573
- * @param {!angular.$window } $window
1593
+ * @param {!angular.$injector } $injector
1574
1594
* @final @constructor
1575
1595
*/
1576
- function MdPanelPosition ( $window ) {
1577
- /** @private @const */
1578
- this . _$window = $window ;
1596
+ function MdPanelPosition ( $injector ) {
1597
+ /** @private @const {!angular.$window} */
1598
+ this . _$window = $injector . get ( '$window' ) ;
1599
+
1600
+ /** @private {boolean} */
1601
+ this . _isRTL = $injector . get ( '$mdUtil' ) . bidi ( ) === 'rtl' ;
1579
1602
1580
1603
/** @private {boolean} */
1581
1604
this . _absolute = false ;
@@ -1635,6 +1658,18 @@ MdPanelPosition.yPosition = {
1635
1658
} ;
1636
1659
1637
1660
1661
+ /**
1662
+ * Possible values of absolute position.
1663
+ * @enum {string}
1664
+ */
1665
+ MdPanelPosition . absPosition = {
1666
+ TOP : 'top' ,
1667
+ RIGHT : 'right' ,
1668
+ BOTTOM : 'bottom' ,
1669
+ LEFT : 'left'
1670
+ } ;
1671
+
1672
+
1638
1673
/**
1639
1674
* Sets absolute positioning for the panel.
1640
1675
* @return {!MdPanelPosition }
@@ -1644,6 +1679,31 @@ MdPanelPosition.prototype.absolute = function() {
1644
1679
return this ;
1645
1680
} ;
1646
1681
1682
+ /**
1683
+ * Sets the value of a position for the panel. Clears any previously set position.
1684
+ * @param {string } position Position to set
1685
+ * @param {string= } value Value of the position. Defaults to '0'.
1686
+ * @returns {MdPanelPosition }
1687
+ * @private
1688
+ */
1689
+ MdPanelPosition . prototype . _setPosition = function ( position , value ) {
1690
+ if ( position === MdPanelPosition . absPosition . RIGHT || position === MdPanelPosition . absPosition . LEFT ) {
1691
+ this . _left = this . _right = '' ;
1692
+ }
1693
+ else if ( position === MdPanelPosition . absPosition . BOTTOM || position === MdPanelPosition . absPosition . TOP ) {
1694
+ this . _top = this . _bottom = '' ;
1695
+ }
1696
+ else {
1697
+ var positions = Object . keys ( MdPanelPosition . absPosition ) . join ( ) . toLowerCase ( ) ;
1698
+
1699
+ throw new Error ( 'Position must be one of ' + positions + '.' ) ;
1700
+ }
1701
+
1702
+ this [ '_' + position ] = angular . isString ( value ) ? value : '0' ;
1703
+
1704
+ return this ;
1705
+ } ;
1706
+
1647
1707
1648
1708
/**
1649
1709
* Sets the value of `top` for the panel. Clears any previously set vertical
@@ -1652,9 +1712,7 @@ MdPanelPosition.prototype.absolute = function() {
1652
1712
* @returns {MdPanelPosition }
1653
1713
*/
1654
1714
MdPanelPosition . prototype . top = function ( top ) {
1655
- this . _bottom = '' ;
1656
- this . _top = top || '0' ;
1657
- return this ;
1715
+ return this . _setPosition ( MdPanelPosition . absPosition . TOP , top ) ;
1658
1716
} ;
1659
1717
1660
1718
@@ -1665,9 +1723,31 @@ MdPanelPosition.prototype.top = function(top) {
1665
1723
* @returns {MdPanelPosition }
1666
1724
*/
1667
1725
MdPanelPosition . prototype . bottom = function ( bottom ) {
1668
- this . _top = '' ;
1669
- this . _bottom = bottom || '0' ;
1670
- return this ;
1726
+ return this . _setPosition ( MdPanelPosition . absPosition . BOTTOM , bottom ) ;
1727
+ } ;
1728
+
1729
+
1730
+ /**
1731
+ * Sets the panel to the start of the page - `left` if `ltr` or `right` for `rtl`. Clears any previously set
1732
+ * horizontal position.
1733
+ * @param {string= } start Value of position. Defaults to '0'.
1734
+ * @returns {MdPanelPosition }
1735
+ */
1736
+ MdPanelPosition . prototype . start = function ( start ) {
1737
+ var position = this . _isRTL ? MdPanelPosition . absPosition . RIGHT : MdPanelPosition . absPosition . LEFT ;
1738
+ return this . _setPosition ( position , start ) ;
1739
+ } ;
1740
+
1741
+
1742
+ /**
1743
+ * Sets the panel to the end of the page - `right` if `ltr` or `left` for `rtl`. Clears any previously set
1744
+ * horizontal position.
1745
+ * @param {string= } end Value of position. Defaults to '0'.
1746
+ * @returns {MdPanelPosition }
1747
+ */
1748
+ MdPanelPosition . prototype . end = function ( end ) {
1749
+ var position = this . _isRTL ? MdPanelPosition . absPosition . LEFT : MdPanelPosition . absPosition . RIGHT ;
1750
+ return this . _setPosition ( position , end ) ;
1671
1751
} ;
1672
1752
1673
1753
@@ -1678,9 +1758,7 @@ MdPanelPosition.prototype.bottom = function(bottom) {
1678
1758
* @returns {MdPanelPosition }
1679
1759
*/
1680
1760
MdPanelPosition . prototype . left = function ( left ) {
1681
- this . _right = '' ;
1682
- this . _left = left || '0' ;
1683
- return this ;
1761
+ return this . _setPosition ( MdPanelPosition . absPosition . LEFT , left ) ;
1684
1762
} ;
1685
1763
1686
1764
@@ -1689,11 +1767,9 @@ MdPanelPosition.prototype.left = function(left) {
1689
1767
* horizontal position.
1690
1768
* @param {string= } right Value of `right`. Defaults to '0'.
1691
1769
* @returns {MdPanelPosition }
1692
- */
1770
+ */
1693
1771
MdPanelPosition . prototype . right = function ( right ) {
1694
- this . _left = '' ;
1695
- this . _right = right || '0' ;
1696
- return this ;
1772
+ return this . _setPosition ( MdPanelPosition . absPosition . RIGHT , right ) ;
1697
1773
} ;
1698
1774
1699
1775
@@ -1971,6 +2047,36 @@ MdPanelPosition.prototype._setPanelPosition = function(panelEl) {
1971
2047
}
1972
2048
} ;
1973
2049
2050
+
2051
+ /**
2052
+ * Switching between 'start' and 'end'
2053
+ * @param {string } position Horizontal position of the panel
2054
+ * @returns {string } Reversed position
2055
+ * @private
2056
+ */
2057
+ MdPanelPosition . prototype . _reverseXPosition = function ( position ) {
2058
+ if ( position === MdPanelPosition . xPosition . CENTER ) {
2059
+ return ;
2060
+ }
2061
+
2062
+ var start = 'start' ;
2063
+ var end = 'end' ;
2064
+
2065
+ return position . indexOf ( start ) > - 1 ? position . replace ( start , end ) : position . replace ( end , start ) ;
2066
+ } ;
2067
+
2068
+
2069
+ /**
2070
+ * Handles horizontal positioning in rtl or ltr environments
2071
+ * @param {string } position Horizontal position of the panel
2072
+ * @returns {string } The correct position according the page direction
2073
+ * @private
2074
+ */
2075
+ MdPanelPosition . prototype . _bidi = function ( position ) {
2076
+ return this . _isRTL ? this . _reverseXPosition ( position ) : position ;
2077
+ } ;
2078
+
2079
+
1974
2080
/**
1975
2081
* Calculates the panel position based on the created panel element and the
1976
2082
* provided positioning.
@@ -1990,25 +2096,21 @@ MdPanelPosition.prototype._calculatePanelPosition = function(panelEl, position)
1990
2096
var targetRight = targetBounds . right ;
1991
2097
var targetWidth = targetBounds . width ;
1992
2098
1993
- switch ( position . x ) {
2099
+ switch ( this . _bidi ( position . x ) ) {
1994
2100
case MdPanelPosition . xPosition . OFFSET_START :
1995
- // TODO(ErinCoughlan): Change OFFSET_START for rtl vs ltr.
1996
2101
this . _left = targetLeft - panelWidth + 'px' ;
1997
2102
break ;
1998
2103
case MdPanelPosition . xPosition . ALIGN_END :
1999
- // TODO(ErinCoughlan): Change ALIGN_END for rtl vs ltr.
2000
2104
this . _left = targetRight - panelWidth + 'px' ;
2001
2105
break ;
2002
2106
case MdPanelPosition . xPosition . CENTER :
2003
2107
var left = targetLeft + ( 0.5 * targetWidth ) - ( 0.5 * panelWidth ) ;
2004
2108
this . _left = left + 'px' ;
2005
2109
break ;
2006
2110
case MdPanelPosition . xPosition . ALIGN_START :
2007
- // TODO(ErinCoughlan): Change ALIGN_START for rtl vs ltr.
2008
2111
this . _left = targetLeft + 'px' ;
2009
2112
break ;
2010
2113
case MdPanelPosition . xPosition . OFFSET_END :
2011
- // TODO(ErinCoughlan): Change OFFSET_END for rtl vs ltr.
2012
2114
this . _left = targetRight + 'px' ;
2013
2115
break ;
2014
2116
}
0 commit comments