diff --git a/glDatePicker.js b/glDatePicker.js
index a7f1873..bc94ef3 100644
--- a/glDatePicker.js
+++ b/glDatePicker.js
@@ -7,7 +7,7 @@
*
* Date: Tue Jan 1 2013
*/
- ;(function() {
+ ;(function($) {
$.fn.glDatePicker = function(options) {
var pluginName = 'glDatePicker';
@@ -329,7 +329,7 @@
width: (cellWidth * maxCol) + 'px'
});
- $('body').append(calendar);
+ options.container ? options.container.append(calendar) : $('body').append(calendar);
}
else {
if(!eval(calendar.data('is'))) {
@@ -759,6 +759,10 @@
// Run the callback signaling end of the render
renderCalback = renderCalback || (function() {});
renderCalback();
+
+ if(typeof options.onRender == 'function') {
+ options.onRender(options.firstDate);
+ }
}
};
@@ -815,4 +819,4 @@
return $.inArray(value, this);
}
})();
-})();
\ No newline at end of file
+})(jQuery);
diff --git a/glDatePicker.min.js b/glDatePicker.min.js
index e380153..4346a85 100644
--- a/glDatePicker.min.js
+++ b/glDatePicker.min.js
@@ -1,16 +1 @@
-/*! 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(e){var t="glDatePicker";var n=this.data(t);if(!n){return this.each(function(){return $(this).data(t,new glDatePicker(this,e))})}return e===true?n:this};$.fn.glDatePicker.defaults={cssName:"default",zIndex:1e3,borderSize:1,calendarOffset:{x:0,y:1},showAlways:false,hideOnClick:true,allowMonthSelect:true,allowYearSelect:true,todayDate:new Date,selectedDate:null,prevArrow:"◄",nextArrow:"►",selectableDates:null,selectableDateRange:null,specialDates:null,selectableMonths:null,selectableYears:null,selectableDOW:null,monthNames:null,dowNames:null,dowOffset:0,onClick:function(e,t,n,r){e.val(n.toLocaleDateString())},onHover:function(e,t,n,r){},onShow:function(e){e.show()},onHide:function(e){e.hide()},firstDate:null};var glDatePicker=function(){function glDatePicker(e,t){var n=this;n.el=$(e);var r=n.el;n.options=$.extend(true,{},$.fn.glDatePicker.defaults,t);var i=n.options;n.calendar=$($.find("[gldp-el="+r.attr("gldp-id")+" ]"));i.selectedDate=i.selectedDate||i.todayDate;i.firstDate=(new Date(i.firstDate||i.selectedDate))._first();if(!(r.attr("gldp-id")||"").length){r.attr("gldp-id","gldp-"+Math.round(Math.random()*1e10))}r.addClass("gldp-el").bind("click",function(e){n.show(e)}).bind("focus",function(e){n.show(e)});if(n.calendar.length&&!i.showAlways){n.calendar.hide()}$(document).bind("mouseup",function(e){var t=e.target;var i=n.calendar;if(!r.is(t)&&!i.is(t)&&i.has(t).length===0&&i.is(":visible")){n.hide()}});n.render()}glDatePicker.prototype={show:function(){$.each($(".gldp-el").not(this.el),function(e,t){if(t.length){t.options.onHide(t.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(e,t,n){var r=[];for(var i=e;i<=t;i++){r.push(i)}if(n){var s=[];$.each(n,function(n,r){if(r>=e&&r<=t&&s._indexOf(r)<0){s.push(r)}});r=s.length?s:r}r.sort();return r};var selectableMonths=getSelectableList(0,11,options.selectableMonths);var selectableYears=getSelectableList(todayVal.year-5,todayVal.year+5,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(e,t){return e/t+options.borderSize/t*(t-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"});options.container?options.container.append(calendar):$("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 e=el.offset();calendar.css({top:e.top+el.outerHeight()+options.calendarOffset.y+"px",left:e.left+options.calendarOffset.x+"px"})};$(window).resize(onResize);onResize();var cellCSS={width:cellWidth+"px",height:cellHeight+"px",lineHeight:cellHeight+"px"};var setFirstDate=function(e){if(e){options.firstDate=e;self.render()}};var getFirstDate=function(e){var t=new Date(options.firstDate);e=e||0;while(true){t.setMonth(t.getMonth()+e);t.setDate(Math.min(1,t._max()));if(e==0){break}var n=t._val();var r=n.month;var i=n.year;if(selectableMonths._indexOf(r)!=-1){if(selectableYears._indexOf(i)!=-1){break}else{if(iselectableYears[selectableYears.length-1]){return null}}}}return t};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(e,t){if(e.repeatYear===true){t.setYear(cellDateVal.year)}if(e.repeatMonth===true){t.setMonth(cellDateVal.month)}return t._val()};cell.html(cellDateVal.date);if(options.selectableDateRange){isSelectable=false;$.each(options.selectableDateRange,function(e,t){var n=t.from;var r=t.to||null;r=r||new Date(t.from.getFullYear(),t.from.getMonth(),t.from._max());n=getRepeatDate(t,n);r=getRepeatDate(t,r);if(cellDateTime>=n.time&&cellDateTime<=r.time){isSelectable=true;return true}})}if(options.selectableDates){if(options.selectableDateRange&&!isSelectable||isSelectable&&!options.selectableDateRange){isSelectable=false}$.each(options.selectableDates,function(e,t){var n=getRepeatDate(t,t.date);if(n.time==cellDateTime){return isSelectable=true}})}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(e,t){var n=getRepeatDate(t,t.date);if(n.time==cellDateTime){cellClass=t.cssClass||"special";cellZIndex+=52;specialData=t.data}})}cell.mousedown(function(){return false}).hover(function(e){e.stopPropagation();var t=$(this).data("data");options.onHover(el,cell,t.date,t.data)}).click(function(e){e.stopPropagation();var t=$(this).data("data");options.selectedDate=options.firstDate=t.date;self.render(function(){if(!options.showAlways&&options.hideOnClick){self.hide()}});options.onClick(el,$(this),t.date,t.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(e){var t="inline-block";var n="none";if(options.allowMonthSelect){monthText.css({display:!e?n:t});monthSelect.css({display:!e?t:n})}if(options.allowYearSelect){yearText.css({display:e?n:t});yearSelect.css({display:e?t:n})}};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(e,t){if(options.allowMonthSelect&&selectableMonths._indexOf(e)!=-1){var n=$("").html(t).attr("value",e);if(e==firstDateMonth){n.attr("selected","selected")}monthSelect.append(n)}});$.each(selectableYears,function(e,t){if(options.allowYearSelect){var n=$("").html(t).attr("value",t);if(t==firstDateYear){n.attr("selected","selected")}yearSelect.append(n)}});var titleYearMonth=$("").append(monthText).append(monthSelect).append(yearText).append(yearSelect);titleCell.children().remove();titleCell.append(titleYearMonth);renderCalback=renderCalback||function(){};renderCalback();if(typeof options.onRender=="function"){options.onRender(options.firstDate)}}};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 e=(new Date(this.getYear(),1,29)).getMonth()==1?1:0;var t=[31,28+e,31,30,31,30,31,31,30,31,30,31];return t[this.getMonth()]};Date.prototype._add=function(e){this.setDate(this.getDate()+e)};Date.prototype._first=function(){var e=new Date(this);e.setDate(1);return e};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(e){return $.inArray(e,this)}})()})(jQuery)