@@ -218,7 +218,7 @@ angular
218
218
* @description
219
219
* Creates a panel with the specified options.
220
220
*
221
- * @param config {!Object=} Specific configuration object that may contain the
221
+ * @param {!Object= } config Specific configuration object that may contain the
222
222
* following properties:
223
223
*
224
224
* - `id` - `{string=}`: An ID to track the panel by. When an ID is provided,
@@ -348,25 +348,6 @@ angular
348
348
* @returns {!MdPanelAnimation } panelAnimation
349
349
*/
350
350
351
- /**
352
- * @ngdoc method
353
- * @name $mdPanel#newPanelGroup
354
- * @description
355
- * Creates a panel group and adds it to a tracked list of panel groups.
356
- *
357
- * @param {string } groupName Name of the group to create.
358
- * @param {!Object= } config Specific configuration object that may contain the
359
- * following properties:
360
- *
361
- * - `maxOpen` - `{number=}`: The maximum number of panels that are allowed to
362
- * be open within a defined panel group.
363
- *
364
- * @returns {!Object<string,
365
- * {panels: !Array<!MdPanelRef>,
366
- * openPanels: !Array<!MdPanelRef>,
367
- * maxOpen: number}>} panelGroup
368
- */
369
-
370
351
/**
371
352
* @ngdoc method
372
353
* @name $mdPanel#setGroupMaxOpen
@@ -1018,6 +999,16 @@ function $getProvider() {
1018
999
] ;
1019
1000
}
1020
1001
1002
+ /**
1003
+ * @param {string|[] } value
1004
+ * @returns {[] } the input string wrapped in an Array or the original Array
1005
+ */
1006
+ function coerceToArray ( value ) {
1007
+ if ( angular . isString ( value ) ) {
1008
+ value = [ value ] ;
1009
+ }
1010
+ return value ;
1011
+ }
1021
1012
1022
1013
/*****************************************************************************
1023
1014
* MdPanel Service *
@@ -1171,9 +1162,7 @@ MdPanelService.prototype.create = function(preset, config) {
1171
1162
1172
1163
// Add the panel to each of its requested groups.
1173
1164
if ( this . _config . groupName ) {
1174
- if ( angular . isString ( this . _config . groupName ) ) {
1175
- this . _config . groupName = [ this . _config . groupName ] ;
1176
- }
1165
+ this . _config . groupName = coerceToArray ( this . _config . groupName ) ;
1177
1166
angular . forEach ( this . _config . groupName , function ( group ) {
1178
1167
panelRef . addToGroup ( group ) ;
1179
1168
} ) ;
@@ -1236,28 +1225,27 @@ MdPanelService.prototype.newPanelAnimation = function() {
1236
1225
1237
1226
1238
1227
/**
1228
+ * @ngdoc method
1229
+ * @name $mdPanel#newPanelGroup
1230
+ * @description
1239
1231
* Creates a panel group and adds it to a tracked list of panel groups.
1240
- * @param groupName {string} Name of the group to create.
1241
- * @param config {!Object =} Specific configuration object that may contain the
1242
- * following properties:
1232
+ * @param {string } groupName Name of the group to create.
1233
+ * @param { {maxOpen: number} = } config Configuration object that may contain the following
1234
+ * properties:
1243
1235
*
1244
- * - `maxOpen` - `{number=}`: The maximum number of panels that are allowed
1245
- * open within a defined panel group.
1236
+ * - `maxOpen`: The maximum number of panels that are allowed open within a defined panel group.
1246
1237
*
1247
- * @returns {!Object<string,
1248
- * {panels: !Array<!MdPanelRef>,
1249
- * openPanels: !Array<!MdPanelRef>,
1250
- * maxOpen: number}>} panelGroup
1238
+ * @returns {!{panels: !Array<!MdPanelRef>, openPanels: !Array<!MdPanelRef>, maxOpen: number} }
1239
+ * the new panel group
1251
1240
*/
1252
1241
MdPanelService . prototype . newPanelGroup = function ( groupName , config ) {
1253
1242
if ( ! this . _groups [ groupName ] ) {
1254
1243
config = config || { } ;
1255
- var group = {
1244
+ this . _groups [ groupName ] = {
1256
1245
panels : [ ] ,
1257
1246
openPanels : [ ] ,
1258
1247
maxOpen : config . maxOpen > 0 ? config . maxOpen : Infinity
1259
1248
} ;
1260
- this . _groups [ groupName ] = group ;
1261
1249
}
1262
1250
return this . _groups [ groupName ] ;
1263
1251
} ;
@@ -1301,7 +1289,10 @@ MdPanelService.prototype._openCountExceedsMaxOpen = function(groupName) {
1301
1289
* @private
1302
1290
*/
1303
1291
MdPanelService . prototype . _closeFirstOpenedPanel = function ( groupName ) {
1304
- this . _groups [ groupName ] . openPanels [ 0 ] . close ( ) ;
1292
+ var group = this . _groups [ groupName ] ;
1293
+ if ( group && group . openPanels . length ) {
1294
+ group . openPanels [ 0 ] . close ( ) ;
1295
+ }
1305
1296
} ;
1306
1297
1307
1298
@@ -1483,6 +1474,7 @@ MdPanelRef.prototype.open = function() {
1483
1474
var show = self . _simpleBind ( self . show , self ) ;
1484
1475
var checkGroupMaxOpen = function ( ) {
1485
1476
if ( self . config . groupName ) {
1477
+ self . config . groupName = coerceToArray ( self . config . groupName ) ;
1486
1478
angular . forEach ( self . config . groupName , function ( group ) {
1487
1479
if ( self . _$mdPanel . _openCountExceedsMaxOpen ( group ) ) {
1488
1480
self . _$mdPanel . _closeFirstOpenedPanel ( group ) ;
@@ -1621,6 +1613,7 @@ MdPanelRef.prototype.detach = function() {
1621
1613
MdPanelRef . prototype . destroy = function ( ) {
1622
1614
var self = this ;
1623
1615
if ( this . config . groupName ) {
1616
+ this . config . groupName = coerceToArray ( this . config . groupName ) ;
1624
1617
angular . forEach ( this . config . groupName , function ( group ) {
1625
1618
self . removeFromGroup ( group ) ;
1626
1619
} ) ;
@@ -1662,8 +1655,12 @@ MdPanelRef.prototype.show = function() {
1662
1655
var onOpenComplete = self . config [ 'onOpenComplete' ] || angular . noop ;
1663
1656
var addToGroupOpen = function ( ) {
1664
1657
if ( self . config . groupName ) {
1658
+ self . config . groupName = coerceToArray ( self . config . groupName ) ;
1665
1659
angular . forEach ( self . config . groupName , function ( group ) {
1666
- self . _$mdPanel . _groups [ group ] . openPanels . push ( self ) ;
1660
+ group = self . _$mdPanel . _groups [ group ] ;
1661
+ if ( group ) {
1662
+ group . openPanels . push ( self ) ;
1663
+ }
1667
1664
} ) ;
1668
1665
}
1669
1666
} ;
@@ -1706,6 +1703,7 @@ MdPanelRef.prototype.hide = function() {
1706
1703
var removeFromGroupOpen = function ( ) {
1707
1704
if ( self . config . groupName ) {
1708
1705
var index ;
1706
+ self . config . groupName = coerceToArray ( self . config . groupName ) ;
1709
1707
angular . forEach ( self . config . groupName , function ( group ) {
1710
1708
group = self . _$mdPanel . _groups [ group ] ;
1711
1709
index = group . openPanels . indexOf ( self ) ;
@@ -1734,7 +1732,6 @@ MdPanelRef.prototype.hide = function() {
1734
1732
} ) ;
1735
1733
} ;
1736
1734
1737
-
1738
1735
/**
1739
1736
* Add a class to the panel. DO NOT use this to hide/show the panel.
1740
1737
* @deprecated
0 commit comments