Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: chrome/browser/resources/settings/controls/dialog_drawer.js

Issue 2465433002: Create implementation of the side panel using a dialog. (Closed)
Patch Set: Address feedback. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 Polymer({
6 is: 'dialog-drawer',
7 extends: 'dialog',
8
9 properties: {
10 /** Enables notifications for |Dialog.open|. */
11 open: {
12 type: Boolean,
13 notify: true,
14 },
15
16 /** The alignment of the drawer on the screen ('left' or 'right'). */
17 align: {
18 type: String,
19 value: 'left',
20 reflectToAttribute: true,
21 },
22 },
23
24 listeners: {
25 'cancel': 'onDialogCancel_',
26 'tap': 'onDialogTap_',
27 'transitionend': 'onDialogTransitionEnd_',
28 },
29
30 /** Toggles the drawer open and close. */
31 toggle: function() {
32 if (this.open)
33 this.closeDrawer();
34 else
35 this.openDrawer();
36 },
37
38 /** Shows drawer and slides it into view. */
39 openDrawer: function() {
40 if (!this.open) {
41 this.showModal();
42 this.classList.add('opening');
43 }
44 },
45
46 /** Slides the drawer away, then closes it after the transition has ended. */
47 closeDrawer: function() {
48 if (this.open) {
49 this.classList.remove('opening');
50 this.classList.add('closing');
51 }
52 },
53
54 /**
55 * Listens for a tap event outside the dialog in order to close it.
56 * @param {Event} event
57 * @private
58 */
59 onDialogTap_: function(event) {
60 if (event.target != this) // Only care about self.
61 return;
62
63 var rect = this.getBoundingClientRect();
dpapad 2016/12/08 22:27:22 We can avoid the need to call getBoundingClientRec
hcarmona 2016/12/09 16:14:42 Good to know. Done.
64
65 // We can ignore checking top/bottom because dialog is height 100%.
66 if (event.detail.x < rect.left || event.detail.x > rect.right)
67 this.closeDrawer();
68 },
69
70 /**
71 * Overrides the default cancel machanism to allow for a close animation.
72 * @param {Event} event
73 * @private
74 */
75 onDialogCancel_: function(event) {
76 event.preventDefault();
77 this.closeDrawer();
78 },
79
80 /**
81 * Closes the dialog when the closing animation is over.
82 * @private
83 */
84 onDialogTransitionEnd_: function() {
85 if (this.classList.contains('opening')) {
86 this.fire('open'); // Notify tests that dialog is now open.
dpapad 2016/12/08 22:27:22 Can we rename the event to something more specific
hcarmona 2016/12/09 16:14:42 As per our conversation: I've removed the event an
87 } else if (this.classList.contains('closing')) {
88 this.classList.remove('closing');
89 this.close();
90 }
91 },
92 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698