blob: 1ac79f4974527e1a5c8739b498d15c9764d3e857 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview This file contains methods that allow to tweak
* internal page UI based on the status of current user (owner/user/guest).
* It is assumed that required data is passed via i18n strings
* (using loadTimeData dictionary) that are filled with call to
* AddAccountUITweaksLocalizedValues in ui_account_tweaks.cc.
* It is also assumed that tweaked page has chrome://resources/css/widgets.css
* included.
*/
cr.define('uiAccountTweaks', function() {
/////////////////////////////////////////////////////////////////////////////
// UIAccountTweaks class:
/**
* Encapsulated handling of ChromeOS accounts options page.
* @constructor
*/
function UIAccountTweaks() {
}
/**
* @return {boolean} Whether the current user is owner or not.
*/
UIAccountTweaks.currentUserIsOwner = function() {
return loadTimeData.getBoolean('currentUserIsOwner');
};
/**
* @return {boolean} Whether we're currently in guest mode.
*/
UIAccountTweaks.loggedInAsGuest = function() {
return loadTimeData.getBoolean('loggedInAsGuest');
};
/**
* Disables or hides some elements in Guest mode in ChromeOS.
* All elements within given document with guest-visibility
* attribute are either hidden (for guest-visibility="hidden")
* or disabled (for guest-visibility="disabled").
*
* @param {Document} document Document that should processed.
*/
UIAccountTweaks.applyGuestModeVisibility = function(document) {
if (!cr.isChromeOS || !UIAccountTweaks.loggedInAsGuest())
return;
var elements = document.querySelectorAll('[guest-visibility]');
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var visibility = element.getAttribute('guest-visibility');
if (visibility == 'hidden')
element.hidden = true;
else if (visibility == 'disabled')
UIAccountTweaks.disableElementsForGuest(element);
}
}
/**
* Disables and marks page elements for Guest mode.
* Adds guest-disabled css class to all elements within given subtree,
* disables interactive elements (input/select/button), and removes href
* attribute from <a> elements.
*
* @param {Element} element Root element of DOM subtree that should be
* disabled.
*/
UIAccountTweaks.disableElementsForGuest = function(element) {
UIAccountTweaks.disableElementForGuest_(element);
// Walk the tree, searching each ELEMENT node.
var walker = document.createTreeWalker(element,
NodeFilter.SHOW_ELEMENT,
null,
false);
var node = walker.nextNode();
while (node) {
UIAccountTweaks.disableElementForGuest_(node);
node = walker.nextNode();
}
};
/**
* Disables single element for Guest mode.
* Adds guest-disabled css class, adds disabled attribute for appropriate
* elements (input/select/button), and removes href attribute from
* <a> element.
*
* @private
* @param {Element} element Element that should be disabled.
*/
UIAccountTweaks.disableElementForGuest_ = function(element) {
element.classList.add('guest-disabled');
if (element.nodeName == 'INPUT' ||
element.nodeName == 'SELECT' ||
element.nodeName == 'BUTTON')
element.disabled = true;
if (element.nodeName == 'A') {
element.onclick = function() {
return false;
};
}
};
// Export
return {
UIAccountTweaks: UIAccountTweaks
};
});
|