Permalink
Browse files

massive refactoring. namespaced all functions and vars. tweaked behav…

…ior of control buttons. fixed various settings bugs.

release version... v1.1
  • Loading branch information...
=
= committed Jun 12, 2010
1 parent 98b1956 commit fffa9ee5d2eba631b4b9ce3ea08971dc8f429f47
@@ -23,6 +23,13 @@ body {
font-weight: bolder;
}
+#controls {
+ height:16px;
+ top:3px;
+ right:3px;
+ position:absolute;
+}
+
img#restart {
- margin-left: 6px;
+ margin-left: 4px;
}
@@ -7,126 +7,104 @@
System.Gadget.settingsUI = "settings.html";
System.Gadget.onSettingsClosed = onSettingsClosed;
-var seconds = 0;
-var countdown_timer = null;
-var debug_mode = 0;
+FTTA.countdownTimer.main.seconds = 0;
+FTTA.countdownTimer.main.countdown_timer = null;
+FTTA.countdownTimer.main.alarm_timer = null;
-
-function init()
-{
- loadSettings();
-}
-
-function resetCountdown()
-{
- pauseCountdown();
-
- seconds = 60 * countdown_min;
- document.getElementById('countdown_block').innerHTML = seconds / 60;
-}
-
-function startCountdown()
-{
- countdown();
- showPauseButton();
-}
-function pauseCountdown(obj)
-{
- clearTimeout(countdown_timer);
- showPlayButton();
-}
-function countdown()
-{
- if (seconds > 0) {
- seconds -= 1;
- var time_statement = seconds > 60 ? (Math.floor(seconds / 60) + " MIN") : (seconds + " SEC");
- document.getElementById('countdown_block').innerHTML = time_statement;
- document.getElementById('countdown_block').title = seconds + " seconds remain";
- updateProgressBar();
- countdown_timer = setTimeout('countdown()', 1000);
- } else {
- timesUp(0);
+FTTA.countdownTimer.main.countdown = {
+ reset: function() {
+ this.pause();
+ FTTA.countdownTimer.main.seconds = 60 * FTTA.countdownTimer.global.countdown_min;
+ document.getElementById('countdown_block').innerHTML = FTTA.countdownTimer.main.seconds / 60 + " MIN";
+ FTTA.countdownTimer.ui.updateProgressBar();
+ },
+ start: function() {
+ this.run();
+ FTTA.countdownTimer.ui.showPause();
+ },
+ pause: function(obj) {
+ clearTimeout(FTTA.countdownTimer.main.countdown_timer);
+ clearTimeout(FTTA.countdownTimer.main.alarm_timer);
+ FTTA.countdownTimer.ui.showPlay();
+ },
+ run: function () {
+ if (FTTA.countdownTimer.main.seconds > 0) {
+ FTTA.countdownTimer.main.seconds -= 1;
+ var time_statement = FTTA.countdownTimer.main.seconds > 60 ? (Math.floor(FTTA.countdownTimer.main.seconds / 60) + " MIN") : (FTTA.countdownTimer.main.seconds + " SEC");
+ document.getElementById('countdown_block').innerHTML = time_statement;
+ document.getElementById('countdown_block').title = FTTA.countdownTimer.main.seconds + " seconds";
+ FTTA.countdownTimer.ui.updateProgressBar();
+ FTTA.countdownTimer.main.countdown_timer = setTimeout('FTTA.countdownTimer.main.countdown.run()', 1000);
+ } else {
+ FTTA.countdownTimer.ui.timesUp(0);
+ }
}
}
-function updateProgressBar()
-{
- var width = Math.round(seconds / (60*countdown_min) * 100);
- document.getElementById('progress_bar').style.width = width + "%";
-
- var tick = document.getElementById('countdown_tick');
- if (tick.style.color == '#666') {
- tick.style.color = '#ccc';
- } else {
- tick.style.color = '#666';
- }
-}
-function timesUp(i)
-{
- if (i++ < max_alarm_notifies) {
- System.Sound.playSound("sound/alarm.wav");
- document.getElementById('countdown_block').innerHTML = "<marquee>TIMES UP</marquee>";
+FTTA.countdownTimer.ui = {
+ updateProgressBar: function() {
+ var width = Math.round(FTTA.countdownTimer.main.seconds / (60*FTTA.countdownTimer.global.countdown_min) * 100);
+ document.getElementById('progress_bar').style.width = width + "%";
- setTimeout("timesUp("+i+");", 4000);
- } else {
- showPlayButton();
- }
-}
-function showPlayButton()
-{
- if (document.getElementById('pause')) {
- var pause_btn = document.getElementById('pause');
- pause_btn.onclick = function() { startCountdown(); }
- pause_btn.src = "images/play.png";
- pause_btn.id = "play";
- }
-}
-function showPauseButton()
-{
- if (document.getElementById('play')) {
- var play_btn = document.getElementById('play');
- play_btn.onclick = function() { pauseCountdown(); }
- play_btn.src = "images/pause.png";
- play_btn.id = "pause";
+ var tick = document.getElementById('countdown_tick');
+
+ if (tick.style.color == '#666') {
+ tick.style.color = '#ccc';
+ } else {
+ tick.style.color = '#666';
+ }
+ },
+ timesUp: function(i) {
+ if (i++ < FTTA.countdownTimer.global.num_audible_alarm) {
+ System.Sound.playSound("sound/alarm.wav");
+ FTTA.countdownTimer.main.alarm_timer = setTimeout("FTTA.countdownTimer.ui.timesUp("+i+");", 4000);
+ } else {
+ this.showPlay();
+ }
+ document.getElementById('countdown_block').innerHTML = "<marquee>TIME'S UP</marquee>";
+ },
+ showPlay: function() {
+ if (document.getElementById('pause')) {
+ var pause_btn = document.getElementById('pause');
+ pause_btn.onclick = function() { FTTA.countdownTimer.main.countdown.start(); }
+ pause_btn.src = "images/play.png";
+ pause_btn.id = "play";
+ }
+ },
+ showPause: function() {
+ if (document.getElementById('play')) {
+ var play_btn = document.getElementById('play');
+ play_btn.onclick = function() { FTTA.countdownTimer.main.countdown.pause(); }
+ play_btn.src = "images/pause.png";
+ play_btn.id = "pause";
+ }
}
}
-function debug(msg)
+
+FTTA.countdownTimer.main.init = function()
{
- if (debug_mode) {
- //System.Debug.outputString(msg);
- window.prompt(msg);
- }
+ FTTA.countdownTimer.main.getSettings();
}
-function loadSettings()
+FTTA.countdownTimer.main.getSettings = function()
{
- var setting_min = 0;
+ FTTA.countdownTimer.global.getSettings();
+
+ // override global countdown if custom is set
var custom_countdown = System.Gadget.Settings.readString("custom_countdown_min");
if (custom_countdown > 0) {
- setting_min = custom_countdown;
- } else {
- setting_min = System.Gadget.Settings.readString("countdown_minutes");
+ FTTA.countdownTimer.global.countdown_min = custom_countdown;
}
- var setting_alarm_notifs = System.Gadget.Settings.read("countdown_alarm_notifies");
-
- max_alarm_notifies = setting_alarm_notifs == '' ? 2 : setting_alarm_notifs;
- countdown_min = setting_min == '' ? 30 : setting_min;
-
- resetCountdown();
+ FTTA.countdownTimer.main.countdown.reset();
}
function onSettingsClosed(event)
{
// User hits OK on the settings page.
if (event.closeAction == event.Action.commit)
{
- loadSettings();
+ FTTA.countdownTimer.main.getSettings();
}
- // User hits Cancel on the settings page.
- //else if (event.closeAction == event.Action.cancel)
- //{
- // SetContentText("Cancelled");
- //}
}
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<gadget>
<name>Countdown Timer</name>
- <namespace>naraku.gadgets</namespace>
+ <namespace>ftta.gadgets</namespace>
<version>1.0.0.0</version>
<author name="Nate Vogel">
- <info url="http://naraku.net" text="naraku.net"/>
+ <info url="http://funtothinkabout.com" text="FTTA"/>
</author>
<copyright>
&#169; 2010
</copyright>
<description>
- Simple Countdown Timer
+ A Simple, Configurable Countdown Timer
</description>
<icons>
<icon src="icon.png"/>
@@ -4,7 +4,41 @@
-
- http://funtothinkabout.com
*/
+FTTA = {
+ countdownTimer: {
+ global: {},
+ main: {},
+ settings: {}
+ }
+}
+FTTA.countdownTimer.global.getSettings = function()
+{
+ // override Defaults HERE:
+ FTTA.countdownTimer.global.countdown_min = 30;
+ FTTA.countdownTimer.global.num_audible_alarm = 2;
+ FTTA.countdownTimer.global.presets_list_values = "1||5||15||30||60||240";
+
+ // leave these alone.
+ var first_run = System.Gadget.Settings.readString("countdown_first_run");
+ if (System.Gadget.Settings.readString("countdown_first_run") != '') {
+ FTTA.countdownTimer.global.countdown_min = System.Gadget.Settings.read("countdown_minutes");
+ FTTA.countdownTimer.global.presets_list_values = System.Gadget.Settings.read("countdown_presets");
+ FTTA.countdownTimer.global.num_audible_alarm = System.Gadget.Settings.read("countdown_alarm_notifies");
+ }
+ //+"\npresets:"+FTTA.countdownTimer.global.presets_list_values
+ debug("countdown_min:"+FTTA.countdownTimer.global.countdown_min+"\nnum alarms:"+FTTA.countdownTimer.global.num_audible_alarm);
+}
+
function getTimeSuffix(seconds)
{
return seconds > 3600 ? "HR" : seconds > 60 ? "MIN" : "SEC";
}
+
+FTTA.countdownTimer.global.debug_mode = 0;
+function debug(msg)
+{
+ if (FTTA.countdownTimer.global.debug_mode) {
+ //System.Debug.outputString(msg);
+ window.prompt(msg);
+ }
+}
@@ -7,16 +7,16 @@
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Countdown Timer</title>
- <link href="countdown_timer.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="countdown_timer.js"></script>
+ <link href="countdown_timer.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="global.js"></script>
+ <script type="text/javascript" src="countdown_timer.js"></script>
</head>
-<body onload="init();">
+<body onload="FTTA.countdownTimer.main.init();">
- <div style="float:right;">
- <img id="play" src="images/play.png" width="14" height="12" title="Play/Pause" onclick="startCountdown();">
- <img id="restart" src="images/restart.png" width="14" height="12" title="Restart" onclick="resetCountdown();">
+ <div id="controls">
+ <img id="play" src="images/play.png" title="Play/Pause" onclick="FTTA.countdownTimer.main.countdown.start();">
+ <img id="restart" src="images/restart.png" title="Reset" onclick="FTTA.countdownTimer.main.countdown.reset();">
</div>
<span id="countdown_tick">:</span><span id="countdown_block"></span>
<div id="progress_bar">&nbsp;</div>
@@ -7,12 +7,12 @@
<html>
<head>
<title>Countdown Timer Settings</title>
- <script type="text/javascript" src="settings.js"></script>
<script type="text/javascript" src="global.js"></script>
+ <script type="text/javascript" src="settings.js"></script>
<link rel="stylesheet" href="settings.css">
</head>
-<body onload="loadSettings();">
+<body onload="FTTA.countdownTimer.settings.getSettings();">
<strong>Custom Countdown</strong>
<input type="text" name="custom_countdown_min" value="" />
@@ -24,7 +24,7 @@
<input type="text" size="1" name="num_audible_alarm" id="num_audible_alarm" />
<br /><br />
- For Tips and About Visit:<br />
+ For Tips and More, Visit:<br />
<strong><a href="http://funtothinkabout.com">Fun To Think About</a></strong>
</body>
</html>
@@ -4,11 +4,10 @@
-
- http://funtothinkabout.com
*/
-System.Gadget.onSettingsClosing = SettingsClosing;
+System.Gadget.onSettingsClosing = FTTA.countdownTimer.settings.SettingsClosing;
-function SettingsClosing(event)
+function FTTA.countdownTimer.settings.SettingsClosing(event)
{
- // Save the settings if the user clicked OK.
if (event.closeAction == event.Action.commit)
{
System.Gadget.Settings.write("countdown_first_run", false);
@@ -41,35 +40,26 @@ function SettingsClosing(event)
event.cancel = false;
}
-var countdown_min;
-var presets_list_values;
-var num_audible_alarm;
-function loadSettings()
+FTTA.countdownTimer.settings.getSettings = function()
{
- if (System.Gadget.Settings.read("countdown_first_run") == '') {
- loadDefaults();
- } else {
- countdown_min = System.Gadget.Settings.read("countdown_minutes");
- presets_list_values = System.Gadget.Settings.read("countdown_presets");
- num_audible_alarm = System.Gadget.Settings.read("countdown_alarm_notifies");
- }
+ FTTA.countdownTimer.global.getSettings();
var presets_list = document.getElementById('preset_list');
- presets_list_values = presets_list_values.split("||");
+ presets_list_values = FTTA.countdownTimer.global.presets_list_values.split("||");
+
// populate countdown minute presets
for (i = 0; i < presets_list_values.length; i++) {
var option = document.createElement('option');
option.appendChild(document.createTextNode(presets_list_values[i]));
option.setAttribute("value", presets_list_values[i]);
- if (countdown_min == presets_list_values[i]) {
+ if (FTTA.countdownTimer.global.countdown_min == presets_list_values[i]) {
option.setAttribute("selected", "selected");
}
presets_list.appendChild(option);
}
// populate number of alarm sounds
- document.getElementById("num_audible_alarm").value = num_audible_alarm;
+ document.getElementById("num_audible_alarm").value = FTTA.countdownTimer.global.num_audible_alarm;
return;
}
-

0 comments on commit fffa9ee

Please sign in to comment.