Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@ var $$ = document.querySelectorAll.bind(document);
var App = function($el){
this.$el = $el;
this.load();

this.$el.addEventListener(
'submit', this.submit.bind(this)
);

if (this.dob) {
this.renderAgeLoop();
} else {
this.renderChoose();
}
this.renderAgeLoop();
};


App.fn = App.prototype;

App.fn.load = function(){
Expand All @@ -27,58 +19,40 @@ App.fn.load = function(){
this.dob = new Date(parseInt(value));
};

App.fn.save = function(){
if (this.dob)
localStorage.dob = this.dob.getTime();
};

App.fn.submit = function(e){
e.preventDefault();

var input = this.$$('input')[0];
if ( !input.valueAsDate ) return;

this.dob = input.valueAsDate;
this.save();
this.renderAgeLoop();
};

App.fn.renderChoose = function(){
this.html(this.view('dob')());
};

App.fn.renderAgeLoop = function(){
this.interval = setInterval(this.renderAge.bind(this), 100);
};

App.fn.renderAge = function(){
var now = new Date
var now = new Date;
var duration = now - this.dob;
var years = duration / 31556900000;
var seconds = duration / 1000;

var majorMinor = years.toFixed(9).toString().split('.');
var majorMinor = seconds.toFixed(4).toString().split('.');

requestAnimationFrame(function(){
// console.log(this.view('age'), "<= thisviewage");
this.html(this.view('age')({
year: majorMinor[0],
milliseconds: majorMinor[1]
}));
}.bind(this));
};

App.fn.$$ = function(sel){
return this.$el.querySelectorAll(sel);
};

App.fn.html = function(html){
// console.log(html);
this.$el.innerHTML = html;
};

App.fn.view = function(name){

var $el = $(name + '-template');
// console.log($el.innerHTML, "<= $el.innerHTML");
return Handlebars.compile($el.innerHTML);
};

window.app = new App($('app'))

app = new App($('secCount'));
console.log(app, "<=app at bottom");
// console.log(app);
app.dob = new Date;
})();
87 changes: 0 additions & 87 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -1,87 +0,0 @@
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box;
}

body,
html {
margin: 0;
padding: 0;
height: 100%;
}

body {
-moz-osx-font-smoothing: grayscale;
-webkit-align-items: center;
-webkit-flex-direction: column;
-webkit-font-smoothing: antialiased;
-webkit-justify-content: center;
}

body, input {
display: -webkit-flex;
font-family: 'Avenir', 'helvetica neue', helvetica, arial, sans-serif;
}

.age-label {
color: #B0B5B9;
font-size: 1.2rem;
line-height: 1;
margin: 0 0 0 2px;
}

.count {
color: #494949;
margin: 0;
font-size: 6rem;
line-height: 1;
font-weight: 600;
}

.count sup {
font-size: 2.4rem;
margin-left: 7px;
}

label {
display: block;
}

input, button {
padding: 0.375rem 0.75rem;
font-size: 1.5rem;
appearance: none;
-webkit-appearance: none;
}

input {
margin-right: 0.5rem;
box-sizing: border-box;
border-width: 1px;
border-style: solid;
border-radius: 0.25rem;
border-color: #CCC;
background-color: #FFF;
}

button {
outline: none;
display: block;
cursor: pointer;
color: #FFF;
border: none;
border-radius: 0.25rem;
background-color: #0BE;
}

footer {
padding-top: 0.5rem;
display: -webkit-flex;
-webkit-flex-direction: row;
-webkit-justify-content: center;
}
22 changes: 3 additions & 19 deletions dashboard.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>New Tab</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/style.css">
</head>
<body>

<div id="app"></div>

<script id="dob-template" type="text/x-handlebars-template">
<form>
<h1 id="dob" class="age-label">When were you born?</h1>
<body>

<footer>
<input type="date" name="dob" id="dob">
<button type="submit">Motivate</button>
</footer>
<form>
</script>
<div id="secCount"></div>

<script id="age-template" type="text/x-handlebars-template">
<h1 class="age-label">AGE</h1>
<h2 class="count">{{year}}<sup>.{{milliseconds}}</sup></h2>
</script>

Expand Down