Confirmed users
1,340
edits
(→Proposed API: take onFoo methods) |
No edit summary |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{| style="color:red; font-weight: bold; background-color:yellow; padding:0px; margin: 20px; border: red;" cellpadding="0" cellspacing="0" border="1" | |||
|This wiki page is out of date.<br> | |||
The work on Battery API has been moved to the official W3C specification in the DAP Working Group: http://www.w3.org/TR/battery-status/ | |||
|} | |||
== Device API specification == | == Device API specification == | ||
The DAP WG (W3C) has specification sharing this proposal goal [1]. | The DAP WG (W3C) has specification sharing this proposal goal [1]. The specification recently moved to match our proposal. So, most of it should look like the proposed API below. | ||
[1] http://www.w3.org/TR/2011/WD-battery-status-20110915/ | [1] http://www.w3.org/TR/2011/WD-battery-status-20110915/ | ||
Line 11: | Line 15: | ||
== Demo == | == Demo == | ||
You can find a demo at | You can find a demo at these URLs:<br> | ||
http://oldworld.fr/mozilla/battery.html | * http://oldworld.fr/mozilla/battery.html | ||
* http://oldworld.fr/mozilla/battery-test.html | |||
* [http://robnyman.github.com/battery/ Demo by Robert Nyman] | |||
== Proposed API == | == Proposed API == | ||
Line 21: | Line 27: | ||
readonly attribute boolean charging; | readonly attribute boolean charging; | ||
readonly attribute float level; | readonly attribute float level; | ||
attribute Function? onchargingchange; | attribute Function? onchargingchange; | ||
attribute Function? onlevelchange; | attribute Function? onlevelchange; | ||
} | } | ||
The charging attribute will return true if the device is currently charging and false otherwise. True if there is no battery or if this information is not available.<br> | |||
The level attribute will return the current battery level of the device from 0.0 to 1.0. 1.0 if there is no battery or if this information is not available.<br> | |||
The charging attribute will return true if the device is currently charging and false otherwise.<br> | |||
The level attribute will return the current battery level of the device from 0.0 to | |||
The following events can be sent to the mozBattery object: | The following events can be sent to the mozBattery object: | ||
''chargingchange'': when the charging state changes; | ''chargingchange'': when the charging state changes; | ||
''levelchange'': when the level value changes of at least | ''levelchange'': when the level value changes of at least 0.01; | ||
== Considered changes == | == Considered changes == | ||
Line 45: | Line 45: | ||
** In that case, we could allow authors to set the low and critical values threshold; | ** In that case, we could allow authors to set the low and critical values threshold; | ||
** In that case, not having a battery should be handled differently; | ** In that case, not having a battery should be handled differently; | ||
[[Category:Web APIs]] |