diff --git a/glDatePicker.js b/glDatePicker.js
index a7f1873..7738fc2 100644
--- a/glDatePicker.js
+++ b/glDatePicker.js
@@ -181,7 +181,21 @@
onHide: function(calendar) { calendar.hide(); },
// First date of the month.
- firstDate: null
+ firstDate: null,
+
+ /*
+ * Previous years
+ * Number of years prior to the current that can be listed
+ * Example: Current year equal 2015 and previous_years equal 5
+ * First year equal 2010
+ */
+ previous_years: 5,
+
+ //subsequent years
+ subsequent_years: 5,
+
+ //disable specific dates (array with dates that not must be selected)
+ noSelectTableDates: null
};
// Our plugin object
@@ -301,7 +315,7 @@
// Selectable (constants)
var selectableMonths = getSelectableList(0, 11, options.selectableMonths);
- var selectableYears = getSelectableList(todayVal.year - 5, todayVal.year + 5, options.selectableYears);
+ var selectableYears = getSelectableList(todayVal.year - options.previous_years, todayVal.year + options.subsequent_years, options.selectableYears);
var selectableDOW = getSelectableList(0, 6, options.selectableDOW);
var dowNames = options.dowNames || [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ];
var monthNames = options.monthNames || [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ];
@@ -590,7 +604,17 @@
}
});
}
-
+
+ //Disable specific dates (no selected)
+ if(options.noSelectTableDates){
+ $.each(options.noSelectTableDates, function (i, v){
+
+ if(v.date.getTime() == cellDateTime){
+ isSelectable = false;
+ }
+ });
+ }
+
// If not active or if not within selectableMonths, set to noday otherwise evaluate accordingly
if(!isSelectable ||
selectableYears._indexOf(cellDateVal.year) < 0 ||
diff --git a/glDatePicker.min.js b/glDatePicker.min.js
index e380153..e3be48a 100644
--- a/glDatePicker.min.js
+++ b/glDatePicker.min.js
@@ -1,16 +1,30 @@
/*! glDatePicker v2.0 | Tue Jan 1 2013 | http://glad.github.com/glDatePicker/ */;
-(function(){$.fn.glDatePicker=function(a){var G=this.data("glDatePicker");return!G?this.each(function(){return $(this).data("glDatePicker",new O(this,a))}):!0===a?G:this};$.fn.glDatePicker.defaults={cssName:"default",zIndex:1E3,borderSize:1,calendarOffset:{x:0,y:1},showAlways:!1,hideOnClick:!0,allowMonthSelect:!0,allowYearSelect:!0,todayDate:new Date,selectedDate:null,prevArrow:"\u25c4",nextArrow:"\u25ba",selectableDates:null,selectableDateRange:null,specialDates:null,selectableMonths:null,selectableYears:null,
-selectableDOW:null,monthNames:null,dowNames:null,dowOffset:0,onClick:function(a,G,g){a.val(g.toLocaleDateString())},onHover:function(){},onShow:function(a){a.show()},onHide:function(a){a.hide()},firstDate:null};var O=function(){function a(a,g){var d=this;d.el=$(a);var b=d.el;d.options=$.extend(!0,{},$.fn.glDatePicker.defaults,g);var c=d.options;d.calendar=$($.find("[gldp-el="+b.attr("gldp-id")+" ]"));c.selectedDate=c.selectedDate||c.todayDate;c.firstDate=(new Date(c.firstDate||c.selectedDate))._first();
-(b.attr("gldp-id")||"").length||b.attr("gldp-id","gldp-"+Math.round(1E10*Math.random()));b.addClass("gldp-el").bind("click",function(b){d.show(b)}).bind("focus",function(b){d.show(b)});d.calendar.length&&!c.showAlways&&d.calendar.hide();$(document).bind("mouseup",function(a){var a=a.target,c=d.calendar;!b.is(a)&&(!c.is(a)&&0===c.has(a).length&&c.is(":visible"))&&d.hide()});d.render()}a.prototype={show:function(){$.each($(".gldp-el").not(this.el),function(a,g){if(g.length)g.options.onHide(g.calendar)});
-this.options.onShow(this.calendar)},hide:function(){if(this.options&&!this.options.showAlways)this.options.onHide(this.calendar)},render:function(a){var g=this,d=g.el,b=g.options,c=g.calendar,j="gldp-"+b.cssName,t=b.todayDate._val(),u=t.time,h=b.borderSize+"px",y=function(b,m,a){for(var c=[],e=b;e<=m;e++)c.push(e);if(a){var d=[];$.each(a,function(a,c){c>=b&&(c<=m&&0>d._indexOf(c))&&d.push(c)});c=d.length?d:c}c.sort();return c},H=y(0,11,b.selectableMonths),v=y(t.year-5,t.year+5,b.selectableYears),
-y=y(0,6,b.selectableDOW),z=b.dowNames||"Sun Mon Tue Wed Thu Fri Sat".split(" "),t=b.monthNames||"January February March April May June July August September October November December".split(" "),f=d.outerWidth(),e,k=f/7+6*(b.borderSize/7),f=f/8+7*(b.borderSize/8);c.length?eval(c.data("is"))||(f=c.outerWidth(),e=c.outerHeight(),k=f/7+6*(b.borderSize/7),f=e/8+7*(b.borderSize/8)):(g.calendar=c=$("
").attr("gldp-el",d.attr("gldp-id")).data("is",!0).css({display:b.showAlways?void 0:"none",zIndex:b.zIndex,
-width:7*k+"px"}),$("body").append(c));d.is(":visible")||c.hide();c.removeClass().addClass(j).children().remove();j=function(){var i=d.offset();c.css({top:i.top+d.outerHeight()+b.calendarOffset.y+"px",left:i.left+b.calendarOffset.x+"px"})};$(window).resize(j);j();var j={width:k+"px",height:f+"px",lineHeight:f+"px"},f=function(i){for(var m=new Date(b.firstDate),i=i||0;;){m.setMonth(m.getMonth()+i);m.setDate(Math.min(1,m._max()));if(0==i)break;var c=m._val(),a=c.year;if(-1!=H._indexOf(c.month))if(-1!=
-v._indexOf(a))break;else if(av[v.length-1])return null}return m},A=f(-1),B=f(1),f=b.firstDate=f();e=f._val();var I=e.month,J=e.year,f=new Date(f);e=Math.abs(Math.min(6,Math.max(0,b.dowOffset)));var l=f.getDay()-e,l=1>l?-7-l:-l,z=z.concat(z).slice(e,e+7);f._add(l);e=$("").addClass(" core border monyear ").css($.extend({},j,{borderWidth:h+" 0 0 "+h})).append($("").addClass("prev-arrow"+(A?"":"-off")).html(b.prevArrow)).mousedown(function(){return!1}).click(function(i){""!=b.prevArrow&&
-A&&(i.stopPropagation(),A&&(b.firstDate=A,g.render()))});k=5*k-5*b.borderSize+b.borderSize;k=$("").addClass(" core border monyear title").css($.extend({},j,{width:k+"px",borderTopWidth:h,marginLeft:"-"+h}));l=$("").addClass(" core border monyear ").css($.extend({},j,{marginLeft:"-"+h,borderWidth:h+" "+h+" 0 0"})).append($("").addClass("next-arrow"+(B?"":"-off")).html(b.nextArrow)).mousedown(function(){return!1}).click(function(i){""!=b.nextArrow&&B&&(i.stopPropagation(),B&&(b.firstDate=
-B,g.render()))});c.append(e).append(k).append(l);for(l=e=0;7>e;e++)for(var q=0;7>q;q++,l++){var C=new Date(f),n="day",r=b.zIndex+l,w=$("");if(e){C._add(q+7*(e-1));var p=C._val(),x=p.time,K=null,s=!0,D=function(b,a){!0===b.repeatYear&&a.setYear(p.year);!0===b.repeatMonth&&a.setMonth(p.month);return a._val()};w.html(p.date);b.selectableDateRange&&(s=!1,$.each(b.selectableDateRange,function(b,a){var c=a.from,d=a.to||null,d=d||new Date(a.from.getFullYear(),a.from.getMonth(),a.from._max()),c=D(a,
-c),d=D(a,d);if(x>=c.time&&x<=d.time)return s=!0}));if(b.selectableDates){if(b.selectableDateRange&&!s||s&&!b.selectableDateRange)s=!1;$.each(b.selectableDates,function(b,a){if(D(a,a.date).time==x)return s=!0})}!s||0>v._indexOf(p.year)||0>H._indexOf(p.month)||0>y._indexOf(p.day)?n="noday":(n="sun mon tue wed thu fri sat".split(" ")[p.day],I!=p.month&&(n+=" outday"),u==x&&(n="today",r+=50),b.selectedDate._time()==x&&(n="selected",r+=51),b.specialDates&&$.each(b.specialDates,function(b,a){D(a,a.date).time==
-x&&(n=a.cssClass||"special",r+=52,K=a.data)}),w.mousedown(function(){return!1}).hover(function(a){a.stopPropagation();a=$(this).data("data");b.onHover(d,w,a.date,a.data)}).click(function(a){a.stopPropagation();a=$(this).data("data");b.selectedDate=b.firstDate=a.date;g.render(function(){!b.showAlways&&b.hideOnClick&&g.hide()});b.onClick(d,$(this),a.date,a.data)}))}else n="dow",w.html(z[q]),C=null;$.extend(j,{borderTopWidth:h,borderBottomWidth:h,borderLeftWidth:0").hide().change(u),F=$("").hide().change(u),
-L=$("").html(t[I]).mousedown(function(){return!1}).click(function(a){a.stopPropagation();N(!1)}),M=$("").html(J).mousedown(function(){return!1}).click(function(a){a.stopPropagation();N(!0)});$.each(t,function(a,c){if(b.allowMonthSelect&&-1!=H._indexOf(a)){var d=$("").html(c).attr("value",a);a==I&&d.attr("selected","selected");E.append(d)}});$.each(v,function(a,c){if(b.allowYearSelect){var d=$("").html(c).attr("value",c);c==J&&d.attr("selected","selected");F.append(d)}});
-u=$("").append(L).append(E).append(M).append(F);k.children().remove();k.append(u);(a||function(){})()}};return a}();Date.prototype._clear=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this};Date.prototype._time=function(){return this._clear().getTime()};Date.prototype._max=function(){return[31,28+(1==(new Date(this.getYear(),1,29)).getMonth()?1:0),31,30,31,30,31,31,30,31,30,31][this.getMonth()]};Date.prototype._add=function(a){this.setDate(this.getDate()+
-a)};Date.prototype._first=function(){var a=new Date(this);a.setDate(1);return a};Date.prototype._val=function(){this._clear();return{year:this.getFullYear(),month:this.getMonth(),date:this.getDate(),time:this.getTime(),day:this.getDay()}};Array.prototype._indexOf=function(a){return $.inArray(a,this)}})();
+;(function(){$.fn.glDatePicker=function(options){var pluginName='glDatePicker';var instance=this.data(pluginName);if(!instance){return this.each(function(){return $(this).data(pluginName,new glDatePicker(this,options));});}
+return(options===true)?instance:this;};$.fn.glDatePicker.defaults={cssName:'default',zIndex:1000,borderSize:1,calendarOffset:{x:0,y:1},showAlways:false,hideOnClick:true,allowMonthSelect:true,allowYearSelect:true,todayDate:new Date(),selectedDate:null,prevArrow:'\u25c4',nextArrow:'\u25ba',selectableDates:null,selectableDateRange:null,specialDates:null,selectableMonths:null,selectableYears:null,selectableDOW:null,monthNames:null,dowNames:null,dowOffset:0,onClick:(function(el,cell,date,data){el.val(date.toLocaleDateString());}),onHover:function(el,cell,date,data){},onShow:function(calendar){calendar.show();},onHide:function(calendar){calendar.hide();},firstDate:null,previous_years:5,subsequent_years:5,noSelectTableDates:null};var glDatePicker=(function(){function glDatePicker(element,userOptions){var self=this;self.el=$(element);var el=self.el;self.options=$.extend(true,{},$.fn.glDatePicker.defaults,userOptions);var options=self.options;self.calendar=$($.find('[gldp-el='+el.attr('gldp-id')+' ]'));options.selectedDate=options.selectedDate||options.todayDate;options.firstDate=(new Date((options.firstDate||options.selectedDate)))._first();if(!(el.attr('gldp-id')||'').length){el.attr('gldp-id','gldp-'+Math.round(Math.random()*1e10))}
+el.addClass('gldp-el').bind('click',function(e){self.show(e);}).bind('focus',function(e){self.show(e);});if(self.calendar.length&&!options.showAlways){self.calendar.hide();}
+$(document).bind('mouseup',function(e){var target=e.target;var calendar=self.calendar;if(!el.is(target)&&!calendar.is(target)&&calendar.has(target).length===0&&calendar.is(':visible')){self.hide();}});self.render();};glDatePicker.prototype={show:function(){$.each($('.gldp-el').not(this.el),function(i,o){if(o.length){o.options.onHide(o.calendar);}});this.options.onShow(this.calendar);},hide:function(){if(this.options&&!this.options.showAlways){this.options.onHide(this.calendar);}},render:function(renderCalback){var self=this;var el=self.el;var options=self.options;var calendar=self.calendar;var coreClass=' core border ';var cssName='gldp-'+options.cssName;var todayVal=options.todayDate._val();var todayTime=todayVal.time;var maxRow=6;var maxCol=7;var borderSize=options.borderSize+'px';var getSelectableList=function(min,max,userList){var resultList=[];for(var i=min;i<=max;i++){resultList.push(i);}
+if(userList){var newList=[];$.each(userList,function(i,v){if(v>=min&&v<=max&&newList._indexOf(v)<0){newList.push(v);}});resultList=newList.length?newList:resultList;};resultList.sort();return resultList;};var selectableMonths=getSelectableList(0,11,options.selectableMonths);var selectableYears=getSelectableList(todayVal.year-options.previous_years,todayVal.year+options.subsequent_years,options.selectableYears);var selectableDOW=getSelectableList(0,6,options.selectableDOW);var dowNames=options.dowNames||['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];var monthNames=options.monthNames||['January','February','March','April','May','June','July','August','September','October','November','December'];var containerWidth=el.outerWidth();var containerHeight=containerWidth;var getCellSize=function(_size,_count){return(_size / _count)+((options.borderSize / _count)*(_count-1));};var cellWidth=getCellSize(containerWidth,maxCol);var cellHeight=getCellSize(containerHeight,maxRow+2);if(!calendar.length){self.calendar=calendar=$('').attr('gldp-el',el.attr('gldp-id')).data('is',true).css({display:(options.showAlways?undefined:'none'),zIndex:options.zIndex,width:(cellWidth*maxCol)+'px'});$('body').append(calendar);}
+else{if(!eval(calendar.data('is'))){containerWidth=calendar.outerWidth();containerHeight=calendar.outerHeight();cellWidth=getCellSize(containerWidth,maxCol);cellHeight=getCellSize(containerHeight,maxRow+2);}}
+if(!el.is(':visible')){calendar.hide();}
+calendar.removeClass().addClass(cssName).children().remove();var onResize=function(){var elPos=el.offset();calendar.css({top:(elPos.top+el.outerHeight()+options.calendarOffset.y)+'px',left:(elPos.left+options.calendarOffset.x)+'px'});};$(window).resize(onResize);onResize();var cellCSS={width:cellWidth+'px',height:cellHeight+'px',lineHeight:cellHeight+'px'};var setFirstDate=function(_date){if(_date){options.firstDate=_date;self.render();}};var getFirstDate=function(_offset){var _date=new Date(options.firstDate);_offset=_offset||0;while(true){_date.setMonth(_date.getMonth()+_offset);_date.setDate(Math.min(1,_date._max()));if(_offset==0){break;}
+var dateVal=_date._val();var dateMonth=dateVal.month;var dateYear=dateVal.year;if(selectableMonths._indexOf(dateMonth)!=-1){if(selectableYears._indexOf(dateYear)!=-1){break;}
+else{if(dateYearselectableYears[selectableYears.length-1]){return null;}}}}
+return _date;};var prevFirstDate=getFirstDate(-1);var nextFirstDate=getFirstDate(1);var firstDate=(options.firstDate=getFirstDate());var firstDateVal=firstDate._val();var firstDateMonth=firstDateVal.month;var firstDateYear=firstDateVal.year;var startDate=new Date(firstDate);var dowOffset=Math.abs(Math.min(6,Math.max(0,options.dowOffset)));var startOffset=startDate.getDay()-dowOffset;startOffset=startOffset<1?-7-startOffset:-startOffset;dowNames=(dowNames.concat(dowNames)).slice(dowOffset,dowOffset+7);startDate._add(startOffset);var showPrev=(prevFirstDate);var showNext=(nextFirstDate);var monyearClass=coreClass+'monyear ';var prevCell=$('').addClass(monyearClass).css($.extend({},cellCSS,{borderWidth:borderSize+' 0 0 '+borderSize})).append($('').addClass('prev-arrow'+(showPrev?'':'-off')).html(options.prevArrow)).mousedown(function(){return false;}).click(function(e){if(options.prevArrow!=''&&showPrev){e.stopPropagation();setFirstDate(prevFirstDate);}});var titleCellCount=maxCol-2;var titleWidth=(cellWidth*titleCellCount)-(titleCellCount*options.borderSize)+(options.borderSize);var titleCell=$('').addClass(monyearClass+'title').css($.extend({},cellCSS,{width:titleWidth+'px',borderTopWidth:borderSize,marginLeft:'-'+(borderSize)}));var nextCell=$('').addClass(monyearClass).css($.extend({},cellCSS,{marginLeft:'-'+(borderSize),borderWidth:borderSize+' '+borderSize+' 0 0'})).append($('').addClass('next-arrow'+(showNext?'':'-off')).html(options.nextArrow)).mousedown(function(){return false;}).click(function(e){if(options.nextArrow!=''&&showNext){e.stopPropagation();setFirstDate(nextFirstDate);}});calendar.append(prevCell).append(titleCell).append(nextCell);for(var row=0,cellIndex=0;row')
+if(!row){cellClass='dow';cell.html(dowNames[col]);cellDate=null;}
+else{cellDate._add(col+((row-1)*maxCol));var cellDateVal=cellDate._val();var cellDateTime=cellDateVal.time;var specialData=null;var isSelectable=true;var getRepeatDate=function(v,date){if(v.repeatYear===true){date.setYear(cellDateVal.year);}
+if(v.repeatMonth===true){date.setMonth(cellDateVal.month);}
+return date._val();};cell.html(cellDateVal.date);if(options.selectableDateRange){isSelectable=false;$.each(options.selectableDateRange,function(i,v){var dateFrom=v.from;var dateTo=(v.to||null);dateTo=dateTo||new Date(v.from.getFullYear(),v.from.getMonth(),v.from._max());dateFrom=getRepeatDate(v,dateFrom);dateTo=getRepeatDate(v,dateTo);if(cellDateTime>=dateFrom.time&&cellDateTime<=dateTo.time){isSelectable=true;return true;}});}
+if(options.selectableDates){if((options.selectableDateRange&&!isSelectable)||(isSelectable&&!options.selectableDateRange)){isSelectable=false;}
+$.each(options.selectableDates,function(i,v){var vDate=getRepeatDate(v,v.date);if(vDate.time==cellDateTime){return(isSelectable=true);}});}
+if(options.noSelectTableDates){$.each(options.noSelectTableDates,function(i,v){if(v.date.getTime()==cellDateTime){isSelectable=false;}});}
+if(!isSelectable||selectableYears._indexOf(cellDateVal.year)<0||selectableMonths._indexOf(cellDateVal.month)<0||selectableDOW._indexOf(cellDateVal.day)<0){cellClass='noday';}
+else{cellClass=(['sun','mon','tue','wed','thu','fri','sat'])[cellDateVal.day];if(firstDateMonth!=cellDateVal.month){cellClass+=' outday';}
+if(todayTime==cellDateTime){cellClass='today';cellZIndex+=50;}
+if(options.selectedDate._time()==cellDateTime){cellClass='selected';cellZIndex+=51;}
+if(options.specialDates){$.each(options.specialDates,function(i,v){var vDate=getRepeatDate(v,v.date);if(vDate.time==cellDateTime){cellClass=(v.cssClass||'special');cellZIndex+=52;specialData=v.data;}});}
+cell.mousedown(function(){return false;}).hover(function(e){e.stopPropagation();var hoverData=$(this).data('data');options.onHover(el,cell,hoverData.date,hoverData.data);}).click(function(e){e.stopPropagation();var clickedData=$(this).data('data');options.selectedDate=options.firstDate=clickedData.date;self.render(function(){if(!options.showAlways&&options.hideOnClick){self.hide();}});options.onClick(el,$(this),clickedData.date,clickedData.data);});}}
+$.extend(cellCSS,{borderTopWidth:borderSize,borderBottomWidth:borderSize,borderLeftWidth:(row>0||(!row&&!col))?borderSize:0,borderRightWidth:(row>0||(!row&&col==6))?borderSize:0,marginLeft:(col>0)?'-'+(borderSize):0,marginTop:(row>0)?'-'+(borderSize):0,zIndex:cellZIndex});cell.data('data',{date:cellDate,data:specialData}).addClass(coreClass+cellClass).css(cellCSS);calendar.append(cell);}}
+var toggleYearMonthSelect=function(showYear){var show='inline-block';var hide='none';if(options.allowMonthSelect){monthText.css({display:!showYear?hide:show});monthSelect.css({display:!showYear?show:hide});}
+if(options.allowYearSelect){yearText.css({display:showYear?hide:show});yearSelect.css({display:showYear?show:hide});}};var onYearMonthSelect=function(){options.firstDate=new Date(yearSelect.val(),monthSelect.val(),1);self.render();};var monthSelect=$('').hide().change(onYearMonthSelect);var yearSelect=$('').hide().change(onYearMonthSelect);var monthText=$('').html(monthNames[firstDateMonth]).mousedown(function(){return false;}).click(function(e){e.stopPropagation();toggleYearMonthSelect(false);});var yearText=$('').html(firstDateYear).mousedown(function(){return false;}).click(function(e){e.stopPropagation();toggleYearMonthSelect(true);});$.each(monthNames,function(i,v){if(options.allowMonthSelect&&selectableMonths._indexOf(i)!=-1){var o=$('').html(v).attr('value',i);if(i==firstDateMonth){o.attr('selected','selected');}
+monthSelect.append(o);}});$.each(selectableYears,function(i,v){if(options.allowYearSelect){var o=$('').html(v).attr('value',v);if(v==firstDateYear){o.attr('selected','selected');}
+yearSelect.append(o);}});var titleYearMonth=$('').append(monthText).append(monthSelect).append(yearText).append(yearSelect);titleCell.children().remove();titleCell.append(titleYearMonth);renderCalback=renderCalback||(function(){});renderCalback();}};return glDatePicker;})();(function(){Date.prototype._clear=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this;};Date.prototype._time=function(){return this._clear().getTime();};Date.prototype._max=function(){var isLeapYear=(new Date(this.getYear(),1,29).getMonth()==1)?1:0;var days=[31,28+isLeapYear,31,30,31,30,31,31,30,31,30,31];return days[this.getMonth()];};Date.prototype._add=function(days){this.setDate(this.getDate()+days);};Date.prototype._first=function(){var date=new Date(this);date.setDate(1);return date;};Date.prototype._val=function(){this._clear();return{year:this.getFullYear(),month:this.getMonth(),date:this.getDate(),time:this.getTime(),day:this.getDay()};};Array.prototype._indexOf=function(value){return $.inArray(value,this);}})();})();
\ No newline at end of file