Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ $('#ca').calendar({
// override class
customClass: '',

// callback to add additional class for every DayItem
dayClass: function(date) {
return '';
},

// set display view, optional date or month
view: 'date',

Expand Down
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
outline: none;
}

.weekend {
color: #f00;
}

</style>
</head>
<body>
Expand Down Expand Up @@ -83,11 +87,21 @@ <h2>Trigger calendar</h2>
value: '2016-10-31'
}];

var dayClass = function(date) {
if (date.getDay() === 0) {
return 'weekend';
} else if (date.getDay() === 6) {
return 'weekend';
}
return '';
};

// inline
var $ca = $('#one').calendar({
// view: 'month',
width: 320,
height: 320,
dayClass: dayClass,
// startWeek: 0,
// selectedRang: [new Date(), null],
data: data,
Expand Down
8 changes: 8 additions & 0 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@

// 自定义类,用于重写样式
customClass: '',

// 自定義每一天的class
dayClass: function(date) {
return '';
},

// 显示视图
// 可选:date, month
Expand Down Expand Up @@ -275,6 +280,7 @@
this.$element = $(element);
this.options = $.extend({}, $.fn.calendar.defaults, options);
this.$element.addClass('calendar ' + this.options.customClass);
this.dayClass = this.options.dayClass;
this.width = this.options.width;
this.height = this.options.height;
this.date = this.options.date;
Expand Down Expand Up @@ -337,6 +343,8 @@
if (dt.isSame(y, m, d)) {
data['class'] += ' ' + TODAY_CLASS;
}

data['class'] += this.dayClass(idt);

data.date = idt.format(this.options.format);
data.action = this.getDayAction(idt);
Expand Down