Chromium Code Reviews| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 */ | 68 */ |
| 69 UIAccountTweaks.applySessionTypeVisibility_ = function(document, | 69 UIAccountTweaks.applySessionTypeVisibility_ = function(document, |
| 70 sessionType) { | 70 sessionType) { |
| 71 var elements = document.querySelectorAll('['+ sessionType +'-visibility]'); | 71 var elements = document.querySelectorAll('['+ sessionType +'-visibility]'); |
| 72 for (var i = 0; i < elements.length; i++) { | 72 for (var i = 0; i < elements.length; i++) { |
| 73 var element = elements[i]; | 73 var element = elements[i]; |
| 74 var visibility = element.getAttribute(sessionType +'-visibility'); | 74 var visibility = element.getAttribute(sessionType +'-visibility'); |
| 75 if (visibility == 'hidden') | 75 if (visibility == 'hidden') |
| 76 element.hidden = true; | 76 element.hidden = true; |
| 77 else if (visibility == 'disabled') | 77 else if (visibility == 'disabled') |
| 78 UIAccountTweaks.disableElementsForSessionType(element, sessionType); | 78 UIAccountTweaks.disableNodeForSessionType(element, sessionType); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * Updates specific visibility of elements for Guest session in ChromeOS. | 83 * Updates specific visibility of elements for Guest session in ChromeOS. |
| 84 * Calls applySessionTypeVisibility_ method. | 84 * Calls applySessionTypeVisibility_ method. |
| 85 * | 85 * |
| 86 * @param {Document} document Document that should processed. | 86 * @param {Document} document Document that should processed. |
| 87 */ | 87 */ |
| 88 UIAccountTweaks.applyGuestSessionVisibility = function(document) { | 88 UIAccountTweaks.applyGuestSessionVisibility = function(document) { |
| 89 if (!cr.isChromeOS || !UIAccountTweaks.loggedInAsGuest()) | 89 if (!cr.isChromeOS || !UIAccountTweaks.loggedInAsGuest()) |
| 90 return; | 90 return; |
| 91 UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_GUEST); | 91 UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_GUEST); |
| 92 } | 92 } |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * Updates specific visibility of elements for Public account session in | 95 * Updates specific visibility of elements for Public account session in |
| 96 * ChromeOS. Calls applySessionTypeVisibility_ method. | 96 * ChromeOS. Calls applySessionTypeVisibility_ method. |
| 97 * | 97 * |
| 98 * @param {Document} document Document that should processed. | 98 * @param {Document} document Document that should processed. |
| 99 */ | 99 */ |
| 100 UIAccountTweaks.applyPublicSessionVisibility = function(document) { | 100 UIAccountTweaks.applyPublicSessionVisibility = function(document) { |
| 101 if (!cr.isChromeOS || !UIAccountTweaks.loggedInAsPublicAccount()) | 101 if (!cr.isChromeOS || !UIAccountTweaks.loggedInAsPublicAccount()) |
| 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 nodes for specified session type. |
| 108 * Adds #-disabled css class to all elements within given subtree, | 108 * Adds #-disabled css class to all nodes within given subtree, |
| 109 * disables interactive elements (input/select/button), and removes href | 109 * disables interactive nodes (input/select/button), and removes href |
| 110 * attribute from <a> elements. | 110 * attribute from <a> nodes. |
| 111 * | 111 * |
| 112 * @param {Element} element Root element of DOM subtree that should be | 112 * @param {!Node} node Root node of DOM subtree that should be disabled. |
|
arv (Not doing code reviews)
2014/07/24 16:44:24
!Element was more correct. Here is a case where th
Dan Beam
2014/07/25 01:52:32
see what you think of updated changes
| |
| 113 * disabled. | |
| 114 * @param {string} sessionType session type specificator. | 113 * @param {string} sessionType session type specificator. |
| 115 */ | 114 */ |
| 116 UIAccountTweaks.disableElementsForSessionType = function(element, | 115 UIAccountTweaks.disableNodeForSessionType = function(node, sessionType) { |
| 117 sessionType) { | 116 UIAccountTweaks.disableNodeForSessionType_(node, sessionType); |
| 118 UIAccountTweaks.disableElementForSessionType_(element, sessionType); | |
| 119 | 117 |
| 120 // Walk the tree, searching each ELEMENT node. | 118 // Walk the tree, searching each ELEMENT node. |
| 121 var walker = document.createTreeWalker(element, | 119 var walker = document.createTreeWalker(node, |
| 122 NodeFilter.SHOW_ELEMENT, | 120 NodeFilter.SHOW_ELEMENT, |
| 123 null, | 121 null, |
| 124 false); | 122 false); |
| 125 | 123 |
| 126 var node = walker.nextNode(); | 124 var temp = walker.nextNode(); |
| 127 while (node) { | 125 while (temp) { |
| 128 UIAccountTweaks.disableElementForSessionType_(node, sessionType); | 126 UIAccountTweaks.disableNodeForSessionType_(temp, sessionType); |
| 129 node = walker.nextNode(); | 127 temp = walker.nextNode(); |
| 130 } | 128 } |
| 131 }; | 129 }; |
| 132 | 130 |
| 133 /** | 131 /** |
| 134 * Disables single element for given session type. | 132 * Disables single node for given session type. |
| 135 * Adds *sessionType*-disabled css class, adds disabled attribute for | 133 * Adds *sessionType*-disabled css class, adds disabled attribute for |
| 136 * appropriate elements (input/select/button), and removes href attribute from | 134 * appropriate nodes (input/select/button), and removes href attribute from |
| 137 * <a> element. | 135 * <a> node. |
| 138 * | 136 * |
| 137 * @param {Node} node Node to disable. | |
| 138 * @param {string} sessionType account session Type specificator. | |
| 139 * @private | 139 * @private |
| 140 * @param {Element} element Element that should be disabled. | |
| 141 * @param {string} sessionType account session Type specificator. | |
| 142 */ | 140 */ |
| 143 UIAccountTweaks.disableElementForSessionType_ = function(element, | 141 UIAccountTweaks.disableNodeForSessionType_ = function(node, sessionType) { |
| 144 sessionType) { | 142 node.classList.add(sessionType + '-disabled'); |
|
arv (Not doing code reviews)
2014/07/24 16:44:24
Node does not have classList property. It is a pro
Dan Beam
2014/07/25 01:52:32
that's what i thought as well, but it didn't. i t
| |
| 145 element.classList.add(sessionType + '-disabled'); | 143 |
| 146 if (element.nodeName == 'INPUT' || | 144 if (/^(INPUT|SELECT|BUTTON)$/.test(node.nodeName)) |
|
arv (Not doing code reviews)
2014/07/24 16:44:24
If you are refactoring this a switch would be the
Dan Beam
2014/07/25 01:52:32
reverted
| |
| 147 element.nodeName == 'SELECT' || | 145 node.disabled = true; |
|
arv (Not doing code reviews)
2014/07/24 16:44:24
Node does not have a disabled property. Is the typ
Dan Beam
2014/07/25 01:52:32
externs
| |
| 148 element.nodeName == 'BUTTON') | 146 else if (node.nodeName == 'A') |
| 149 element.disabled = true; | 147 node.onclick = function() { return false; }; |
| 150 if (element.nodeName == 'A') { | |
| 151 element.onclick = function() { | |
| 152 return false; | |
| 153 }; | |
| 154 } | |
| 155 }; | 148 }; |
| 156 | 149 |
| 157 // Export | 150 // Export |
| 158 return { | 151 return { |
| 159 UIAccountTweaks: UIAccountTweaks | 152 UIAccountTweaks: UIAccountTweaks |
| 160 }; | 153 }; |
| 161 | 154 |
| 162 }); | 155 }); |
| OLD | NEW |