| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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('options', function() { | 5 cr.define('options', function() { |
| 6 ///////////////////////////////////////////////////////////////////////////// | 6 ///////////////////////////////////////////////////////////////////////////// |
| 7 // OptionsPage class: | 7 // OptionsPage class: |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Base class for options page. | 10 * Base class for options page. |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 if (topPage.willHidePage) | 397 if (topPage.willHidePage) |
| 398 topPage.willHidePage(); | 398 topPage.willHidePage(); |
| 399 topPage.visible = false; | 399 topPage.visible = false; |
| 400 topPage = topPage.parentPage; | 400 topPage = topPage.parentPage; |
| 401 } | 401 } |
| 402 | 402 |
| 403 this.updateHistoryState_(); | 403 this.updateHistoryState_(); |
| 404 }; | 404 }; |
| 405 | 405 |
| 406 /** | 406 /** |
| 407 * Updates managed banner visibility state based on the topmost page. | |
| 408 */ | |
| 409 OptionsPage.updateManagedBannerVisibility = function() { | |
| 410 var topPage = this.getTopmostVisiblePage(); | |
| 411 if (topPage) | |
| 412 topPage.updateManagedBannerVisibility(); | |
| 413 }; | |
| 414 | |
| 415 /** | |
| 416 * Shows the tab contents for the given navigation tab. | 407 * Shows the tab contents for the given navigation tab. |
| 417 * @param {!Element} tab The tab that the user clicked. | 408 * @param {!Element} tab The tab that the user clicked. |
| 418 */ | 409 */ |
| 419 OptionsPage.showTab = function(tab) { | 410 OptionsPage.showTab = function(tab) { |
| 420 // Search parents until we find a tab, or the nav bar itself. This allows | 411 // Search parents until we find a tab, or the nav bar itself. This allows |
| 421 // tabs to have child nodes, e.g. labels in separately-styled spans. | 412 // tabs to have child nodes, e.g. labels in separately-styled spans. |
| 422 while (tab && !tab.classList.contains('subpages-nav-tabs') && | 413 while (tab && !tab.classList.contains('subpages-nav-tabs') && |
| 423 !tab.classList.contains('tab')) { | 414 !tab.classList.contains('tab')) { |
| 424 tab = tab.parentNode; | 415 tab = tab.parentNode; |
| 425 } | 416 } |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 * @type {OptionsPage} | 891 * @type {OptionsPage} |
| 901 */ | 892 */ |
| 902 associatedControls: null, | 893 associatedControls: null, |
| 903 | 894 |
| 904 /** | 895 /** |
| 905 * Initializes page content. | 896 * Initializes page content. |
| 906 */ | 897 */ |
| 907 initializePage: function() {}, | 898 initializePage: function() {}, |
| 908 | 899 |
| 909 /** | 900 /** |
| 910 * Updates managed banner visibility state. This function iterates over | |
| 911 * all input fields of a window and if any of these is marked as managed | |
| 912 * it triggers the managed banner to be visible. The banner can be enforced | |
| 913 * being on through the managed flag of this class but it can not be forced | |
| 914 * being off if managed items exist. | |
| 915 */ | |
| 916 updateManagedBannerVisibility: function() { | |
| 917 var bannerDiv = $('managed-prefs-banner'); | |
| 918 | |
| 919 var controlledByPolicy = false; | |
| 920 var controlledByExtension = false; | |
| 921 var inputElements = this.pageDiv.querySelectorAll('input[controlled-by]'); | |
| 922 for (var i = 0, len = inputElements.length; i < len; i++) { | |
| 923 if (inputElements[i].controlledBy == 'policy') | |
| 924 controlledByPolicy = true; | |
| 925 else if (inputElements[i].controlledBy == 'extension') | |
| 926 controlledByExtension = true; | |
| 927 } | |
| 928 if (!controlledByPolicy && !controlledByExtension) { | |
| 929 bannerDiv.hidden = true; | |
| 930 } else { | |
| 931 bannerDiv.hidden = false; | |
| 932 var height = window.getComputedStyle(bannerDiv).height; | |
| 933 if (controlledByPolicy && !controlledByExtension) { | |
| 934 $('managed-prefs-text').textContent = | |
| 935 templateData.policyManagedPrefsBannerText; | |
| 936 } else if (!controlledByPolicy && controlledByExtension) { | |
| 937 $('managed-prefs-text').textContent = | |
| 938 templateData.extensionManagedPrefsBannerText; | |
| 939 } else if (controlledByPolicy && controlledByExtension) { | |
| 940 $('managed-prefs-text').textContent = | |
| 941 templateData.policyAndExtensionManagedPrefsBannerText; | |
| 942 } | |
| 943 } | |
| 944 }, | |
| 945 | |
| 946 /** | |
| 947 * Gets page visibility state. | 901 * Gets page visibility state. |
| 948 */ | 902 */ |
| 949 get visible() { | 903 get visible() { |
| 950 return !this.pageDiv.hidden; | 904 return !this.pageDiv.hidden; |
| 951 }, | 905 }, |
| 952 | 906 |
| 953 /** | 907 /** |
| 954 * Sets page visibility. | 908 * Sets page visibility. |
| 955 */ | 909 */ |
| 956 set visible(visible) { | 910 set visible(visible) { |
| 957 if ((this.visible && visible) || (!this.visible && !visible)) | 911 if ((this.visible && visible) || (!this.visible && !visible)) |
| 958 return; | 912 return; |
| 959 | 913 |
| 960 this.setContainerVisibility_(visible); | 914 this.setContainerVisibility_(visible); |
| 961 this.pageDiv.hidden = !visible; | 915 this.pageDiv.hidden = !visible; |
| 962 | 916 |
| 963 OptionsPage.updatePageFreezeStates(); | 917 OptionsPage.updatePageFreezeStates(); |
| 964 | 918 |
| 965 // The managed prefs banner is global, so after any visibility change | |
| 966 // update it based on the topmost page, not necessarily this page | |
| 967 // (e.g., if an ancestor is made visible after a child). | |
| 968 OptionsPage.updateManagedBannerVisibility(); | |
| 969 | |
| 970 // A subpage was shown or hidden. | 919 // A subpage was shown or hidden. |
| 971 if (!this.isOverlay && this.nestingLevel > 0) | 920 if (!this.isOverlay && this.nestingLevel > 0) |
| 972 OptionsPage.updateDisplayForShowOrHideSubpage_(); | 921 OptionsPage.updateDisplayForShowOrHideSubpage_(); |
| 973 else if (this.isOverlay && !visible) | 922 else if (this.isOverlay && !visible) |
| 974 OptionsPage.updateScrollPosition_(); | 923 OptionsPage.updateScrollPosition_(); |
| 975 | 924 |
| 976 cr.dispatchPropertyChange(this, 'visible', visible, !visible); | 925 cr.dispatchPropertyChange(this, 'visible', visible, !visible); |
| 977 }, | 926 }, |
| 978 | 927 |
| 979 /** | 928 /** |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 canShowPage: function() { | 1052 canShowPage: function() { |
| 1104 return true; | 1053 return true; |
| 1105 }, | 1054 }, |
| 1106 }; | 1055 }; |
| 1107 | 1056 |
| 1108 // Export | 1057 // Export |
| 1109 return { | 1058 return { |
| 1110 OptionsPage: OptionsPage | 1059 OptionsPage: OptionsPage |
| 1111 }; | 1060 }; |
| 1112 }); | 1061 }); |
| OLD | NEW |