Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for "First day of the week" #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions javascripts/calendarview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -280,6 +281,7 @@ Calendar.prototype = {
minYear: 1900,
maxYear: 2100,
dateFormat: '%Y-%m-%d',
firstDayOfTheWeek: 0,

// Dates
date: new Date(),
Expand All @@ -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)
},


Expand Down Expand Up @@ -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) - ((7 - this.firstDayOfTheWeek) % 7) )

// Fill in the days of the month
Element.getElementsBySelector(this.container, 'tbody tr').each(
Expand Down Expand Up @@ -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.
Expand All @@ -397,6 +399,7 @@ Calendar.prototype = {
} else {
this.isPopup = false
}
if (options.firstDayOfTheWeek) this.firstDayOfTheWeek = options.firstDayOfTheWeek;

// Calendar Table
var table = new Element('table')
Expand Down Expand Up @@ -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)
Expand Down