This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
panel.js
3417 lines (2924 loc) · 96.6 KB
/
panel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @ngdoc module
* @name material.components.panel
*/
angular
.module('material.components.panel', [
'material.core',
'material.components.backdrop'
])
.provider('$mdPanel', MdPanelProvider);
/*****************************************************************************
* PUBLIC DOCUMENTATION *
*****************************************************************************/
/**
* @ngdoc service
* @name $mdPanelProvider
* @module material.components.panel
*
* @description
* `$mdPanelProvider` allows users to create configuration presets that will be
* stored within a cached presets object. When the configuration is needed, the
* user can request the preset by passing it as the first parameter in the
* `$mdPanel.create` or `$mdPanel.open` methods.
*
* @usage
* <hljs lang="js">
* (function(angular, undefined) {
* 'use strict';
*
* angular
* .module('demoApp', ['ngMaterial'])
* .config(DemoConfig)
* .controller('DemoCtrl', DemoCtrl)
* .controller('DemoMenuCtrl', DemoMenuCtrl);
*
* function DemoConfig($mdPanelProvider) {
* $mdPanelProvider.definePreset('demoPreset', {
* attachTo: angular.element(document.body),
* controller: DemoMenuCtrl,
* controllerAs: 'ctrl',
* template: '' +
* '<div class="menu-panel" md-whiteframe="4">' +
* ' <div class="menu-content">' +
* ' <div class="menu-item" ng-repeat="item in ctrl.items">' +
* ' <button class="md-button">' +
* ' <span>{{item}}</span>' +
* ' </button>' +
* ' </div>' +
* ' <md-divider></md-divider>' +
* ' <div class="menu-item">' +
* ' <button class="md-button" ng-click="ctrl.closeMenu()">' +
* ' <span>Close Menu</span>' +
* ' </button>' +
* ' </div>' +
* ' </div>' +
* '</div>',
* panelClass: 'menu-panel-container',
* focusOnOpen: false,
* zIndex: 100,
* propagateContainerEvents: true,
* groupName: 'menus'
* });
* }
*
* function PanelProviderCtrl($mdPanel) {
* this.navigation = {
* name: 'navigation',
* items: [
* 'Home',
* 'About',
* 'Contact'
* ]
* };
* this.favorites = {
* name: 'favorites',
* items: [
* 'Add to Favorites'
* ]
* };
* this.more = {
* name: 'more',
* items: [
* 'Account',
* 'Sign Out'
* ]
* };
*
* $mdPanel.newPanelGroup('menus', {
* maxOpen: 2
* });
*
* this.showMenu = function($event, menu) {
* $mdPanel.open('demoPreset', {
* id: 'menu_' + menu.name,
* position: $mdPanel.newPanelPosition()
* .relativeTo($event.target)
* .addPanelPosition(
* $mdPanel.xPosition.ALIGN_START,
* $mdPanel.yPosition.BELOW
* ),
* locals: {
* items: menu.items
* },
* openFrom: $event
* });
* };
* }
*
* function PanelMenuCtrl(mdPanelRef) {
* // 'mdPanelRef' is injected in the controller.
* this.closeMenu = function() {
* if (mdPanelRef) {
* mdPanelRef.close();
* }
* };
* }
* })(angular);
* </hljs>
*/
/**
* @ngdoc method
* @name $mdPanelProvider#definePreset
* @description
* Takes the passed in preset name and preset configuration object and adds it
* to the `_presets` object of the provider. This `_presets` object is then
* passed along to the `$mdPanel` service.
*
* @param {string} name Preset name.
* @param {!Object} preset Specific configuration object that can contain any
* and all of the parameters available within the `$mdPanel.create` method.
* However, parameters that pertain to id, position, animation, and user
* interaction are not allowed and will be removed from the preset
* configuration.
*/
/*****************************************************************************
* MdPanel Service *
*****************************************************************************/
/**
* @ngdoc service
* @name $mdPanel
* @module material.components.panel
*
* @description
* `$mdPanel` is a robust, low-level service for creating floating panels on
* the screen. It can be used to implement tooltips, dialogs, pop-ups, etc.
*
* The following types, referenced below, have separate documentation:
* - <a ng-href="api/type/MdPanelAnimation">MdPanelAnimation</a> from `$mdPanel.newPanelAnimation()`
* - <a ng-href="api/type/MdPanelPosition">MdPanelPosition</a> from `$mdPanel.newPanelPosition()`
* - <a ng-href="api/type/MdPanelRef">MdPanelRef</a> from the `$mdPanel.open()` Promise or
* injected in the panel's controller
*
* @usage
* <hljs lang="js">
* (function(angular, undefined) {
* 'use strict';
*
* angular
* .module('demoApp', ['ngMaterial'])
* .controller('DemoDialogController', DialogController)
* .controller('DemoCtrl', function($mdPanel) {
*
* var panelRef;
*
* function showPanel($event) {
* var panelPosition = $mdPanel.newPanelPosition()
* .absolute()
* .top('50%')
* .left('50%');
*
* var panelAnimation = $mdPanel.newPanelAnimation()
* .openFrom($event)
* .duration(200)
* .closeTo('.show-button')
* .withAnimation($mdPanel.animation.SCALE);
*
* var config = {
* attachTo: angular.element(document.body),
* controller: DialogController,
* controllerAs: 'ctrl',
* position: panelPosition,
* animation: panelAnimation,
* targetEvent: $event,
* templateUrl: 'dialog-template.html',
* clickOutsideToClose: true,
* escapeToClose: true,
* focusOnOpen: true
* };
*
* $mdPanel.open(config)
* .then(function(result) {
* panelRef = result;
* });
* }
* }
*
* function DialogController(MdPanelRef) {
* function closeDialog() {
* if (MdPanelRef) MdPanelRef.close();
* }
* }
* })(angular);
* </hljs>
*/
/**
* @ngdoc method
* @name $mdPanel#create
* @description
* Creates a panel with the specified options.
*
* @param {!Object=} config Specific configuration object that may contain the
* following properties:
*
* - `id` - `{string=}`: An ID to track the panel by. When an ID is provided,
* the created panel is added to a tracked panels object. Any subsequent
* requests made to create a panel with that ID are ignored. This is useful
* in having the panel service not open multiple panels from the same user
* interaction when there is no backdrop and events are propagated. Defaults
* to an arbitrary string that is not tracked.
* - `template` - `{string=}`: HTML template to show in the panel. This
* **must** be trusted HTML with respect to AngularJS’s
* [$sce service](https://docs.angularjs.org/api/ng/service/$sce).
* - `templateUrl` - `{string=}`: The URL that will be used as the content of
* the panel.
* - `contentElement` - `{(string|!JQLite|!Element)=}`: Pre-compiled
* element to be used as the panel's content.
* - `controller` - `{(function|string)=}`: The controller to associate with
* the panel. The controller can inject a reference to the returned
* panelRef, which allows the panel to be closed, hidden, and shown. Any
* fields passed in through locals or resolve will be bound to the
* controller.
* - `controllerAs` - `{string=}`: An alias to assign the controller to on
* the scope.
* - `bindToController` - `{boolean=}`: Binds locals to the controller
* instead of passing them in. Defaults to true, as this is a best
* practice.
* - `locals` - `{Object=}`: An object containing key/value pairs. The keys
* will be used as names of values to inject into the controller. For
* example, `locals: {three: 3}` would inject `three` into the controller,
* with the value 3. 'mdPanelRef' is a reserved key, and will always
* be set to the created `MdPanelRef` instance.
* - `resolve` - `{Object=}`: Similar to locals, except it takes promises as
* values. The panel will not open until all of the promises resolve.
* - `attachTo` - `{(string|!JQLite|!Element)=}`: The element to
* attach the panel to. Defaults to appending to the root element of the
* application.
* - `propagateContainerEvents` - `{boolean=}`: Whether pointer or touch
* events should be allowed to propagate 'go through' the container, aka the
* wrapper, of the panel. Defaults to false.
* - `panelClass` - `{string=}`: A css class to apply to the panel element.
* This class should define any borders, box-shadow, etc. for the panel.
* - `zIndex` - `{number=}`: The z-index to place the panel at.
* Defaults to 80.
* - `position` - `{MdPanelPosition=}`: An MdPanelPosition object that
* specifies the alignment of the panel. For more information, see
* `MdPanelPosition`.
* - `clickOutsideToClose` - `{boolean=}`: Whether the user can click
* outside the panel to close it. Defaults to false.
* - `escapeToClose` - `{boolean=}`: Whether the user can press escape to
* close the panel. Defaults to false.
* - `onCloseSuccess` - `{function(!panelRef, string)=}`: Function that is
* called after the close successfully finishes. The first parameter passed
* into this function is the current panelRef and the 2nd is an optional
* string explaining the close reason. The currently supported closeReasons
* can be found in the `MdPanelRef.closeReasons` enum. These are by default
* passed along by the panel.
* - `trapFocus` - `{boolean=}`: Whether focus should be trapped within the
* panel. If `trapFocus` is true, the user will not be able to interact
* with the rest of the page until the panel is dismissed. Defaults to
* false.
* - `focusOnOpen` - `{boolean=}`: An option to override focus behavior on
* open. Only disable if focusing some other way, as focus management is
* required for panels to be accessible. Defaults to true.
* - `fullscreen` - `{boolean=}`: Whether the panel should be full screen.
* Applies the class `._md-panel-fullscreen` to the panel on open. Defaults
* to false.
* - `animation` - `{MdPanelAnimation=}`: An MdPanelAnimation object that
* specifies the animation of the panel. For more information, see
* `MdPanelAnimation`.
* - `hasBackdrop` - `{boolean=}`: Whether there should be an opaque backdrop
* behind the panel. Defaults to false.
* - `disableParentScroll` - `{boolean=}`: Whether the user can scroll the
* page behind the panel. Defaults to false.
* - `onDomAdded` - `{function=}`: Callback function used to announce when
* the panel is added to the DOM.
* - `onOpenComplete` - `{function=}`: Callback function used to announce
* when the open() action is finished.
* - `onRemoving` - `{function=}`: Callback function used to announce the
* close/hide() action is starting.
* - `onDomRemoved` - `{function=}`: Callback function used to announce when
* the panel is removed from the DOM.
* - `origin` - `{(string|!JQLite|!Element)=}`: The element to focus
* on when the panel closes. This is commonly the element which triggered
* the opening of the panel. If you do not use `origin`, you need to control
* the focus manually.
* - `groupName` - `{(string|!Array<string>)=}`: A group name or an array of
* group names. The group name is used for creating a group of panels. The
* group is used for configuring the number of open panels and identifying
* specific behaviors for groups. For instance, all tooltips could be
* identified using the same groupName.
*
* @returns {!MdPanelRef} panelRef
*/
/**
* @ngdoc method
* @name $mdPanel#open
* @description
* Calls the create method above, then opens the panel. This is a shortcut for
* creating and then calling open manually. If custom methods need to be
* called when the panel is added to the DOM or opened, do not use this method.
* Instead create the panel, chain promises on the domAdded and openComplete
* methods, and call open from the returned panelRef.
*
* @param {!Object=} config Specific configuration object that may contain
* the properties defined in `$mdPanel.create`.
* @returns {!Q.IPromise<!MdPanelRef>} panelRef A promise that resolves
* to an instance of the panel.
*/
/**
* @ngdoc method
* @name $mdPanel#newPanelPosition
* @description
* Returns a new instance of the MdPanelPosition object. Use this to create
* the position config object.
*
* @returns {!MdPanelPosition} panelPosition
*/
/**
* @ngdoc method
* @name $mdPanel#newPanelAnimation
* @description
* Returns a new instance of the MdPanelAnimation object. Use this to create
* the animation config object.
*
* @returns {!MdPanelAnimation} panelAnimation
*/
/**
* @ngdoc method
* @name $mdPanel#setGroupMaxOpen
* @description
* Sets the maximum number of panels in a group that can be opened at a given
* time.
*
* @param {string} groupName The name of the group to configure.
* @param {number} maxOpen The maximum number of panels that can be
* opened. Infinity can be passed in to remove the maxOpen limit.
*/
/*****************************************************************************
* MdPanelRef *
*****************************************************************************/
/**
* @ngdoc type
* @name MdPanelRef
* @module material.components.panel
* @description
* A reference to a created panel. This reference contains a unique id for the
* panel, along with the following properties:
*
* - `id` - `{string}`: The unique id for the panel. This id is used to track
* when a panel was interacted with.
* - `config` - `{!Object=}`: The entire config object that was used in
* create.
* - `isAttached` - `{boolean}`: Whether the panel is attached to the DOM.
* Visibility to the user does not factor into isAttached.
* - `panelContainer` - `{JQLite}`: The wrapper element containing the
* panel. This property is added in order to have access to the `addClass`,
* `removeClass`, `toggleClass`, etc methods.
* - `panelEl` - `{JQLite}`: The panel element. This property is added
* in order to have access to the `addClass`, `removeClass`, `toggleClass`,
* etc methods.
*/
/**
* @ngdoc method
* @name MdPanelRef#open
* @description
* Attaches and shows the panel.
*
* @returns {!Q.IPromise} A promise that is resolved when the panel is
* opened.
*/
/**
* @ngdoc method
* @name MdPanelRef#close
* @description
* Hides and detaches the panel. Note that this will **not** destroy the panel.
* If you don't intend on using the panel again, call the {@link #destroy
* destroy} method afterwards.
*
* @returns {!Q.IPromise} A promise that is resolved when the panel is
* closed.
*/
/**
* @ngdoc method
* @name MdPanelRef#attach
* @description
* Create the panel elements and attach them to the DOM. The panel will be
* hidden by default.
*
* @returns {!Q.IPromise} A promise that is resolved when the panel is
* attached.
*/
/**
* @ngdoc method
* @name MdPanelRef#detach
* @description
* Removes the panel from the DOM. This will NOT hide the panel before removing
* it.
*
* @returns {!Q.IPromise} A promise that is resolved when the panel is
* detached.
*/
/**
* @ngdoc method
* @name MdPanelRef#show
* @description
* Shows the panel.
*
* @returns {!Q.IPromise} A promise that is resolved when the panel has
* shown and animations are completed.
*/
/**
* @ngdoc method
* @name MdPanelRef#hide
* @description
* Hides the panel.
*
* @returns {!Q.IPromise} A promise that is resolved when the panel has
* hidden and animations are completed.
*/
/**
* @ngdoc method
* @name MdPanelRef#destroy
* @description
* Destroys the panel. The panel cannot be opened again after this is called.
*/
/**
* @ngdoc method
* @name MdPanelRef#updatePosition
* @description
* Updates the position configuration of a panel. Use this to update the
* position of a panel that is open, without having to close and re-open the
* panel.
*
* @param {!MdPanelPosition} position
*/
/**
* @ngdoc method
* @name MdPanelRef#addToGroup
* @description
* Adds a panel to a group if the panel does not exist within the group already.
* A panel can only exist within a single group.
*
* @param {string} groupName The name of the group to add the panel to.
*/
/**
* @ngdoc method
* @name MdPanelRef#removeFromGroup
* @description
* Removes a panel from a group if the panel exists within that group. The group
* must be created ahead of time.
*
* @param {string} groupName The name of the group.
*/
/**
* @ngdoc method
* @name MdPanelRef#registerInterceptor
* @description
* Registers an interceptor with the panel. The callback should return a promise,
* which will allow the action to continue when it gets resolved, or will
* prevent an action if it is rejected. The interceptors are called sequentially
* and it reverse order. `type` must be one of the following
* values available on `$mdPanel.interceptorTypes`:
* * `CLOSE` - Gets called before the panel begins closing.
*
* @param {string} type Type of interceptor.
* @param {!Q.IPromise<any>} callback Callback to be registered.
* @returns {!MdPanelRef}
*/
/**
* @ngdoc method
* @name MdPanelRef#removeInterceptor
* @description
* Removes a registered interceptor.
*
* @param {string} type Type of interceptor to be removed.
* @param {function(): !Q.IPromise<any>} callback Interceptor to be removed.
* @returns {!MdPanelRef}
*/
/**
* @ngdoc method
* @name MdPanelRef#removeAllInterceptors
* @description
* Removes all interceptors. If a type is supplied, only the
* interceptors of that type will be cleared.
*
* @param {string=} type Type of interceptors to be removed.
* @returns {!MdPanelRef}
*/
/**
* @ngdoc method
* @name MdPanelRef#updateAnimation
* @description
* Updates the animation configuration for a panel. You can use this to change
* the panel's animation without having to re-create it.
*
* @param {!MdPanelAnimation} animation
*/
/*****************************************************************************
* MdPanelPosition *
*****************************************************************************/
/**
* @ngdoc type
* @name MdPanelPosition
* @module material.components.panel
* @description
*
* Object for configuring the position of the panel.
*
* @usage
*
* #### Centering the panel
*
* <hljs lang="js">
* new MdPanelPosition().absolute().center();
* </hljs>
*
* #### Overlapping the panel with an element
*
* <hljs lang="js">
* new MdPanelPosition()
* .relativeTo(someElement)
* .addPanelPosition(
* $mdPanel.xPosition.ALIGN_START,
* $mdPanel.yPosition.ALIGN_TOPS
* );
* </hljs>
*
* #### Aligning the panel with the bottom of an element
*
* <hljs lang="js">
* new MdPanelPosition()
* .relativeTo(someElement)
* .addPanelPosition($mdPanel.xPosition.CENTER, $mdPanel.yPosition.BELOW);
* </hljs>
*/
/**
* @ngdoc method
* @name MdPanelPosition#absolute
* @description
* Positions the panel absolutely relative to the parent element. If the parent
* is document.body, this is equivalent to positioning the panel absolutely
* within the viewport.
*
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#relativeTo
* @description
* Positions the panel relative to a specific element.
*
* @param {string|!Element|!JQLite} element Query selector, DOM element,
* or angular element to position the panel with respect to.
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#top
* @description
* Sets the value of `top` for the panel. Clears any previously set vertical
* position.
*
* @param {string=} top Value of `top`. Defaults to '0'.
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#bottom
* @description
* Sets the value of `bottom` for the panel. Clears any previously set vertical
* position.
*
* @param {string=} bottom Value of `bottom`. Defaults to '0'.
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#start
* @description
* Sets the panel to the start of the page - `left` if `ltr` or `right` for
* `rtl`. Clears any previously set horizontal position.
*
* @param {string=} start Value of position. Defaults to '0'.
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#end
* @description
* Sets the panel to the end of the page - `right` if `ltr` or `left` for `rtl`.
* Clears any previously set horizontal position.
*
* @param {string=} end Value of position. Defaults to '0'.
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#left
* @description
* Sets the value of `left` for the panel. Clears any previously set
* horizontal position.
*
* @param {string=} left Value of `left`. Defaults to '0'.
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#right
* @description
* Sets the value of `right` for the panel. Clears any previously set
* horizontal position.
*
* @param {string=} right Value of `right`. Defaults to '0'.
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#centerHorizontally
* @description
* Centers the panel horizontally in the viewport. Clears any previously set
* horizontal position.
*
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#centerVertically
* @description
* Centers the panel vertically in the viewport. Clears any previously set
* vertical position.
*
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#center
* @description
* Centers the panel horizontally and vertically in the viewport. This is
* equivalent to calling both `centerHorizontally` and `centerVertically`.
* Clears any previously set horizontal and vertical positions.
*
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#addPanelPosition
* @description
* Sets the x and y position for the panel relative to another element. Can be
* called multiple times to specify an ordered list of panel positions. The
* first position which allows the panel to be completely on-screen will be
* chosen; the last position will be chose whether it is on-screen or not.
*
* xPosition must be one of the following values available on
* $mdPanel.xPosition:
*
*
* CENTER | ALIGN_START | ALIGN_END | OFFSET_START | OFFSET_END
*
* <pre>
* *************
* * *
* * PANEL *
* * *
* *************
* A B C D E
*
* A: OFFSET_START (for LTR displays)
* B: ALIGN_START (for LTR displays)
* C: CENTER
* D: ALIGN_END (for LTR displays)
* E: OFFSET_END (for LTR displays)
* </pre>
*
* yPosition must be one of the following values available on
* $mdPanel.yPosition:
*
* CENTER | ALIGN_TOPS | ALIGN_BOTTOMS | ABOVE | BELOW
*
* <pre>
* F
* G *************
* * *
* H * PANEL *
* * *
* I *************
* J
*
* F: BELOW
* G: ALIGN_TOPS
* H: CENTER
* I: ALIGN_BOTTOMS
* J: ABOVE
* </pre>
*
* @param {string} xPosition
* @param {string} yPosition
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#withOffsetX
* @description
* Sets the value of the offset in the x-direction.
*
* @param {string|number} offsetX
* @returns {!MdPanelPosition}
*/
/**
* @ngdoc method
* @name MdPanelPosition#withOffsetY
* @description
* Sets the value of the offset in the y-direction.
*
* @param {string|number} offsetY
* @returns {!MdPanelPosition}
*/
/*****************************************************************************
* MdPanelAnimation *
*****************************************************************************/
/**
* @ngdoc type
* @name MdPanelAnimation
* @module material.components.panel
* @description
* Animation configuration object. To use, create an MdPanelAnimation with the
* desired properties, then pass the object as part of $mdPanel creation.
*
* @usage
*
* <hljs lang="js">
* var panelAnimation = new MdPanelAnimation()
* .openFrom(myButtonEl)
* .duration(1337)
* .closeTo('.my-button')
* .withAnimation($mdPanel.animation.SCALE);
*
* $mdPanel.create({
* animation: panelAnimation
* });
* </hljs>
*/
/**
* @ngdoc method
* @name MdPanelAnimation#openFrom
* @description
* Specifies where to start the open animation. `openFrom` accepts a
* click event object, query selector, DOM element, or a Rect object that
* is used to determine the bounds. When passed a click event, the location
* of the click will be used as the position to start the animation.
*
* @param {string|!Element|!Event|{top: number, left: number}}
* @returns {!MdPanelAnimation}
*/
/**
* @ngdoc method
* @name MdPanelAnimation#closeTo
* @description
* Specifies where to animate the panel close. `closeTo` accepts a
* query selector, DOM element, or a Rect object that is used to determine
* the bounds.
*
* @param {string|!Element|{top: number, left: number}}
* @returns {!MdPanelAnimation}
*/
/**
* @ngdoc method
* @name MdPanelAnimation#withAnimation
* @description
* Specifies the animation class.
*
* There are several default animations that can be used: `$mdPanel.animation.`
* - `SLIDE`: The panel slides in and out from the specified
* elements. It will not fade in or out.
* - `SCALE`: The panel scales in and out. Slide and fade are
* included in this animation.
* - `FADE`: The panel fades in and out.
*
* Custom classes will by default fade in and out unless
* `transition: opacity 1ms` is added to the to custom class.
*
* @param {string|{open: string, close: string}} cssClass
* @returns {!MdPanelAnimation}
*/
/**
* @ngdoc method
* @name MdPanelAnimation#duration
* @description
* Specifies the duration of the animation in milliseconds. The `duration`
* method accepts either a number or an object with separate open and close
* durations.
*
* @param {number|{open: number, close: number}} duration
* @returns {!MdPanelAnimation}
*/
/*****************************************************************************
* PUBLIC DOCUMENTATION *
*****************************************************************************/
var MD_PANEL_Z_INDEX = 80;
var MD_PANEL_HIDDEN = '_md-panel-hidden';
var FOCUS_TRAP_TEMPLATE;
var _presets = {};
/**
* A provider that is used for creating presets for the panel API.
* @final @constructor @ngInject
*/
function MdPanelProvider() {
return {
'definePreset': definePreset,
'getAllPresets': getAllPresets,
'clearPresets': clearPresets,
'$get': $getProvider()
};
}
/**
* Takes the passed in panel configuration object and adds it to the `_presets`
* object at the specified name.
* @param {string} name Name of the preset to set.
* @param {!Object} preset Specific configuration object that can contain any
* and all of the parameters available within the `$mdPanel.create` method.
* However, parameters that pertain to id, position, animation, and user
* interaction are not allowed and will be removed from the preset
* configuration.
*/
function definePreset(name, preset) {
if (!name || !preset) {
throw new Error('mdPanelProvider: The panel preset definition is ' +
'malformed. The name and preset object are required.');
} else if (_presets.hasOwnProperty(name)) {
throw new Error('mdPanelProvider: The panel preset you have requested ' +
'has already been defined.');
}
// Delete any property on the preset that is not allowed.
delete preset.id;
delete preset.position;
delete preset.animation;
_presets[name] = preset;
}
/**
* Gets a clone of the `_presets`.
* @return {!Object}
*/
function getAllPresets() {
return angular.copy(_presets);
}
/**
* Clears all of the stored presets.
*/
function clearPresets() {
_presets = {};
}
/**
* Represents the `$get` method of the AngularJS provider. From here, a new
* reference to the MdPanelService is returned where the needed arguments are
* passed in including the MdPanelProvider `_presets`.
* @param {!Object} _presets
* @param {!JQLite} $rootElement
* @param {!angular.Scope} $rootScope
* @param {!IInjectorService} $injector
* @param {!IWindowService} $window
*/
function $getProvider() {
return [
'$rootElement', '$rootScope', '$injector', '$window',
function($rootElement, $rootScope, $injector, $window) {
return new MdPanelService(_presets, $rootElement, $rootScope,
$injector, $window);
}
];
}
/**
* @param {string|[]} value
* @returns {[]} the input string wrapped in an Array or the original Array
*/
function coerceToArray(value) {
if (angular.isString(value)) {
value = [value];
}
return value;
}
/*****************************************************************************
* MdPanel Service *
*****************************************************************************/
/**
* A service that is used for controlling/displaying panels on the screen.
* @param {!Object} presets
* @param {!JQLite} $rootElement
* @param {!angular.Scope} $rootScope
* @param {!IInjectorService} $injector
* @param {!IWindowService} $window
* @final @constructor @ngInject
*/
function MdPanelService(presets, $rootElement, $rootScope, $injector, $window) {
/**
* Default config options for the panel.
* Anything angular related needs to be done later. Therefore
* scope: $rootScope.$new(true),
* attachTo: $rootElement,
* are added later.
* @private {!Object}
*/
this._defaultConfigOptions = {
bindToController: true,
clickOutsideToClose: false,
disableParentScroll: false,
escapeToClose: false,
focusOnOpen: true,
fullscreen: false,
hasBackdrop: false,
propagateContainerEvents: false,
transformTemplate: angular.bind(this, this._wrapTemplate),
trapFocus: false,