Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
/* global BaseIcon */
|
|
'use strict';
|
|
|
|
(function(exports) {
|
|
var BatteryIcon = function(manager) {
|
|
BaseIcon.call(this, manager);
|
|
};
|
|
BatteryIcon.prototype = Object.create(BaseIcon.prototype);
|
|
BatteryIcon.prototype.name = 'BatteryIcon';
|
|
BatteryIcon.prototype.update = function() {
|
|
if (!this.element) {
|
|
return;
|
|
}
|
|
var battery = this.manager._battery;
|
|
if (!battery || !Number.isFinite(battery.level)) {
|
|
this.hide();
|
|
return;
|
|
}
|
|
this.show();
|
|
var icon = this.element;
|
|
var previousLevel = parseInt(icon.dataset.level, 10);
|
|
var previousCharging = (icon.dataset.charging === 'true');
|
|
|
|
icon.dataset.charging = battery.charging;
|
|
var level = Math.floor(battery.level * 10) * 10;
|
|
|
|
this.debug('previous level: ', previousLevel);
|
|
this.debug('current level:', level);
|
|
|
|
if (previousLevel === level &&
|
|
previousCharging === battery.charging) {
|
|
return;
|
|
}
|
|
|
|
icon.dataset.level = level;
|
|
navigator.mozL10n.setAttributes(
|
|
icon,
|
|
battery.charging ? 'statusbarBatteryCharging' : 'statusbarBattery',
|
|
{level: level}
|
|
);
|
|
this.previousCharging = battery.charging;
|
|
this.publish('changed');
|
|
};
|
|
|
|
BatteryIcon.prototype.view = function view() {
|
|
return `<div id="statusbar-battery"
|
|
class="sb-icon sb-icon-battery"
|
|
role="listitem">
|
|
</div>`;
|
|
};
|
|
|
|
exports.BatteryIcon = BatteryIcon;
|
|
}(window));
|