| OLD | NEW |
| (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 * Stop propagation of a tap event inside the container. This will allow |
| 56 * |onDialogTap_| to only be called when clicked outside the container. |
| 57 * @param {!Event} event |
| 58 * @private |
| 59 */ |
| 60 onContainerTap_: function(event) { |
| 61 event.stopPropagation(); |
| 62 }, |
| 63 |
| 64 /** |
| 65 * Close the dialog when tapped outside the container. |
| 66 * @private |
| 67 */ |
| 68 onDialogTap_: function() { |
| 69 this.closeDrawer(); |
| 70 }, |
| 71 |
| 72 /** |
| 73 * Overrides the default cancel machanism to allow for a close animation. |
| 74 * @param {!Event} event |
| 75 * @private |
| 76 */ |
| 77 onDialogCancel_: function(event) { |
| 78 event.preventDefault(); |
| 79 this.closeDrawer(); |
| 80 }, |
| 81 |
| 82 /** |
| 83 * Closes the dialog when the closing animation is over. |
| 84 * @private |
| 85 */ |
| 86 onDialogTransitionEnd_: function() { |
| 87 if (this.classList.contains('closing')) { |
| 88 this.classList.remove('closing'); |
| 89 this.close(); |
| 90 } |
| 91 }, |
| 92 }); |
| OLD | NEW |