The problem is here (timeline.js, line 53) for(j = i; j > 0 && events[j - 1].date > tmp.date; j--)
. j = 1
, but events
is array of objects, with empty first 5 elements. And it produces an error Unable to get property 'date' of undefined or null reference
.
First 5 elements are missing, because of
if (date == "Invalid Date")
continue;
this.events[i] = {
It skips some events, but still increases i
counter, leaving empty elements in array. Try to replace this.events[i] = {
with this.events.push({
and add )
at the closing }
. Or make all date
valid :)
The date is invalid because new Date()
is not recognizing "11 01 2014" as a valid date. Try to write it in a title as "2014-01-11" ("yyyy-mm-dd")
ps: as a quick 'fix' - replace var date = new Date(eventItems[i].getAttribute("title"));
with var date = new Date(eventItems[i].getAttribute("title").replace(/(\d+)\s+(\d+)\s+(\d+)/, '$3-$1-$2'));
pps: tired of all the messages. This is how your portion of the code should look like
for (var i = 0; i < eventItems.length; i++) {
var date = new Date(eventItems[i].getAttribute("title")
.replace(/(\d+)\s+(\d+)\s+(\d+)/, '$3-$1-$2'));
if (date == "Invalid Date")
continue;
this.events.push({
name : eventItems[i].className,
date : date,
day : date.getDate(),
month : date.getMonth(),
year : date.getFullYear(),
content : jQuery(eventItems[i]).text()
});
}