summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/settings/settings_main/settings_main.js
blob: f683d4799e3225d8187111afb22def23eb0f3574 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview
 * 'settings-main' displays the selected settings page.
 *
 * Example:
 *
 *     <settings-main pages="[[pages]]" selected-page-id="{{selectedId}}">
 *     </settings-main>
 *
 * See settings-drawer for example of use in 'paper-drawer-panel'.
 *
 * @group Chrome Settings Elements
 * @element settings-main
 */
Polymer({
  is: 'settings-main',

  properties: {
    /**
     * Preferences state.
     *
     * @type {?CrSettingsPrefsElement}
     */
    prefs: {
      type: Object,
      notify: true,
    },

    /**
     * The current active route.
     */
    currentRoute: {
      type: Object,
      notify: true,
      observer: 'currentRouteChanged_',
    },

    // If false the 'basic' page should be shown.
    showAdvancedPage_: {
      type: Boolean,
      value: false
    }
  },

  listeners: {
    'expand-animation-complete': 'onExpandAnimationComplete_',
  },

  /** @private */
  currentRouteChanged_: function(newRoute, oldRoute) {
    this.showAdvancedPage_ = newRoute.page == 'advanced';

    var pageContainer = this.$.pageContainer;
    if (!oldRoute) {
      pageContainer.classList.toggle('expanded', newRoute.section);
      return;
    }

    // For contraction only, apply new styling immediately.
    if (!newRoute.section && oldRoute.section) {
      pageContainer.classList.remove('expanded');

      // TODO(tommycli): Save and restore scroll position. crbug.com/537359.
      pageContainer.scrollTop = 0;
    }
  },

  /** @private */
  onExpandAnimationComplete_: function() {
    if (this.currentRoute.section) {
      var pageContainer = this.$.pageContainer;
      pageContainer.classList.add('expanded');
      pageContainer.scrollTop = 0;
    }
  },
});