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

Side by Side Diff: chrome/browser/resources/chromeos/emulator/device_emulator.js

Issue 1205753002: Create chrome://device-emulator and add the ability to get a battery percentage and send an updated… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Create chrome://device-emulator and add the ability to get a battery percentage and send an updated… Created 5 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('device_emulator', function() {
6 'use strict';
7
8 /**
9 * Updates the UI with the battery status
michaelpg 2015/06/25 18:18:19 nit: end comments/sentences with a period
rfrappier 2015/06/25 21:43:24 Done.
10 * @param {number} percent Battery percentage (out of 100).
11 */
12 function setBatteryInfo(percent) {
13 var slider = $('battery-percent-slider');
14 var text = $('battery-percent-text');
15
16 slider.value = percent;
17 text.value = percent.toString();
18 }
19
20 /**
21 * Event listener fired when the battery percent slider is moved and the mouse
22 * is released. Updates the ChromeOS UI.
23 * @param {event} event Contains information about the event which was fired.
michaelpg 2015/06/25 18:18:19 {Event}
rfrappier 2015/06/25 21:43:24 Done.
24 */
25 function onBatterySliderChange(event) {
26 var slider = event.target;
27 chrome.send('updateBatteryInfo', [slider.valueAsNumer]);
28 }
29
30 /**
31 * Event listener fired when the battery percent slider is moved. Updates
32 * the battery slider's associated text input.
33 * @param {event} event Contains information about the event which was fired.
34 */
35 function onBatterySliderInput(event) {
36 var slider = event.target;
37 var text = $('battery-percent-text');
38
39 text.value = slider.value;
40 }
41
42 /**
43 * Event listener fired when a percentage is entered in the battery
44 * percentage text input. Updates the slider and ChromeOS UI.
45 * @param {event} event Contains information about the event which was fired.
46 */
47 function onBatteryTextChange(event) {
48 var text = event.target;
49 var slider = $('battery-percent-slider');
50 var percent = text.valueAsNumber;
51
52 if (isNaN(percent)) {
53 percent = 0;
54 text.valueAsNumber = 0;
55 }
56
57 slider.value = percent;
58
59 chrome.send('updateBatteryInfo', [percent]);
60 }
61
62 function initialize() {
63 chrome.send('requestBatteryInfo');
64
65 var slider = $('battery-percent-slider');
66 var text = $('battery-percent-text');
67
68 slider.addEventListener('change', onBatterySliderChange);
69 slider.addEventListener('input', onBatterySliderInput);
70 text.addEventListener('input', onBatteryTextChange);
71 }
72
73 // Return an object with all of the exports.
74 return {
75 initialize: initialize,
76 setBatteryInfo: setBatteryInfo,
77 };
78 });
79
80 document.addEventListener('DOMContentLoaded', device_emulator.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698