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

Side by Side Diff: third_party/polymer/v1_0/components-chromium/paper-drawer-panel/paper-drawer-panel-extracted.js

Issue 1766433002: Roll Polymer to 1.3.1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 months 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
1 (function() { 1 (function() {
2 'use strict'; 2 'use strict';
3 3
4 // this would be the only `paper-drawer-panel` in 4 // this would be the only `paper-drawer-panel` in
5 // the whole app that can be in `dragging` state 5 // the whole app that can be in `dragging` state
6 var sharedPanel = null; 6 var sharedPanel = null;
7 7
8 function classNames(obj) { 8 function classNames(obj) {
9 var classes = []; 9 var classes = [];
10 for (var key in obj) { 10 for (var key in obj) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 /** 182 /**
183 * The attribute on elements that should toggle the drawer on tap, als o elements will 183 * The attribute on elements that should toggle the drawer on tap, als o elements will
184 * automatically be hidden in wide layout. 184 * automatically be hidden in wide layout.
185 */ 185 */
186 drawerToggleAttribute: { 186 drawerToggleAttribute: {
187 type: String, 187 type: String,
188 value: 'paper-drawer-toggle' 188 value: 'paper-drawer-toggle'
189 }, 189 },
190 190
191 /** 191 /**
192 * The CSS selector for the element that should receive focus when the drawer is open.
193 * By default, when the drawer opens, it focuses the first tabbable el ement. That is,
194 * the first element that can receive focus.
195 */
196 drawerFocusSelector: {
197 type: String,
198 value:
199 'a[href]:not([tabindex="-1"]),'+
200 'area[href]:not([tabindex="-1"]),'+
201 'input:not([disabled]):not([tabindex="-1"]),'+
202 'select:not([disabled]):not([tabindex="-1"]),'+
203 'textarea:not([disabled]):not([tabindex="-1"]),'+
204 'button:not([disabled]):not([tabindex="-1"]),'+
205 'iframe:not([tabindex="-1"]),'+
206 '[tabindex]:not([tabindex="-1"]),'+
207 '[contentEditable=true]:not([tabindex="-1"])'
208 },
209
210 /**
192 * Whether the transition is enabled. 211 * Whether the transition is enabled.
193 */ 212 */
194 _transition: { 213 _transition: {
195 type: Boolean, 214 type: Boolean,
196 value: false 215 value: false
197 }, 216 },
198 217
199 }, 218 },
200 219
201 listeners: { 220 listeners: {
202 tap: '_onTap', 221 tap: '_onTap',
203 track: '_onTrack', 222 track: '_onTrack',
204 down: '_downHandler', 223 down: '_downHandler',
205 up: '_upHandler' 224 up: '_upHandler',
225 transitionend: '_onTransitionEnd'
206 }, 226 },
207 227
208 observers: [ 228 observers: [
209 '_forceNarrowChanged(forceNarrow, defaultSelected)' 229 '_forceNarrowChanged(forceNarrow, defaultSelected)',
230 '_toggleFocusListener(selected)'
210 ], 231 ],
211 232
233 ready: function() {
234 // Avoid transition at the beginning e.g. page loads and enable
235 // transitions only after the element is rendered and ready.
236 this._transition = true;
237 this._boundFocusListener = this._didFocus.bind(this);
238 },
239
212 /** 240 /**
213 * Toggles the panel open and closed. 241 * Toggles the panel open and closed.
214 * 242 *
215 * @method togglePanel 243 * @method togglePanel
216 */ 244 */
217 togglePanel: function() { 245 togglePanel: function() {
218 if (this._isMainSelected()) { 246 if (this._isMainSelected()) {
219 this.openDrawer(); 247 this.openDrawer();
220 } else { 248 } else {
221 this.closeDrawer(); 249 this.closeDrawer();
(...skipping 11 matching lines...) Expand all
233 261
234 /** 262 /**
235 * Closes the drawer. 263 * Closes the drawer.
236 * 264 *
237 * @method closeDrawer 265 * @method closeDrawer
238 */ 266 */
239 closeDrawer: function() { 267 closeDrawer: function() {
240 this.selected = 'main'; 268 this.selected = 'main';
241 }, 269 },
242 270
243 ready: function() { 271 _onTransitionEnd: function (e) {
244 // Avoid transition at the beginning e.g. page loads and enable 272 var target = Polymer.dom(e).localTarget;
245 // transitions only after the element is rendered and ready. 273 if (target !== this) {
246 this._transition = true; 274 // ignore events coming from the light dom
247 }, 275 return;
248 276 }
249 _onMainTransitionEnd: function (e) { 277 if (e.propertyName === 'left' || e.propertyName === 'right') {
250 if (e.currentTarget === this.$.main && (e.propertyName === 'left' || e .propertyName === 'right')) {
251 this.notifyResize(); 278 this.notifyResize();
252 } 279 }
280 if (e.propertyName === 'transform' && this.selected === 'drawer') {
281 var focusedChild = this._getAutoFocusedNode();
282 focusedChild && focusedChild.focus();
283 }
253 }, 284 },
254 285
255 _computeIronSelectorClass: function(narrow, transition, dragging, rightD rawer, peeking) { 286 _computeIronSelectorClass: function(narrow, transition, dragging, rightD rawer, peeking) {
256 return classNames({ 287 return classNames({
257 dragging: dragging, 288 dragging: dragging,
258 'narrow-layout': narrow, 289 'narrow-layout': narrow,
259 'right-drawer': rightDrawer, 290 'right-drawer': rightDrawer,
260 'left-drawer': !rightDrawer, 291 'left-drawer': !rightDrawer,
261 transition: transition, 292 transition: transition,
262 peeking: peeking 293 peeking: peeking
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 case 'start': 326 case 'start':
296 this._trackStart(event); 327 this._trackStart(event);
297 break; 328 break;
298 case 'track': 329 case 'track':
299 this._trackX(event); 330 this._trackX(event);
300 break; 331 break;
301 case 'end': 332 case 'end':
302 this._trackEnd(event); 333 this._trackEnd(event);
303 break; 334 break;
304 } 335 }
305
306 }, 336 },
307 337
308 _responsiveChange: function(narrow) { 338 _responsiveChange: function(narrow) {
309 this._setNarrow(narrow); 339 this._setNarrow(narrow);
310 340
311 if (this.narrow) { 341 this.selected = this.narrow ? this.defaultSelected : null;
312 this.selected = this.defaultSelected;
313 }
314 342
315 this.setScrollDirection(this._swipeAllowed() ? 'y' : 'all'); 343 this.setScrollDirection(this._swipeAllowed() ? 'y' : 'all');
316 this.fire('paper-responsive-change', {narrow: this.narrow}); 344 this.fire('paper-responsive-change', {narrow: this.narrow});
317 }, 345 },
318 346
319 _onQueryMatchesChanged: function(event) { 347 _onQueryMatchesChanged: function(event) {
320 this._responsiveChange(event.detail.value); 348 this._responsiveChange(event.detail.value);
321 }, 349 },
322 350
323 _forceNarrowChanged: function() { 351 _forceNarrowChanged: function() {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } else { 467 } else {
440 this[xDirection ? 'openDrawer' : 'closeDrawer'](); 468 this[xDirection ? 'openDrawer' : 'closeDrawer']();
441 } 469 }
442 } 470 }
443 }, 471 },
444 472
445 _transformForTranslateX: function(translateX) { 473 _transformForTranslateX: function(translateX) {
446 if (translateX === null) { 474 if (translateX === null) {
447 return ''; 475 return '';
448 } 476 }
449
450 return this.hasWillChange ? 'translateX(' + translateX + 'px)' : 477 return this.hasWillChange ? 'translateX(' + translateX + 'px)' :
451 'translate3d(' + translateX + 'px, 0, 0)'; 478 'translate3d(' + translateX + 'px, 0, 0)';
452 }, 479 },
453 480
454 _moveDrawer: function(translateX) { 481 _moveDrawer: function(translateX) {
455 this.transform(this._transformForTranslateX(translateX), this.$.drawer ); 482 this.transform(this._transformForTranslateX(translateX), this.$.drawer );
483 },
484
485 _getDrawerContent: function() {
486 return Polymer.dom(this.$.drawerContent).getDistributedNodes()[0];
487 },
488
489 _getAutoFocusedNode: function() {
490 var drawerContent = this._getDrawerContent();
491 return Polymer.dom(drawerContent).querySelector(this.drawerFocusSelect or) || drawerContent;
492 },
493
494 _toggleFocusListener: function(selected) {
495 if (selected === 'drawer') {
496 document.addEventListener('focus', this._boundFocusListener, true);
497 } else {
498 document.removeEventListener('focus', this._boundFocusListener, true );
499 }
500 },
501
502 _didFocus: function(event) {
503 var path = Polymer.dom(event).path;
504 var focusedChild = path[0];
505 var drawerContent = this._getDrawerContent();
506 var focusedChildCameFromDrawer = false;
507 var autoFocusedNode = this._getAutoFocusedNode();
508
509 while (!focusedChildCameFromDrawer && path[0] && path[0].hasAttribute) {
510 focusedChildCameFromDrawer = path.shift() === drawerContent;
511 }
512 if (!focusedChildCameFromDrawer && autoFocusedNode) {
513 autoFocusedNode.focus();
514 }
515 },
516
517 _isDrawerClosed: function(narrow, selected) {
518 return !narrow || selected !== 'drawer';
456 } 519 }
520 });
457 521
458 });
459 }()); 522 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698