From a7813a6c3ea520eecfdb1dc0a930545cbf61bd78 Mon Sep 17 00:00:00 2001 From: JimmyLiao Date: Tue, 26 Dec 2017 09:25:45 +0800 Subject: [PATCH 1/3] add callback function to add class for DayItem --- README.md | 5 +++++ index.html | 14 ++++++++++++++ src/calendar.js | 14 ++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/README.md b/README.md index 6dac7f2..25fc1cf 100644 --- a/README.md +++ b/README.md @@ -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', diff --git a/index.html b/index.html index bf17228..8abc69b 100644 --- a/index.html +++ b/index.html @@ -48,6 +48,10 @@ outline: none; } + .weekend { + color: #f00; + } + @@ -83,11 +87,21 @@

Trigger calendar

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, diff --git a/src/calendar.js b/src/calendar.js index ee92993..6fbc72d 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -34,6 +34,17 @@ // 自定义类,用于重写样式 customClass: '', + + // 自定義每一天的class + dayClass: function(date) { + return ''; + }, + + + // 自定義每一天的class + dayClass: function(date) { + return ''; + }, // 显示视图 // 可选:date, month @@ -275,6 +286,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; @@ -337,6 +349,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); From 69655b9150dd06c4c531dddacc000f7a9c3a886c Mon Sep 17 00:00:00 2001 From: Jimmy Liao Date: Tue, 26 Dec 2017 09:50:04 +0800 Subject: [PATCH 2/3] Update calendar.js delete duplicate code --- src/calendar.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 6fbc72d..a42f981 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -35,12 +35,6 @@ // 自定义类,用于重写样式 customClass: '', - // 自定義每一天的class - dayClass: function(date) { - return ''; - }, - - // 自定義每一天的class dayClass: function(date) { return ''; From 71e2883d4b0df32cc112831b06a434a9bc3c4352 Mon Sep 17 00:00:00 2001 From: JimmyLiao Date: Tue, 26 Dec 2017 09:50:42 +0800 Subject: [PATCH 3/3] delete duplicate code --- src/calendar.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 6fbc72d..a42f981 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -35,12 +35,6 @@ // 自定义类,用于重写样式 customClass: '', - // 自定義每一天的class - dayClass: function(date) { - return ''; - }, - - // 自定義每一天的class dayClass: function(date) { return '';