Skip to content

Commit

Permalink
Adding random picture button
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-desteffen committed Dec 16, 2012
1 parent c76f067 commit 97e38d8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/templates/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<div id="image"></div>
<div id="image_credit"></div>
<div id="explanation"></div>
<a id="download" class="btn" download="" href="">Download</a>
<a id="download" class="bottomControls btn" download="" href="">Download</a>
<a id="random" class="bottomControls btn" href="#">Random</a>
</div>
2 changes: 1 addition & 1 deletion assets/css/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ body{
width: 1000px;
}

#download{
.bottomControls {
margin-top: 20px;
}
17 changes: 13 additions & 4 deletions assets/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Apod = {};

// TODOS
// - Calendar
// - Random button

var ratyOptions = {
hints : ['1', '2', '3', '4', '5'],
Expand Down Expand Up @@ -41,9 +40,10 @@ Apod.View = Backbone.View.extend({
router: null,

events: {
"click .next": "nextApod",
"click .previous": "previousApod",
"click #rating": "vote"
"click .next" : "nextApod",
"click .previous" : "previousApod",
"click #rating" : "vote",
"click #random" : "random"
},

initialize: function () {
Expand Down Expand Up @@ -163,6 +163,15 @@ Apod.View = Backbone.View.extend({
var formattedDate = century + date[0] + date[1] + "-" + date[2] + date[3] + "-" + date[4] + date[5];
this.currentDate = moment(formattedDate);
}
},

random: function(event){
event.preventDefault();
var oldest = new Date(1995, 6, 16); // First APOD
var newest = new Date();
var randomDate = new Date(oldest.getTime() + Math.random() * (newest.getTime() - oldest.getTime()));
this.currentDate = moment(randomDate);
this.router.navigate(this.param(), {trigger: true});
}

});
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from app import models
from app.apod import Apod

apod = Apod('991204')
apod = Apod('970608')
#apod.vote(5)

print apod.id
Expand Down

0 comments on commit 97e38d8

Please sign in to comment.