Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ior of control buttons. fixed various settings bugs.

release version... v1.1
  • Loading branch information...
commit fffa9ee5d2eba631b4b9ce3ea08971dc8f429f47 1 parent 98b1956
= authored
9 CountdownTimer.gadget/countdown_timer.css
@@ -23,6 +23,13 @@ body {
23 23 font-weight: bolder;
24 24 }
25 25
  26 +#controls {
  27 + height:16px;
  28 + top:3px;
  29 + right:3px;
  30 + position:absolute;
  31 +}
  32 +
26 33 img#restart {
27   - margin-left: 6px;
  34 + margin-left: 4px;
28 35 }
174 CountdownTimer.gadget/countdown_timer.js
@@ -7,114 +7,97 @@
7 7 System.Gadget.settingsUI = "settings.html";
8 8 System.Gadget.onSettingsClosed = onSettingsClosed;
9 9
10   -var seconds = 0;
11   -var countdown_timer = null;
12   -var debug_mode = 0;
  10 +FTTA.countdownTimer.main.seconds = 0;
  11 +FTTA.countdownTimer.main.countdown_timer = null;
  12 +FTTA.countdownTimer.main.alarm_timer = null;
13 13
14   -
15   -function init()
16   -{
17   - loadSettings();
18   -}
19   -
20   -function resetCountdown()
21   -{
22   - pauseCountdown();
23   -
24   - seconds = 60 * countdown_min;
25   - document.getElementById('countdown_block').innerHTML = seconds / 60;
26   -}
27   -
28   -function startCountdown()
29   -{
30   - countdown();
31   - showPauseButton();
32   -}
33   -function pauseCountdown(obj)
34   -{
35   - clearTimeout(countdown_timer);
36   - showPlayButton();
37   -}
38   -function countdown()
39   -{
40   - if (seconds > 0) {
41   - seconds -= 1;
42   - var time_statement = seconds > 60 ? (Math.floor(seconds / 60) + " MIN") : (seconds + " SEC");
43   - document.getElementById('countdown_block').innerHTML = time_statement;
44   - document.getElementById('countdown_block').title = seconds + " seconds remain";
45   - updateProgressBar();
46   - countdown_timer = setTimeout('countdown()', 1000);
47   - } else {
48   - timesUp(0);
  14 +FTTA.countdownTimer.main.countdown = {
  15 + reset: function() {
  16 + this.pause();
  17 + FTTA.countdownTimer.main.seconds = 60 * FTTA.countdownTimer.global.countdown_min;
  18 + document.getElementById('countdown_block').innerHTML = FTTA.countdownTimer.main.seconds / 60 + " MIN";
  19 + FTTA.countdownTimer.ui.updateProgressBar();
  20 + },
  21 + start: function() {
  22 + this.run();
  23 + FTTA.countdownTimer.ui.showPause();
  24 + },
  25 + pause: function(obj) {
  26 + clearTimeout(FTTA.countdownTimer.main.countdown_timer);
  27 + clearTimeout(FTTA.countdownTimer.main.alarm_timer);
  28 + FTTA.countdownTimer.ui.showPlay();
  29 + },
  30 + run: function () {
  31 + if (FTTA.countdownTimer.main.seconds > 0) {
  32 + FTTA.countdownTimer.main.seconds -= 1;
  33 + var time_statement = FTTA.countdownTimer.main.seconds > 60 ? (Math.floor(FTTA.countdownTimer.main.seconds / 60) + " MIN") : (FTTA.countdownTimer.main.seconds + " SEC");
  34 + document.getElementById('countdown_block').innerHTML = time_statement;
  35 + document.getElementById('countdown_block').title = FTTA.countdownTimer.main.seconds + " seconds";
  36 + FTTA.countdownTimer.ui.updateProgressBar();
  37 + FTTA.countdownTimer.main.countdown_timer = setTimeout('FTTA.countdownTimer.main.countdown.run()', 1000);
  38 + } else {
  39 + FTTA.countdownTimer.ui.timesUp(0);
  40 + }
49 41 }
50 42 }
51   -function updateProgressBar()
52   -{
53   - var width = Math.round(seconds / (60*countdown_min) * 100);
54   - document.getElementById('progress_bar').style.width = width + "%";
55   -
56   - var tick = document.getElementById('countdown_tick');
57 43
58   - if (tick.style.color == '#666') {
59   - tick.style.color = '#ccc';
60   - } else {
61   - tick.style.color = '#666';
62   - }
63   -}
64   -function timesUp(i)
65   -{
66   - if (i++ < max_alarm_notifies) {
67   - System.Sound.playSound("sound/alarm.wav");
68   - document.getElementById('countdown_block').innerHTML = "<marquee>TIMES UP</marquee>";
  44 +FTTA.countdownTimer.ui = {
  45 + updateProgressBar: function() {
  46 + var width = Math.round(FTTA.countdownTimer.main.seconds / (60*FTTA.countdownTimer.global.countdown_min) * 100);
  47 + document.getElementById('progress_bar').style.width = width + "%";
69 48
70   - setTimeout("timesUp("+i+");", 4000);
71   - } else {
72   - showPlayButton();
73   - }
74   -}
75   -function showPlayButton()
76   -{
77   - if (document.getElementById('pause')) {
78   - var pause_btn = document.getElementById('pause');
79   - pause_btn.onclick = function() { startCountdown(); }
80   - pause_btn.src = "images/play.png";
81   - pause_btn.id = "play";
82   - }
83   -}
84   -function showPauseButton()
85   -{
86   - if (document.getElementById('play')) {
87   - var play_btn = document.getElementById('play');
88   - play_btn.onclick = function() { pauseCountdown(); }
89   - play_btn.src = "images/pause.png";
90   - play_btn.id = "pause";
  49 + var tick = document.getElementById('countdown_tick');
  50 +
  51 + if (tick.style.color == '#666') {
  52 + tick.style.color = '#ccc';
  53 + } else {
  54 + tick.style.color = '#666';
  55 + }
  56 + },
  57 + timesUp: function(i) {
  58 + if (i++ < FTTA.countdownTimer.global.num_audible_alarm) {
  59 + System.Sound.playSound("sound/alarm.wav");
  60 + FTTA.countdownTimer.main.alarm_timer = setTimeout("FTTA.countdownTimer.ui.timesUp("+i+");", 4000);
  61 + } else {
  62 + this.showPlay();
  63 + }
  64 + document.getElementById('countdown_block').innerHTML = "<marquee>TIME'S UP</marquee>";
  65 + },
  66 + showPlay: function() {
  67 + if (document.getElementById('pause')) {
  68 + var pause_btn = document.getElementById('pause');
  69 + pause_btn.onclick = function() { FTTA.countdownTimer.main.countdown.start(); }
  70 + pause_btn.src = "images/play.png";
  71 + pause_btn.id = "play";
  72 + }
  73 + },
  74 + showPause: function() {
  75 + if (document.getElementById('play')) {
  76 + var play_btn = document.getElementById('play');
  77 + play_btn.onclick = function() { FTTA.countdownTimer.main.countdown.pause(); }
  78 + play_btn.src = "images/pause.png";
  79 + play_btn.id = "pause";
  80 + }
91 81 }
92 82 }
93 83
94   -function debug(msg)
  84 +
  85 +FTTA.countdownTimer.main.init = function()
95 86 {
96   - if (debug_mode) {
97   - //System.Debug.outputString(msg);
98   - window.prompt(msg);
99   - }
  87 + FTTA.countdownTimer.main.getSettings();
100 88 }
101 89
102   -function loadSettings()
  90 +FTTA.countdownTimer.main.getSettings = function()
103 91 {
104   - var setting_min = 0;
  92 + FTTA.countdownTimer.global.getSettings();
  93 +
  94 + // override global countdown if custom is set
105 95 var custom_countdown = System.Gadget.Settings.readString("custom_countdown_min");
106 96 if (custom_countdown > 0) {
107   - setting_min = custom_countdown;
108   - } else {
109   - setting_min = System.Gadget.Settings.readString("countdown_minutes");
  97 + FTTA.countdownTimer.global.countdown_min = custom_countdown;
110 98 }
111 99
112   - var setting_alarm_notifs = System.Gadget.Settings.read("countdown_alarm_notifies");
113   -
114   - max_alarm_notifies = setting_alarm_notifs == '' ? 2 : setting_alarm_notifs;
115   - countdown_min = setting_min == '' ? 30 : setting_min;
116   -
117   - resetCountdown();
  100 + FTTA.countdownTimer.main.countdown.reset();
118 101 }
119 102
120 103 function onSettingsClosed(event)
@@ -122,11 +105,6 @@ function onSettingsClosed(event)
122 105 // User hits OK on the settings page.
123 106 if (event.closeAction == event.Action.commit)
124 107 {
125   - loadSettings();
  108 + FTTA.countdownTimer.main.getSettings();
126 109 }
127   - // User hits Cancel on the settings page.
128   - //else if (event.closeAction == event.Action.cancel)
129   - //{
130   - // SetContentText("Cancelled");
131   - //}
132 110 }
6 CountdownTimer.gadget/gadget.xml
... ... @@ -1,16 +1,16 @@
1 1 <?xml version="1.0" encoding="utf-8" ?>
2 2 <gadget>
3 3 <name>Countdown Timer</name>
4   - <namespace>naraku.gadgets</namespace>
  4 + <namespace>ftta.gadgets</namespace>
5 5 <version>1.0.0.0</version>
6 6 <author name="Nate Vogel">
7   - <info url="http://naraku.net" text="naraku.net"/>
  7 + <info url="http://funtothinkabout.com" text="FTTA"/>
8 8 </author>
9 9 <copyright>
10 10 &#169; 2010
11 11 </copyright>
12 12 <description>
13   - Simple Countdown Timer
  13 + A Simple, Configurable Countdown Timer
14 14 </description>
15 15 <icons>
16 16 <icon src="icon.png"/>
34 CountdownTimer.gadget/global.js
@@ -4,7 +4,41 @@
4 4 -
5 5 - http://funtothinkabout.com
6 6 */
  7 +FTTA = {
  8 + countdownTimer: {
  9 + global: {},
  10 + main: {},
  11 + settings: {}
  12 + }
  13 +}
  14 +FTTA.countdownTimer.global.getSettings = function()
  15 +{
  16 + // override Defaults HERE:
  17 + FTTA.countdownTimer.global.countdown_min = 30;
  18 + FTTA.countdownTimer.global.num_audible_alarm = 2;
  19 + FTTA.countdownTimer.global.presets_list_values = "1||5||15||30||60||240";
  20 +
  21 + // leave these alone.
  22 + var first_run = System.Gadget.Settings.readString("countdown_first_run");
  23 + if (System.Gadget.Settings.readString("countdown_first_run") != '') {
  24 + FTTA.countdownTimer.global.countdown_min = System.Gadget.Settings.read("countdown_minutes");
  25 + FTTA.countdownTimer.global.presets_list_values = System.Gadget.Settings.read("countdown_presets");
  26 + FTTA.countdownTimer.global.num_audible_alarm = System.Gadget.Settings.read("countdown_alarm_notifies");
  27 + }
  28 + //+"\npresets:"+FTTA.countdownTimer.global.presets_list_values
  29 + debug("countdown_min:"+FTTA.countdownTimer.global.countdown_min+"\nnum alarms:"+FTTA.countdownTimer.global.num_audible_alarm);
  30 +}
  31 +
7 32 function getTimeSuffix(seconds)
8 33 {
9 34 return seconds > 3600 ? "HR" : seconds > 60 ? "MIN" : "SEC";
10 35 }
  36 +
  37 +FTTA.countdownTimer.global.debug_mode = 0;
  38 +function debug(msg)
  39 +{
  40 + if (FTTA.countdownTimer.global.debug_mode) {
  41 + //System.Debug.outputString(msg);
  42 + window.prompt(msg);
  43 + }
  44 +}
12 CountdownTimer.gadget/main.html
@@ -7,16 +7,16 @@
7 7 <html xmlns="http://www.w3.org/1999/xhtml" >
8 8 <head>
9 9 <title>Countdown Timer</title>
10   - <link href="countdown_timer.css" rel="stylesheet" type="text/css" />
11   - <script type="text/javascript" src="countdown_timer.js"></script>
  10 + <link href="countdown_timer.css" rel="stylesheet" type="text/css" />
12 11 <script type="text/javascript" src="global.js"></script>
  12 + <script type="text/javascript" src="countdown_timer.js"></script>
13 13 </head>
14 14
15   -<body onload="init();">
  15 +<body onload="FTTA.countdownTimer.main.init();">
16 16
17   - <div style="float:right;">
18   - <img id="play" src="images/play.png" width="14" height="12" title="Play/Pause" onclick="startCountdown();">
19   - <img id="restart" src="images/restart.png" width="14" height="12" title="Restart" onclick="resetCountdown();">
  17 + <div id="controls">
  18 + <img id="play" src="images/play.png" title="Play/Pause" onclick="FTTA.countdownTimer.main.countdown.start();">
  19 + <img id="restart" src="images/restart.png" title="Reset" onclick="FTTA.countdownTimer.main.countdown.reset();">
20 20 </div>
21 21 <span id="countdown_tick">:</span><span id="countdown_block"></span>
22 22 <div id="progress_bar">&nbsp;</div>
6 CountdownTimer.gadget/settings.html
@@ -7,12 +7,12 @@
7 7 <html>
8 8 <head>
9 9 <title>Countdown Timer Settings</title>
10   - <script type="text/javascript" src="settings.js"></script>
11 10 <script type="text/javascript" src="global.js"></script>
  11 + <script type="text/javascript" src="settings.js"></script>
12 12 <link rel="stylesheet" href="settings.css">
13 13 </head>
14 14
15   -<body onload="loadSettings();">
  15 +<body onload="FTTA.countdownTimer.settings.getSettings();">
16 16 <strong>Custom Countdown</strong>
17 17 <input type="text" name="custom_countdown_min" value="" />
18 18
@@ -24,7 +24,7 @@
24 24 <input type="text" size="1" name="num_audible_alarm" id="num_audible_alarm" />
25 25
26 26 <br /><br />
27   - For Tips and About Visit:<br />
  27 + For Tips and More, Visit:<br />
28 28 <strong><a href="http://funtothinkabout.com">Fun To Think About</a></strong>
29 29 </body>
30 30 </html>
26 CountdownTimer.gadget/settings.js
@@ -4,11 +4,10 @@
4 4 -
5 5 - http://funtothinkabout.com
6 6 */
7   -System.Gadget.onSettingsClosing = SettingsClosing;
  7 +System.Gadget.onSettingsClosing = FTTA.countdownTimer.settings.SettingsClosing;
8 8
9   -function SettingsClosing(event)
  9 +function FTTA.countdownTimer.settings.SettingsClosing(event)
10 10 {
11   - // Save the settings if the user clicked OK.
12 11 if (event.closeAction == event.Action.commit)
13 12 {
14 13 System.Gadget.Settings.write("countdown_first_run", false);
@@ -41,35 +40,26 @@ function SettingsClosing(event)
41 40 event.cancel = false;
42 41 }
43 42
44   -var countdown_min;
45   -var presets_list_values;
46   -var num_audible_alarm;
47   -function loadSettings()
  43 +FTTA.countdownTimer.settings.getSettings = function()
48 44 {
49   - if (System.Gadget.Settings.read("countdown_first_run") == '') {
50   - loadDefaults();
51   - } else {
52   - countdown_min = System.Gadget.Settings.read("countdown_minutes");
53   - presets_list_values = System.Gadget.Settings.read("countdown_presets");
54   - num_audible_alarm = System.Gadget.Settings.read("countdown_alarm_notifies");
55   - }
  45 + FTTA.countdownTimer.global.getSettings();
56 46
57 47 var presets_list = document.getElementById('preset_list');
58   - presets_list_values = presets_list_values.split("||");
  48 + presets_list_values = FTTA.countdownTimer.global.presets_list_values.split("||");
  49 +
59 50 // populate countdown minute presets
60 51 for (i = 0; i < presets_list_values.length; i++) {
61 52 var option = document.createElement('option');
62 53 option.appendChild(document.createTextNode(presets_list_values[i]));
63 54 option.setAttribute("value", presets_list_values[i]);
64   - if (countdown_min == presets_list_values[i]) {
  55 + if (FTTA.countdownTimer.global.countdown_min == presets_list_values[i]) {
65 56 option.setAttribute("selected", "selected");
66 57 }
67 58 presets_list.appendChild(option);
68 59 }
69 60
70 61 // populate number of alarm sounds
71   - document.getElementById("num_audible_alarm").value = num_audible_alarm;
  62 + document.getElementById("num_audible_alarm").value = FTTA.countdownTimer.global.num_audible_alarm;
72 63
73 64 return;
74 65 }
75   -

0 comments on commit fffa9ee

Please sign in to comment.
Something went wrong with that request. Please try again.