Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / resources / settings / settings_page / settings_section.js
blobe6131e0f0043bf8219f2fefb7dfee1728866f36b
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @fileoverview
7 * 'cr-settings-section' shows a paper material themed section with a header
8 * which shows its page title and icon.
10 * Example:
12 * <cr-settings-section page-title="[[pageTitle]]" icon="[[icon]]">
13 * <!-- Insert your section controls here -->
14 * </cr-settings-section>
16 * @group Chrome Settings Elements
17 * @element cr-settings-section
19 Polymer({
20 is: 'cr-settings-section',
22 behaviors: [
23 Polymer.NeonAnimationRunnerBehavior,
26 properties: {
27 /**
28 * The current active route.
30 currentRoute: {
31 type: Object,
32 observer: 'currentRouteChanged_',
35 /**
36 * The section is expanded to a full-page view when this property matches
37 * currentRoute.section.
39 section: {
40 type: String,
43 /**
44 * Title for the page header and navigation menu.
46 pageTitle: String,
48 /**
49 * Name of the 'iron-icon' to show.
51 icon: String,
53 /**
54 * Container that determines the sizing of expanded sections.
56 expandContainer: {
57 type: Object,
58 notify: true,
61 animationConfig: {
62 value: function() {
63 return {
64 expand: {
65 name: 'expand-card-animation',
66 node: this,
68 collapse: {
69 name: 'collapse-card-animation',
70 node: this,
77 /** @private */
78 expanded_: false,
80 /** @private */
81 currentRouteChanged_: function() {
82 var expanded = this.currentRoute.section == this.section;
84 if (expanded == this.expanded_)
85 return;
87 this.expanded_ = expanded;
88 this.playAnimation(expanded ? 'expand' : 'collapse');
90 });
92 Polymer({
93 is: 'expand-card-animation',
95 behaviors: [
96 Polymer.NeonAnimationBehavior
99 configure: function(config) {
100 var node = config.node;
101 var containerRect = node.expandContainer.getBoundingClientRect();
102 var nodeRect = node.getBoundingClientRect();
104 // Save section's original height.
105 node.unexpandedHeight = nodeRect.height;
107 var headerHeight = node.$.header.getBoundingClientRect().height;
108 var newTop = containerRect.top - headerHeight;
109 var newHeight = containerRect.height + headerHeight;
111 node.style.position = 'fixed';
112 node.style.zIndex = '1';
114 this._effect = new KeyframeEffect(node, [
115 {'top': nodeRect.top + 'px', 'height': nodeRect.height + 'px'},
116 {'top': newTop + 'px', 'height': newHeight + 'px'},
117 ], this.timingFromConfig(config));
118 return this._effect;
121 complete: function(config) {
122 config.node.style.position = 'absolute';
123 config.node.style.top =
124 -config.node.$.header.getBoundingClientRect().height + 'px';
125 config.node.style.bottom = 0;
129 Polymer({
130 is: 'collapse-card-animation',
132 behaviors: [
133 Polymer.NeonAnimationBehavior
136 configure: function(config) {
137 var node = config.node;
139 var oldRect = node.getBoundingClientRect();
141 // Temporarily set position to static to determine new height.
142 node.style.position = '';
143 var newTop = node.getBoundingClientRect().top;
145 // TODO(tommycli): This value is undefined when the user navigates to a
146 // subpage directly by URL instead of from the settings root. Find a better
147 // method than using 200 as a dummy height.
148 var newHeight = node.unexpandedHeight || 200;
150 node.style.position = 'fixed';
152 this._effect = new KeyframeEffect(node, [
153 {'top': oldRect.top + 'px', 'height': oldRect.height + 'px'},
154 {'top': newTop + 'px', 'height': newHeight + 'px'},
155 ], this.timingFromConfig(config));
156 return this._effect;
159 complete: function(config) {
160 config.node.style.position = '';
161 config.node.style.zIndex = '0';