Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new features #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"customStylesheetURL": null,
"yearLength": 120,
"hideAge": false
"hideAge": false,
"sortEventsByDate": false
}
39 changes: 36 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ <h1 id="title">Life</h1>
config: {
yearLength: 120, // 120px per year
hideAge: false, // Hide age from year axis
customStylesheetURL: null // Custom stylesheet
customStylesheetURL: null, // Custom stylesheet
sortEventsByDate: false,
},
start: function(){
life.loadConfig(function(config){
Expand Down Expand Up @@ -219,22 +220,37 @@ <h1 id="title">Life</h1>
parseTime: function(time, point){
if (!point) point = 'start';
var data = {};
var date = new Date()
date.setFullYear(new Date().getFullYear(), 0, 1);
if (/^\~\d+$/.test(time)){ // ~YYYY
var year = parseInt(time.slice(1), 10);
date.setFullYear(year)
data = {
startYear: parseInt(time.slice(1), 10),
startYear: year,
startDateIns: date,
estimate: true
};
} else if (/^\d+$/.test(time)){ // YYYY
data[point + 'Year'] = parseInt(time, 10);
var year = parseInt(time, 10);
data[point + 'Year'] = year;
date.setFullYear(year)
data[point + 'DateIns'] = date
} else if (/^\d+\/\d+$/.test(time)){ // MM/YYYY
var t = time.split('/');
data[point + 'Month'] = parseInt(t[0], 10);
data[point + 'Year'] = parseInt(t[1], 10);
date.setFullYear(data[point + 'Year']);
date.setMonth(data[point + 'Month']-1);
data[point + 'DateIns'] = date;
} else if (/^\d+\/\d+\/\d+$/.test(time)){ // DD/MM/YYYY
var t = time.split('/');
data[point + 'Date'] = parseInt(t[0], 10);
data[point + 'Month'] = parseInt(t[1], 10);
data[point + 'Year'] = parseInt(t[2], 10);
date.setFullYear(data[point + 'Year']);
date.setMonth(data[point + 'Month']-1);
date.setDate(data[point + 'Date']);
data[point + 'DateIns'] = date;
} else if (/\d\-/.test(time)){ // TIME-TIME
var splitTime = time.split('-');
var startTime = life.parseTime(splitTime[0]);
Expand All @@ -246,6 +262,11 @@ <h1 id="title">Life</h1>
data.endYear = now.getFullYear();
data.endMonth = now.getMonth()+1;
data.endDate = now.getDate();
data.startYear = now.getFullYear();
data.startMonth = now.getMonth()+1;
data.startDate = now.getDate();
data.startDateIns = now;
data.endDateIns = now;
}
data.title = time;
return data;
Expand Down Expand Up @@ -321,6 +342,18 @@ <h1 id="title">Life</h1>
return html;
},
render: function(title, data){
if(life.config.sortEventsByDate) {
data.sort(function(one, two) {
if (one.time.startDateIns < two.time.startDateIns) {
return -1;
} else if(one.time.startDateIns > two.time.startDateIns){
return 1
}

return 0
});
}

document.title = title;
life.$title.innerHTML = title;

Expand Down