~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to gears/sdk/samples/running_man/step2/model.js

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var global = new Object();
 
2
 
 
3
/*
 
4
 * Main function
 
5
 */
 
6
function main() {
 
7
  global.startTime = null;
 
8
  updateTime();
 
9
  global.siteUrl = "http://code.google.com/apis/gears/samples/running_man/step2/index.html";
 
10
  installShortcut();
 
11
}
 
12
 
 
13
/*
 
14
 * Install shortcut
 
15
 */
 
16
function installShortcut() {
 
17
  var desktop = google.gears.factory.create('beta.desktop');
 
18
  desktop.createShortcut("RunningMan", global.siteUrl,
 
19
    { "48x48" : "../images/icon.png" }, "RunningMan Step2");
 
20
}
 
21
 
 
22
/*
 
23
 * Timers functions
 
24
 */
 
25
 
 
26
function startRun() {
 
27
  global.updateInterval = setInterval("updateTime()", 1000);
 
28
  global.startTime = new Date();
 
29
}
 
30
 
 
31
function stopRun() {
 
32
  clearInterval(global.updateInterval);
 
33
}
 
34
 
 
35
function resetRun() {
 
36
  stopRun();
 
37
  global.startTime = null;
 
38
  updateTime();
 
39
}
 
40
 
 
41
/*
 
42
 * display stopwatch time value
 
43
 */
 
44
function updateTime() {
 
45
  var time = 0;
 
46
  if (global.startTime != null) {
 
47
    time = (new Date()).getTime() - global.startTime;
 
48
    time = (time/1000)|0;
 
49
  }
 
50
  var timeDiv = document.getElementById("timeDisplay");
 
51
  timeDiv.innerHTML = formatTime(time);
 
52
}
 
53
 
 
54
/*
 
55
 * Format a time value given in seconds
 
56
 */
 
57
function formatTime(aTime) {
 
58
  var seconds = aTime % 60;
 
59
  var minutes = ((aTime / 60) |0) % 60;
 
60
  var hours = (aTime / 3600) |0;
 
61
  var time = "0";
 
62
  if (seconds > 0) {
 
63
    time = seconds + " s";
 
64
  }
 
65
  if (minutes > 0) {
 
66
    time = minutes + " min " + time;
 
67
  }
 
68
  if (hours > 0) {
 
69
    time = hours + " h " + time;
 
70
  }
 
71
  return time;
 
72
}
 
73
 
 
74
 
 
75
 
 
76
/*
 
77
 * Navigation functions
 
78
 */
 
79
 
 
80
function go(name) {
 
81
  hideAllScreens();
 
82
  var functionName = "on_" + name;
 
83
  showDiv(name);
 
84
  if (window[functionName] != null) {
 
85
    window[functionName]();
 
86
  }
 
87
}
 
88
 
 
89
function showDiv(name) {
 
90
  var elem = document.getElementById(name);
 
91
  if (elem) {
 
92
    elem.style.display="block";
 
93
  }
 
94
}
 
95
 
 
96
function hideDiv(name) {
 
97
  var elem = document.getElementById(name);
 
98
  if (elem) {
 
99
    elem.style.display="none";
 
100
  }
 
101
}
 
102
 
 
103
function hideAllScreens() {
 
104
  hideDiv('mainScreen');
 
105
  hideDiv('watch');
 
106
  hideDiv('journeys');
 
107
}