| OLD | NEW |
| 1 Polymer({ | 1 Polymer({ |
| 2 is: 'app-drawer-layout', | 2 is: 'app-drawer-layout', |
| 3 | 3 |
| 4 behaviors: [ | 4 behaviors: [ |
| 5 Polymer.IronResizableBehavior | 5 Polymer.IronResizableBehavior |
| 6 ], | 6 ], |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** | 9 /** |
| 10 * If true, ignore `responsiveWidth` setting and force the narrow layout
. | 10 * If true, ignore `responsiveWidth` setting and force the narrow layout
. |
| 11 */ | 11 */ |
| 12 forceNarrow: { | 12 forceNarrow: { |
| 13 type: Boolean, | 13 type: Boolean, |
| 14 value: false | 14 value: false |
| 15 }, | 15 }, |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * If the viewport's width is smaller than this value, the panel will ch
ange to narrow layout. | 18 * If the viewport's width is smaller than this value, the panel will ch
ange to narrow |
| 19 * In the mode the drawer will be closed. | 19 * layout. In the mode the drawer will be closed. |
| 20 */ | 20 */ |
| 21 responsiveWidth: { | 21 responsiveWidth: { |
| 22 type: String, | 22 type: String, |
| 23 value: '640px' | 23 value: '640px' |
| 24 }, | 24 }, |
| 25 | 25 |
| 26 _narrow: Boolean | 26 /** |
| 27 * Returns true if it is in narrow layout. This is useful if you need to
show/hide |
| 28 * elements based on the layout. |
| 29 */ |
| 30 narrow: { |
| 31 type: Boolean, |
| 32 readOnly: true, |
| 33 notify: true |
| 34 } |
| 27 }, | 35 }, |
| 28 | 36 |
| 29 listeners: { | 37 listeners: { |
| 30 'tap': '_tapHandler', | 38 'tap': '_tapHandler', |
| 31 'app-drawer-reset-layout': 'resetLayout' | 39 'app-drawer-reset-layout': 'resetLayout' |
| 32 }, | 40 }, |
| 33 | 41 |
| 34 observers: [ | 42 observers: [ |
| 35 'resetLayout(_narrow, isAttached)' | 43 'resetLayout(narrow, isAttached)' |
| 36 ], | 44 ], |
| 37 | 45 |
| 38 /** | 46 /** |
| 39 * A reference to the app-drawer element. | 47 * A reference to the app-drawer element. |
| 40 * | 48 * |
| 41 * @property drawer | 49 * @property drawer |
| 42 */ | 50 */ |
| 43 get drawer() { | 51 get drawer() { |
| 44 return Polymer.dom(this.$.drawerContent).getDistributedNodes()[0]; | 52 return Polymer.dom(this.$.drawerContent).getDistributedNodes()[0]; |
| 45 }, | 53 }, |
| 46 | 54 |
| 47 _tapHandler: function(e) { | 55 _tapHandler: function(e) { |
| 48 var target = Polymer.dom(e).localTarget; | 56 var target = Polymer.dom(e).localTarget; |
| 49 if (target && target.hasAttribute('drawer-toggle')) { | 57 if (target && target.hasAttribute('drawer-toggle')) { |
| 50 this.drawer.toggle(); | 58 this.drawer.toggle(); |
| 51 } | 59 } |
| 52 }, | 60 }, |
| 53 | 61 |
| 54 resetLayout: function() { | 62 resetLayout: function() { |
| 55 this.debounce('_resetLayout', function() { | 63 this.debounce('_resetLayout', function() { |
| 56 if (!this.isAttached) { | 64 if (!this.isAttached) { |
| 57 return; | 65 return; |
| 58 } | 66 } |
| 59 | 67 |
| 60 var drawer = this.drawer; | 68 var drawer = this.drawer; |
| 61 var drawerWidth = this.drawer.getWidth(); | 69 var drawerWidth = this.drawer.getWidth(); |
| 62 var contentContainer = this.$.contentContainer; | 70 var contentContainer = this.$.contentContainer; |
| 63 | 71 |
| 64 if (this._narrow) { | 72 if (this.narrow) { |
| 65 drawer.opened = drawer.persistent = false; | 73 drawer.opened = drawer.persistent = false; |
| 66 contentContainer.classList.add('narrow'); | 74 contentContainer.classList.add('narrow'); |
| 67 | 75 |
| 68 contentContainer.style.marginLeft = ''; | 76 contentContainer.style.marginLeft = ''; |
| 69 contentContainer.style.marginRight = ''; | 77 contentContainer.style.marginRight = ''; |
| 70 } else { | 78 } else { |
| 71 drawer.opened = drawer.persistent = true; | 79 drawer.opened = drawer.persistent = true; |
| 72 contentContainer.classList.remove('narrow'); | 80 contentContainer.classList.remove('narrow'); |
| 73 | 81 |
| 74 if (drawer.position == 'right') { | 82 if (drawer.position == 'right') { |
| 75 contentContainer.style.marginLeft = ''; | 83 contentContainer.style.marginLeft = ''; |
| 76 contentContainer.style.marginRight = drawerWidth + 'px'; | 84 contentContainer.style.marginRight = drawerWidth + 'px'; |
| 77 } else { | 85 } else { |
| 78 contentContainer.style.marginLeft = drawerWidth + 'px'; | 86 contentContainer.style.marginLeft = drawerWidth + 'px'; |
| 79 contentContainer.style.marginRight = ''; | 87 contentContainer.style.marginRight = ''; |
| 80 } | 88 } |
| 81 } | 89 } |
| 82 | 90 |
| 83 this.notifyResize(); | 91 this.notifyResize(); |
| 84 }); | 92 }); |
| 85 }, | 93 }, |
| 86 | 94 |
| 95 _onQueryMatchesChanged: function(event) { |
| 96 this._setNarrow(event.detail.value); |
| 97 }, |
| 98 |
| 87 _computeMediaQuery: function(forceNarrow, responsiveWidth) { | 99 _computeMediaQuery: function(forceNarrow, responsiveWidth) { |
| 88 return forceNarrow ? '(min-width: 0px)' : '(max-width: ' + responsiveWid
th + ')'; | 100 return forceNarrow ? '(min-width: 0px)' : '(max-width: ' + responsiveWid
th + ')'; |
| 89 } | 101 } |
| 90 }); | 102 }); |
| OLD | NEW |