OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Toggles visibility of the specified printing options sections. | 9 * Toggles visibility of the specified printing options sections. |
10 * @param {!print_preview.DestinationStore} destinationStore To listen for | 10 * @param {!print_preview.DestinationStore} destinationStore To listen for |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 enterDocument: function() { | 51 enterDocument: function() { |
52 print_preview.Component.prototype.enterDocument.call(this); | 52 print_preview.Component.prototype.enterDocument.call(this); |
53 | 53 |
54 this.tracker.add(this.getElement(), 'click', this.onClick_.bind(this)); | 54 this.tracker.add(this.getElement(), 'click', this.onClick_.bind(this)); |
55 this.tracker.add( | 55 this.tracker.add( |
56 this.destinationStore_, | 56 this.destinationStore_, |
57 print_preview.DestinationStore.EventType.DESTINATION_SELECT, | 57 print_preview.DestinationStore.EventType.DESTINATION_SELECT, |
58 this.onDestinationChanged_.bind(this)); | 58 this.onDestinationChanged_.bind(this)); |
59 this.tracker.add( | 59 this.tracker.add( |
60 this.destinationStore_, | 60 this.destinationStore_, |
61 print_preview.DestinationStore.EventType. | 61 print_preview.DestinationStore.EventType |
62 SELECTED_DESTINATION_CAPABILITIES_READY, | 62 .SELECTED_DESTINATION_CAPABILITIES_READY, |
63 this.onDestinationCapabilitiesReady_.bind(this)); | 63 this.onDestinationCapabilitiesReady_.bind(this)); |
64 this.settingsSections_.forEach(function(section) { | 64 this.settingsSections_.forEach(function(section) { |
65 this.tracker.add( | 65 this.tracker.add( |
66 section, | 66 section, |
67 print_preview.SettingsSection.EventType.COLLAPSIBLE_CONTENT_CHANGED, | 67 print_preview.SettingsSection.EventType.COLLAPSIBLE_CONTENT_CHANGED, |
68 this.updateState_.bind(this)); | 68 this.updateState_.bind(this)); |
69 }.bind(this)); | 69 }.bind(this)); |
70 | 70 |
71 this.updateState_(true); | 71 this.updateState_(true); |
72 }, | 72 }, |
73 | 73 |
74 /** | 74 /** |
75 * Toggles "more/fewer options" state and notifies all the options sections | 75 * Toggles "more/fewer options" state and notifies all the options sections |
76 * to reflect the new state. | 76 * to reflect the new state. |
77 * @private | 77 * @private |
78 */ | 78 */ |
79 onClick_: function() { | 79 onClick_: function() { |
80 this.showAll_ = !this.showAll_; | 80 this.showAll_ = !this.showAll_; |
81 this.updateState_(false); | 81 this.updateState_(false); |
82 this.metrics_.record(this.isExpanded ? | 82 this.metrics_.record( |
83 print_preview.Metrics.PrintSettingsUiBucket.MORE_SETTINGS_CLICKED : | 83 this.isExpanded ? print_preview.Metrics.PrintSettingsUiBucket |
84 print_preview.Metrics.PrintSettingsUiBucket.LESS_SETTINGS_CLICKED); | 84 .MORE_SETTINGS_CLICKED : |
| 85 print_preview.Metrics.PrintSettingsUiBucket |
| 86 .LESS_SETTINGS_CLICKED); |
85 }, | 87 }, |
86 | 88 |
87 /** | 89 /** |
88 * Called when the destination selection has changed. Updates UI elements. | 90 * Called when the destination selection has changed. Updates UI elements. |
89 * @private | 91 * @private |
90 */ | 92 */ |
91 onDestinationChanged_: function() { | 93 onDestinationChanged_: function() { |
92 this.firstDestinationReady_ = true; | 94 this.firstDestinationReady_ = true; |
93 this.capabilitiesReady_ = false; | 95 this.capabilitiesReady_ = false; |
94 this.updateState_(false); | 96 this.updateState_(false); |
(...skipping 18 matching lines...) Expand all Loading... |
113 if (!this.firstDestinationReady_) { | 115 if (!this.firstDestinationReady_) { |
114 fadeOutElement(this.getElement()); | 116 fadeOutElement(this.getElement()); |
115 return; | 117 return; |
116 } | 118 } |
117 // When capabilities are not known yet, don't change the state to avoid | 119 // When capabilities are not known yet, don't change the state to avoid |
118 // unnecessary fade in/out cycles. | 120 // unnecessary fade in/out cycles. |
119 if (!this.capabilitiesReady_) | 121 if (!this.capabilitiesReady_) |
120 return; | 122 return; |
121 | 123 |
122 this.getChildElement('.more-settings-label').textContent = | 124 this.getChildElement('.more-settings-label').textContent = |
123 loadTimeData.getString(this.isExpanded ? 'lessOptionsLabel' : | 125 loadTimeData.getString( |
124 'moreOptionsLabel'); | 126 this.isExpanded ? 'lessOptionsLabel' : 'moreOptionsLabel'); |
125 var iconEl = this.getChildElement('.more-settings-icon'); | 127 var iconEl = this.getChildElement('.more-settings-icon'); |
126 iconEl.classList.toggle('more-settings-icon-plus', !this.isExpanded); | 128 iconEl.classList.toggle('more-settings-icon-plus', !this.isExpanded); |
127 iconEl.classList.toggle('more-settings-icon-minus', this.isExpanded); | 129 iconEl.classList.toggle('more-settings-icon-minus', this.isExpanded); |
128 | 130 |
129 var availableSections = this.settingsSections_.reduce( | 131 var availableSections = |
130 function(count, section) { | 132 this.settingsSections_.reduce(function(count, section) { |
131 return count + (section.isAvailable() ? 1 : 0); | 133 return count + (section.isAvailable() ? 1 : 0); |
132 }, 0); | 134 }, 0); |
133 | 135 |
134 // Magic 6 is chosen as the number of sections when it still feels like | 136 // Magic 6 is chosen as the number of sections when it still feels like |
135 // manageable and not too crowded. | 137 // manageable and not too crowded. |
136 var hasSectionsToToggle = | 138 var hasSectionsToToggle = availableSections > 6 && |
137 availableSections > 6 && | |
138 this.settingsSections_.some(function(section) { | 139 this.settingsSections_.some(function(section) { |
139 return section.hasCollapsibleContent(); | 140 return section.hasCollapsibleContent(); |
140 }); | 141 }); |
141 | 142 |
142 if (hasSectionsToToggle) | 143 if (hasSectionsToToggle) |
143 fadeInElement(this.getElement(), noAnimation); | 144 fadeInElement(this.getElement(), noAnimation); |
144 else | 145 else |
145 fadeOutElement(this.getElement()); | 146 fadeOutElement(this.getElement()); |
146 | 147 |
147 var collapseContent = !this.isExpanded && hasSectionsToToggle; | 148 var collapseContent = !this.isExpanded && hasSectionsToToggle; |
148 this.settingsSections_.forEach(function(section) { | 149 this.settingsSections_.forEach(function(section) { |
149 section.setCollapseContent(collapseContent, noAnimation); | 150 section.setCollapseContent(collapseContent, noAnimation); |
150 }); | 151 }); |
151 } | 152 } |
152 }; | 153 }; |
153 | 154 |
154 // Export | 155 // Export |
155 return { | 156 return {MoreSettings: MoreSettings}; |
156 MoreSettings: MoreSettings | |
157 }; | |
158 }); | 157 }); |
OLD | NEW |