Permalink
Browse files

Feature detection to avoid errors

  • Loading branch information...
1 parent 24f6b3f commit 136446be650478e5fd864d8a03ee5e3959cfd6d7 @stopsatgreen committed Jul 5, 2013
@@ -18,9 +18,10 @@ <h2 id="status"></h2>
var status,
el = document.getElementById('status'),
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
- chargeLevel = function () {
+ var chargeLevel = function () {
meter.value = battery.level;
meter.textContent = battery.level;
},
@@ -17,9 +17,10 @@ <h2 id="status"></h2>
'use strict';
var el = document.getElementById('status'),
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
- status = (battery.charging) ? 'Charging' : 'Discharging';
+ var status = (battery.charging) ? 'Charging' : 'Discharging';
el.textContent = status;
// Get charge level and update meter
meter.value = battery.level;
@@ -12,11 +12,12 @@
<script>
document.addEventListener('DOMContentLoaded',function () {
'use strict';
- navigator.connection = (
+ var hasConnect = navigator.connection = (
navigator.connection ||
navigator.mozConnection ||
navigator.webkitConnection
);
+ if (!hasConnect) { return false; }
var status,
target = document.querySelector('h1'),
showStatus = function () {

0 comments on commit 136446b

Please sign in to comment.