index.html
51.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html lang="en" dir="ltr">
<head>
<title>Battery Status API</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<style type="text/css">
/*****************************************************************
* ReSpec CSS
* Robin Berjon (robin at berjon dot com)
* v0.05 - 2009-07-31
*****************************************************************/
/* --- INLINES --- */
em.rfc2119 {
text-transform: lowercase;
font-variant: small-caps;
font-style: normal;
color: #900;
}
h1 acronym, h2 acronym, h3 acronym, h4 acronym, h5 acronym, h6 acronym, a acronym,
h1 abbr, h2 abbr, h3 abbr, h4 abbr, h5 abbr, h6 abbr, a abbr {
border: none;
}
dfn {
font-weight: bold;
}
a.internalDFN {
color: inherit;
border-bottom: 1px solid #99c;
text-decoration: none;
}
a.externalDFN {
color: inherit;
border-bottom: 1px dotted #ccc;
text-decoration: none;
}
a.bibref {
text-decoration: none;
}
code {
color: #ff4500;
}
/* --- WEB IDL --- */
pre.idl {
border-top: 1px solid #90b8de;
border-bottom: 1px solid #90b8de;
padding: 1em;
line-height: 120%;
}
pre.idl::before {
content: "WebIDL";
display: block;
width: 150px;
background: #90b8de;
color: #fff;
font-family: initial;
padding: 3px;
font-weight: bold;
margin: -1em 0 1em -1em;
}
.idlType {
color: #ff4500;
font-weight: bold;
text-decoration: none;
}
/*.idlModule*/
/*.idlModuleID*/
/*.idlInterface*/
.idlInterfaceID, .idlDictionaryID {
font-weight: bold;
color: #005a9c;
}
.idlSuperclass {
font-style: italic;
color: #005a9c;
}
/*.idlAttribute*/
.idlAttrType, .idlFieldType, .idlMemberType {
color: #005a9c;
}
.idlAttrName, .idlFieldName, .idlMemberName {
color: #ff4500;
}
.idlAttrName a, .idlFieldName a, .idlMemberName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlMethod*/
.idlMethType {
color: #005a9c;
}
.idlMethName {
color: #ff4500;
}
.idlMethName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlParam*/
.idlParamType {
color: #005a9c;
}
.idlParamName {
font-style: italic;
}
.extAttr {
color: #666;
}
/*.idlConst*/
.idlConstType {
color: #005a9c;
}
.idlConstName {
color: #ff4500;
}
.idlConstName a {
color: #ff4500;
border-bottom: 1px dotted #ff4500;
text-decoration: none;
}
/*.idlException*/
.idlExceptionID {
font-weight: bold;
color: #c00;
}
.idlTypedefID, .idlTypedefType {
color: #005a9c;
}
.idlRaises, .idlRaises a.idlType, .idlRaises a.idlType code, .excName a, .excName a code {
color: #c00;
font-weight: normal;
}
.excName a {
font-family: monospace;
}
.idlRaises a.idlType, .excName a.idlType {
border-bottom: 1px dotted #c00;
}
.excGetSetTrue, .excGetSetFalse, .prmNullTrue, .prmNullFalse, .prmOptTrue, .prmOptFalse {
width: 45px;
text-align: center;
}
.excGetSetTrue, .prmNullTrue, .prmOptTrue { color: #0c0; }
.excGetSetFalse, .prmNullFalse, .prmOptFalse { color: #c00; }
.idlImplements a {
font-weight: bold;
}
dl.attributes, dl.methods, dl.constants, dl.fields, dl.dictionary-members {
margin-left: 2em;
}
.attributes dt, .methods dt, .constants dt, .fields dt, .dictionary-members dt {
font-weight: normal;
}
.attributes dt code, .methods dt code, .constants dt code, .fields dt code, .dictionary-members dt code {
font-weight: bold;
color: #000;
font-family: monospace;
}
.attributes dt code, .fields dt code, .dictionary-members dt code {
background: #ffffd2;
}
.attributes dt .idlAttrType code, .fields dt .idlFieldType code, .dictionary-members dt .idlMemberType code {
color: #005a9c;
background: transparent;
font-family: inherit;
font-weight: normal;
font-style: italic;
}
.methods dt code {
background: #d9e6f8;
}
.constants dt code {
background: #ddffd2;
}
.attributes dd, .methods dd, .constants dd, .fields dd, .dictionary-members dd {
margin-bottom: 1em;
}
table.parameters, table.exceptions {
border-spacing: 0;
border-collapse: collapse;
margin: 0.5em 0;
width: 100%;
}
table.parameters { border-bottom: 1px solid #90b8de; }
table.exceptions { border-bottom: 1px solid #deb890; }
.parameters th, .exceptions th {
color: #fff;
padding: 3px 5px;
text-align: left;
font-family: initial;
font-weight: normal;
text-shadow: #666 1px 1px 0;
}
.parameters th { background: #90b8de; }
.exceptions th { background: #deb890; }
.parameters td, .exceptions td {
padding: 3px 10px;
border-top: 1px solid #ddd;
vertical-align: top;
}
.parameters tr:first-child td, .exceptions tr:first-child td {
border-top: none;
}
.parameters td.prmName, .exceptions td.excName, .exceptions td.excCodeName {
width: 100px;
}
.parameters td.prmType {
width: 120px;
}
table.exceptions table {
border-spacing: 0;
border-collapse: collapse;
width: 100%;
}
/* --- TOC --- */
.toc a {
text-decoration: none;
}
a .secno {
color: #000;
}
/* --- TABLE --- */
table.simple {
border-spacing: 0;
border-collapse: collapse;
border-bottom: 3px solid #005a9c;
}
.simple th {
background: #005a9c;
color: #fff;
padding: 3px 5px;
text-align: left;
}
.simple th[scope="row"] {
background: inherit;
color: inherit;
border-top: 1px solid #ddd;
}
.simple td {
padding: 3px 10px;
border-top: 1px solid #ddd;
}
.simple tr:nth-child(even) {
background: #f0f6ff;
}
/* --- DL --- */
.section dd > p:first-child {
margin-top: 0;
}
.section dd > p:last-child {
margin-bottom: 0;
}
.section dd {
margin-bottom: 1em;
}
.section dl.attrs dd, .section dl.eldef dd {
margin-bottom: 0;
}
/* --- EXAMPLES --- */
pre.example {
border-top: 1px solid #ff4500;
border-bottom: 1px solid #ff4500;
padding: 1em;
margin-top: 1em;
}
pre.example::before {
content: "Example";
display: block;
width: 150px;
background: #ff4500;
color: #fff;
font-family: initial;
padding: 3px;
font-weight: bold;
margin: -1em 0 1em -1em;
}
/* --- EDITORIAL NOTES --- */
.issue {
padding: 1em;
margin: 1em 0em 0em;
border: 1px solid #f00;
background: #ffc;
}
.issue::before {
content: "Issue";
display: block;
width: 150px;
margin: -1.5em 0 0.5em 0;
font-weight: bold;
border: 1px solid #f00;
background: #fff;
padding: 3px 1em;
}
.note {
margin: 1em 0em 0em;
padding: 1em;
border: 2px solid #cff6d9;
background: #e2fff0;
}
.note::before {
content: "Note";
display: block;
width: 150px;
margin: -1.5em 0 0.5em 0;
font-weight: bold;
border: 1px solid #cff6d9;
background: #fff;
padding: 3px 1em;
}
/* --- Best Practices --- */
div.practice {
border: solid #bebebe 1px;
margin: 2em 1em 1em 2em;
}
span.practicelab {
margin: 1.5em 0.5em 1em 1em;
font-weight: bold;
font-style: italic;
}
span.practicelab { background: #dfffff; }
span.practicelab {
position: relative;
padding: 0 0.5em;
top: -1.5em;
}
p.practicedesc {
margin: 1.5em 0.5em 1em 1em;
}
@media screen {
p.practicedesc {
position: relative;
top: -2em;
padding: 0;
margin: 1.5em 0.5em -1em 1em;
}
}
/* --- SYNTAX HIGHLIGHTING --- */
pre.sh_sourceCode {
background-color: white;
color: black;
font-style: normal;
font-weight: normal;
}
pre.sh_sourceCode .sh_keyword { color: #005a9c; font-weight: bold; } /* language keywords */
pre.sh_sourceCode .sh_type { color: #666; } /* basic types */
pre.sh_sourceCode .sh_usertype { color: teal; } /* user defined types */
pre.sh_sourceCode .sh_string { color: red; font-family: monospace; } /* strings and chars */
pre.sh_sourceCode .sh_regexp { color: orange; font-family: monospace; } /* regular expressions */
pre.sh_sourceCode .sh_specialchar { color: #ffc0cb; font-family: monospace; } /* e.g., \n, \t, \\ */
pre.sh_sourceCode .sh_comment { color: #A52A2A; font-style: italic; } /* comments */
pre.sh_sourceCode .sh_number { color: purple; } /* literal numbers */
pre.sh_sourceCode .sh_preproc { color: #00008B; font-weight: bold; } /* e.g., #include, import */
pre.sh_sourceCode .sh_symbol { color: blue; } /* e.g., *, + */
pre.sh_sourceCode .sh_function { color: black; font-weight: bold; } /* function calls and declarations */
pre.sh_sourceCode .sh_cbracket { color: red; } /* block brackets (e.g., {, }) */
pre.sh_sourceCode .sh_todo { font-weight: bold; background-color: #00FFFF; } /* TODO and FIXME */
/* Predefined variables and functions (for instance glsl) */
pre.sh_sourceCode .sh_predef_var { color: #00008B; }
pre.sh_sourceCode .sh_predef_func { color: #00008B; font-weight: bold; }
/* for OOP */
pre.sh_sourceCode .sh_classname { color: teal; }
/* line numbers (not yet implemented) */
pre.sh_sourceCode .sh_linenum { display: none; }
/* Internet related */
pre.sh_sourceCode .sh_url { color: blue; text-decoration: underline; font-family: monospace; }
/* for ChangeLog and Log files */
pre.sh_sourceCode .sh_date { color: blue; font-weight: bold; }
pre.sh_sourceCode .sh_time, pre.sh_sourceCode .sh_file { color: #00008B; font-weight: bold; }
pre.sh_sourceCode .sh_ip, pre.sh_sourceCode .sh_name { color: #006400; }
/* for Prolog, Perl... */
pre.sh_sourceCode .sh_variable { color: #006400; }
/* for LaTeX */
pre.sh_sourceCode .sh_italics { color: #006400; font-style: italic; }
pre.sh_sourceCode .sh_bold { color: #006400; font-weight: bold; }
pre.sh_sourceCode .sh_underline { color: #006400; text-decoration: underline; }
pre.sh_sourceCode .sh_fixed { color: green; font-family: monospace; }
pre.sh_sourceCode .sh_argument { color: #006400; }
pre.sh_sourceCode .sh_optionalargument { color: purple; }
pre.sh_sourceCode .sh_math { color: orange; }
pre.sh_sourceCode .sh_bibtex { color: blue; }
/* for diffs */
pre.sh_sourceCode .sh_oldfile { color: orange; }
pre.sh_sourceCode .sh_newfile { color: #006400; }
pre.sh_sourceCode .sh_difflines { color: blue; }
/* for css */
pre.sh_sourceCode .sh_selector { color: purple; }
pre.sh_sourceCode .sh_property { color: blue; }
pre.sh_sourceCode .sh_value { color: #006400; font-style: italic; }
/* other */
pre.sh_sourceCode .sh_section { color: black; font-weight: bold; }
pre.sh_sourceCode .sh_paren { color: red; }
pre.sh_sourceCode .sh_attribute { color: #006400; }
</style><link charset="utf-8" type="text/css" rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-WD"></head>
<body style="display: inherit;"><div class="head"><p><a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" alt="W3C" height="48" width="72"></a></p><h1 class="title" id="title">Battery Status API</h1><h2 id="w3c-working-draft-29-november-2011"><acronym title="World Wide Web Consortium">W3C</acronym> Working Draft 29 November 2011</h2><dl><dt>This version:</dt><dd><a href="http://www.w3.org/TR/2011/WD-battery-status-20111129/">http://www.w3.org/TR/2011/WD-battery-status-20111129/</a></dd><dt>Latest published version:</dt><dd><a href="http://www.w3.org/TR/battery-status/">http://www.w3.org/TR/battery-status/</a></dd><dt>Latest editor's draft:</dt><dd><a href="http://dev.w3.org/2009/dap/system-info/battery-status.html">http://dev.w3.org/2009/dap/system-info/battery-status.html</a></dd><dt>Previous version:</dt><dd><a href="http://www.w3.org/TR/2011/WD-battery-status-20110915/">http://www.w3.org/TR/2011/WD-battery-status-20110915/</a></dd><dt>Editor:</dt><dd><span>Anssi Kostiainen</span>, Nokia</dd>
</dl><p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2011 <a href="http://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>, <a href="http://www.ercim.eu/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. <acronym title="World Wide Web Consortium">W3C</acronym> <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p><hr></div>
<div class="introductory section" id="abstract"><h2>Abstract</h2>
This specification defines an API that provides information about the
battery status of the hosting device.
</div><div id="sotd" class="introductory section"><h2>Status of This Document</h2><p><em>This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current <acronym title="World Wide Web Consortium">W3C</acronym> publications and the latest revision of this technical report can be found in the <a href="http://www.w3.org/TR/"><acronym title="World Wide Web Consortium">W3C</acronym> technical reports index</a> at http://www.w3.org/TR/.</em></p>
<p>
The functionality described in this specification was initially specified as part of the
<a href="http://www.w3.org/TR/system-info-api/">System Information API</a> but has been
extracted in order to be more readily available, more straightforward to implement, and
in order to produce a specification that could be implemented on its own merits without
interference with other, often unrelated, features.
</p>
<p>This document was published by the <a href="http://www.w3.org/2009/dap/">Device APIs Working Group</a> as a Last Call Working Draft. This document is intended to become a <acronym title="World Wide Web Consortium">W3C</acronym> Recommendation. If you wish to make comments regarding this document, please send them to <a href="mailto:public-device-apis@w3.org">public-device-apis@w3.org</a> (<a href="mailto:public-device-apis-request@w3.org?subject=subscribe">subscribe</a>, <a href="http://lists.w3.org/Archives/Public/public-device-apis/">archives</a>). The Last Call period ends 20 December 2011. All feedback is welcome.</p><p>Publication as a Working Draft does not imply endorsement by the <acronym title="World Wide Web Consortium">W3C</acronym> Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.</p><p>This is a Last Call Working Draft and thus the Working Group has determined that this document has satisfied the relevant technical requirements and is sufficiently stable to advance through the Technical Recommendation process.</p><p>This document was produced by a group operating under the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 <acronym title="World Wide Web Consortium">W3C</acronym> Patent Policy</a>. <acronym title="World Wide Web Consortium">W3C</acronym> maintains a <a href="http://www.w3.org/2004/01/pp-impl/43696/status" rel="disclosure">public list of any patent disclosures</a> made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the <acronym title="World Wide Web Consortium">W3C</acronym> Patent Policy</a>.</p></div><div class="section" id="toc"><h2 class="introductory">Table of Contents</h2><ul class="toc"><li class="tocline"><a class="tocxref" href="#introduction"><span class="secno">1. </span>Introduction</a></li><li class="tocline"><a class="tocxref" href="#conformance"><span class="secno">2. </span>Conformance</a></li><li class="tocline"><a class="tocxref" href="#navigatorbattery-interface"><span class="secno">3. </span><span class="idlType formerLink idlType"><code>NavigatorBattery</code></span> Interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes"><span class="secno">3.1 </span>Attributes</a></li></ul></li><li class="tocline"><a class="tocxref" href="#batterymanager-interface"><span class="secno">4. </span><span class="idlType formerLink idlType"><code>BatteryManager</code></span> Interface</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#attributes-1"><span class="secno">4.1 </span>Attributes</a></li></ul></li><li class="tocline"><a class="tocxref" href="#examples"><span class="secno">5. </span>Examples</a></li><li class="tocline"><a class="tocxref" href="#acknowledgements"><span class="secno">A. </span>Acknowledgements</a></li><li class="tocline"><a class="tocxref" href="#references"><span class="secno">B. </span>References</a><ul class="toc"><li class="tocline"><a class="tocxref" href="#normative-references"><span class="secno">B.1 </span>Normative references</a></li><li class="tocline"><a class="tocxref" href="#informative-references"><span class="secno">B.2 </span>Informative references</a></li></ul></li></ul></div>
<div id="introduction" class="informative section">
<!--OddPage--><h2><span class="secno">1. </span>Introduction</h2><p><em>This section is non-normative.</em></p>
<p>
The Battery Status API specification defines a means for web
developers to programmatically determine the battery status of the
hosting device. Without knowing the battery status of a device, a web
developer must design the web application with an assumption of
sufficient battery level for the task at hand. This means the battery
of a device may exhaust faster than desired because web developers are
unable to make decisions based on the battery status. Given knowledge
of the battery status, web developers are able to craft web content and
applications which are power-efficient, thereby leading to improved user
experience.
</p>
<p>
The Battery Status API can be used to defer or scale back work when
the device is not charging in or is low on battery. An archetype of an
advanced web application, a web-based email client, may check the
server for new email every few seconds if the device is charging,
but do so less frequently if the device is not charging or is low on
battery. Another example is a web-based word processor which could
monitor the battery level and save changes before the battery runs
out to prevent data loss.
</p>
<p>
The following example shows how a web-based email client could check
for new emails every ten seconds without knowledge of the battery status:
</p>
<pre class="example sh_javascript sh_sourceCode"><span class="sh_symbol"><!</span>DOCTYPE html<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>html<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>head<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>title<span class="sh_symbol">></span>Email Client<span class="sh_symbol"></</span>title<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>script<span class="sh_symbol">></span>
<span class="sh_keyword">var</span> mail <span class="sh_symbol">=</span> <span class="sh_cbracket">{</span>
INTERVAL_DEFAULT<span class="sh_symbol">:</span> <span class="sh_number">1000</span> <span class="sh_symbol">*</span> <span class="sh_number">10</span><span class="sh_symbol">,</span>
interval<span class="sh_symbol">:</span> <span class="sh_keyword">null</span><span class="sh_symbol">,</span>
timer<span class="sh_symbol">:</span> <span class="sh_number">0</span><span class="sh_symbol">,</span>
check<span class="sh_symbol">:</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
console<span class="sh_symbol">.</span><span class="sh_function">log</span><span class="sh_symbol">(</span><span class="sh_string">'Checking the server for new emails using an interval of '</span> <span class="sh_symbol">+</span>
<span class="sh_symbol">(</span>mail<span class="sh_symbol">.</span><span class="sh_normal">interval </span><span class="sh_symbol">/</span> <span class="sh_number">1000</span><span class="sh_symbol">)</span> <span class="sh_symbol">+</span> <span class="sh_string">' seconds.'</span><span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">,</span>
setTimer<span class="sh_symbol">:</span> <span class="sh_keyword">function</span> <span class="sh_symbol">(</span>interval<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span>
<span class="sh_keyword">if</span> <span class="sh_symbol">(</span>interval <span class="sh_symbol">===</span> mail<span class="sh_symbol">.</span>interval<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span> <span class="sh_keyword">return</span><span class="sh_symbol">;</span> <span class="sh_cbracket">}</span>
<span class="sh_keyword">if</span> <span class="sh_symbol">(</span>mail<span class="sh_symbol">.</span>timer <span class="sh_symbol">!==</span> <span class="sh_number">0</span><span class="sh_symbol">)</span> <span class="sh_cbracket">{</span> <span class="sh_function">clearTimeout</span><span class="sh_symbol">(</span>mail<span class="sh_symbol">.</span>timer<span class="sh_symbol">);</span> <span class="sh_cbracket">}</span>
<span class="sh_keyword">if</span> <span class="sh_symbol">(</span>interval<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span> mail<span class="sh_symbol">.</span>timer <span class="sh_symbol">=</span> <span class="sh_function">setInterval</span><span class="sh_symbol">(</span><span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span> mail<span class="sh_symbol">.</span><span class="sh_function">check</span><span class="sh_symbol">();</span> <span class="sh_cbracket">}</span><span class="sh_symbol">,</span> interval<span class="sh_symbol">);</span> <span class="sh_cbracket">}</span>
mail<span class="sh_symbol">.</span>interval <span class="sh_symbol">=</span> interval<span class="sh_symbol">;</span>
<span class="sh_cbracket">}</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">;</span>
window<span class="sh_symbol">.</span><span class="sh_function">addEventListener</span><span class="sh_symbol">(</span><span class="sh_string">'load'</span><span class="sh_symbol">,</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
mail<span class="sh_symbol">.</span><span class="sh_function">setTimer</span><span class="sh_symbol">(!</span>mail<span class="sh_symbol">.</span>interval <span class="sh_symbol">?</span> mail<span class="sh_symbol">.</span>INTERVAL_DEFAULT <span class="sh_symbol">:</span> mail<span class="sh_symbol">.</span>interval<span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">,</span> <span class="sh_keyword">false</span><span class="sh_symbol">);</span>
<span class="sh_symbol"></</span>script<span class="sh_symbol">></span>
<span class="sh_symbol"></</span>head<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>body<span class="sh_symbol">></</span>body<span class="sh_symbol">></span>
<span class="sh_symbol"></</span>html<span class="sh_symbol">></span></pre>
<p>
The script will always check for emails every ten seconds, even if the
battery level is critically low and the device is not charging.
This is an example of poor resource management.
</p>
<p>
Using the <a class="idlType" href="#idl-def-BatteryManager"><code>BatteryManager</code></a> interface, the web application is, for
example, able to throttle checking for emails if the device is low on
battery, stop checking for emails if the battery is critically low and
resume normal operation when the battery is charging:
</p>
<pre class="example sh_javascript sh_sourceCode"><span class="sh_symbol"><!</span>DOCTYPE html<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>html<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>head<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>title<span class="sh_symbol">></span>Battery<span class="sh_symbol">-</span>aware Email Client<span class="sh_symbol"></</span>title<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>script<span class="sh_symbol">></span>
<span class="sh_keyword">var</span> mail <span class="sh_symbol">=</span> <span class="sh_cbracket">{</span>
INTERVAL_BATTERY_LOW<span class="sh_symbol">:</span> <span class="sh_number">1000</span> <span class="sh_symbol">*</span> <span class="sh_number">60</span> <span class="sh_symbol">*</span> <span class="sh_number">10</span><span class="sh_symbol">,</span>
INTERVAL_DEFAULT<span class="sh_symbol">:</span> <span class="sh_number">1000</span> <span class="sh_symbol">*</span> <span class="sh_number">10</span><span class="sh_symbol">,</span>
interval<span class="sh_symbol">:</span> <span class="sh_keyword">null</span><span class="sh_symbol">,</span>
timer<span class="sh_symbol">:</span> <span class="sh_number">0</span><span class="sh_symbol">,</span>
check<span class="sh_symbol">:</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
console<span class="sh_symbol">.</span><span class="sh_function">log</span><span class="sh_symbol">(</span><span class="sh_string">'Checking the server for new emails using an interval of '</span> <span class="sh_symbol">+</span>
<span class="sh_symbol">(</span>mail<span class="sh_symbol">.</span><span class="sh_normal">interval </span><span class="sh_symbol">/</span> <span class="sh_number">1000</span><span class="sh_symbol">)</span> <span class="sh_symbol">+</span> <span class="sh_string">' seconds.'</span><span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">,</span>
setTimer<span class="sh_symbol">:</span> <span class="sh_keyword">function</span> <span class="sh_symbol">(</span>interval<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span>
<span class="sh_keyword">if</span> <span class="sh_symbol">(</span>interval <span class="sh_symbol">===</span> mail<span class="sh_symbol">.</span>interval<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span> <span class="sh_keyword">return</span><span class="sh_symbol">;</span> <span class="sh_cbracket">}</span>
<span class="sh_keyword">if</span> <span class="sh_symbol">(</span>mail<span class="sh_symbol">.</span>timer <span class="sh_symbol">!==</span> <span class="sh_number">0</span><span class="sh_symbol">)</span> <span class="sh_cbracket">{</span> <span class="sh_function">clearTimeout</span><span class="sh_symbol">(</span>mail<span class="sh_symbol">.</span>timer<span class="sh_symbol">);</span> <span class="sh_cbracket">}</span>
<span class="sh_keyword">if</span> <span class="sh_symbol">(</span>interval<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span> mail<span class="sh_symbol">.</span>timer <span class="sh_symbol">=</span> <span class="sh_function">setInterval</span><span class="sh_symbol">(</span><span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span> mail<span class="sh_symbol">.</span><span class="sh_function">check</span><span class="sh_symbol">();</span> <span class="sh_cbracket">}</span><span class="sh_symbol">,</span> interval<span class="sh_symbol">);</span> <span class="sh_cbracket">}</span>
mail<span class="sh_symbol">.</span>interval <span class="sh_symbol">=</span> interval<span class="sh_symbol">;</span>
<span class="sh_cbracket">}</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">;</span>
window<span class="sh_symbol">.</span><span class="sh_function">addEventListener</span><span class="sh_symbol">(</span><span class="sh_string">'load'</span><span class="sh_symbol">,</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
mail<span class="sh_symbol">.</span><span class="sh_function">setTimer</span><span class="sh_symbol">(!</span>mail<span class="sh_symbol">.</span>interval <span class="sh_symbol">?</span> mail<span class="sh_symbol">.</span>INTERVAL_DEFAULT <span class="sh_symbol">:</span> mail<span class="sh_symbol">.</span>interval<span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">,</span> <span class="sh_keyword">false</span><span class="sh_symbol">);</span>
<span class="sh_keyword">var</span> battery <span class="sh_symbol">=</span> navigator<span class="sh_symbol">.</span>battery<span class="sh_symbol">;</span>
battery<span class="sh_symbol">.</span><span class="sh_function">addEventListener</span><span class="sh_symbol">(</span><span class="sh_string">'dischargingtimechange'</span><span class="sh_symbol">,</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
<span class="sh_keyword">if</span> <span class="sh_symbol">(</span>battery<span class="sh_symbol">.</span>dischargingTime <span class="sh_symbol"><</span> <span class="sh_number">60</span> <span class="sh_symbol">*</span> <span class="sh_number">30</span> <span class="sh_symbol">||</span> battery<span class="sh_symbol">.</span>level <span class="sh_symbol"><</span> <span class="sh_number">0.1</span><span class="sh_symbol">)</span> <span class="sh_cbracket">{</span>
mail<span class="sh_symbol">.</span><span class="sh_function">setTimer</span><span class="sh_symbol">(</span>mail<span class="sh_symbol">.</span>INTERVAL_BATTERY_LOW<span class="sh_symbol">);</span>
console<span class="sh_symbol">.</span><span class="sh_function">log</span><span class="sh_symbol">(</span><span class="sh_string">'30 minutes remaining or level below 10%, checking the server less frequently.'</span><span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span> <span class="sh_keyword">else</span> <span class="sh_keyword">if</span> <span class="sh_symbol">(</span>battery<span class="sh_symbol">.</span>dischargingTime <span class="sh_symbol"><</span> <span class="sh_number">60</span> <span class="sh_symbol">*</span> <span class="sh_number">10</span> <span class="sh_symbol">||</span> battery<span class="sh_symbol">.</span>level <span class="sh_symbol"><</span> <span class="sh_number">0.05</span><span class="sh_symbol">)</span> <span class="sh_cbracket">{</span>
mail<span class="sh_symbol">.</span><span class="sh_function">setTimer</span><span class="sh_symbol">(</span><span class="sh_keyword">null</span><span class="sh_symbol">);</span>
console<span class="sh_symbol">.</span><span class="sh_function">log</span><span class="sh_symbol">(</span><span class="sh_string">'10 minutes remaining or level below 5%, stop checking the server.'</span><span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">,</span> <span class="sh_keyword">false</span><span class="sh_symbol">);</span>
battery<span class="sh_symbol">.</span><span class="sh_function">addEventListener</span><span class="sh_symbol">(</span><span class="sh_string">'chargingchange'</span><span class="sh_symbol">,</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
<span class="sh_keyword">if</span> <span class="sh_symbol">(</span>battery<span class="sh_symbol">.</span>charging<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span>
mail<span class="sh_symbol">.</span><span class="sh_function">setTimer</span><span class="sh_symbol">(</span>mail<span class="sh_symbol">.</span>INTERVAL_DEFAULT<span class="sh_symbol">);</span>
console<span class="sh_symbol">.</span><span class="sh_function">log</span><span class="sh_symbol">(</span><span class="sh_string">'Battery is charging, checking the server normally.'</span><span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">,</span> <span class="sh_keyword">false</span><span class="sh_symbol">);</span>
<span class="sh_symbol"></</span>script<span class="sh_symbol">></span>
<span class="sh_symbol"></</span>head<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>body<span class="sh_symbol">></</span>body<span class="sh_symbol">></span>
<span class="sh_symbol"></</span>html<span class="sh_symbol">></span></pre>
</div>
<div class="section" id="conformance"><!--OddPage--><h2><span class="secno">2. </span>Conformance</h2><p>As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.</p>
<p>The key words <em title="must" class="rfc2119">must</em>, <em title="must not" class="rfc2119">must not</em>, <em title="required" class="rfc2119">required</em>, <em title="should" class="rfc2119">should</em>, <em title="should not" class="rfc2119">should not</em>, <em title="recommended" class="rfc2119">recommended</em>, <em title="may" class="rfc2119">may</em>, and <em title="optional" class="rfc2119">optional</em> in this specification are to be interpreted as described in [<cite><a href="#bib-RFC2119" rel="biblioentry" class="bibref">RFC2119</a></cite>].</p>
<p>
This specification defines conformance criteria that apply to a single
product: the <dfn id="ua">user agent</dfn> that implements the
interfaces that it contains.
</p>
<p>
Implementations that use ECMAScript to implement the APIs defined in
this specification must implement them in a manner consistent with the
ECMAScript Bindings defined in the Web IDL specification [<cite><a href="#bib-WEBIDL" rel="biblioentry" class="bibref">WEBIDL</a></cite>],
as this specification uses that specification and terminology.
</p>
</div>
<div class="section" id="navigatorbattery-interface">
<!--OddPage--><h2><span class="secno">3. </span><a class="idlType" href="#idl-def-NavigatorBattery"><code>NavigatorBattery</code></a> Interface</h2>
<p>
The <a class="idlType" href="#idl-def-NavigatorBattery"><code>NavigatorBattery</code></a> interface is exposed on the
<code>Navigator</code> object.
</p>
<pre class="idl"><span class="idlImplements"><a>Navigator</a> implements <a class="idlType" href="#idl-def-NavigatorBattery"><code>NavigatorBattery</code></a>;</span></pre><div class="idlImplementsDesc"><p>All instances of the <code><a>Navigator</a></code> type are defined to also implement the <a class="idlType" href="#idl-def-NavigatorBattery"><code>NavigatorBattery</code></a> interface.</p></div>
<pre class="idl"><span class="idlInterface" id="idl-def-NavigatorBattery">[<span class="extAttr">NoInterfaceObject</span>]
interface <span class="idlInterfaceID">NavigatorBattery</span> {
<span class="idlAttribute"> readonly attribute <span class="idlAttrType"><a class="idlType" href="#idl-def-BatteryManager"><code>BatteryManager</code></a></span> <span class="idlAttrName"><a href="#widl-NavigatorBattery-battery">battery</a></span>;</span>
};</span>
</pre><div class="section" id="attributes"><h3><span class="secno">3.1 </span>Attributes</h3><dl class="attributes"><dt id="widl-NavigatorBattery-battery"><code>battery</code> of type <span class="idlAttrType"><a class="idlType" href="#idl-def-BatteryManager"><code>BatteryManager</code></a></span>, readonly</dt><dd>
The object that exposes the battery status information.
<div><em>No exceptions.</em></div></dd></dl></div>
</div>
<div class="section" id="batterymanager-interface">
<!--OddPage--><h2><span class="secno">4. </span><a class="idlType" href="#idl-def-BatteryManager"><code>BatteryManager</code></a> Interface</h2>
<pre class="idl"><span class="idlInterface" id="idl-def-BatteryManager">[<span class="extAttr">NoInterfaceObject</span>]
interface <span class="idlInterfaceID">BatteryManager</span> : <span class="idlSuperclass"><a>EventTarget</a></span> {
<span class="idlAttribute"> readonly attribute <span class="idlAttrType"><a>boolean</a></span> <span class="idlAttrName"><a href="#widl-BatteryManager-charging">charging</a></span>;</span>
<span class="idlAttribute"> readonly attribute <span class="idlAttrType"><a>double</a></span> <span class="idlAttrName"><a href="#widl-BatteryManager-chargingTime">chargingTime</a></span>;</span>
<span class="idlAttribute"> readonly attribute <span class="idlAttrType"><a>double</a></span> <span class="idlAttrName"><a href="#widl-BatteryManager-level">level</a></span>;</span>
<span class="idlAttribute"> readonly attribute <span class="idlAttrType"><a>double</a></span> <span class="idlAttrName"><a href="#widl-BatteryManager-dischargingTime">dischargingTime</a></span>;</span>
<span class="idlAttribute"> attribute <span class="idlAttrType"><a>Function</a>?</span> <span class="idlAttrName"><a href="#widl-BatteryManager-onchargingchange">onchargingchange</a></span>;</span>
<span class="idlAttribute"> attribute <span class="idlAttrType"><a>Function</a>?</span> <span class="idlAttrName"><a href="#widl-BatteryManager-onchargingtimechange">onchargingtimechange</a></span>;</span>
<span class="idlAttribute"> attribute <span class="idlAttrType"><a>Function</a>?</span> <span class="idlAttrName"><a href="#widl-BatteryManager-onlevelchange">onlevelchange</a></span>;</span>
<span class="idlAttribute"> attribute <span class="idlAttrType"><a>Function</a>?</span> <span class="idlAttrName"><a href="#widl-BatteryManager-ondischargingtimechange">ondischargingtimechange</a></span>;</span>
};</span>
</pre><div class="section" id="attributes-1"><h3><span class="secno">4.1 </span>Attributes</h3><dl class="attributes"><dt id="widl-BatteryManager-charging"><code>charging</code> of type <span class="idlAttrType"><a>boolean</a></span>, readonly</dt><dd>
Represents if the system's battery is charging. The attribute <em title="must" class="rfc2119">must</em> be
set to false if the battery is discharging, and set to true, if the
battery is charging, full, the implementation is unable to report the
state, or there is no battery attached to the system, or otherwise.
<div><em>No exceptions.</em></div></dd><dt id="widl-BatteryManager-chargingTime"><code>chargingTime</code> of type <span class="idlAttrType"><a>double</a></span>, readonly</dt><dd>
Represents the time remaining in seconds until the system's battery
is fully charged. The attribute <em title="must" class="rfc2119">must</em> be set to 0, if the battery is
full or there is no battery attached to the system, and to the value
positive Infinity if the battery is discharging, the implementation
is unable to report the remaining charging time, or otherwise.
<div><em>No exceptions.</em></div></dd><dt id="widl-BatteryManager-dischargingTime"><code>dischargingTime</code> of type <span class="idlAttrType"><a>double</a></span>, readonly</dt><dd>
Represents the time remaining in seconds until the system's battery
is completely discharged and the system is about to be suspended. The
attribute <em title="must" class="rfc2119">must</em> be set to the value positive Infinity, if the battery
is charging, the implementation is unable to report the remaining
discharging time, there is no battery attached to the system, or
otherwise.
<div><em>No exceptions.</em></div></dd><dt id="widl-BatteryManager-level"><code>level</code> of type <span class="idlAttrType"><a>double</a></span>, readonly</dt><dd>
Represents the current battery level scaled from 0 to 1.0. The
attribute <em title="must" class="rfc2119">must</em> be set to 0 if the system's battery is depleted and
the system is about to be suspended, and to 1.0 if the battery is
full, the implementation is unable to report the battery's level,
or there is no battery attached to the system.
<div><em>No exceptions.</em></div></dd><dt id="widl-BatteryManager-onchargingchange"><code>onchargingchange</code> of type <span class="idlAttrType"><a>Function</a></span>, nullable</dt><dd>
<div><em>No exceptions.</em></div></dd><dt id="widl-BatteryManager-onchargingtimechange"><code>onchargingtimechange</code> of type <span class="idlAttrType"><a>Function</a></span>, nullable</dt><dd>
<div><em>No exceptions.</em></div></dd><dt id="widl-BatteryManager-ondischargingtimechange"><code>ondischargingtimechange</code> of type <span class="idlAttrType"><a>Function</a></span>, nullable</dt><dd>
<div><em>No exceptions.</em></div></dd><dt id="widl-BatteryManager-onlevelchange"><code>onlevelchange</code> of type <span class="idlAttrType"><a>Function</a></span>, nullable</dt><dd>
<div><em>No exceptions.</em></div></dd></dl></div>
<p>
When a <code>BatteryManager</code> object is created,
<code>charging</code> <em title="must" class="rfc2119">must</em> be set to true, <code>chargingTime</code>
to 0, <code>level</code> to 1.0 and <code>dischargingTime</code> to
the value positive Infinity, if the implementation is unable to report
the battery's charging state, charging time, level or remaining time
respectively.
</p>
<p>
When the value of <code>charging</code>, <code>chargingTime</code>,
<code>level</code> or <code>dischargingTime</code> attribute changes,
the <a class="product-ua" href="#ua">user agent</a> <em title="must" class="rfc2119">must</em> fire a simple
event [<cite><a href="#bib-HTML5" rel="biblioentry" class="bibref">HTML5</a></cite>], which does not bubble and is not cancelable, named
<code>chargingchange</code>, <code>chargingtimechange</code>,
<code>levelchange</code> or <code>dischargingtimechange</code>
respectively at the <a class="idlType" href="#idl-def-BatteryManager"><code>BatteryManager</code></a> object.
</p>
<div class="note">
The definition of how often the <code>chargingtimechange</code>,
<code>levelchange</code> and <code>dischargingtimechange</code> events
are fired is left to the implementation.
</div>
</div>
<div id="examples" class="informative section">
<!--OddPage--><h2><span class="secno">5. </span>Examples</h2><p><em>This section is non-normative.</em></p>
<p>
This trivial example writes the battery level to the console each time
the level changes:
</p>
<div class="example">
<pre class="example sh_javascript sh_sourceCode">navigator<span class="sh_symbol">.</span>battery<span class="sh_symbol">.</span>onlevelchange <span class="sh_symbol">=</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
console<span class="sh_symbol">.</span><span class="sh_function">log</span><span class="sh_symbol">(</span>navigator<span class="sh_symbol">.</span>battery<span class="sh_symbol">.</span>level<span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">;</span></pre>
</div>
<p>
Alternatively, the same using the <code>addEventListener()</code>
method:
</p>
<div class="example">
<pre class="example sh_javascript sh_sourceCode">navigator<span class="sh_symbol">.</span>battery<span class="sh_symbol">.</span><span class="sh_function">addEventListener</span><span class="sh_symbol">(</span><span class="sh_string">'levelchange'</span><span class="sh_symbol">,</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
console<span class="sh_symbol">.</span><span class="sh_function">log</span><span class="sh_symbol">(</span>navigator<span class="sh_symbol">.</span>battery<span class="sh_symbol">.</span>level<span class="sh_symbol">);</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">,</span> <span class="sh_keyword">false</span><span class="sh_symbol">);</span></pre>
</div>
<p>
The following example updates the indicators to show the charging
state, level and time remaining in minutes:
</p>
<div class="example">
<pre class="example sh_javascript sh_sourceCode"><span class="sh_symbol"><!</span>DOCTYPE html<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>html<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>head<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>title<span class="sh_symbol">></span>Battery Status API Example<span class="sh_symbol"></</span>title<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>script<span class="sh_symbol">></span>
<span class="sh_keyword">var</span> battery <span class="sh_symbol">=</span> navigator<span class="sh_symbol">.</span>battery<span class="sh_symbol">;</span>
battery<span class="sh_symbol">.</span>onchargingchange <span class="sh_symbol">=</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
document<span class="sh_symbol">.</span><span class="sh_function">querySelector</span><span class="sh_symbol">(</span><span class="sh_string">'#charging'</span><span class="sh_symbol">).</span>textContent <span class="sh_symbol">=</span> battery<span class="sh_symbol">.</span>charging <span class="sh_symbol">?</span> <span class="sh_string">'charging'</span> <span class="sh_symbol">:</span> <span class="sh_string">'not charging'</span><span class="sh_symbol">;</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">;</span>
battery<span class="sh_symbol">.</span>onlevelchange <span class="sh_symbol">=</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
document<span class="sh_symbol">.</span><span class="sh_function">querySelector</span><span class="sh_symbol">(</span><span class="sh_string">'#level'</span><span class="sh_symbol">).</span>textContent <span class="sh_symbol">=</span> battery<span class="sh_symbol">.</span>level<span class="sh_symbol">;</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">;</span>
battery<span class="sh_symbol">.</span>ondischargingtimechange <span class="sh_symbol">=</span> <span class="sh_keyword">function</span> <span class="sh_symbol">()</span> <span class="sh_cbracket">{</span>
document<span class="sh_symbol">.</span><span class="sh_function">querySelector</span><span class="sh_symbol">(</span><span class="sh_string">'#dischargingTime'</span><span class="sh_symbol">).</span>textContent <span class="sh_symbol">=</span> battery<span class="sh_symbol">.</span><span class="sh_normal">dischargingTime </span><span class="sh_symbol">/</span> <span class="sh_number">60</span><span class="sh_symbol">;</span>
<span class="sh_cbracket">}</span><span class="sh_symbol">;</span>
<span class="sh_symbol"></</span>script<span class="sh_symbol">></span>
<span class="sh_symbol"></</span>head<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>body<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>div id<span class="sh_symbol">=</span><span class="sh_string">"charging"</span><span class="sh_symbol">>(</span>charging state unknown<span class="sh_symbol">)</</span>div<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>div id<span class="sh_symbol">=</span><span class="sh_string">"level"</span><span class="sh_symbol">>(</span>battery level unknown<span class="sh_symbol">)</</span>div<span class="sh_symbol">></span>
<span class="sh_symbol"><</span>div id<span class="sh_symbol">=</span><span class="sh_string">"dischargingTime"</span><span class="sh_symbol">>(</span>discharging time unknown<span class="sh_symbol">)</</span>div<span class="sh_symbol">></span>
<span class="sh_symbol"></</span>body<span class="sh_symbol">></span>
<span class="sh_symbol"></</span>html<span class="sh_symbol">></span></pre>
</div>
</div>
<div id="acknowledgements" class="appendix section">
<!--OddPage--><h2><span class="secno">A. </span>Acknowledgements</h2>
<p>
Big thanks to the Mozilla WebAPI team for their invaluable feedback
based on prototype implementations. Many thanks to the people behind
the System Information API and Device Orientation Event specification
for the initial inspiration. Also thanks to the nice folks bringing us
the Page Visibility specification, which motivated the editor of this
specification to write the introduction chapter discussing some
real-world high value use cases that apply equally to this
specification. Special thanks to all the participants of the Device
APIs Working Group and others who have sent in substantial feedback
and comments, and made the Web a better place for everyone by
doing so.
</p>
</div>
<div class="appendix section" id="references"><!--OddPage--><h2><span class="secno">B. </span>References</h2><div class="section" id="normative-references"><h3><span class="secno">B.1 </span>Normative references</h3><dl class="bibliography"><dt id="bib-HTML5">[HTML5]</dt><dd>Ian Hickson; David Hyatt. <a href="http://www.w3.org/TR/html5"><cite>HTML5.</cite></a> 25 May 2011. W3C Working Draft. (Work in progress.) URL: <a href="http://www.w3.org/TR/html5">http://www.w3.org/TR/html5</a>
</dd><dt id="bib-RFC2119">[RFC2119]</dt><dd>S. Bradner. <a href="http://www.ietf.org/rfc/rfc2119.txt"><cite>Key words for use in RFCs to Indicate Requirement Levels.</cite></a> March 1997. Internet RFC 2119. URL: <a href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a>
</dd><dt id="bib-WEBIDL">[WEBIDL]</dt><dd>Cameron McCormack. <a href="http://www.w3.org/TR/2008/WD-WebIDL-20081219"><cite>Web IDL.</cite></a> 19 December 2008. W3C Working Draft. (Work in progress.) URL: <a href="http://www.w3.org/TR/2008/WD-WebIDL-20081219">http://www.w3.org/TR/2008/WD-WebIDL-20081219</a>
</dd></dl></div><div class="section" id="informative-references"><h3><span class="secno">B.2 </span>Informative references</h3><p>No informative references.</p></div></div></body></html>