@@ -338,14 +338,12 @@ angular
338
338
* Overlapping the panel with an element:
339
339
* `new MdPanelPosition()
340
340
* .relativeTo(someElement)
341
- * .withPanelXPosition($mdPanel.xPosition.ALIGN_START)
342
- * .withPanelYPosition($mdPanel.yPosition.ALIGN_TOPS);`
341
+ * .addPanelPosition($mdPanel.xPosition.ALIGN_START, $mdPanel.yPosition.ALIGN_TOPS);`
343
342
*
344
343
* Aligning the panel with the bottom of an element:
345
344
* `new MdPanelPosition()
346
345
* .relativeTo(someElement)
347
- * .withPanelXPosition($mdPanel.xPosition.CENTER)
348
- * .withPanelYPosition($mdPanel.yPosition.BELOW);`
346
+ * .addPanelPosition($mdPanel.xPosition.CENTER, $mdPanel.yPosition.BELOW);
349
347
*/
350
348
351
349
/**
@@ -438,10 +436,15 @@ angular
438
436
439
437
/**
440
438
* @ngdoc method
441
- * @name MdPanelPosition#withPanelXPosition
439
+ * @name MdPanelPosition#addPanelPosition
442
440
* @param {string } xPosition
441
+ * @param {string } yPosition
443
442
* @description
444
- * Sets the x position for the panel relative to another element.
443
+ * Sets the x and y position for the panel relative to another element. Can be
444
+ * called multiple times to specify an ordered list of panel positions. The
445
+ * first position which allows the panel to be completely on-screen will be
446
+ * chosen; the last position will be chose whether it is on-screen or not.
447
+ *
445
448
* xPosition must be one of the following values available on
446
449
* $mdPanel.xPosition:
447
450
*
@@ -459,14 +462,7 @@ angular
459
462
* C: CENTER
460
463
* D: ALIGN_END (for LTR displays)
461
464
* E: OFFSET_END (for LTR displays)
462
- */
463
-
464
- /**
465
- * @ngdoc method
466
- * @name MdPanelPosition#withPanelYPosition
467
- * @param {string } yPosition
468
- * @description
469
- * Sets the y position for the panel relative to another element.
465
+ *
470
466
* yPosition must be one of the following values available on
471
467
* $mdPanel.yPosition:
472
468
*
@@ -485,6 +481,7 @@ angular
485
481
* H: CENTER
486
482
* I: ALIGN_BOTTOMS
487
483
* J: ABOVE
484
+ * @returns {MdPanelPosition }
488
485
*/
489
486
490
487
/**
@@ -1090,7 +1087,7 @@ MdPanelRef.prototype._addStyles = function() {
1090
1087
return this . _$q ( function ( resolve ) {
1091
1088
self . _panelContainer . css ( 'z-index' , self . _config [ 'zIndex' ] ) ;
1092
1089
self . _panelEl . css ( 'z-index' , self . _config [ 'zIndex' ] + 1 ) ;
1093
-
1090
+
1094
1091
if ( self . _config [ 'fullscreen' ] ) {
1095
1092
self . _panelEl . addClass ( '_md-panel-fullscreen' ) ;
1096
1093
resolve ( self ) ;
@@ -1436,11 +1433,8 @@ function MdPanelPosition() {
1436
1433
/** @private {!Array<string>} */
1437
1434
this . _translateY = [ ] ;
1438
1435
1439
- /** @private {string} */
1440
- this . _xPosition = '' ;
1441
-
1442
- /** @private {string} */
1443
- this . _yPosition = '' ;
1436
+ /** @private {!Array<{x:string, y:string}> } */
1437
+ this . _positions = [ ] ;
1444
1438
}
1445
1439
1446
1440
@@ -1583,60 +1577,77 @@ MdPanelPosition.prototype.relativeTo = function(element) {
1583
1577
1584
1578
1585
1579
/**
1586
- * Sets the x position for the panel relative to another element.
1587
- * xPosition must be one of the MdPanelPosition.xPosition values.
1588
- *
1589
- * @param {string } xPosition
1580
+ * Sets the x and y positions for the panel relative to another element.
1581
+ * @param {string } xPosition must be one of the MdPanelPosition.xPosition values.
1582
+ * @param {string } yPosition must be one of the MdPanelPosition.yPosition values.
1590
1583
* @returns {MdPanelPosition }
1591
1584
*/
1592
- MdPanelPosition . prototype . withPanelXPosition = function ( xPosition ) {
1585
+ MdPanelPosition . prototype . addPanelPosition = function ( xPosition , yPosition ) {
1593
1586
if ( ! this . _relativeToRect ) {
1594
- throw new Error ( 'withPanelXPosition can only be used with relative' +
1587
+ throw new Error ( 'addPanelPosition can only be used with relative ' +
1595
1588
'positioning. Set relativeTo first.' ) ;
1596
1589
}
1597
1590
1598
- var positionKeys = Object . keys ( MdPanelPosition . xPosition ) ;
1591
+ this . _validateXPosition ( xPosition ) ;
1592
+ this . _validateYPosition ( yPosition ) ;
1593
+
1594
+ this . _positions . push ( {
1595
+ x : xPosition ,
1596
+ y : yPosition ,
1597
+ } ) ;
1598
+ return this ;
1599
+ } ;
1600
+
1601
+
1602
+ /**
1603
+ * Ensure that yPosition is a valid position name. Throw an exception if not.
1604
+ * @param {string } yPosition
1605
+ */
1606
+ MdPanelPosition . prototype . _validateYPosition = function ( yPosition ) {
1607
+ // empty is ok
1608
+ if ( yPosition == null ) {
1609
+ return ;
1610
+ }
1611
+
1612
+ var positionKeys = Object . keys ( MdPanelPosition . yPosition ) ;
1599
1613
var positionValues = [ ] ;
1600
1614
for ( var key , i = 0 ; key = positionKeys [ i ] ; i ++ ) {
1601
- var position = MdPanelPosition . xPosition [ key ] ;
1615
+ var position = MdPanelPosition . yPosition [ key ] ;
1602
1616
positionValues . push ( position ) ;
1603
- if ( position === xPosition ) {
1604
- this . _xPosition = xPosition ;
1605
- return this ;
1617
+
1618
+ if ( position === yPosition ) {
1619
+ return ;
1606
1620
}
1607
1621
}
1608
1622
1609
- throw new Error ( 'withPanelXPosition only accepts the following values:\n' +
1610
- positionValues . join ( ' | ' ) ) ;
1623
+ throw new Error ( 'Panel y position only accepts the following values:\n' +
1624
+ positionValues . join ( ' | ' ) ) ;
1611
1625
} ;
1612
1626
1613
1627
1614
1628
/**
1615
- * Sets the y position for the panel relative to another element.
1616
- * yPosition must be one of the MdPanelPosition.yPosition values.
1617
- *
1618
- * @param {string } yPosition
1619
- * @returns {MdPanelPosition }
1629
+ * Ensure that xPosition is a valid position name. Throw an exception if not.
1630
+ * @param {string } xPosition
1620
1631
*/
1621
- MdPanelPosition . prototype . withPanelYPosition = function ( yPosition ) {
1622
- if ( ! this . _relativeToRect ) {
1623
- throw new Error ( 'withPanelYPosition can only be used with relative ' +
1624
- 'positioning. Set relativeTo first.' ) ;
1632
+ MdPanelPosition . prototype . _validateXPosition = function ( xPosition ) {
1633
+ // empty is ok
1634
+ if ( xPosition == null ) {
1635
+ return ;
1625
1636
}
1626
1637
1627
- var positionKeys = Object . keys ( MdPanelPosition . yPosition ) ;
1638
+ var positionKeys = Object . keys ( MdPanelPosition . xPosition ) ;
1628
1639
var positionValues = [ ] ;
1629
1640
for ( var key , i = 0 ; key = positionKeys [ i ] ; i ++ ) {
1630
- var position = MdPanelPosition . yPosition [ key ] ;
1641
+ var position = MdPanelPosition . xPosition [ key ] ;
1631
1642
positionValues . push ( position ) ;
1632
- if ( position === yPosition ) {
1633
- this . _yPosition = yPosition ;
1634
- return this ;
1643
+ if ( position === xPosition ) {
1644
+ return ;
1635
1645
}
1636
1646
}
1637
1647
1638
- throw new Error ( 'withPanelYPosition only accepts the following values:\n' +
1648
+ throw new Error ( 'Panel x Position only accepts the following values:\n' +
1639
1649
positionValues . join ( ' | ' ) ) ;
1650
+
1640
1651
} ;
1641
1652
1642
1653
@@ -1722,6 +1733,16 @@ MdPanelPosition.prototype.getTransform = function() {
1722
1733
} ;
1723
1734
1724
1735
1736
+ /**
1737
+ * Gets the first x/y position that can fit on-screen.
1738
+ * @returns {string }
1739
+ */
1740
+ MdPanelPosition . prototype . getActualPosition = function ( ) {
1741
+ // TODO(gmoothart): intelligently pick the first on-screen position.
1742
+ return this . _positions [ 0 ] || { } ;
1743
+ } ;
1744
+
1745
+
1725
1746
/**
1726
1747
* Reduces a list of translate values to a string that can be used within
1727
1748
* transform.
@@ -1765,7 +1786,9 @@ MdPanelPosition.prototype._calculatePanelPosition = function(panelEl) {
1765
1786
var targetRight = targetBounds . right ;
1766
1787
var targetWidth = targetBounds . width ;
1767
1788
1768
- switch ( this . _xPosition ) {
1789
+ var pos = this . getActualPosition ( ) ;
1790
+
1791
+ switch ( pos . x ) {
1769
1792
case MdPanelPosition . xPosition . OFFSET_START :
1770
1793
// TODO(ErinCoughlan): Change OFFSET_START for rtl vs ltr.
1771
1794
this . _left = targetLeft - panelWidth + 'px' ;
@@ -1792,7 +1815,7 @@ MdPanelPosition.prototype._calculatePanelPosition = function(panelEl) {
1792
1815
var targetBottom = targetBounds . bottom ;
1793
1816
var targetHeight = targetBounds . height ;
1794
1817
1795
- switch ( this . _yPosition ) {
1818
+ switch ( pos . y ) {
1796
1819
case MdPanelPosition . yPosition . ABOVE :
1797
1820
this . _top = targetTop - panelHeight + 'px' ;
1798
1821
break ;
0 commit comments