From 1fb2405a4de39c61a09d74ae5acf558296dc547f Mon Sep 17 00:00:00 2001 From: Gargaj Date: Thu, 16 Aug 2012 16:01:10 +0200 Subject: [PATCH 1/3] added feature to define first day of the week for us Europeans --- javascripts/calendarview.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/javascripts/calendarview.js b/javascripts/calendarview.js index f4be8f7..b231af6 100644 --- a/javascripts/calendarview.js +++ b/javascripts/calendarview.js @@ -218,11 +218,12 @@ Calendar.setup = function(params) param_default('parentElement', null) param_default('selectHandler', null) param_default('closeHandler', null) + param_default('firstDayOfTheWeek', 0) // In-Page Calendar if (params.parentElement) { - var calendar = new Calendar(params.parentElement) + var calendar = new Calendar(params.parentElement, params) calendar.setSelectHandler(params.selectHandler || Calendar.defaultSelectHandler) if (params.dateFormat) calendar.setDateFormat(params.dateFormat) @@ -243,7 +244,7 @@ Calendar.setup = function(params) { var triggerElement = $(params.triggerElement || params.dateField) triggerElement.onclick = function() { - var calendar = new Calendar() + var calendar = new Calendar(null, params) calendar.setSelectHandler(params.selectHandler || Calendar.defaultSelectHandler) calendar.setCloseHandler(params.closeHandler || Calendar.defaultCloseHandler) if (params.dateFormat) @@ -280,6 +281,7 @@ Calendar.prototype = { minYear: 1900, maxYear: 2100, dateFormat: '%Y-%m-%d', + firstDayOfTheWeek: 0, // Dates date: new Date(), @@ -296,12 +298,12 @@ Calendar.prototype = { // Initialize //---------------------------------------------------------------------------- - initialize: function(parent) + initialize: function(parent, options) { if (parent) - this.create($(parent)) + this.create($(parent), options) else - this.create() + this.create(null, options) }, @@ -330,7 +332,7 @@ Calendar.prototype = { // Calculate the first day to display (including the previous month) date.setDate(1) - date.setDate(-(date.getDay()) + 1) + date.setDate(-(date.getDay()) + 1 + this.firstDayOfTheWeek) // Fill in the days of the month Element.getElementsBySelector(this.container, 'tbody tr').each( @@ -387,7 +389,7 @@ Calendar.prototype = { // Create/Draw the Calendar HTML Elements //---------------------------------------------------------------------------- - create: function(parent) + create: function(parent, options) { // If no parent was specified, assume that we are creating a popup calendar. @@ -397,6 +399,7 @@ Calendar.prototype = { } else { this.isPopup = false } + if (options.firstDayOfTheWeek) this.firstDayOfTheWeek = options.firstDayOfTheWeek; // Calendar Table var table = new Element('table') @@ -424,7 +427,7 @@ Calendar.prototype = { // Day Names row = new Element('tr') for (var i = 0; i < 7; ++i) { - cell = new Element('th').update(Calendar.SHORT_DAY_NAMES[i]) + cell = new Element('th').update(Calendar.SHORT_DAY_NAMES[(i + this.firstDayOfTheWeek) % 7]) if (i == 0 || i == 6) cell.addClassName('weekend') row.appendChild(cell) From 5f35751d1a05c2ab6e3b3bc66de984dc06953acc Mon Sep 17 00:00:00 2001 From: Gargaj Date: Thu, 16 Aug 2012 16:03:35 +0200 Subject: [PATCH 2/3] minor codeproofing --- javascripts/calendarview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascripts/calendarview.js b/javascripts/calendarview.js index b231af6..c5cec2a 100644 --- a/javascripts/calendarview.js +++ b/javascripts/calendarview.js @@ -332,7 +332,7 @@ Calendar.prototype = { // Calculate the first day to display (including the previous month) date.setDate(1) - date.setDate(-(date.getDay()) + 1 + this.firstDayOfTheWeek) + date.setDate(-(date.getDay()) + (1 + this.firstDayOfTheWeek) % 7) // Fill in the days of the month Element.getElementsBySelector(this.container, 'tbody tr').each( From 1734d9486e5070921d740253ae8f3594225ce85c Mon Sep 17 00:00:00 2001 From: Gargaj Date: Sun, 11 Jan 2015 16:16:58 +0100 Subject: [PATCH 3/3] This bugs out if 1st is Sunday --- javascripts/calendarview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascripts/calendarview.js b/javascripts/calendarview.js index c5cec2a..223ca40 100644 --- a/javascripts/calendarview.js +++ b/javascripts/calendarview.js @@ -332,7 +332,7 @@ Calendar.prototype = { // Calculate the first day to display (including the previous month) date.setDate(1) - date.setDate(-(date.getDay()) + (1 + this.firstDayOfTheWeek) % 7) + date.setDate( -(date.getDay() - 1) - ((7 - this.firstDayOfTheWeek) % 7) ) // Fill in the days of the month Element.getElementsBySelector(this.container, 'tbody tr').each(