diff --git a/.gitignore b/.gitignore
index d01b4b4..482a31f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+.idea/
+
# Logs
logs
*.log
diff --git a/README.md b/README.md
index 41a9aba..1bd9ca1 100644
--- a/README.md
+++ b/README.md
@@ -77,7 +77,12 @@ $('#ca').calendar({
// Fixed date range: [new Date(2016, 0, 1), new Date(2016, 11, 31)] or ['2016/1/1', '2016/12/1']
// Starting today: [new Date(), null] or [new Date()]
selectedRang: null,
-
+
+ // 휴일 관리 Array
+ // value : [ days ....]
+ // 예시 ['2017/02/17','2017/02/18']
+ holidays: null,
+
// display data when mouse enter
// value: `[{ date: String || Date, value: object }, ... ]`
// example: [ { date: '2016/1/1', value: 'A new Year'} ] or [ { date: new Date(), value: 'What to do'} ]
diff --git a/index.html b/index.html
index fef8ad5..a93d17a 100644
--- a/index.html
+++ b/index.html
@@ -91,8 +91,9 @@
Trigger calendar
// startWeek: 0,
// selectedRang: [new Date(), null],
data: data,
+ holidays : ['2017/02/18','2017/02/19'],
monthArray: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
- date: new Date(2016, 9, 31),
+ //date: new Date(2016, 9, 31),
onSelected: function (view, date, data) {
console.log('view:' + view)
console.log('date:' + date)
@@ -100,7 +101,6 @@ Trigger calendar
},
viewChange: function (view, y, m) {
console.log(view, y, m)
-
}
});
diff --git a/src/calendar.js b/src/calendar.js
index d02046b..92ce285 100644
--- a/src/calendar.js
+++ b/src/calendar.js
@@ -59,6 +59,8 @@
// 如设置2015年11月23日以前不可选:[new Date(), null] or ['2015/11/23']
selectedRang: null,
+ holidays:null,
+
// 日期关联数据 [{ date: string, value: object }, ... ]
// 日期格式与 format 一致
// 如 [ {date: '2015/11/23', value: '面试'} ]
@@ -173,13 +175,20 @@
}
// extension methods
-
String.prototype.repeat = function (data) {
return this.replace(/\{\w+\}/g, function (str) {
var prop = str.replace(/\{|\}/g, '');
return data[prop] || '';
});
}
+
+ String.prototype.lpad = function (padLength, padString) {
+ var str = this;
+ while(str.length < padLength) {
+ str = padString + str;
+ }
+ return str;
+ }
String.prototype.toDate = function () {
var dt = new Date(),
@@ -191,10 +200,12 @@
Date.prototype.format = function (exp) {
var y = this.getFullYear(),
- m = this.getMonth() + 1,
+ m = ''+(this.getMonth() + 1),
d = this.getDate();
-
- return exp.replace('yyyy', y).replace('mm', m).replace('dd', d);
+
+ m= m.lpad(2,0);
+
+ return exp.replace('yyyy', y).replace('MM', m).replace('dd', d);
}
Date.prototype.isSame = function (y, m, d) {
@@ -279,6 +290,7 @@
this.height = this.options.height;
this.date = this.options.date;
this.selectedRang = this.options.selectedRang;
+ this.holidays = this.options.holidays;
this.data = this.options.data;
this.init();
}
@@ -296,6 +308,16 @@
}
}
+ if(this.holidays) {
+
+ this.holidays.forEach(function (v,i) {
+ if(day.getTime() == Date.tryParse(v).getTime()) {
+ console.log(v);
+ action = DISABLED;
+ }
+ });
+ }
+
return action;
},
getDayData: function (day) {
@@ -635,7 +657,7 @@
toggleClass.call(this);
}
- return new Date(y, m - 1, d);
+ return new Date(y, m - 1, d).format(this.options.format);
},
showLabel: function (event, view, date, data) {
var $lbl = this.$label;
@@ -710,6 +732,7 @@
var day = _this.selectedDay(d, type);
_this.options.onSelected.call(this, 'date', day, $(this).data(MARK_DATA));
+ console.log('selected1');
_this.$trigger && _this.hide('date', day, $(this).data(MARK_DATA));
@@ -720,6 +743,7 @@
_this.updateDateView(y, m);
vc('date', y, m);
_this.options.onSelected.call(this, 'month', new Date(y, m - 1));
+ console.log('selected2');
});
// hover
@@ -795,4 +819,4 @@
$.fn.calendar.defaults = defaults;
-}));
+}));
\ No newline at end of file