Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview This file contains methods that allow to tweak | |
| 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 | |
| 9 * (using templateData variable) that are filled with call to | |
| 10 * AddAccountUITweaksLocalizedValues in ui_account_tweaks.cc. | |
| 11 * It is also assumed that tweaked page has chrome://resources/css/widgets.css | |
| 12 * included. | |
| 13 */ | |
| 14 | |
| 15 cr.define('uiAccountTweaks', function() { | |
| 16 | |
| 17 ///////////////////////////////////////////////////////////////////////////// | |
| 18 // UIAccountTweaks class: | |
| 19 | |
| 20 /** | |
| 21 * Encapsulated handling of ChromeOS accounts options page. | |
| 22 * @constructor | |
| 23 */ | |
| 24 function UIAccountTweaks() { | |
| 25 } | |
| 26 | |
| 27 /** | |
|
James Hawkins
2012/04/10 18:26:54
Indentation is off.
Denis Kuznetsov (DE-MUC)
2012/04/11 13:51:14
Done.
| |
| 28 * Returns whether the current user is owner or not. | |
| 29 */ | |
| 30 UIAccountTweaks.currentUserIsOwner = function() { | |
| 31 return templateData['currentUserIsOwner'] == 'true'; | |
| 32 }; | |
| 33 | |
| 34 /** | |
| 35 * Returns whether we're currently in guest mode. | |
|
James Hawkins
2012/04/10 18:26:54
@return
Denis Kuznetsov (DE-MUC)
2012/04/11 13:51:14
Done.
| |
| 36 */ | |
| 37 UIAccountTweaks.loggedInAsGuest = function() { | |
| 38 return templateData['loggedInAsGuest'] == 'true'; | |
| 39 }; | |
| 40 | |
| 41 /** | |
| 42 * Disable or hide some elements in Guest mode in ChromeOS. | |
|
James Hawkins
2012/04/10 18:26:54
"Disables or hides"
Denis Kuznetsov (DE-MUC)
2012/04/11 13:51:14
Done.
| |
| 43 * All elements within given document with guest-visibility | |
| 44 * attribute are either hidden (for guest-visibility="hidden") | |
| 45 * or disabled (for guest-visibility="disabled"). | |
| 46 * | |
| 47 * @param {Document} document Document that should processed. | |
| 48 */ | |
| 49 UIAccountTweaks.applyGuestModeVisibility = function(document) { | |
| 50 if (!cr.isChromeOS || !UIAccountTweaks.loggedInAsGuest()) | |
| 51 return; | |
| 52 var elements = document.querySelectorAll('[guest-visibility]'); | |
| 53 for (var i = 0; i < elements.length; i++) { | |
| 54 var element = elements[i]; | |
| 55 var visibility = element.getAttribute('guest-visibility'); | |
| 56 if (visibility == 'hidden') { | |
|
James Hawkins
2012/04/10 18:26:54
No braces for single-line blocks.
Denis Kuznetsov (DE-MUC)
2012/04/11 13:51:14
Done.
| |
| 57 element.hidden = true; | |
| 58 } else if (visibility == 'disabled') { | |
| 59 UIAccountTweaks.disableElementsForGuest(element); | |
| 60 } | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 /** | |
| 65 * Disables and marks page elements for Guest mode. | |
| 66 * Adds guest-disabled css class to all elements within given subtree, | |
| 67 * disables interactive elements (input/select/button), and removes href | |
| 68 * attribute from <a> elements. | |
| 69 * | |
| 70 * @param {Element} element Root element of DOM subtree that should be | |
| 71 * disabled. | |
| 72 */ | |
| 73 UIAccountTweaks.disableElementsForGuest = function(element) { | |
| 74 UIAccountTweaks.disableElementForGuest_(element); | |
| 75 | |
| 76 // Walk the tree, searching each ELEMENT node. | |
| 77 var walker = document.createTreeWalker(element, | |
| 78 NodeFilter.SHOW_ELEMENT, | |
| 79 null, | |
| 80 false); | |
| 81 | |
| 82 var node = walker.nextNode(); | |
| 83 while (node) { | |
| 84 UIAccountTweaks.disableElementForGuest_(node); | |
| 85 node = walker.nextNode(); | |
| 86 } | |
| 87 }; | |
| 88 | |
| 89 /** | |
| 90 * Disables single element for Guest mode. | |
| 91 * Adds guest-disabled css class, adds disabled attribute for appropriate | |
| 92 * elements (input/select/button), and removes href attribute from | |
| 93 * <a> element. | |
| 94 * | |
| 95 * @private | |
| 96 * @param {Element} element Element that should be disabled. | |
| 97 */ | |
| 98 UIAccountTweaks.disableElementForGuest_ = function(element) { | |
| 99 element.classList.add('guest-disabled'); | |
| 100 if (element.nodeName == 'INPUT' || | |
| 101 element.nodeName == 'SELECT' || | |
| 102 element.nodeName == 'BUTTON') | |
| 103 element.disabled = true; | |
| 104 if (element.nodeName == 'A') { | |
| 105 console.log(element); | |
|
James Hawkins
2012/04/10 18:26:54
Remove console spam.
Denis Kuznetsov (DE-MUC)
2012/04/11 13:51:14
Mea culpa.
Done.
| |
| 106 element.onclick = function() { | |
| 107 return false; | |
| 108 }; | |
| 109 } | |
| 110 }; | |
| 111 | |
| 112 // Export | |
| 113 return { | |
| 114 UIAccountTweaks: UIAccountTweaks | |
| 115 }; | |
| 116 | |
| 117 }); | |
| OLD | NEW |