Remove the 'gyp_config' concept from MB.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / paper-drawer-panel / paper-drawer-panel-extracted.js
blob11d316408b5e955a9312434b825b1c659b27a191
1 (function() {
3 'use strict';
5 // this would be the only `paper-drawer-panel` in
6 // the whole app that can be in `dragging` state
7 var sharedPanel = null;
9 function classNames(obj) {
10 var classes = [];
11 for (var key in obj) {
12 if (obj.hasOwnProperty(key) && obj[key]) {
13 classes.push(key);
17 return classes.join(' ');
20 Polymer({
22 is: 'paper-drawer-panel',
24 /**
25 * Fired when the narrow layout changes.
27 * @event paper-responsive-change {{narrow: boolean}} detail -
28 * narrow: true if the panel is in narrow layout.
31 /**
32 * Fired when the a panel is selected.
34 * Listening for this event is an alternative to observing changes in the `selected` attribute.
35 * This event is fired both when a panel is selected.
37 * @event iron-select {{item: Object}} detail -
38 * item: The panel that the event refers to.
41 /**
42 * Fired when a panel is deselected.
44 * Listening for this event is an alternative to observing changes in the `selected` attribute.
45 * This event is fired both when a panel is deselected.
47 * @event iron-deselect {{item: Object}} detail -
48 * item: The panel that the event refers to.
50 properties: {
52 /**
53 * The panel to be selected when `paper-drawer-panel` changes to narrow
54 * layout.
56 defaultSelected: {
57 type: String,
58 value: 'main'
61 /**
62 * If true, swipe from the edge is disable.
64 disableEdgeSwipe: {
65 type: Boolean,
66 value: false
69 /**
70 * If true, swipe to open/close the drawer is disabled.
72 disableSwipe: {
73 type: Boolean,
74 value: false
77 /**
78 * Whether the user is dragging the drawer interactively.
80 dragging: {
81 type: Boolean,
82 value: false,
83 readOnly: true,
84 notify: true
87 /**
88 * Width of the drawer panel.
90 drawerWidth: {
91 type: String,
92 value: '256px'
95 /**
96 * How many pixels on the side of the screen are sensitive to edge
97 * swipes and peek.
99 edgeSwipeSensitivity: {
100 type: Number,
101 value: 30
105 * If true, ignore `responsiveWidth` setting and force the narrow layout.
107 forceNarrow: {
108 type: Boolean,
109 value: false
113 * Whether the browser has support for the transform CSS property.
115 hasTransform: {
116 type: Boolean,
117 value: function() {
118 return 'transform' in this.style;
123 * Whether the browser has support for the will-change CSS property.
125 hasWillChange: {
126 type: Boolean,
127 value: function() {
128 return 'willChange' in this.style;
133 * Returns true if the panel is in narrow layout. This is useful if you
134 * need to show/hide elements based on the layout.
136 narrow: {
137 reflectToAttribute: true,
138 type: Boolean,
139 value: false,
140 readOnly: true,
141 notify: true
145 * Whether the drawer is peeking out from the edge.
147 peeking: {
148 type: Boolean,
149 value: false,
150 readOnly: true,
151 notify: true
155 * Max-width when the panel changes to narrow layout.
157 responsiveWidth: {
158 type: String,
159 value: '640px'
163 * If true, position the drawer to the right.
165 rightDrawer: {
166 type: Boolean,
167 value: false
171 * The panel that is being selected. `drawer` for the drawer panel and
172 * `main` for the main panel.
174 selected: {
175 reflectToAttribute: true,
176 notify: true,
177 type: String,
178 value: null
182 * The attribute on elements that should toggle the drawer on tap, also elements will
183 * automatically be hidden in wide layout.
185 drawerToggleAttribute: {
186 type: String,
187 value: 'paper-drawer-toggle'
191 * Whether the transition is enabled.
193 transition: {
194 type: Boolean,
195 value: false
200 listeners: {
201 tap: '_onTap',
202 track: '_onTrack',
203 down: '_downHandler',
204 up: '_upHandler'
207 observers: [
208 '_forceNarrowChanged(forceNarrow, defaultSelected)'
212 * Toggles the panel open and closed.
214 * @method togglePanel
216 togglePanel: function() {
217 if (this._isMainSelected()) {
218 this.openDrawer();
219 } else {
220 this.closeDrawer();
225 * Opens the drawer.
227 * @method openDrawer
229 openDrawer: function() {
230 this.selected = 'drawer';
234 * Closes the drawer.
236 * @method closeDrawer
238 closeDrawer: function() {
239 this.selected = 'main';
242 ready: function() {
243 // Avoid transition at the beginning e.g. page loads and enable
244 // transitions only after the element is rendered and ready.
245 this.transition = true;
248 _computeIronSelectorClass: function(narrow, transition, dragging, rightDrawer, peeking) {
249 return classNames({
250 dragging: dragging,
251 'narrow-layout': narrow,
252 'right-drawer': rightDrawer,
253 'left-drawer': !rightDrawer,
254 transition: transition,
255 peeking: peeking
259 _computeDrawerStyle: function(drawerWidth) {
260 return 'width:' + drawerWidth + ';';
263 _computeMainStyle: function(narrow, rightDrawer, drawerWidth) {
264 var style = '';
266 style += 'left:' + ((narrow || rightDrawer) ? '0' : drawerWidth) + ';';
268 if (rightDrawer) {
269 style += 'right:' + (narrow ? '' : drawerWidth) + ';';
272 return style;
275 _computeMediaQuery: function(forceNarrow, responsiveWidth) {
276 return forceNarrow ? '' : '(max-width: ' + responsiveWidth + ')';
279 _computeSwipeOverlayHidden: function(narrow, disableEdgeSwipe) {
280 return !narrow || disableEdgeSwipe;
283 _onTrack: function(event) {
284 if (sharedPanel && this !== sharedPanel) {
285 return;
287 switch (event.detail.state) {
288 case 'start':
289 this._trackStart(event);
290 break;
291 case 'track':
292 this._trackX(event);
293 break;
294 case 'end':
295 this._trackEnd(event);
296 break;
301 _responsiveChange: function(narrow) {
302 this._setNarrow(narrow);
304 if (this.narrow) {
305 this.selected = this.defaultSelected;
308 this.setScrollDirection(this._swipeAllowed() ? 'y' : 'all');
309 this.fire('paper-responsive-change', {narrow: this.narrow});
312 _onQueryMatchesChanged: function(event) {
313 this._responsiveChange(event.detail.value);
316 _forceNarrowChanged: function() {
317 // set the narrow mode only if we reached the `responsiveWidth`
318 this._responsiveChange(this.forceNarrow || this.$.mq.queryMatches);
321 _swipeAllowed: function() {
322 return this.narrow && !this.disableSwipe;
325 _isMainSelected: function() {
326 return this.selected === 'main';
329 _startEdgePeek: function() {
330 this.width = this.$.drawer.offsetWidth;
331 this._moveDrawer(this._translateXForDeltaX(this.rightDrawer ?
332 -this.edgeSwipeSensitivity : this.edgeSwipeSensitivity));
333 this._setPeeking(true);
336 _stopEdgePeek: function() {
337 if (this.peeking) {
338 this._setPeeking(false);
339 this._moveDrawer(null);
343 _downHandler: function(event) {
344 if (!this.dragging && this._isMainSelected() && this._isEdgeTouch(event) && !sharedPanel) {
345 this._startEdgePeek();
346 // cancel selection
347 event.preventDefault();
348 // grab this panel
349 sharedPanel = this;
353 _upHandler: function() {
354 this._stopEdgePeek();
355 // release the panel
356 sharedPanel = null;
359 _onTap: function(event) {
360 var targetElement = Polymer.dom(event).localTarget;
361 var isTargetToggleElement = targetElement &&
362 this.drawerToggleAttribute &&
363 targetElement.hasAttribute(this.drawerToggleAttribute);
365 if (isTargetToggleElement) {
366 this.togglePanel();
370 _isEdgeTouch: function(event) {
371 var x = event.detail.x;
373 return !this.disableEdgeSwipe && this._swipeAllowed() &&
374 (this.rightDrawer ?
375 x >= this.offsetWidth - this.edgeSwipeSensitivity :
376 x <= this.edgeSwipeSensitivity);
379 _trackStart: function(event) {
380 if (this._swipeAllowed()) {
381 sharedPanel = this;
382 this._setDragging(true);
384 if (this._isMainSelected()) {
385 this._setDragging(this.peeking || this._isEdgeTouch(event));
388 if (this.dragging) {
389 this.width = this.$.drawer.offsetWidth;
390 this.transition = false;
395 _translateXForDeltaX: function(deltaX) {
396 var isMain = this._isMainSelected();
398 if (this.rightDrawer) {
399 return Math.max(0, isMain ? this.width + deltaX : deltaX);
400 } else {
401 return Math.min(0, isMain ? deltaX - this.width : deltaX);
405 _trackX: function(event) {
406 if (this.dragging) {
407 var dx = event.detail.dx;
409 if (this.peeking) {
410 if (Math.abs(dx) <= this.edgeSwipeSensitivity) {
411 // Ignore trackx until we move past the edge peek.
412 return;
414 this._setPeeking(false);
417 this._moveDrawer(this._translateXForDeltaX(dx));
421 _trackEnd: function(event) {
422 if (this.dragging) {
423 var xDirection = event.detail.dx > 0;
425 this._setDragging(false);
426 this.transition = true;
427 sharedPanel = null;
428 this._moveDrawer(null);
430 if (this.rightDrawer) {
431 this[xDirection ? 'closeDrawer' : 'openDrawer']();
432 } else {
433 this[xDirection ? 'openDrawer' : 'closeDrawer']();
438 _transformForTranslateX: function(translateX) {
439 if (translateX === null) {
440 return '';
443 return this.hasWillChange ? 'translateX(' + translateX + 'px)' :
444 'translate3d(' + translateX + 'px, 0, 0)';
447 _moveDrawer: function(translateX) {
448 this.transform(this._transformForTranslateX(translateX), this.$.drawer);
453 }());