2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 `core-drawer-panel` contains a drawer panel and a main panel. The drawer
12 and the main panel are side-by-side with drawer on the left. When browser
13 window size is smaller than the `responsiveWidth`, `core-drawer-panel`
14 changes to narrow layout. In narrow layout, the drawer will be stacked on top
15 of the main panel. The drawer will be slided in/out to hide/reveal the main
18 Use the attribute `drawer` to indicate the element is a drawer panel and
19 `main` to indicate is a main panel.
24 <div drawer> Drawer panel... </div>
25 <div main> Main panel... </div>
28 The drawer and the main panels are not scrollable. You can set CSS overflow
29 property on the elements to make them scrollable or use `core-header-panel`.
34 <core-header-panel drawer>
35 <core-toolbar></core-toolbar>
36 <div> Drawer content... </div>
38 <core-header-panel main>
39 <core-toolbar></core-toolbar>
40 <div> Main content... </div>
44 To position the drawer to the right, add `rightDrawer` attribute.
46 <core-drawer-panel rightDrawer>
47 <div drawer> Drawer panel... </div>
48 <div main> Main panel... </div>
51 @group Polymer Core Elements
52 @element core-drawer-panel
56 <link rel=
"import" href=
"../core-media-query/core-media-query.html">
57 <link rel=
"import" href=
"../core-selector/core-selector.html">
59 <polymer-element name=
"core-drawer-panel" touch-action=
"auto">
62 <link rel=
"stylesheet" href=
"core-drawer-panel.css">
64 <core-media-query query=
"max-width: {{responsiveWidth}}" queryMatches=
"{{queryMatches}}"></core-media-query>
66 <core-selector class=
"{{ {'narrow-layout' : queryMatches, transition : transition, dragging : dragging, 'right-drawer': rightDrawer} | tokenList }}" valueattr=
"id" selected=
"{{selected}}">
68 <div id=
"main" _style=
"left: {{ narrow || rightDrawer ? '0' : drawerWidth }}; right: {{ rightDrawer ? (narrow ? '' : drawerWidth) : '' }};">
69 <content select=
"[main]"></content>
70 <div id=
"scrim" on-tap=
"{{togglePanel}}"></div>
73 <div id=
"drawer" _style=
"width: {{ drawerWidth }}">
74 <content select=
"[drawer]"></content>
82 Polymer('core-drawer-panel', {
84 * Fired when the narrow layout changes.
86 * @event core-responsive-change
87 * @param {Object} detail
88 * @param {boolean} detail.narrow true if the panel is in narrow layout.
94 * Width of the drawer panel.
96 * @attribute drawerWidth
100 drawerWidth
: '256px',
103 * Max-width when the panel changes to narrow layout.
105 * @attribute responsiveWidth
109 responsiveWidth
: '640px',
112 * The panel that is being selected. `drawer` for the drawer panel and
113 * `main` for the main panel.
115 * @attribute selected
119 selected
: {value
: null, reflect
: true},
122 * The panel to be selected when `core-drawer-panel` changes to narrow
125 * @attribute defaultSelected
129 defaultSelected
: 'main',
132 * Returns true if the panel is in narrow layout. This is useful if you
133 * need to show/hide elements based on the layout.
139 narrow
: {value
: false, reflect
: true},
142 * If true, position the drawer to the right.
144 * @attribute rightDrawer
151 * If true, swipe to open/close the drawer is disabled.
153 * @attribute disableSwipe
161 trackstart
: 'trackStart',
168 edgeSwipeSensitivity
: 15,
172 domReady: function() {
173 // to avoid transition at the beginning e.g. page loads
174 // NOTE: domReady is already raf delayed and delaying another frame
175 // ensures a layout has occurred.
176 this.async(function() {
177 this.transition
= true;
182 * Toggles the panel open and closed.
184 * @method togglePanel
186 togglePanel: function() {
187 this.selected
= this.selected
=== 'main' ? 'drawer' : 'main';
195 openDrawer: function() {
196 this.selected
= 'drawer';
202 * @method closeDrawer
204 closeDrawer: function() {
205 this.selected
= 'main';
208 queryMatchesChanged: function() {
209 if (this.queryMatches
) {
210 this.selected
= this.defaultSelected
;
212 this.narrow
= this.queryMatches
;
213 this.setAttribute('touch-action',
214 this.narrow
&& !this.disableSwipe
? 'pan-y' : '');
215 this.fire('core-responsive-change', {narrow
: this.narrow
});
218 // swipe support for the drawer, inspired by
219 // https://github.com/Polymer/core-drawer-panel/pull/6
220 trackStart : function(e
) {
221 if (this.narrow
&& !this.disableSwipe
) {
222 this.dragging
= true;
224 if (this.selected
=== 'main') {
225 this.dragging
= this.rightDrawer
?
226 e
.pageX
>= this.offsetWidth
- this.edgeSwipeSensitivity
:
227 e
.pageX
<= this.edgeSwipeSensitivity
;
231 this.width
= this.$.drawer
.offsetWidth
;
232 this.transition
= false;
238 trackx : function(e
) {
241 if (this.rightDrawer
) {
242 x
= Math
.max(0, (this.selected
=== 'main') ? this.width
+ e
.dx
: e
.dx
);
244 x
= Math
.min(0, (this.selected
=== 'main') ? e
.dx
- this.width
: e
.dx
);
250 trackEnd : function(e
) {
252 this.dragging
= false;
253 this.transition
= true;
254 this.moveDrawer(null);
256 if (this.rightDrawer
) {
257 this.selected
= e
.xDirection
> 0 ? 'main' : 'drawer';
259 this.selected
= e
.xDirection
> 0 ? 'drawer' : 'main';
264 moveDrawer: function(translateX
) {
265 var s
= this.$.drawer
.style
;
266 s
.webkitTransform
= s
.transform
=
267 translateX
=== null ? '' : 'translate3d(' + translateX
+ 'px, 0, 0)';