From b28bc0042e9df289001a4d497e7f78417b3daad0 Mon Sep 17 00:00:00 2001 From: Mark Henderson Date: Sun, 21 Jan 2024 13:50:40 -0500 Subject: [PATCH] new features --- config.example.json | 3 ++- index.html | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/config.example.json b/config.example.json index 83ce44a..70d742d 100644 --- a/config.example.json +++ b/config.example.json @@ -1,5 +1,6 @@ { "customStylesheetURL": null, "yearLength": 120, - "hideAge": false + "hideAge": false, + "sortEventsByDate": false } \ No newline at end of file diff --git a/index.html b/index.html index 8cd0e55..b5225c4 100644 --- a/index.html +++ b/index.html @@ -156,7 +156,8 @@

Life

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){ @@ -219,22 +220,37 @@

Life

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]); @@ -246,6 +262,11 @@

Life

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; @@ -321,6 +342,18 @@

Life

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;