'use strict'; $.fn.calendar = function(options) { //check is select, if nothing select, return this if (!this.length) { if (options && options.debug && window.console) { console.log("nothing select"); } return this; } var self = $(this);
// default parameter setting var defaults = { cssPath: '', //user-define loading path of css file eventName: 'click', //user-define the event name that triggers the control onSelectDate: null, //callback function after select date autoClose: false };
//default as data of the day var d_date = new Date(); var _date = { year: d_date.getFullYear(), month: d_date.getMonth() + 1, day: d_date.getDate(), week: d_date.getDay() };
//obtain what the first day of one month is in a week function getFirstWeek(year, month) { var date = new Date(year, month - 1, 1); return date.getDay(); }
//obtain the year, month, day of today function getToday() { var date = new Date(); return today = [date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getDay()]; }
//obtain the number of days for a month function getmaxDay(year, month) { var date = new Date(year, month, 0); return date.getDate(); }
//obtain the number of days for last month function getMaxDayByLastMonth(year, month) { month = month - 1 year = month == 12 ? year - 1 : year; return getmaxDay(year, month); }
//obtain the number of days for next month function getMaxDayByNextMonth(year, month) { month = month + 1 > 12 ? 1 : month + 1; year = month == 1 ? year + 1 : year; return getmaxDay(year, month); }
//obtain the days list of a certain year and month, return array function getDayList(year, month) { var _list = [], maxday = getmaxDay(year, month), month = month - 1; for (var i = 1; i var d = new Date(year, month, i); _list[i - 1] = d.getDay(); } return _list; } } })(jQuery, window);