Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 6273f1e

Browse files
committed
code review
1 parent d64e4c1 commit 6273f1e

File tree

2 files changed

+43
-63
lines changed

2 files changed

+43
-63
lines changed

src/components/panel/panel.js

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,12 @@ angular
338338
* Overlapping the panel with an element:
339339
* `new MdPanelPosition()
340340
* .relativeTo(someElement)
341-
* .withPanelPosition($mdPanel.xPosition.ALIGN_START,
342-
* $mdPanel.yPosition.ALIGN_TOPS);`
341+
* .addPanelPosition($mdPanel.xPosition.ALIGN_START, $mdPanel.yPosition.ALIGN_TOPS);`
343342
*
344343
* Aligning the panel with the bottom of an element:
345344
* `new MdPanelPosition()
346345
* .relativeTo(someElement)
347-
* .withPanelPosition($mdPanel.xPosition.CENTER, $mdPanel.yPosition.BELOW);
346+
* .addPanelPosition($mdPanel.xPosition.CENTER, $mdPanel.yPosition.BELOW);
348347
*/
349348

350349
/**
@@ -437,11 +436,15 @@ angular
437436

438437
/**
439438
* @ngdoc method
440-
* @name MdPanelPosition#withPanelPosition
441-
* @param {string} xpos
442-
* @param {string} ypos
439+
* @name MdPanelPosition#addPanelPosition
440+
* @param {string} xPosition
441+
* @param {string} yPosition
443442
* @description
444-
* Sets the x and y 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+
*
445448
* xPosition must be one of the following values available on
446449
* $mdPanel.xPosition:
447450
*
@@ -478,16 +481,7 @@ angular
478481
* H: CENTER
479482
* I: ALIGN_BOTTOMS
480483
* J: ABOVE
481-
*/
482-
483-
/**
484-
* @ngdoc method
485-
* @name MdPanelPosition#tryPanelPositions
486-
* @description
487-
* Specify an ordered list of panel positions. The first position which
488-
* allows the panel to be completely on-screen will be chosen; the last position
489-
* will be chose whether it is on-screen or not.
490-
* @param {!Array<{y: string, x:string}>} posArray
484+
* @returns {MdPanelPosition}
491485
*/
492486

