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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/

# Logs
logs
*.log
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'} ]
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ <h2>Trigger calendar</h2>
// 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)
console.log('data:' + (data || '无'));
},
viewChange: function (view, y, m) {
console.log(view, y, m)

}
});

Expand Down
36 changes: 30 additions & 6 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '面试'} ]
Expand Down Expand Up @@ -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(),
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand All @@ -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
Expand Down Expand Up @@ -795,4 +819,4 @@

$.fn.calendar.defaults = defaults;

}));
}));