Permalink
Browse files

API testing and tweaks

  • Loading branch information...
robnyman committed Jan 18, 2013
1 parent 4e2d9b3 commit a6308aa72768401e71997d8cd9207759c170feef
Showing with 50 additions and 18 deletions.
  1. +4 −1 index.html
  2. +45 −16 js/webapp.js
  3. +1 −1 manifest.appcache
View
@@ -66,10 +66,13 @@ <h2>WebAPIs</h2>
<button id="vibrate">Vibrate 2 sec</button>
- <!-- <button id="add-alarm">Add alarm</button> -->
+ <button id="add-alarm">Add alarm</button>
<button id="check-connection">Check connection</button>
<div id="connection-display"></div>
+
+ <button id="check-battery">Check battery</button>
+ <div id="battery-display"></div>
</div>
<footer>
View
@@ -147,13 +147,15 @@
var shareImage = document.querySelector("#share-image"),
imgToShare = document.querySelector("#image-to-share");
- if (shareImage && imgToShare) {
+ if (shareImage && imgToShare) {
shareImage.onclick = function () {
+ //alert(window.URL.createObjectURL(imgToShare.src));
var sharingImage = new MozActivity({
name: "share",
data: {
type: "image/png",
- url: imgToShare // Find parameter for sharing DOM object
+ // blobs: window.URL.createObjectURL(imgToShare) // Find parameter for sharing DOM object
+ filenames: imgToShare.src
}
});
}
@@ -207,7 +209,7 @@
notification.createNotification(
"See this",
"This is a notification"
- );
+ );
};
}
@@ -225,6 +227,9 @@
"portrait-secondary"

*/
var portraitLock = screen.mozLockOrientation("portrait");
+ if (portraitLock) {
+ alert("Orientation locked to portrait");
+ }
};
}
@@ -243,19 +248,6 @@
};
}
- // Check connection
- var checkConnection = document.querySelector("#check-connection"),
- connectionDisplay = document.querySelector("#connection-display");
- if (checkConnection && connectionDisplay) {
- checkConnection.onclick = function () {
- var connection = window.navigator.mozConnection,
- online = "Connected: " + (connection.bandwidth > 0),
- metered = ", metered: " + connection.metered;

-
- connectionDisplay.innerHTML = online + metered;
- };
- }
-
// Alarm API
var addAlarm = document.querySelector("#add-alarm");
if (addAlarm) {
@@ -276,5 +268,42 @@
alert(event.target.error.name);

};
}
+
+ // Check connection
+ var checkConnection = document.querySelector("#check-connection"),
+ connectionDisplay = document.querySelector("#connection-display");
+
+ if (checkConnection && connectionDisplay) {
+ checkConnection.onclick = function () {
+ var connection = window.navigator.mozConnection,
+ online = "<strong>Connected:</strong> " + (connection.bandwidth),
+ metered = "<strong>Metered:</strong> " + connection.metered;

+
+ connectionDisplay.innerHTML = online + "<br>" + metered;
+ connectionDisplay.style.display = "block";
+ };
+ }
+
+ // Check battery
+ var checkBattery = document.querySelector("#check-battery"),
+ batteryDisplay = document.querySelector("#battery-display");
+ if (checkBattery && batteryDisplay) {
+ checkBattery.onclick = function () {
+ var battery = navigator.battery,
+ batteryLevel = Math.round(battery.level * 100) + "%",
+ charging = battery.charging,
+ chargingTime = parseInt(battery.chargingTime / 60, 10),
+ dischargingTime = parseInt(battery.dischargingTime / 60, 10),
+ batteryInfo;
+
+ batteryInfo = "<strong>Battery level:</strong> " + batteryLevel + "<br>";
+ batteryInfo += "<strong>Battery charging:</strong> " + charging + "<br>";
+ batteryInfo += "<strong>Battery charging time:</strong> " + chargingTime + "<br>";
+ batteryInfo += "<strong>Battery discharging time:</strong> " + dischargingTime;
+
+ batteryDisplay.innerHTML = batteryInfo;
+ batteryDisplay.style.display = "block";
+ };
+ }
}
})();
View
@@ -1,5 +1,5 @@
CACHE MANIFEST
-# Version 0.66
+# Version 0.6799999
index.html
css/base.css

0 comments on commit a6308aa

Please sign in to comment.