OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('print_preview', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * Toggles visibility of the specified printing options sections. |
| 10 * @param {!Array.<print_preview.SettingsSection>} settingsSections Sections |
| 11 * to toggle by this component. |
| 12 * @constructor |
| 13 * @extends {print_preview.Component} |
| 14 */ |
| 15 function MoreSettings(settingsSections) { |
| 16 print_preview.Component.call(this); |
| 17 |
| 18 /** @private {!Array.<print_preview.SettingsSection>} */ |
| 19 this.settingsSections_ = settingsSections; |
| 20 |
| 21 /** @private {MoreSettings.SettingsToShow} */ |
| 22 this.settingsToShow_ = MoreSettings.SettingsToShow.MOST_POPULAR; |
| 23 }; |
| 24 |
| 25 /** |
| 26 * Which settings are visible to the user. |
| 27 * @enum {number} |
| 28 */ |
| 29 MoreSettings.SettingsToShow = { |
| 30 MOST_POPULAR: 1, |
| 31 ALL: 2 |
| 32 }; |
| 33 |
| 34 MoreSettings.prototype = { |
| 35 __proto__: print_preview.Component.prototype, |
| 36 |
| 37 /** @override */ |
| 38 enterDocument: function() { |
| 39 print_preview.Component.prototype.enterDocument.call(this); |
| 40 |
| 41 this.tracker.add(this.getElement(), 'click', this.onClick_.bind(this)); |
| 42 this.settingsSections_.forEach(function(section) { |
| 43 this.tracker.add( |
| 44 section, |
| 45 print_preview.SettingsSection.EventType.COLLAPSIBLE_CONTENT_CHANGED, |
| 46 this.updateState_.bind(this)); |
| 47 }.bind(this)); |
| 48 |
| 49 this.updateState_(); |
| 50 }, |
| 51 |
| 52 /** |
| 53 * Toggles "more/fewer options" state and notifies all the options sections |
| 54 * to reflect the new state. |
| 55 * @private |
| 56 */ |
| 57 onClick_: function() { |
| 58 this.settingsToShow_ = |
| 59 this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR ? |
| 60 MoreSettings.SettingsToShow.ALL : |
| 61 MoreSettings.SettingsToShow.MOST_POPULAR; |
| 62 this.updateState_(); |
| 63 }, |
| 64 |
| 65 /** |
| 66 * Updates the component appearance according to the current state. |
| 67 * @private |
| 68 */ |
| 69 updateState_: function() { |
| 70 var all = this.settingsToShow_ == MoreSettings.SettingsToShow.ALL; |
| 71 this.getChildElement('.more-settings-label').textContent = |
| 72 localStrings.getString(all ? 'lessOptionsLabel' : 'moreOptionsLabel'); |
| 73 var iconEl = this.getChildElement('.more-settings-icon'); |
| 74 iconEl.classList.toggle('more-settings-icon-plus', !all); |
| 75 iconEl.classList.toggle('more-settings-icon-minus', all); |
| 76 |
| 77 var hasSectionsToToggle = this.settingsSections_.some(function(section) { |
| 78 return section.hasCollapsibleContent(); |
| 79 }); |
| 80 |
| 81 if (hasSectionsToToggle) |
| 82 fadeInElement(this.getElement()); |
| 83 else |
| 84 fadeOutElement(this.getElement()); |
| 85 |
| 86 var collapseContent = |
| 87 this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR && |
| 88 hasSectionsToToggle; |
| 89 this.settingsSections_.forEach(function(section) { |
| 90 section.collapseContent = collapseContent; |
| 91 }); |
| 92 } |
| 93 }; |
| 94 |
| 95 // Export |
| 96 return { |
| 97 MoreSettings: MoreSettings |
| 98 }; |
| 99 }); |
OLD | NEW |