Skip to content

Commit

Permalink
Feature detection to avoid errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stopsatgreen committed Jul 5, 2013
1 parent 24f6b3f commit 136446b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Code Examples/Chapter 06/battery-event.html
Expand Up @@ -18,9 +18,10 @@ <h2 id="status"></h2>
var status, var status,
el = document.getElementById('status'), el = document.getElementById('status'),
meter = document.querySelector('meter'), meter = document.querySelector('meter'),
battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery, battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery;
if (!battery) { return false; }
// Get charge level and update meter // Get charge level and update meter
chargeLevel = function () { var chargeLevel = function () {
meter.value = battery.level; meter.value = battery.level;
meter.textContent = battery.level; meter.textContent = battery.level;
}, },
Expand Down
5 changes: 3 additions & 2 deletions Code Examples/Chapter 06/battery.html
Expand Up @@ -17,9 +17,10 @@ <h2 id="status"></h2>
'use strict'; 'use strict';
var el = document.getElementById('status'), var el = document.getElementById('status'),
meter = document.querySelector('meter'), meter = document.querySelector('meter'),
battery = navigator.battery || navigator.webkitBattery, battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery;
if (!battery) { return false; }
// Check charge status and update h2 // Check charge status and update h2
status = (battery.charging) ? 'Charging' : 'Discharging'; var status = (battery.charging) ? 'Charging' : 'Discharging';
el.textContent = status; el.textContent = status;
// Get charge level and update meter // Get charge level and update meter
meter.value = battery.level; meter.value = battery.level;
Expand Down
3 changes: 2 additions & 1 deletion Code Examples/Chapter 06/network.html
Expand Up @@ -12,11 +12,12 @@ <h1>Getting Connection...</h1>
<script> <script>
document.addEventListener('DOMContentLoaded',function () { document.addEventListener('DOMContentLoaded',function () {
'use strict'; 'use strict';
navigator.connection = ( var hasConnect = navigator.connection = (
navigator.connection || navigator.connection ||
navigator.mozConnection || navigator.mozConnection ||
navigator.webkitConnection navigator.webkitConnection
); );
if (!hasConnect) { return false; }
var status, var status,
target = document.querySelector('h1'), target = document.querySelector('h1'),
showStatus = function () { showStatus = function () {
Expand Down

0 comments on commit 136446b

Please sign in to comment.