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 {!Array.<print_preview.SettingsSection>} settingsSections Sections | 10 * @param {!Array.<print_preview.SettingsSection>} settingsSections Sections |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 * @private | 67 * @private |
68 */ | 68 */ |
69 updateState_: function() { | 69 updateState_: function() { |
70 var all = this.settingsToShow_ == MoreSettings.SettingsToShow.ALL; | 70 var all = this.settingsToShow_ == MoreSettings.SettingsToShow.ALL; |
71 this.getChildElement('.more-settings-label').textContent = | 71 this.getChildElement('.more-settings-label').textContent = |
72 localStrings.getString(all ? 'lessOptionsLabel' : 'moreOptionsLabel'); | 72 localStrings.getString(all ? 'lessOptionsLabel' : 'moreOptionsLabel'); |
73 var iconEl = this.getChildElement('.more-settings-icon'); | 73 var iconEl = this.getChildElement('.more-settings-icon'); |
74 iconEl.classList.toggle('more-settings-icon-plus', !all); | 74 iconEl.classList.toggle('more-settings-icon-plus', !all); |
75 iconEl.classList.toggle('more-settings-icon-minus', all); | 75 iconEl.classList.toggle('more-settings-icon-minus', all); |
76 | 76 |
77 var hasSectionsToToggle = this.settingsSections_.some(function(section) { | 77 var availableSections = this.settingsSections_.reduce( |
78 return section.hasCollapsibleContent(); | 78 function(count, section) { |
79 }); | 79 return count + (section.isAvailable() ? 1 : 0); |
| 80 }, 0); |
| 81 |
| 82 // Magic 6 is chosen as the number of sections when it still feels like |
| 83 // manageable and not too crowded. |
| 84 var hasSectionsToToggle = |
| 85 availableSections > 6 && |
| 86 this.settingsSections_.some(function(section) { |
| 87 return section.hasCollapsibleContent(); |
| 88 }); |
80 | 89 |
81 if (hasSectionsToToggle) | 90 if (hasSectionsToToggle) |
82 fadeInElement(this.getElement()); | 91 fadeInElement(this.getElement()); |
83 else | 92 else |
84 fadeOutElement(this.getElement()); | 93 fadeOutElement(this.getElement()); |
85 | 94 |
86 var collapseContent = | 95 var collapseContent = |
87 this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR && | 96 this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR && |
88 hasSectionsToToggle; | 97 hasSectionsToToggle; |
89 this.settingsSections_.forEach(function(section) { | 98 this.settingsSections_.forEach(function(section) { |
90 section.collapseContent = collapseContent; | 99 section.collapseContent = collapseContent; |
91 }); | 100 }); |
92 } | 101 } |
93 }; | 102 }; |
94 | 103 |
95 // Export | 104 // Export |
96 return { | 105 return { |
97 MoreSettings: MoreSettings | 106 MoreSettings: MoreSettings |
98 }; | 107 }; |
99 }); | 108 }); |
OLD | NEW |