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 if (!(node instanceof Element)) { |
arv (Not doing code reviews)
2014/07/25 18:27:13
this is always false
Dan Beam
2014/07/25 21:58:18
whoops, removed and changed back to cast
| |
129 UIAccountTweaks.disableElementForSessionType_( | |
130 /** @type {!Element} */(node), sessionType); | |
131 } | |
129 node = walker.nextNode(); | 132 node = walker.nextNode(); |
130 } | 133 } |
131 }; | 134 }; |
132 | 135 |
133 /** | 136 /** |
134 * Disables single element for given session type. | 137 * Disables single element for given session type. |
135 * Adds *sessionType*-disabled css class, adds disabled attribute for | 138 * Adds *sessionType*-disabled css class, adds disabled attribute for |
136 * appropriate elements (input/select/button), and removes href attribute from | 139 * appropriate elements (input/select/button), and removes href attribute from |
137 * <a> element. | 140 * <a> element. |
138 * | 141 * |
139 * @private | 142 * @private |
140 * @param {Element} element Element that should be disabled. | 143 * @param {!Element} element Element that should be disabled. |
141 * @param {string} sessionType account session Type specificator. | 144 * @param {string} sessionType account session Type specificator. |
142 */ | 145 */ |
143 UIAccountTweaks.disableElementForSessionType_ = function(element, | 146 UIAccountTweaks.disableElementForSessionType_ = function(element, |
144 sessionType) { | 147 sessionType) { |
145 element.classList.add(sessionType + '-disabled'); | 148 element.classList.add(sessionType + '-disabled'); |
146 if (element.nodeName == 'INPUT' || | 149 if (element.nodeName == 'INPUT' || |
147 element.nodeName == 'SELECT' || | 150 element.nodeName == 'SELECT' || |
148 element.nodeName == 'BUTTON') | 151 element.nodeName == 'BUTTON') { |
149 element.disabled = true; | 152 element.disabled = true; |
150 if (element.nodeName == 'A') { | 153 } else if (element.nodeName == 'A') { |
151 element.onclick = function() { | 154 element.onclick = function() { |
152 return false; | 155 return false; |
153 }; | 156 }; |
154 } | 157 } |
155 }; | 158 }; |
156 | 159 |
157 // Export | 160 // Export |
158 return { | 161 return { |
159 UIAccountTweaks: UIAccountTweaks | 162 UIAccountTweaks: UIAccountTweaks |
160 }; | 163 }; |
161 | 164 |
162 }); | 165 }); |
OLD | NEW |