jquery-week-calendar
jquery-week-calendar copied to clipboard
firstDayOfWeek option not set on initial render
I'm configuring this plugin with default settings so users don't need to specify them manually unless they wish to override.
For example, I have a map of options
options = { "timeslotsPerHour": 4, "timeslotHeight": 15, "allowCalEventOverlap": false, "defaultEventLength": 4, "useShortDayNames": true, "use24Hour": true, "scrollToHourMillis": 500, "buttons": false, "businessHours": {start: 0, end:24}, // it's business time... "timeFormat": "H:i", "firstDayOfWeek": 1, "daysToShow": 7, "startOnFirstDayOfWeek": true, "dateFormat": "" };
A user then may initialize the calendar using these options.
calendar.weekCalendar( { data: { 'events' : events, 'options' : options } });
What is strange is that all of these options seem to work, except for 'firstDayOf Week'. When I step through the jquery.weekcalendar.js code, it seems it does get set, but not in time for the first render.
If I call a refresh event after I initialize the calendar with my options and events, this option then is rendered properly. Is this expected behavior?
The problem with me doing the refresh in order to get this option picked up - is that in Chrome it seems to cause a problem. In Chrome, if I do this - I can create an event, but then if I try to move, resize, etc - I cannot. If I click anywhere else on the page, and then try again it works. So in between event manipulation, if I click somewhere else I can then manipulate the event.
Perhaps this is just a Chrome issue, it seems to work just fine in IE 8.0.6, and Firefox 7.0.1. Using Chrome 14.0.835.
Can anyone else confirm this issue, or provide some insight into why I have to refresh in order to get firstDayOfWeek option to be rendered?
Another way I've been able to work around, is to manuall return 1 from firstDayOfWeek function in the weekcalendar js. I'd rather not change the source to work around this if possible.
example:
firstDayOfWeek: function(calendar) { return 1; // *** workaround *** if ($(calendar).weekCalendar('option', 'daysToShow') != 5) { return 0; } else { //workweek return 1; } }, // 0 = Sunday, 1 = Monday, 2 = Tuesday, ... , 6 = Saturday
The unit test cases that I've written seem to work ok, this makes sense as I believe the option gets set, just not in time ?
On the documentation page - https://github.com/themouette/jquery-week-calendar/wiki/Script-options
- It lists the option as taking an integer, but internally the option is a function.
firstDayOfWeek: [integer | default: 0] – Determines what day of the week to start on. 0 = sunday, 1 = monday etc.
Does this exclude the ability to provide 'firstDayOfWeek' in the options map?
The options pulled from the data.options map aren't merged into the options map until _renderEvents which is called at the end of _loadCalEvents. By that point weekStartDate, and weekEndDate are already calculated.
Inserting the following code into _loadCalEvents just before weekStartDate and weeEndDate are calculated fixes my issue.
// Update firstDayOfWeek if it exists in the data options map // before calculating weekStartDate and weekEndDate if (options.data.options.firstDayOfWeek !== 'undefined') { options.firstDayOfWeek = options.data.options.firstDayOfWeek; }
This is still a work around, are there others options that may need to pulled out of the data.options map earlier than they currently are? This really only solves the issue for this specific option.