| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 cr.define('chrome.supervised_user_internals', function() { | 5 cr.define('chrome.supervised_user_internals', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 function initialize() { | 8 function initialize() { |
| 9 function submitURL(event) { | 9 function submitURL(event) { |
| 10 $('try-url-result').textContent = ''; | 10 $('try-url-result').textContent = ''; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 if (oldStr != '' && oldStr != newStr) { | 32 if (oldStr != '' && oldStr != newStr) { |
| 33 // Note the addListener function does not end up creating duplicate | 33 // Note the addListener function does not end up creating duplicate |
| 34 // listeners. There can be only one listener per event at a time. | 34 // listeners. There can be only one listener per event at a time. |
| 35 // See https://developer.mozilla.org/en/DOM/element.addEventListener | 35 // See https://developer.mozilla.org/en/DOM/element.addEventListener |
| 36 node.addEventListener('webkitAnimationEnd', clearHighlight, false); | 36 node.addEventListener('webkitAnimationEnd', clearHighlight, false); |
| 37 node.setAttribute('highlighted', ''); | 37 node.setAttribute('highlighted', ''); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 function receiveBasicInfo(info) { | 41 function receiveBasicInfo(info) { |
| 42 jstProcess(new JsEvalContext(info), $('info')); | 42 jstProcess(new JsEvalContext(info), $('basic-info')); |
| 43 | 43 |
| 44 // Hack: Schedule another refresh after a while. | 44 // Hack: Schedule another refresh after a while. |
| 45 // TODO(treib): Get rid of this once we're properly notified of all | 45 // TODO(treib): Get rid of this once we're properly notified of all |
| 46 // relevant changes. | 46 // relevant changes. |
| 47 setTimeout(function() { chrome.send('getBasicInfo'); }, 5000); | 47 setTimeout(function() { chrome.send('getBasicInfo'); }, 5000); |
| 48 } | 48 } |
| 49 | 49 |
| 50 function receiveUserSettings(settings) { |
| 51 // The user settings are returned as an object, flatten them into a |
| 52 // list of key/value pairs for easier consumption by the HTML template. |
| 53 // This is not done recursively, values are passed as their JSON |
| 54 // representation. |
| 55 var kvpairs = Object.keys(settings).map(function(key) { |
| 56 return { |
| 57 key: key, |
| 58 value: JSON.stringify(settings[key], null, 2) |
| 59 }; |
| 60 }); |
| 61 |
| 62 jstProcess(new JsEvalContext({settings: kvpairs}), $('user-settings')); |
| 63 } |
| 64 |
| 50 function receiveTryURLResult(result) { | 65 function receiveTryURLResult(result) { |
| 51 $('try-url-result').textContent = result; | 66 $('try-url-result').textContent = result; |
| 52 } | 67 } |
| 53 | 68 |
| 54 /** | 69 /** |
| 55 * Helper to determine if an element is scrolled to its bottom limit. | 70 * Helper to determine if an element is scrolled to its bottom limit. |
| 56 * @param {Element} elem element to check | 71 * @param {Element} elem element to check |
| 57 * @return {boolean} true if the element is scrolled to the bottom | 72 * @return {boolean} true if the element is scrolled to the bottom |
| 58 */ | 73 */ |
| 59 function isScrolledToBottom(elem) { | 74 function isScrolledToBottom(elem) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 88 | 103 |
| 89 if (shouldScrollDown) | 104 if (shouldScrollDown) |
| 90 scrollToBottom(container); | 105 scrollToBottom(container); |
| 91 } | 106 } |
| 92 | 107 |
| 93 // Return an object with all of the exports. | 108 // Return an object with all of the exports. |
| 94 return { | 109 return { |
| 95 initialize: initialize, | 110 initialize: initialize, |
| 96 highlightIfChanged: highlightIfChanged, | 111 highlightIfChanged: highlightIfChanged, |
| 97 receiveBasicInfo: receiveBasicInfo, | 112 receiveBasicInfo: receiveBasicInfo, |
| 113 receiveUserSettings: receiveUserSettings, |
| 98 receiveTryURLResult: receiveTryURLResult, | 114 receiveTryURLResult: receiveTryURLResult, |
| 99 receiveFilteringResult: receiveFilteringResult, | 115 receiveFilteringResult: receiveFilteringResult, |
| 100 }; | 116 }; |
| 101 }); | 117 }); |
| 102 | 118 |
| 103 document.addEventListener('DOMContentLoaded', | 119 document.addEventListener('DOMContentLoaded', |
| 104 chrome.supervised_user_internals.initialize); | 120 chrome.supervised_user_internals.initialize); |
| OLD | NEW |