Created
March 8, 2011 23:31
-
-
Save cbiggins/861365 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="AIRAliases.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
function appLoad(){ | |
air.trace("Tea Timer"); | |
} | |
</script> | |
<script type="text/javascript"> | |
function playSound() | |
{ | |
var soundPath = | |
new air.URLRequest("app:/sound.mp3"); | |
var s = new air.Sound(); | |
s.load(soundPath); | |
s.play(); | |
} | |
</script> | |
<title>Tea Timer</title> | |
</head> | |
<body onLoad="appLoad()"> | |
<h1>Tea Timer!</h1> | |
<span id="notify" style="display:none">Your tea is ready</span> | |
<input type="radio" name="time" id="time" value="360"> 6 Mins<br /> | |
<input type="radio" name="time" id="time" value="300"> 5 Mins<br /> | |
<input type="radio" name="time" id="time" value="240"> 4 Mins<br /> | |
<input type="radio" name="time" id="time" value="30"> 30 Seconds<br /> | |
<input type="radio" name="time" id="time" value="5"> 5 Seconds<br /> | |
<input type="button" onClick="startCounter()" value="Start Timer" /> | |
<input type="text" id="countdown" /> | |
<script> | |
countdown = document.getElementById('countdown'); | |
timeout=false; | |
function niceTime(seconds) { | |
minlabel = Math.floor(seconds/60); // The minutes | |
seclabel = seconds % 60; // The balance of seconds | |
if (seconds < 10) { | |
seclabel = "0"+seclabel; | |
} | |
return minlabel+":"+seclabel; | |
} | |
function getCountdownVal() { | |
return time--; | |
} | |
function setCountdownVal(time) { | |
seconds = getCountdownVal(); | |
countdown.value = niceTime(seconds); | |
if (seconds == 0) { | |
playSound(); | |
if (air.NativeApplication.supportsDockIcon) { | |
var dockIcon = air.NativeApplication.nativeApplication.icon; | |
dockIcon.bounce(air.NotificationType.CRITICAL); | |
} else if (air.NativeWindow.supportsNotification) { | |
window.nativeWindow.notifyUser(air.NotificationType.INFORMATIONAL); | |
} | |
} else { | |
timeout=setTimeout(setCountdownVal, 1000); | |
} | |
} | |
function startCounter() { | |
if (timeout) { | |
clearTimeout(timeout); | |
} | |
timeAmount = document.getElementsByName('time'); | |
for (var i = 0; i < timeAmount.length; i++) { | |
if (timeAmount[i].checked) { | |
time = timeAmount[i].value; | |
break; | |
} | |
} | |
setCountdownVal(time); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment