Skip to content

Commit

Permalink
* initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
apg committed Jul 28, 2010
0 parents commit 64f57dd
Show file tree
Hide file tree
Showing 9 changed files with 1,139 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Timer
=====

What
----

I needed a simple timer for holding lightning talks, so I built one. You can see a demo of it at [http://hackandtell.org/timer](http://hackandtell.org/timer).

Who
---

Andrew Gwozdziewycz originally made this for [http://hackandtell.org](Hack and Tell)

Usage
-----

Just dump all the files in a directory and load up `index.html` in your browser. If you append `#10` to the url, you'll get a 10 minute timer. It defaults to 5

Binary file added clapping.mp3
Binary file not shown.
30 changes: 30 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Hack and Tell Timer</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<meta name="ROBOTS" content="all" />
<meta name="googlebot" content="noodp" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="author" content="Andrew Gwozdziewycz" />
<link rel="shortcut icon" href="http://www.hackandtell.org/favicon.ico" type="image/x-icon" />
<link rel="icon" href="http://www.hackandtell.org/favicon.ico" type="image/x-icon" />

<link rel="stylesheet" type="text/css" href="timer.css" />
</head>
<body>
<div id="wrapper" class="ok">
<div id="timer"></div>
</div>

<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="jquery.fit.js" type="text/javascript"></script>
<script src="timer.js" type="text/javascript"></script>
<audio id="sound" src="clapping.mp3" autobuffer>
</audio>
</body>
</html>

154 changes: 154 additions & 0 deletions jquery-1.4.2.min.js

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions jquery.fit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* (c) 2010, Andrew Gwozdziewycz, GPL Licensed, see LICENSE
*/

(function($) {
$.fn.fit = function(options) {
var config = {
'minsize': 1,
'maxsize': 10000,
'width': null,
'height': null
};

if (options) {
$.extend(config, options);
}

var fits = function(sz, node) {
node.css('fontSize', sz + 'px');
return node.outerWidth() <= config['width'] &&
node.outerHeight() <= config['height'];
};

this.each(function() {
var parent = $(this).parent();
if (!config['height']) {
config['height'] = parent.outerHeight();
}
if (!config['width']) {
config['width'] = parent.outerWidth();
}

var max = config['maxsize'];
var min = config['minsize'];
var iterations = 100;
do {
var hfs = max - min;
var mid = min + (hfs / 2);
if (fits(Math.floor(mid), $(this))) {
min = mid + 1;
}
else {
max = mid - 1;
}
} while (max > min && iterations--);

$(this).css('fontSize', fits(Math.floor(mid), $(this)) ? mid + 'px': min + 'px');
});
};
})(jQuery);
27 changes: 27 additions & 0 deletions textfit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* (C) 2007 Andrew Gwozdziewycz <apgwoz@gmail.com>
* VERSION: 0.1, Released under an MIT License.
* URL: http://www.apgwoz.com/textfit/
**/
function textFit(node, minfs, maxfs, width, height) {
var fits = function(sz) {
node.style.fontSize = sz + 'px';
return node.offsetWidth <= width && node.offsetHeight <= height;
};
var hfs = maxfs - minfs;
var tst = minfs + Math.ceil(hfs / 2);
var opsz = node.style.fontSize;

while ((hfs/2) >= 1) {
if (fits(tst)) {
minfs = tst;
}
else {
maxfs = tst;
}
hfs = maxfs - minfs;
tst = minfs + Math.ceil(hfs/2);
}
opsz = fits(maxfs) ? maxfs: minfs;
node.style.fontSize = opsz + 'px';
}
65 changes: 65 additions & 0 deletions timer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@-webkit-keyframes blink {
0% {
color: #fff;
}
25% {
color: #fff;
}
50% {
color: #aa0000;
}
100% {
color: #fff;
}
}

body {
/* font-size: 62.5%;*/
font-family: Liberation Serif, Times;
background: #ffffff;
margin: 0;
padding: 0;
text-align: center;
}

#wrapper {
margin: auto 0;
}
#wrapper.warning {
background: #ff0000;
}

#wrapper.warning #timer.playing {
color: #ffffff;
}

#wrapper.warning #timer.ohshit {
-webkit-animation-name: blink;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
}

#wrapper.warning #timer.paused {
color: #0000aa;
-webkit-animation-name: blink;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
}

#wrapper.warning #timer.stopped {
color: #ffffff;
}

#wrapper.ok #timer.playing {
color: #00aa00;
}

#wrapper.ok #timer.paused {
color: #0000ff;
}

#wrapper.ok #timer.stopped {
color: #ff0000;
}
121 changes: 121 additions & 0 deletions timer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
var Timer = function(time, e, b) {
this.length = time;
this.element = e;
this.background = b;

this._interval = null;
this._status = Timer.c.STOPPED;
this._timeleft = time;
this._lasttick = null;

// private state
this.init();
};

Timer.c = {
'STOPPED': 0,
'PAUSED': 1,
'PLAYING': 2
};

Timer.cr = {
0: 'STOPPED',
1: 'PAUSED',
2: 'PLAYING'
};

Timer.prototype = {
'init': function() {
// install the handlers
var that = this;
$(this.element).click(function (e) {
that.onclick(e);
});
$(this.element).dblclick(function (e) {
that.ondblclick(e);
});
this.displayTimeFor(this._timeleft);
},
'onclick': function(e) {
if (this._status == Timer.c.STOPPED ||
this._status == Timer.c.PAUSED) {
this.play();
}
else {
this.pause();
}
},
'ondblclick': function(e) {
this.stop();
},
'ontick': function() {
var tick = this.getTime();
if (tick > this._lasttick) {
this._timeleft--;
}

this._lasttick = tick;

if (this._timeleft <= 0) {
document.getElementById('sound').play();
this.pause();
}

this.displayTimeFor(this._timeleft);
},
'play': function() {
this._status = Timer.c.PLAYING;
// establish the interval at .2 seconds
var that = this;
this._interval = setInterval(function() { that.ontick(); }, 200);
this._lasttick = this.getTime();
},
'pause': function() {
this._status = Timer.c.PAUSED;
clearInterval(this._interval);
},
'stop': function() {
this._status = Timer.c.STOPPED;
if (this._interval) {
clearInterval(this._interval);
}
this.displayTimeFor(this.length);
},
'displayTimeFor': function(t) {
var minutes = Math.floor(t / 60);
var seconds = t % 60;
var text = minutes + ':' + (seconds < 10? '0' + seconds: seconds);

if (t < 60) {
this.background.attr('class', 'warning');
}
else if (t >= 60) {
this.background.attr('class', 'ok');
}

if (t < 10) {
this.element.attr('class', 'ohshit ' + Timer.cr[this._status].toLowerCase());
}
else {
this.element.attr('class', Timer.cr[this._status].toLowerCase());
}


$(this.element).text(text);
},
'getTime': function() {
return Math.floor((new Date()).getTime() / 1000);
}
};

jQuery(document).ready(function($) {
var hash = window.location.hash.substring(1);
var mins = parseInt(hash) > 0? parseInt(hash): 5;
new Timer(60 * mins, $('#timer'), $('#wrapper'));
$('#timer').fit({width: $(window).width(), height: $(window).height()});

$(window).resize(function() {
$('#timer').fit({width: $(window).width(), height: $(window).height()});
});
});

0 comments on commit 64f57dd

Please sign in to comment.