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 /** | 5 /** |
6 * @fileoverview This file contains methods that allow to tweak | 6 * @fileoverview This file contains methods that allow to tweak |
7 * internal page UI based on the status of current user (owner/user/guest). | 7 * internal page UI based on the status of current user (owner/user/guest). |
8 * It is assumed that required data is passed via i18n strings | 8 * It is assumed that required data is passed via i18n strings |
9 * (using loadTimeData dictionary) that are filled with call to | 9 * (using loadTimeData dictionary) that are filled with call to |
10 * AddAccountUITweaksLocalizedValues in ui_account_tweaks.cc. | 10 * AddAccountUITweaksLocalizedValues in ui_account_tweaks.cc. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 return; | 102 return; |
103 UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_PUBLIC); | 103 UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_PUBLIC); |
104 } | 104 } |
105 | 105 |
106 /** | 106 /** |
107 * Disables and marks page elements for specified session type. | 107 * Disables and marks page elements for specified session type. |
108 * Adds #-disabled css class to all elements within given subtree, | 108 * Adds #-disabled css class to all elements within given subtree, |
109 * disables interactive elements (input/select/button), and removes href | 109 * disables interactive elements (input/select/button), and removes href |
110 * attribute from <a> elements. | 110 * attribute from <a> elements. |
111 * | 111 * |
112 * @param {Element} element Root element of DOM subtree that should be | 112 * @param {!Element} element Root element of DOM subtree that should be |
113 * disabled. | 113 * disabled. |
114 * @param {string} sessionType session type specificator. | 114 * @param {string} sessionType session type specificator. |
115 */ | 115 */ |
116 UIAccountTweaks.disableElementsForSessionType = function(element, | 116 UIAccountTweaks.disableElementsForSessionType = function(element, |
117 sessionType) { | 117 sessionType) { |
118 UIAccountTweaks.disableElementForSessionType_(element, sessionType); | 118 UIAccountTweaks.disableElementForSessionType_(element, sessionType); |
119 | 119 |
120 // Walk the tree, searching each ELEMENT node. | 120 // Walk the tree, searching each ELEMENT node. |
121 var walker = document.createTreeWalker(element, | 121 var walker = document.createTreeWalker(element, |
122 NodeFilter.SHOW_ELEMENT, | 122 NodeFilter.SHOW_ELEMENT, |
123 null, | 123 null, |
124 false); | 124 false); |
125 | 125 |
126 var node = walker.nextNode(); | 126 var node = walker.nextNode(); |
127 while (node) { | 127 while (node) { |
128 UIAccountTweaks.disableElementForSessionType_(node, sessionType); | 128 UIAccountTweaks.disableElementForSessionType_( |
| 129 /** @type {!Element} */(node), sessionType); |
129 node = walker.nextNode(); | 130 node = walker.nextNode(); |
130 } | 131 } |
131 }; | 132 }; |
132 | 133 |
133 /** | 134 /** |
134 * Disables single element for given session type. | 135 * Disables single element for given session type. |
135 * Adds *sessionType*-disabled css class, adds disabled attribute for | 136 * Adds *sessionType*-disabled css class, adds disabled attribute for |
136 * appropriate elements (input/select/button), and removes href attribute from | 137 * appropriate elements (input/select/button), and removes href attribute from |
137 * <a> element. | 138 * <a> element. |
138 * | 139 * |
139 * @private | 140 * @private |
140 * @param {Element} element Element that should be disabled. | 141 * @param {!Element} element Element that should be disabled. |
141 * @param {string} sessionType account session Type specificator. | 142 * @param {string} sessionType account session Type specificator. |
142 */ | 143 */ |
143 UIAccountTweaks.disableElementForSessionType_ = function(element, | 144 UIAccountTweaks.disableElementForSessionType_ = function(element, |
144 sessionType) { | 145 sessionType) { |
145 element.classList.add(sessionType + '-disabled'); | 146 element.classList.add(sessionType + '-disabled'); |
146 if (element.nodeName == 'INPUT' || | 147 if (element.nodeName == 'INPUT' || |
147 element.nodeName == 'SELECT' || | 148 element.nodeName == 'SELECT' || |
148 element.nodeName == 'BUTTON') | 149 element.nodeName == 'BUTTON') { |
149 element.disabled = true; | 150 element.disabled = true; |
150 if (element.nodeName == 'A') { | 151 } else if (element.nodeName == 'A') { |
151 element.onclick = function() { | 152 element.onclick = function() { |
152 return false; | 153 return false; |
153 }; | 154 }; |
154 } | 155 } |
155 }; | 156 }; |
156 | 157 |
157 // Export | 158 // Export |
158 return { | 159 return { |
159 UIAccountTweaks: UIAccountTweaks | 160 UIAccountTweaks: UIAccountTweaks |
160 }; | 161 }; |
161 | 162 |
162 }); | 163 }); |
OLD | NEW |