Add hideAge option

This commit is contained in:
Lim Chee Aun 2013-12-04 23:21:23 +08:00
parent 517763489c
commit 80ade83195
2 changed files with 27 additions and 9 deletions

View File

@ -1,4 +1,5 @@
{ {
"customStylesheetURL": null, "customStylesheetURL": null,
"yearLength": 120 "yearLength": 120,
"hideAge": false
} }

View File

@ -97,11 +97,27 @@ h1{
var life = { var life = {
$title: document.getElementById('title'), $title: document.getElementById('title'),
$el: document.getElementById('life'), $el: document.getElementById('life'),
yearLength: 120, // 120px per year utils: {
extend: function(object){
var args = Array.prototype.slice.call(arguments, 1);
for (var i=0, source; source=args[i]; i++){
if (!source) continue;
for (var property in source){
object[property] = source[property];
}
}
return object;
}
},
config: {
yearLength: 120, // 120px per year
hideAge: false, // Hide age from year axis
customStylesheetURL: null // Custom stylesheet
},
start: function(){ start: function(){
life.loadConfig(function(config){ life.loadConfig(function(config){
if (config.yearLength) life.yearLength = config.yearLength; life.config = life.utils.extend(life.config, config)
if (config.customStylesheetURL) life.injectStylesheet(config.customStylesheetURL); if (life.config.customStylesheetURL) life.injectStylesheet(life.config.customStylesheetURL);
life.fetch(function(response){ life.fetch(function(response){
var data = life.parse(response); var data = life.parse(response);
@ -193,7 +209,7 @@ h1{
firstYear: null, firstYear: null,
renderEvent: function(d){ renderEvent: function(d){
var firstYear = life.firstYear; var firstYear = life.firstYear;
var yearLength = life.yearLength; var yearLength = life.config.yearLength;
var monthLength = yearLength/12; var monthLength = yearLength/12;
var dayLength = monthLength/30; var dayLength = monthLength/30;
@ -235,13 +251,14 @@ h1{
return ''; return '';
}, },
renderYears: function(firstYear, lastYear){ renderYears: function(firstYear, lastYear){
var dayLength = life.yearLength/12/30; var dayLength = life.config.yearLength/12/30;
var html = ''; var html = '';
var days = 0; var days = 0;
var hideAge = life.config.hideAge;
for (var y=firstYear, age = 0; y<=lastYear+1; y++, age++){ for (var y=firstYear, age = 0; y<=lastYear+1; y++, age++){
html += '<section class="year" style="left: ' + (days*dayLength).toFixed(2) + 'px">' + html += '<section class="year" style="left: ' + (days*dayLength).toFixed(2) + 'px">'
y + ' (' + age + ')' + + y + (hideAge ? '' : (' (' + age + ')'))
'</section>'; + '</section>';
days += (y % 4 == 0) ? 366 : 365; days += (y % 4 == 0) ? 366 : 365;
} }
return html; return html;