Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: ui/webui/resources/js/chromeos/ui_account_tweaks.js

Issue 2597013002: Run clang-format on ui/webui/resources (Closed)
Patch Set: remove cr_shared_menu.js Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
11 * It is also assumed that tweaked page has chrome://resources/css/widgets.css 11 * It is also assumed that tweaked page has chrome://resources/css/widgets.css
12 * included. 12 * included.
13 */ 13 */
14 14
15 cr.define('uiAccountTweaks', function() { 15 cr.define('uiAccountTweaks', function() {
16 16
17 ///////////////////////////////////////////////////////////////////////////// 17 /////////////////////////////////////////////////////////////////////////////
18 // UIAccountTweaks class: 18 // UIAccountTweaks class:
19 19
20 // String specificators for different types of sessions. 20 // String specificators for different types of sessions.
21 /** @const */ var SESSION_TYPE_GUEST = 'guest'; 21 /** @const */ var SESSION_TYPE_GUEST = 'guest';
22 /** @const */ var SESSION_TYPE_PUBLIC = 'public-account'; 22 /** @const */ var SESSION_TYPE_PUBLIC = 'public-account';
23 23
24 /** 24 /**
25 * Encapsulated handling of ChromeOS accounts options page. 25 * Encapsulated handling of ChromeOS accounts options page.
26 * @constructor 26 * @constructor
27 */ 27 */
28 function UIAccountTweaks() { 28 function UIAccountTweaks() {}
29 }
30 29
31 /** 30 /**
32 * @return {boolean} Whether the current user is owner or not. 31 * @return {boolean} Whether the current user is owner or not.
33 */ 32 */
34 UIAccountTweaks.currentUserIsOwner = function() { 33 UIAccountTweaks.currentUserIsOwner = function() {
35 return loadTimeData.getBoolean('currentUserIsOwner'); 34 return loadTimeData.getBoolean('currentUserIsOwner');
36 }; 35 };
37 36
38 /** 37 /**
39 * @return {boolean} Whether we're currently in guest session. 38 * @return {boolean} Whether we're currently in guest session.
(...skipping 27 matching lines...) Expand all
67 sessionType = SESSION_TYPE_GUEST; 66 sessionType = SESSION_TYPE_GUEST;
68 else if (UIAccountTweaks.loggedInAsPublicAccount()) 67 else if (UIAccountTweaks.loggedInAsPublicAccount())
69 sessionType = SESSION_TYPE_PUBLIC; 68 sessionType = SESSION_TYPE_PUBLIC;
70 69
71 if (sessionType && 70 if (sessionType &&
72 element.getAttribute(sessionType + '-visibility') == 'disabled') { 71 element.getAttribute(sessionType + '-visibility') == 'disabled') {
73 return; 72 return;
74 } 73 }
75 74
76 element.disabled = false; 75 element.disabled = false;
77 } 76 };
78 77
79 /** 78 /**
80 * Disables or hides some elements in specified type of session in ChromeOS. 79 * Disables or hides some elements in specified type of session in ChromeOS.
81 * All elements within given document with *sessionType*-visibility 80 * All elements within given document with *sessionType*-visibility
82 * attribute are either hidden (for *sessionType*-visibility="hidden") 81 * attribute are either hidden (for *sessionType*-visibility="hidden")
83 * or disabled (for *sessionType*-visibility="disabled"). 82 * or disabled (for *sessionType*-visibility="disabled").
84 * 83 *
85 * @param {Document} document Document that should processed. 84 * @param {Document} document Document that should processed.
86 * @param {string} sessionType name of the session type processed. 85 * @param {string} sessionType name of the session type processed.
87 * @private 86 * @private
88 */ 87 */
89 UIAccountTweaks.applySessionTypeVisibility_ = function(document, 88 UIAccountTweaks.applySessionTypeVisibility_ = function(
90 sessionType) { 89 document, sessionType) {
91 var elements = document.querySelectorAll('['+ sessionType + '-visibility]'); 90 var elements =
91 document.querySelectorAll('[' + sessionType + '-visibility]');
92 for (var i = 0; i < elements.length; i++) { 92 for (var i = 0; i < elements.length; i++) {
93 var element = elements[i]; 93 var element = elements[i];
94 var visibility = element.getAttribute(sessionType + '-visibility'); 94 var visibility = element.getAttribute(sessionType + '-visibility');
95 if (visibility == 'hidden') 95 if (visibility == 'hidden')
96 element.hidden = true; 96 element.hidden = true;
97 else if (visibility == 'disabled') 97 else if (visibility == 'disabled')
98 UIAccountTweaks.disableElementsForSessionType(element, sessionType); 98 UIAccountTweaks.disableElementsForSessionType(element, sessionType);
99 } 99 }
100 } 100 };
101 101
102 /** 102 /**
103 * Updates specific visibility of elements for Guest session in ChromeOS. 103 * Updates specific visibility of elements for Guest session in ChromeOS.
104 * Calls applySessionTypeVisibility_ method. 104 * Calls applySessionTypeVisibility_ method.
105 * 105 *
106 * @param {Document} document Document that should processed. 106 * @param {Document} document Document that should processed.
107 */ 107 */
108 UIAccountTweaks.applyGuestSessionVisibility = function(document) { 108 UIAccountTweaks.applyGuestSessionVisibility = function(document) {
109 if (!UIAccountTweaks.loggedInAsGuest()) 109 if (!UIAccountTweaks.loggedInAsGuest())
110 return; 110 return;
111 UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_GUEST); 111 UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_GUEST);
112 } 112 };
113 113
114 /** 114 /**
115 * Updates specific visibility of elements for Public account session in 115 * Updates specific visibility of elements for Public account session in
116 * ChromeOS. Calls applySessionTypeVisibility_ method. 116 * ChromeOS. Calls applySessionTypeVisibility_ method.
117 * 117 *
118 * @param {Document} document Document that should processed. 118 * @param {Document} document Document that should processed.
119 */ 119 */
120 UIAccountTweaks.applyPublicSessionVisibility = function(document) { 120 UIAccountTweaks.applyPublicSessionVisibility = function(document) {
121 if (!UIAccountTweaks.loggedInAsPublicAccount()) 121 if (!UIAccountTweaks.loggedInAsPublicAccount())
122 return; 122 return;
123 UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_PUBLIC); 123 UIAccountTweaks.applySessionTypeVisibility_(document, SESSION_TYPE_PUBLIC);
124 } 124 };
125 125
126 /** 126 /**
127 * Disables and marks page elements for specified session type. 127 * Disables and marks page elements for specified session type.
128 * Adds #-disabled css class to all elements within given subtree, 128 * Adds #-disabled css class to all elements within given subtree,
129 * disables interactive elements (input/select/button), and removes href 129 * disables interactive elements (input/select/button), and removes href
130 * attribute from <a> elements. 130 * attribute from <a> elements.
131 * 131 *
132 * @param {!Element} element Root element of DOM subtree that should be 132 * @param {!Element} element Root element of DOM subtree that should be
133 * disabled. 133 * disabled.
134 * @param {string} sessionType session type specificator. 134 * @param {string} sessionType session type specificator.
135 */ 135 */
136 UIAccountTweaks.disableElementsForSessionType = function(element, 136 UIAccountTweaks.disableElementsForSessionType = function(
137 sessionType) { 137 element, sessionType) {
138 UIAccountTweaks.disableElementForSessionType_(element, sessionType); 138 UIAccountTweaks.disableElementForSessionType_(element, sessionType);
139 139
140 // Walk the tree, searching each ELEMENT node. 140 // Walk the tree, searching each ELEMENT node.
141 var walker = document.createTreeWalker(element, 141 var walker = document.createTreeWalker(
142 NodeFilter.SHOW_ELEMENT, 142 element, NodeFilter.SHOW_ELEMENT, null, false);
143 null,
144 false);
145 143
146 var node = walker.nextNode(); 144 var node = walker.nextNode();
147 while (node) { 145 while (node) {
148 UIAccountTweaks.disableElementForSessionType_( 146 UIAccountTweaks.disableElementForSessionType_(
149 /** @type {!Element} */(node), sessionType); 147 /** @type {!Element} */ (node), sessionType);
150 node = walker.nextNode(); 148 node = walker.nextNode();
151 } 149 }
152 }; 150 };
153 151
154 /** 152 /**
155 * Disables single element for given session type. 153 * Disables single element for given session type.
156 * Adds *sessionType*-disabled css class, adds disabled attribute for 154 * Adds *sessionType*-disabled css class, adds disabled attribute for
157 * appropriate elements (input/select/button), and removes href attribute from 155 * appropriate elements (input/select/button), and removes href attribute from
158 * <a> element. 156 * <a> element.
159 * 157 *
160 * @private 158 * @private
161 * @param {!Element} element Element that should be disabled. 159 * @param {!Element} element Element that should be disabled.
162 * @param {string} sessionType account session Type specificator. 160 * @param {string} sessionType account session Type specificator.
163 */ 161 */
164 UIAccountTweaks.disableElementForSessionType_ = function(element, 162 UIAccountTweaks.disableElementForSessionType_ = function(
165 sessionType) { 163 element, sessionType) {
166 element.classList.add(sessionType + '-disabled'); 164 element.classList.add(sessionType + '-disabled');
167 if (element.nodeName == 'INPUT' || 165 if (element.nodeName == 'INPUT' || element.nodeName == 'SELECT' ||
168 element.nodeName == 'SELECT' ||
169 element.nodeName == 'BUTTON') { 166 element.nodeName == 'BUTTON') {
170 element.disabled = true; 167 element.disabled = true;
171 } else if (element.nodeName == 'A') { 168 } else if (element.nodeName == 'A') {
172 element.onclick = function() { 169 element.onclick = function() { return false; };
173 return false;
174 };
175 } 170 }
176 }; 171 };
177 172
178 // Export 173 // Export
179 return { 174 return {UIAccountTweaks: UIAccountTweaks};
180 UIAccountTweaks: UIAccountTweaks
181 };
182 175
183 }); 176 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698