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

Side by Side Diff: chrome/browser/resources/settings/settings_page/main_page_behavior.js

Issue 1916323002: [MD settings] side nav routing to page sections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge with master Created 4 years, 7 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 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Fast out, slow in. 5 // Fast out, slow in.
6 var EASING_FUNCTION = 'cubic-bezier(0.4, 0, 0.2, 1)'; 6 var EASING_FUNCTION = 'cubic-bezier(0.4, 0, 0.2, 1)';
7 var EXPAND_DURATION = 350; 7 var EXPAND_DURATION = 350;
8 8
9 /** 9 /**
10 * Provides animations to expand and collapse individual sections in a page. 10 * Provides animations to expand and collapse individual sections in a page.
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 minHeight: card.origHeight_ + 'px', 302 minHeight: card.origHeight_ + 'px',
303 }]; 303 }];
304 var options = /** @type {!KeyframeEffectOptions} */({ 304 var options = /** @type {!KeyframeEffectOptions} */({
305 duration: EXPAND_DURATION 305 duration: EXPAND_DURATION
306 }); 306 });
307 var promise = this.animateElement('section', card, keyframes, options); 307 var promise = this.animateElement('section', card, keyframes, options);
308 return promise; 308 return promise;
309 }, 309 },
310 }; 310 };
311 311
312
312 /** @polymerBehavior */ 313 /** @polymerBehavior */
313 var MainPageBehavior = [ 314 var MainPageBehavior = [
314 TransitionBehavior, 315 TransitionBehavior,
315 MainPageBehaviorImpl 316 MainPageBehaviorImpl
316 ]; 317 ];
317 318
319
318 /** 320 /**
319 * TODO(michaelpg): integrate slide animations. 321 * TODO(michaelpg): integrate slide animations.
320 * @polymerBehavior RoutableBehavior 322 * @polymerBehavior RoutableBehavior
321 */ 323 */
322 var RoutableBehaviorImpl = { 324 var RoutableBehaviorImpl = {
323 properties: { 325 properties: {
324 /** Contains the current route. */ 326 /** Contains the current route. */
325 currentRoute: { 327 currentRoute: {
326 type: Object, 328 type: Object,
327 notify: true, 329 notify: true,
328 observer: 'currentRouteChanged_', 330 observer: 'currentRouteChanged_',
329 }, 331 },
330 }, 332 },
331 333
334 /**
335 * @param {string} section Name of the item to scroll into view.
336 */
337 scrollToSection: function(section) {
338 if (section) {
339 // TODO(dschuyler): Determine whether this setTimeout can be removed.
340 // See also: https://github.com/Polymer/polymer/issues/3629
341 setTimeout(function() {
342 this.getSection_(section).scrollIntoView();
343 }.bind(this));
344 }
345 },
346
332 /** @private */ 347 /** @private */
333 currentRouteChanged_: function(newRoute, oldRoute) { 348 currentRouteChanged_: function(newRoute, oldRoute) {
334 // route.section is only non-empty when the user is within a subpage. 349 var newRouteIsSubpage = newRoute && newRoute.subpage.length;
335 // When the user is not in a subpage, but on the Basic page, route.section 350 var oldRouteIsSubpage = oldRoute && oldRoute.subpage.length;
336 // is an empty string.
337 var newRouteIsSubpage = newRoute && newRoute.section;
338 var oldRouteIsSubpage = oldRoute && oldRoute.section;
339 351
340 if (!oldRoute && newRouteIsSubpage) { 352 if (!oldRoute && newRouteIsSubpage) {
341 // Allow the page to load before expanding the section. TODO(michaelpg): 353 // Allow the page to load before expanding the section. TODO(michaelpg):
342 // Time this better when refactoring settings-animated-pages. 354 // Time this better when refactoring settings-animated-pages.
343 setTimeout(function() { 355 setTimeout(function() {
344 var section = this.getSection_(newRoute.section); 356 var section = this.getSection_(newRoute.section);
345 if (section) 357 if (section)
346 this.expandSection(section); 358 this.expandSection(section);
347 }.bind(this)); 359 }.bind(this));
348 return; 360 return;
349 } 361 }
350 362
351 if (!newRouteIsSubpage && oldRouteIsSubpage) { 363 if (!newRouteIsSubpage && oldRouteIsSubpage) {
352 var section = this.getSection_(oldRoute.section); 364 var section = this.getSection_(oldRoute.section);
353 if (section) 365 if (section)
354 this.collapseSection(section); 366 this.collapseSection(section);
355 } else if (newRouteIsSubpage && 367 } else if (newRouteIsSubpage &&
356 (!oldRouteIsSubpage || newRoute.section != oldRoute.section)) { 368 (!oldRouteIsSubpage || newRoute.section != oldRoute.section)) {
357 var section = this.getSection_(newRoute.section); 369 var section = this.getSection_(newRoute.section);
358 if (section) 370 if (section)
359 this.expandSection(section); 371 this.expandSection(section);
372 } else if (newRoute && newRoute.section) {
373 this.scrollToSection(newRoute.section);
360 } 374 }
361 }, 375 },
362 376
363 /** 377 /**
364 * Helper function to get a section from the local DOM. 378 * Helper function to get a section from the local DOM.
365 * @param {string} section Section name of the element to get. 379 * @param {string} section Section name of the element to get.
366 * @return {?SettingsSectionElement} 380 * @return {?SettingsSectionElement}
367 * @private 381 * @private
368 */ 382 */
369 getSection_: function(section) { 383 getSection_: function(section) {
370 return /** @type {?SettingsSectionElement} */( 384 return /** @type {?SettingsSectionElement} */(
371 this.$$('[section=' + section + ']')); 385 this.$$('[section=' + section + ']'));
372 }, 386 },
373 }; 387 };
374 388
389
375 /** @polymerBehavior */ 390 /** @polymerBehavior */
376 var RoutableBehavior = [ 391 var RoutableBehavior = [
377 MainPageBehavior, 392 MainPageBehavior,
378 RoutableBehaviorImpl 393 RoutableBehaviorImpl
379 ]; 394 ];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698