JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://michelarteta.com/treehouse/css/foundation.css">
<link rel="stylesheet" href="http://michelarteta.com/treehouse/inc/TimeCircles.css">
<script src="http://michelarteta.com/treehouse/js/vendor/modernizr.js"></script>
<body>
<div class="row">
<div class="large-12 small-12 columns">
<h1 class="text-center">Countdown</h1>
<div id="CountDownTimer" data-date="2014-05-01 12:00:00"></div>
</div>
</div>
</body>
CSS
time_circles {
position: relative;
width: 100%;
height: 100%;
}
/**
* This is all the elements used to house all text used
* in time circles
**/
.time_circles > div {
position: absolute;
text-align: center;
}
/**
* Titles (Days, Hours, etc)
**/
.time_circles > div > h4 {
margin: 0px;
padding: 0px;
text-align: center;
text-transform: uppercase;
font-family:'Century Gothic', Arial;
}
/**
* Time numbers, ie: 12
**/
.time_circles > div > span {
display: block;
width: 100%;
text-align: center;
font-family:'Century Gothic', Arial;
font-size: 300%;
margin-top: 0.4em;
font-weight: bold;
}
JavaScript
(function ($) {
var debug = (location.hash === "#debug");
function debug_log(msg) {
if (debug) {
console.log(msg);
}
}
var nextUnits = {
Seconds: "Minutes",
Minutes: "Hours",
Hours: "Days",
Days: "Years"
};
var secondsIn = {
Seconds: 1,
Minutes: 60,
Hours: 3600,
Days: 86400,
Years: 31536000
};
/**
* Converts hex color code into object containing integer values for the r,g,b use
* This function (hexToRgb) originates from:
* http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
* @param {string} hex color code
*/
function hexToRgb(hex) {
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
return r + r + g + g + b + b;
});
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
/**
* Function s4() and guid() originate from:
* http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
*/
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
/**
* Creates a unique id
* @returns {String}
*/
function guid() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
function parse_date(str) {
var match = str.match(/^[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{1,2}:[0-9]{2}:[0-9]{2}$/);
if (match !== null && match.length > 0) {
var parts = str.split(" ");
var date = parts[0].split("-");
var time =...