I'm trying to enhance a jquery snippet I found here at stackoverlow (HTML markup for multi-day calendar events) but I've run into a perculiar problem that I really don't know how to overcome. Basically what I'm trying to achieve is to avoid stacking of multi-day events on top of each other in the calendar. Since I only have 1 reputation point (as the newbie I am) I can't explain myself with a screen dump, but have to (at least try to) explain myself in writing.
So, here's my problem. Index [3] in the array events[] below begins on day four, but since day four also contain indexes [0, 1] the eventCount is set to 3. This means that if a new event occurs on day four it will be given evenCount 4. So far no problem. On day five however there are three events (indexes [0, 3, 4]). Now... here's my problem. Index [3] began on day 4 on eventCount 3 and continues to day 12 whereas index [5] begin on day 5 and is given the same eventCount as index [3] simply because there are only three events that day. Here's the code snippet (kudos to ThinkingStiff for the basic code):
var events = [{ from: 3, to: 9 }, { from: 4, to: 4 }, { from: 9, to: 11 },{ from: 4, to: 12 },{ from: 5, to: 7 }];
for( var eventIndex = 0, event; event = events[eventIndex], eventIndex < events.length; eventIndex++ ) {
for( var dayIndex = event.from; dayIndex <= event.to; dayIndex++ ) {
var dayElement = document.getElementById( 'day' + dayIndex ),
firstDay = document.getElementsByClassName( 'event' + eventIndex ),
top;
if( firstDay.length ) {
top = firstDay[0].style.top;
} else {
var eventCount = dayElement.getElementsByClassName( 'event' ).length;
top = ( eventCount * 20 ) + 'px';
};
var html = '<div '
+ 'class="event event' + eventIndex + '" '
+ 'style="top: ' + top + ';">'
+ eventIndex
+ '</div>';
dayElement.insertAdjacentHTML( 'beforeEnd', html );
};
};
What I want to achieve is a check that determines if there is a continuing event from the day before that need to be added to the eventCount BEFORE adding new eventCounts so that new events don't stack in top of existing events. How do I achieve this?
And while I'm at it - as it turns out, the array do not allow for additional parameters, such as for example "subject". Is it possible to expand the array to contain custom parameters without breaking the entire code?
Every hint is greatly appreciated.