493487
/**
@@ -1583,55 +1577,37 @@ MdPanelPosition.prototype.relativeTo = function(element) {
15831577

15841578

15851579
/**
1586-
* Sets the x and y postion for the panel relative to another element.
1587-
* @param {string} x must be one of the MdPanelPosition.xPosition values.
1588-
* @param {string} y must be one of the MdPanelPosition.yPosition values.
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.
1583+
* @returns {MdPanelPosition}
15891584
*/
1590-
MdPanelPosition.prototype.withPanelPosition = function(x, y) {
1585+
MdPanelPosition.prototype.addPanelPosition = function(xPosition, yPosition) {
15911586
if (!this._relativeToRect) {
1592-
throw new Error('withPanelPosition can only be used with relative ' +
1587+
throw new Error('addPanelPosition can only be used with relative ' +
15931588
'positioning. Set relativeTo first.');
15941589
}
15951590

15961591
// validate
1597-
this._validateXPosition(x);
1598-
this._validateYPosition(y);
1592+
this._validateXPosition(xPosition);
1593+
this._validateYPosition(yPosition);
15991594

16001595
this._positions.push({
1601-
x: x,
1602-
y: y,
1596+
x: xPosition,
1597+
y: yPosition,
16031598
});
16041599
return this;
16051600
};
16061601

16071602

16081603
/**
1609-
* Specify an ordered list of panel positions. The first position which
1610-
* allows the panel to be completely on-screen will be chosen; the last position
1611-
* will be chose whether it is on-screen or not.
1612-
* @param {!Array<{x:string, y:string}>} pos
1604+
* Ensure that yPosition is a valid position name. Throw an exception if not.
1605+
* @param {string} yPosition
16131606
*/
1614-
MdPanelPosition.prototype.tryPanelPositions = function(posArray) {
1615-
if (!this._relativeToRect) {
1616-
throw new Error('tryPanelPositions can only be used with relative ' +
1617-
'positioning. Set relativeTo first.');
1618-
}
1619-
1620-
// validate
1621-
for (var i = 0; i < pos.length; i++) {
1622-
this._validateXPosition(pos.x);
1623-
this._validateYPosition(pos.y);
1624-
};
1625-
1626-
this._positions = this._positions.concat(posArray);
1627-
return this;
1628-
};
1629-
1630-
16311607
MdPanelPosition.prototype._validateYPosition = function(ypos) {
16321608
// empty is ok
16331609
if (ypos == null) {
1634-
return true;
1610+
return;
16351611
}
16361612

16371613
var positionKeys = Object.keys(MdPanelPosition.yPosition);
@@ -1650,10 +1626,14 @@ MdPanelPosition.prototype._validateYPosition = function(ypos) {
16501626
};
16511627

16521628

1629+
/**
1630+
* Ensure that xPosition is a valid position name. Throw an exception if not.
1631+
* @param {string} xPosition
1632+
*/
16531633
MdPanelPosition.prototype._validateXPosition = function(xpos) {
16541634
// empty is ok
16551635
if (xpos == null) {
1656-
return true;
1636+
return;
16571637
}
16581638

16591639
var positionKeys = Object.keys(MdPanelPosition.xPosition);

src/components/panel/panel.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ describe('$mdPanel', function() {
11181118
it('with respect to an element', function() {
11191119
var position = mdPanelPosition
11201120
.relativeTo(myButton[0])
1121-
.withPanelPosition(xPosition.ALIGN_START, yPosition.ALIGN_TOPS);
1121+
.addPanelPosition(xPosition.ALIGN_START, yPosition.ALIGN_TOPS);
11221122

11231123
config['position'] = position;
11241124

@@ -1132,7 +1132,7 @@ describe('$mdPanel', function() {
11321132
it('with respect to a query selector', function() {
11331133
var position = mdPanelPosition
11341134
.relativeTo('button')
1135-
.withPanelPosition(xPosition.ALIGN_START, yPosition.ALIGN_TOPS);
1135+
.addPanelPosition(xPosition.ALIGN_START, yPosition.ALIGN_TOPS);
11361136

11371137
config['position'] = position;
11381138

@@ -1146,7 +1146,7 @@ describe('$mdPanel', function() {
11461146
it('with respect to a JQLite object', function() {
11471147
var position = mdPanelPosition
11481148
.relativeTo(myButton)
1149-
.withPanelPosition(xPosition.ALIGN_START, yPosition.ALIGN_TOPS);
1149+
.addPanelPosition(xPosition.ALIGN_START, yPosition.ALIGN_TOPS);
11501150

11511151
config['position'] = position;
11521152

@@ -1161,7 +1161,7 @@ describe('$mdPanel', function() {
11611161
it('above an element', function() {
11621162
var position = mdPanelPosition
11631163
.relativeTo(myButton)
1164-
.withPanelPosition(null, yPosition.ABOVE);
1164+
.addPanelPosition(null, yPosition.ABOVE);
11651165

11661166
config['position'] = position;
11671167

@@ -1175,7 +1175,7 @@ describe('$mdPanel', function() {
11751175
it('top aligned with an element', function() {
11761176
var position = mdPanelPosition
11771177
.relativeTo(myButton)
1178-
.withPanelPosition(null, yPosition.ALIGN_TOPS);
1178+
.addPanelPosition(null, yPosition.ALIGN_TOPS);
11791179

11801180
config['position'] = position;
11811181

@@ -1189,7 +1189,7 @@ describe('$mdPanel', function() {
11891189
it('centered with an element', function() {
11901190
var position = mdPanelPosition
11911191
.relativeTo(myButton)
1192-
.withPanelPosition(null, yPosition.CENTER);
1192+
.addPanelPosition(null, yPosition.CENTER);
11931193

11941194
config['position'] = position;
11951195

@@ -1206,7 +1206,7 @@ describe('$mdPanel', function() {
12061206
it('bottom aligned with an element', function() {
12071207
var position = mdPanelPosition
12081208
.relativeTo(myButton)
1209-
.withPanelPosition(null, yPosition.ALIGN_BOTTOMS);
1209+
.addPanelPosition(null, yPosition.ALIGN_BOTTOMS);
12101210

12111211
config['position'] = position;
12121212

@@ -1220,7 +1220,7 @@ describe('$mdPanel', function() {
12201220
it('below an element', function() {
12211221
var position = mdPanelPosition
12221222
.relativeTo(myButton)
1223-
.withPanelPosition(null, yPosition.BELOW);
1223+
.addPanelPosition(null, yPosition.BELOW);
12241224

12251225
config['position'] = position;
12261226

@@ -1236,7 +1236,7 @@ describe('$mdPanel', function() {
12361236
it('offset to the left of an element', function() {
12371237
var position = mdPanelPosition
12381238
.relativeTo(myButton)
1239-
.withPanelPosition(xPosition.OFFSET_START, null);
1239+
.addPanelPosition(xPosition.OFFSET_START, null);
12401240

12411241
config['position'] = position;
12421242

@@ -1250,7 +1250,7 @@ describe('$mdPanel', function() {
12501250
it('right aligned with an element', function() {
12511251
var position = mdPanelPosition
12521252
.relativeTo(myButton)
1253-
.withPanelPosition(xPosition.ALIGN_END, null);
1253+
.addPanelPosition(xPosition.ALIGN_END, null);
12541254

12551255
config['position'] = position;
12561256

@@ -1264,7 +1264,7 @@ describe('$mdPanel', function() {
12641264
it('centered with an element', function() {
12651265
var position = mdPanelPosition
12661266
.relativeTo(myButton)
1267-
.withPanelPosition(xPosition.CENTER, null);
1267+
.addPanelPosition(xPosition.CENTER, null);
12681268

12691269
config['position'] = position;
12701270

@@ -1281,7 +1281,7 @@ describe('$mdPanel', function() {
12811281
it('left aligned with an element', function() {
12821282
var position = mdPanelPosition
12831283
.relativeTo(myButton)
1284-
.withPanelPosition(xPosition.ALIGN_START, null);
1284+
.addPanelPosition(xPosition.ALIGN_START, null);
12851285

12861286
config['position'] = position;
12871287

@@ -1295,7 +1295,7 @@ describe('$mdPanel', function() {
12951295
it('offset to the right of an element', function() {
12961296
var position = mdPanelPosition
12971297
.relativeTo(myButton)
1298-
.withPanelPosition(xPosition.OFFSET_END, null);
1298+
.addPanelPosition(xPosition.OFFSET_END, null);
12991299

13001300
config['position'] = position;
13011301

@@ -1316,7 +1316,7 @@ describe('$mdPanel', function() {
13161316
var expression = function() {
13171317
mdPanelPosition
13181318
.relativeTo(myButton)
1319-
.withPanelPosition('fake-x-position', null);
1319+
.addPanelPosition('fake-x-position', null);
13201320
};
13211321

13221322
expect(expression).toThrow();

0 commit comments

Comments
 (0)