diff --git a/CHANGELOG.md b/CHANGELOG.md index 57addff..e51733d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog +## 0.5.0 (Feb 11, 2017) + +- Added a new option `highlightedClass` for highlight today (#28). +- Fixed the position of picker panel (#49). + + ## 0.4.0 (Oct 15, 2016) - Rename `autoshow` option to `autoShow`. diff --git a/README.md b/README.md index 741dc5d..4d7d25d 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ dist/ ├── datepicker.css ( 4 KB) ├── datepicker.min.css ( 4 KB) -├── datepicker.js (38 KB) +├── datepicker.js (39 KB) └── datepicker.min.js (16 KB) ``` @@ -330,6 +330,14 @@ A class (CSS) for picked item. A class (CSS) for disabled item. +### highlightedClass + +- Type: `String` +- Default: `'highlighted'` + +A class (CSS) for highlight date item. + + ### template - Type: `String` diff --git a/dist/datepicker.css b/dist/datepicker.css index ec9191f..e228453 100644 --- a/dist/datepicker.css +++ b/dist/datepicker.css @@ -1,11 +1,11 @@ /*! - * Datepicker v0.4.0 + * Datepicker v0.5.0 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2016 Fengyuan Chen + * Copyright (c) 2014-2017 Fengyuan Chen * Released under the MIT license * - * Date: 2016-10-15T04:28:09.384Z + * Date: 2017-02-11T13:41:05.813Z */ .datepicker-container { font-size: 12px; @@ -159,7 +159,7 @@ } .datepicker-panel > ul > li:hover { - background-color: #eee; + background-color: #e6f2ff; } .datepicker-panel > ul > li.muted, @@ -167,6 +167,14 @@ color: #999; } +.datepicker-panel > ul > li.highlighted { + background-color: #e6f2ff; +} + +.datepicker-panel > ul > li.highlighted:hover { + background-color: #cce6ff; +} + .datepicker-panel > ul > li.picked, .datepicker-panel > ul > li.picked:hover { color: #39f; @@ -180,6 +188,11 @@ background-color: #fff; } +.datepicker-panel > ul > li.disabled.highlighted, +.datepicker-panel > ul > li.disabled:hover.highlighted { + background-color: #e6f2ff; +} + .datepicker-panel > ul > li[data-view='years prev'], .datepicker-panel > ul > li[data-view='year prev'], .datepicker-panel > ul > li[data-view='month prev'], diff --git a/dist/datepicker.js b/dist/datepicker.js index 8f954d3..5c6b792 100644 --- a/dist/datepicker.js +++ b/dist/datepicker.js @@ -1,11 +1,11 @@ /*! - * Datepicker v0.4.0 + * Datepicker v0.5.0 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2016 Fengyuan Chen + * Copyright (c) 2014-2017 Fengyuan Chen * Released under the MIT license * - * Date: 2016-10-15T04:28:08.752Z + * Date: 2017-02-11T13:41:04.790Z */ (function (factory) { @@ -358,6 +358,7 @@ if (format.hasYear) { this.fillYears(); $yearsPicker.removeClass(CLASS_HIDE); + this.place(); } else { this.showView(0); } @@ -372,6 +373,7 @@ if (format.hasMonth) { this.fillMonths(); $monthsPicker.removeClass(CLASS_HIDE); + this.place(); } else { this.showView(2); } @@ -387,6 +389,7 @@ if (format.hasDay) { this.fillDays(); $daysPicker.removeClass(CLASS_HIDE); + this.place(); } else { this.showView(1); } @@ -452,16 +455,31 @@ view: '', muted: false, picked: false, - disabled: false + disabled: false, + highlighted: false }; + var classes = []; $.extend(defaults, data); + if (defaults.muted) { + classes.push(options.mutedClass); + } + + if (defaults.highlighted) { + classes.push(options.highlightedClass); + } + + if (defaults.picked) { + classes.push(options.pickedClass); + } + + if (defaults.disabled) { + classes.push(options.disabledClass); + } + return ( - '<' + itemTag + ' ' + - (defaults.disabled ? 'class="' + options.disabledClass + '"' : - defaults.picked ? 'class="' + options.pickedClass + '"' : - defaults.muted ? 'class="' + options.mutedClass + '"' : '') + + '<' + itemTag + ' class="' + classes.join(' ') + '"' + (defaults.view ? ' data-view="' + defaults.view + '"' : '') + '>' + defaults.text + @@ -630,6 +648,10 @@ var prevViewYear = viewYear; var prevViewMonth = viewMonth; var nextViewYear = viewYear; + var now = new Date(); + var thisYear = now.getFullYear(); + var thisMonth = now.getMonth(); + var today = now.getDate(); var nextViewMonth = viewMonth; var date = this.date; var year = date.getFullYear(); @@ -692,7 +714,8 @@ text: i, view: 'day prev', muted: true, - disabled: isDisabled + disabled: isDisabled, + highlighted: prevViewYear === thisYear && prevViewMonth === thisMonth && date.getDate() === today })); } @@ -735,7 +758,8 @@ text: i, view: 'day next', muted: true, - disabled: isDisabled + disabled: isDisabled, + highlighted: nextViewYear === thisYear && nextViewMonth === thisMonth && date.getDate() === today })); } @@ -763,7 +787,8 @@ text: i, view: isDisabled ? 'day disabled' : isPicked ? 'day picked' : 'day', picked: isPicked, - disabled: isDisabled + disabled: isDisabled, + highlighted: viewYear === thisYear && viewMonth === thisMonth && date.getDate() === today })); } @@ -1382,6 +1407,9 @@ // A class (CSS) for disabled date item disabledClass: 'disabled', + // A class (CSS) for highlight date item + highlightedClass: 'highlighted', + // The template of the datepicker template: ( '
' + diff --git a/dist/datepicker.min.css b/dist/datepicker.min.css index f209ed9..a2259a6 100644 --- a/dist/datepicker.min.css +++ b/dist/datepicker.min.css @@ -1,9 +1,9 @@ /*! - * Datepicker v0.4.0 + * Datepicker v0.5.0 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2016 Fengyuan Chen + * Copyright (c) 2014-2017 Fengyuan Chen * Released under the MIT license * - * Date: 2016-10-15T04:28:09.384Z - */.datepicker-container{font-size:12px;line-height:30px;position:fixed;z-index:-1;top:0;left:0;width:210px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-color:#fff;direction:ltr!important;-ms-touch-action:none;touch-action:none;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none}.datepicker-container:after,.datepicker-container:before{position:absolute;display:block;width:0;height:0;content:' ';border:5px solid transparent}.datepicker-dropdown{position:absolute;z-index:1;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;border:1px solid #ccc;-webkit-box-shadow:0 3px 6px #ccc;box-shadow:0 3px 6px #ccc}.datepicker-inline{position:static}.datepicker-top-left,.datepicker-top-right{border-top-color:#39f}.datepicker-top-left:after,.datepicker-top-left:before,.datepicker-top-right:after,.datepicker-top-right:before{top:-5px;left:10px;border-top:0}.datepicker-top-left:before,.datepicker-top-right:before{border-bottom-color:#39f}.datepicker-top-left:after,.datepicker-top-right:after{top:-4px;border-bottom-color:#fff}.datepicker-bottom-left,.datepicker-bottom-right{border-bottom-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-left:before,.datepicker-bottom-right:after,.datepicker-bottom-right:before{bottom:-5px;left:10px;border-bottom:0}.datepicker-bottom-left:before,.datepicker-bottom-right:before{border-top-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-right:after{bottom:-4px;border-top-color:#fff}.datepicker-bottom-right:after,.datepicker-bottom-right:before,.datepicker-top-right:after,.datepicker-top-right:before{right:10px;left:auto}.datepicker-panel>ul:after,.datepicker-panel>ul:before{display:table;content:' '}.datepicker-panel>ul:after{clear:both}.datepicker-panel>ul{width:102%;margin:0;padding:0}.datepicker-panel>ul>li{float:left;width:30px;height:30px;margin:0;padding:0;list-style:none;cursor:pointer;text-align:center;background-color:#fff}.datepicker-panel>ul>li:hover{background-color:#eee}.datepicker-panel>ul>li.muted,.datepicker-panel>ul>li.muted:hover{color:#999}.datepicker-panel>ul>li.picked,.datepicker-panel>ul>li.picked:hover{color:#39f}.datepicker-panel>ul>li.disabled,.datepicker-panel>ul>li.disabled:hover{cursor:default;color:#ccc;background-color:#fff}.datepicker-panel>ul>li[data-view='years prev'],.datepicker-panel>ul>li[data-view='year prev'],.datepicker-panel>ul>li[data-view='month prev'],.datepicker-panel>ul>li[data-view='years next'],.datepicker-panel>ul>li[data-view='year next'],.datepicker-panel>ul>li[data-view='month next'],.datepicker-panel>ul>li[data-view=next]{font-size:18px}.datepicker-panel>ul>li[data-view='month current'],.datepicker-panel>ul>li[data-view='years current'],.datepicker-panel>ul>li[data-view='year current']{width:150px}.datepicker-panel>ul[data-view=years]>li,.datepicker-panel>ul[data-view=months]>li{line-height:52.5px;width:52.5px;height:52.5px}.datepicker-panel>ul[data-view=week]>li,.datepicker-panel>ul[data-view=week]>li:hover{cursor:default;background-color:#fff}.datepicker-hide{display:none} \ No newline at end of file + * Date: 2017-02-11T13:41:05.813Z + */.datepicker-container{font-size:12px;line-height:30px;position:fixed;z-index:-1;top:0;left:0;width:210px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-color:#fff;direction:ltr!important;-ms-touch-action:none;touch-action:none;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none}.datepicker-container:after,.datepicker-container:before{position:absolute;display:block;width:0;height:0;content:' ';border:5px solid transparent}.datepicker-dropdown{position:absolute;z-index:1;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;border:1px solid #ccc;-webkit-box-shadow:0 3px 6px #ccc;box-shadow:0 3px 6px #ccc}.datepicker-inline{position:static}.datepicker-top-left,.datepicker-top-right{border-top-color:#39f}.datepicker-top-left:after,.datepicker-top-left:before,.datepicker-top-right:after,.datepicker-top-right:before{top:-5px;left:10px;border-top:0}.datepicker-top-left:before,.datepicker-top-right:before{border-bottom-color:#39f}.datepicker-top-left:after,.datepicker-top-right:after{top:-4px;border-bottom-color:#fff}.datepicker-bottom-left,.datepicker-bottom-right{border-bottom-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-left:before,.datepicker-bottom-right:after,.datepicker-bottom-right:before{bottom:-5px;left:10px;border-bottom:0}.datepicker-bottom-left:before,.datepicker-bottom-right:before{border-top-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-right:after{bottom:-4px;border-top-color:#fff}.datepicker-bottom-right:after,.datepicker-bottom-right:before,.datepicker-top-right:after,.datepicker-top-right:before{right:10px;left:auto}.datepicker-panel>ul:after,.datepicker-panel>ul:before{display:table;content:' '}.datepicker-panel>ul:after{clear:both}.datepicker-panel>ul{width:102%;margin:0;padding:0}.datepicker-panel>ul>li{float:left;width:30px;height:30px;margin:0;padding:0;list-style:none;cursor:pointer;text-align:center;background-color:#fff}.datepicker-panel>ul>li.highlighted,.datepicker-panel>ul>li:hover{background-color:#e6f2ff}.datepicker-panel>ul>li.muted,.datepicker-panel>ul>li.muted:hover{color:#999}.datepicker-panel>ul>li.highlighted:hover{background-color:#cce6ff}.datepicker-panel>ul>li.picked,.datepicker-panel>ul>li.picked:hover{color:#39f}.datepicker-panel>ul>li.disabled,.datepicker-panel>ul>li.disabled:hover{cursor:default;color:#ccc;background-color:#fff}.datepicker-panel>ul>li.disabled.highlighted,.datepicker-panel>ul>li.disabled:hover.highlighted{background-color:#e6f2ff}.datepicker-panel>ul>li[data-view='years prev'],.datepicker-panel>ul>li[data-view='year prev'],.datepicker-panel>ul>li[data-view='month prev'],.datepicker-panel>ul>li[data-view='years next'],.datepicker-panel>ul>li[data-view='year next'],.datepicker-panel>ul>li[data-view='month next'],.datepicker-panel>ul>li[data-view=next]{font-size:18px}.datepicker-panel>ul>li[data-view='month current'],.datepicker-panel>ul>li[data-view='years current'],.datepicker-panel>ul>li[data-view='year current']{width:150px}.datepicker-panel>ul[data-view=years]>li,.datepicker-panel>ul[data-view=months]>li{line-height:52.5px;width:52.5px;height:52.5px}.datepicker-panel>ul[data-view=week]>li,.datepicker-panel>ul[data-view=week]>li:hover{cursor:default;background-color:#fff}.datepicker-hide{display:none} \ No newline at end of file diff --git a/dist/datepicker.min.js b/dist/datepicker.min.js index 7ea26e6..a0018c2 100644 --- a/dist/datepicker.min.js +++ b/dist/datepicker.min.js @@ -1,10 +1,10 @@ /*! - * Datepicker v0.4.0 + * Datepicker v0.5.0 * https://github.com/fengyuanchen/datepicker * - * Copyright (c) 2014-2016 Fengyuan Chen + * Copyright (c) 2014-2017 Fengyuan Chen * Released under the MIT license * - * Date: 2016-10-15T04:28:08.752Z + * Date: 2017-02-11T13:41:04.790Z */ -!function(t){"function"==typeof define&&define.amd?define("datepicker",["jquery"],t):t("object"==typeof exports?require("jquery"):jQuery)}(function(t){"use strict";function e(t){return j.call(t).slice(8,-1).toLowerCase()}function i(t){return"string"==typeof t}function s(t){return"number"==typeof t&&!isNaN(t)}function a(t){return"undefined"==typeof t}function n(t){return"date"===e(t)}function r(t,e){var i=[];return Array.from?Array.from(t).slice(e||0):(s(e)&&i.push(e),i.slice.apply(t,i))}function h(t,e){var i=r(arguments,2);return function(){return t.apply(e,i.concat(r(arguments)))}}function o(t){return t%4===0&&t%100!==0||t%400===0}function l(t,e){return[31,o(t)?29:28,31,30,31,30,31,31,30,31,30,31][e]}function d(t){var e,i,s=String(t).toLowerCase(),a=s.match(x);if(!a||0===a.length)throw new Error("Invalid date format.");for(t={source:s,parts:a},e=a.length,i=0;ia.getTime()&&(n=new Date(a)),this.endDate=a),this.date=n,this.viewDate=new Date(n),this.initialDate=new Date(this.date),this.bind(),(e.autoShow||this.isInline)&&this.show(),e.autoPick&&this.pick()},build:function(){var e,i=this.options,s=this.$element;this.isBuilt||(this.isBuilt=!0,this.$picker=e=t(i.template),this.$week=e.find('[data-view="week"]'),this.$yearsPicker=e.find('[data-view="years picker"]'),this.$yearsPrev=e.find('[data-view="years prev"]'),this.$yearsNext=e.find('[data-view="years next"]'),this.$yearsCurrent=e.find('[data-view="years current"]'),this.$years=e.find('[data-view="years"]'),this.$monthsPicker=e.find('[data-view="months picker"]'),this.$yearPrev=e.find('[data-view="year prev"]'),this.$yearNext=e.find('[data-view="year next"]'),this.$yearCurrent=e.find('[data-view="year current"]'),this.$months=e.find('[data-view="months"]'),this.$daysPicker=e.find('[data-view="days picker"]'),this.$monthPrev=e.find('[data-view="month prev"]'),this.$monthNext=e.find('[data-view="month next"]'),this.$monthCurrent=e.find('[data-view="month current"]'),this.$days=e.find('[data-view="days"]'),this.isInline?t(i.container||s).append(e.addClass(F)):(t(f.body).append(e.addClass(V)),e.addClass(P)),this.fillWeek())},unbuild:function(){this.isBuilt&&(this.isBuilt=!1,this.$picker.remove())},bind:function(){var e=this.options,i=this.$element;t.isFunction(e.show)&&i.on(k,e.show),t.isFunction(e.hide)&&i.on(b,e.hide),t.isFunction(e.pick)&&i.on($,e.pick),this.isInput&&(i.on(g,t.proxy(this.keyup,this)),e.trigger||i.on(v,t.proxy(this.show,this))),this.$trigger.on(m,t.proxy(this.show,this))},unbind:function(){var e=this.options,i=this.$element;t.isFunction(e.show)&&i.off(k,e.show),t.isFunction(e.hide)&&i.off(b,e.hide),t.isFunction(e.pick)&&i.off($,e.pick),this.isInput&&(i.off(g,this.keyup),e.trigger||i.off(v,this.show)),this.$trigger.off(m,this.show)},showView:function(t){var e=this.$yearsPicker,i=this.$monthsPicker,s=this.$daysPicker,a=this.format;if(a.hasYear||a.hasMonth||a.hasDay)switch(w(t)){case 2:case"years":i.addClass(P),s.addClass(P),a.hasYear?(this.fillYears(),e.removeClass(P)):this.showView(0);break;case 1:case"months":e.addClass(P),s.addClass(P),a.hasMonth?(this.fillMonths(),i.removeClass(P)):this.showView(2);break;default:e.addClass(P),i.addClass(P),a.hasDay?(this.fillDays(),s.removeClass(P)):this.showView(1)}},hideView:function(){this.options.autoHide&&this.hide()},place:function(){var t=this.options,e=this.$element,i=this.$picker,s=p.outerWidth(),a=p.outerHeight(),n=e.outerWidth(),r=e.outerHeight(),h=i.width(),o=i.height(),l=e.offset(),d=l.left,u=l.top,c=parseFloat(t.offset)||10,f=M;u>o&&u+r+o>a?(u-=o+c,f=T):u+=r+c,d+h>s&&(d=d+n-h,f=f.replace("left","right")),i.removeClass(A).addClass(f).css({top:u,left:d,zIndex:parseInt(t.zIndex,10)})},trigger:function(e,i){var s=t.Event(e,i);return this.$element.trigger(s),s},createItem:function(e){var i=this.options,s=i.itemTag,a={text:"",view:"",muted:!1,picked:!1,disabled:!1};return t.extend(a,e),"<"+s+" "+(a.disabled?'class="'+i.disabledClass+'"':a.picked?'class="'+i.pickedClass+'"':a.muted?'class="'+i.mutedClass+'"':"")+(a.view?' data-view="'+a.view+'"':"")+">"+a.text+""},fillAll:function(){this.fillYears(),this.fillMonths(),this.fillDays()},fillWeek:function(){var e,i=this.options,s=parseInt(i.weekStart,10)%7,a=i.daysMin,n="";for(a=t.merge(a.slice(s),a.slice(0,s)),e=0;e<=6;e++)n+=this.createItem({text:a[e]});this.$week.html(n)},fillYears:function(){var e,i=this.options,s=i.disabledClass||"",a=i.yearSuffix||"",n=t.isFunction(i.filter)&&i.filter,r=this.startDate,h=this.endDate,o=this.viewDate,l=o.getFullYear(),d=o.getMonth(),u=o.getDate(),c=this.date,f=c.getFullYear(),p=!1,w=!1,y=!1,m=!1,g=!1,v="",D=-5,k=6;for(e=D;e<=k;e++)c=new Date(l+e,d,u),g=e===D||e===k,m=l+e===f,y=!1,r&&(y=c.getFullYear()h.getFullYear(),e===k&&(w=y)),!y&&n&&(y=n.call(this.$element,c)===!1),v+=this.createItem({text:l+e,view:y?"year disabled":m?"year picked":"year",muted:g,picked:m,disabled:y});this.$yearsPrev.toggleClass(s,p),this.$yearsNext.toggleClass(s,w),this.$yearsCurrent.toggleClass(s,!0).html(l+D+a+" - "+(l+k)+a),this.$years.html(v)},fillMonths:function(){var e,i=this.options,s=i.disabledClass||"",a=i.monthsShort,n=t.isFunction(i.filter)&&i.filter,r=this.startDate,h=this.endDate,o=this.viewDate,l=o.getFullYear(),d=o.getDate(),u=this.date,c=u.getFullYear(),f=u.getMonth(),p=!1,w=!1,y=!1,m=!1,g="";for(e=0;e<=11;e++)u=new Date(l,e,d),m=l===c&&e===f,y=!1,r&&(p=u.getFullYear()===r.getFullYear(),y=p&&u.getMonth()h.getMonth()),!y&&n&&(y=n.call(this.$element,u)===!1),g+=this.createItem({index:e,text:a[e],view:y?"month disabled":m?"month picked":"month",picked:m,disabled:y});this.$yearPrev.toggleClass(s,p),this.$yearNext.toggleClass(s,w),this.$yearCurrent.toggleClass(s,p&&w).html(l+i.yearSuffix||""),this.$months.html(g)},fillDays:function(){var e,i,s,a=this.options,n=a.disabledClass||"",r=a.yearSuffix||"",h=a.monthsShort,o=parseInt(a.weekStart,10)%7,d=t.isFunction(a.filter)&&a.filter,u=this.startDate,c=this.endDate,f=this.viewDate,p=f.getFullYear(),w=f.getMonth(),y=p,m=w,g=p,v=w,D=this.date,k=D.getFullYear(),b=D.getMonth(),$=D.getDate(),x=!1,C=!1,S=!1,F=!1,V=[],M=[],I=[],T=42;for(0===w?(y-=1,m=11):m-=1,e=l(y,m),D=new Date(p,w,1),s=D.getDay()-o,s<=0&&(s+=7),u&&(x=D.getTime()<=u.getTime()),i=e-(s-1);i<=e;i++)D=new Date(y,m,i),S=!1,u&&(S=D.getTime()=c.getTime()),i=1;i<=s;i++)D=new Date(g,v,i),S=!1,c&&(S=D.getTime()>c.getTime()),!S&&d&&(S=d.call(this.$element,D)===!1),M.push(this.createItem({text:i,view:"day next",muted:!0,disabled:S}));for(i=1;i<=e;i++)D=new Date(p,w,i),F=p===k&&w===b&&i===$,S=!1,u&&(S=D.getTime()c.getTime()),!S&&d&&(S=d.call(this.$element,D)===!1),I.push(this.createItem({text:i,view:S?"day disabled":F?"day picked":"day",picked:F,disabled:S}));this.$monthPrev.toggleClass(n,x),this.$monthNext.toggleClass(n,C),this.$monthCurrent.toggleClass(n,x&&C).html(a.yearFirst?p+r+" "+h[w]:h[w]+" "+p+r),this.$days.html(V.join("")+I.join(" ")+M.join(""))},click:function(e){var i,s,a,n,r,h,o=t(e.target),l=this.viewDate;if(e.stopPropagation(),e.preventDefault(),!o.hasClass("disabled"))switch(i=l.getFullYear(),s=l.getMonth(),a=l.getDate(),h=o.data("view")){case"years prev":case"years next":i="years prev"===h?i-10:i+10,r=o.text(),n=S.test(r),n&&(i=parseInt(r,10),this.date=new Date(i,s,N(a,28))),this.viewDate=new Date(i,s,N(a,28)),this.fillYears(),n&&(this.showView(1),this.pick("year"));break;case"year prev":case"year next":i="year prev"===h?i-1:i+1,this.viewDate=new Date(i,s,N(a,28)),this.fillMonths();break;case"year current":this.format.hasYear&&this.showView(2);break;case"year picked":this.format.hasMonth?this.showView(1):this.hideView();break;case"year":i=parseInt(o.text(),10),this.date=new Date(i,s,N(a,28)),this.viewDate=new Date(i,s,N(a,28)),this.format.hasMonth?this.showView(1):this.hideView(),this.pick("year");break;case"month prev":case"month next":s="month prev"===h?s-1:"month next"===h?s+1:s,this.viewDate=new Date(i,s,N(a,28)),this.fillDays();break;case"month current":this.format.hasMonth&&this.showView(1);break;case"month picked":this.format.hasDay?this.showView(0):this.hideView();break;case"month":s=t.inArray(o.text(),this.options.monthsShort),this.date=new Date(i,s,N(a,28)),this.viewDate=new Date(i,s,N(a,28)),this.format.hasDay?this.showView(0):this.hideView(),this.pick("month");break;case"day prev":case"day next":case"day":s="day prev"===h?s-1:"day next"===h?s+1:s,a=parseInt(o.text(),10),this.date=new Date(i,s,a),this.viewDate=new Date(i,s,a),this.fillDays(),"day"===h&&this.hideView(),this.pick("day");break;case"day picked":this.hideView(),this.pick("day")}},clickDoc:function(t){for(var e,i=t.target,s=this.$trigger[0];i!==f;){if(i===s){e=!0;break}i=i.parentNode}e||this.hide()},keyup:function(){this.update()},getValue:function(){var t=this.$element,e="";return this.isInput?e=t.val():this.isInline?this.options.container&&(e=t.text()):e=t.text(),e},setValue:function(t){var e=this.$element;t=i(t)?t:"",this.isInput?e.val(t):this.isInline?this.options.container&&e.text(t):e.text(t)},show:function(){this.isBuilt||this.build(),this.isShown||this.trigger(k).isDefaultPrevented()||(this.isShown=!0,this.$picker.removeClass(P).on(m,t.proxy(this.click,this)),this.showView(this.options.startView),this.isInline||(c.on(D,this._place=h(this.place,this)),p.on(m,this._clickDoc=h(this.clickDoc,this)),this.place()))},hide:function(){this.isShown&&(this.trigger(b).isDefaultPrevented()||(this.isShown=!1,this.$picker.addClass(P).off(m,this.click),this.isInline||(c.off(D,this._place),p.off(m,this._clickDoc))))},update:function(){var t=this.getValue();t!==this.oldValue&&(this.setDate(t,!0),this.oldValue=t)},pick:function(t){var e=this.$element,i=this.date;this.trigger($,{view:t||"",date:i}).isDefaultPrevented()||(this.setValue(i=this.formatDate(this.date)),this.isInput&&e.trigger("change"))},reset:function(){this.setDate(this.initialDate,!0),this.setValue(this.initialValue),this.isShown&&this.showView(this.options.startView)},getMonthName:function(e,i){var n=this.options,r=n.months;return t.isNumeric(e)?e=w(e):a(i)&&(i=e),i===!0&&(r=n.monthsShort),r[s(e)?e:this.date.getMonth()]},getDayName:function(e,i,n){var r=this.options,h=r.days;return t.isNumeric(e)?e=w(e):(a(n)&&(n=i),a(i)&&(i=e)),h=n===!0?r.daysMin:i===!0?r.daysShort:h,h[s(e)?e:this.date.getDay()]},getDate:function(t){var e=this.date;return t?this.formatDate(e):new Date(e)},setDate:function(e,s){var a=this.options.filter;if(n(e)||i(e)){if(e=this.parseDate(e),t.isFunction(a)&&a.call(this.$element,e)===!1)return;this.date=e,this.viewDate=new Date(e),s||this.pick(),this.isBuilt&&this.fillAll()}},setStartDate:function(t){(n(t)||i(t))&&(this.startDate=this.parseDate(t),this.isBuilt&&this.fillAll())},setEndDate:function(t){(n(t)||i(t))&&(this.endDate=this.parseDate(t),this.isBuilt&&this.fillAll())},parseDate:function(t){var e,s,a,r,h,o,l=this.format,d=[];if(n(t))return new Date(t.getFullYear(),t.getMonth(),t.getDate());if(i(t)&&(d=t.match(C)||[]),t=new Date,s=t.getFullYear(),a=t.getDate(),r=t.getMonth(),e=l.parts.length,d.length===e)for(o=0;o
          ',offset:10,zIndex:1e3,filter:null,show:null,hide:null,pick:null},u.setDefaults=function(e){e=t.isPlainObject(e)?e:{},e.language&&(e=t.extend({},u.LANGUAGES[e.language],e)),t.extend(u.DEFAULTS,e)},u.other=t.fn.datepicker,t.fn.datepicker=function(e){var s,n=r(arguments,1);return this.each(function(){var a,r,h=t(this),o=h.data(y);if(!o){if(/destroy/.test(e))return;a=t.extend({},h.data(),t.isPlainObject(e)&&e),h.data(y,o=new u(this,a))}i(e)&&t.isFunction(r=o[e])&&(s=r.apply(o,n))}),a(s)?this:s},t.fn.datepicker.Constructor=u,t.fn.datepicker.languages=u.LANGUAGES,t.fn.datepicker.setDefaults=u.setDefaults,t.fn.datepicker.noConflict=function(){return t.fn.datepicker=u.other,this}}); \ No newline at end of file +!function(t){"function"==typeof define&&define.amd?define("datepicker",["jquery"],t):t("object"==typeof exports?require("jquery"):jQuery)}(function(t){"use strict";function e(t){return j.call(t).slice(8,-1).toLowerCase()}function i(t){return"string"==typeof t}function s(t){return"number"==typeof t&&!isNaN(t)}function a(t){return"undefined"==typeof t}function n(t){return"date"===e(t)}function h(t,e){var i=[];return Array.from?Array.from(t).slice(e||0):(s(e)&&i.push(e),i.slice.apply(t,i))}function r(t,e){var i=h(arguments,2);return function(){return t.apply(e,i.concat(h(arguments)))}}function l(t){return t%4===0&&t%100!==0||t%400===0}function o(t,e){return[31,l(t)?29:28,31,30,31,30,31,31,30,31,30,31][e]}function d(t){var e,i,s=String(t).toLowerCase(),a=s.match(x);if(!a||0===a.length)throw new Error("Invalid date format.");for(t={source:s,parts:a},e=a.length,i=0;ia.getTime()&&(n=new Date(a)),this.endDate=a),this.date=n,this.viewDate=new Date(n),this.initialDate=new Date(this.date),this.bind(),(e.autoShow||this.isInline)&&this.show(),e.autoPick&&this.pick()},build:function(){var e,i=this.options,s=this.$element;this.isBuilt||(this.isBuilt=!0,this.$picker=e=t(i.template),this.$week=e.find('[data-view="week"]'),this.$yearsPicker=e.find('[data-view="years picker"]'),this.$yearsPrev=e.find('[data-view="years prev"]'),this.$yearsNext=e.find('[data-view="years next"]'),this.$yearsCurrent=e.find('[data-view="years current"]'),this.$years=e.find('[data-view="years"]'),this.$monthsPicker=e.find('[data-view="months picker"]'),this.$yearPrev=e.find('[data-view="year prev"]'),this.$yearNext=e.find('[data-view="year next"]'),this.$yearCurrent=e.find('[data-view="year current"]'),this.$months=e.find('[data-view="months"]'),this.$daysPicker=e.find('[data-view="days picker"]'),this.$monthPrev=e.find('[data-view="month prev"]'),this.$monthNext=e.find('[data-view="month next"]'),this.$monthCurrent=e.find('[data-view="month current"]'),this.$days=e.find('[data-view="days"]'),this.isInline?t(i.container||s).append(e.addClass(S)):(t(f.body).append(e.addClass(M)),e.addClass(P)),this.fillWeek())},unbuild:function(){this.isBuilt&&(this.isBuilt=!1,this.$picker.remove())},bind:function(){var e=this.options,i=this.$element;t.isFunction(e.show)&&i.on(k,e.show),t.isFunction(e.hide)&&i.on(b,e.hide),t.isFunction(e.pick)&&i.on($,e.pick),this.isInput&&(i.on(m,t.proxy(this.keyup,this)),e.trigger||i.on(v,t.proxy(this.show,this))),this.$trigger.on(y,t.proxy(this.show,this))},unbind:function(){var e=this.options,i=this.$element;t.isFunction(e.show)&&i.off(k,e.show),t.isFunction(e.hide)&&i.off(b,e.hide),t.isFunction(e.pick)&&i.off($,e.pick),this.isInput&&(i.off(m,this.keyup),e.trigger||i.off(v,this.show)),this.$trigger.off(y,this.show)},showView:function(t){var e=this.$yearsPicker,i=this.$monthsPicker,s=this.$daysPicker,a=this.format;if(a.hasYear||a.hasMonth||a.hasDay)switch(g(t)){case 2:case"years":i.addClass(P),s.addClass(P),a.hasYear?(this.fillYears(),e.removeClass(P),this.place()):this.showView(0);break;case 1:case"months":e.addClass(P),s.addClass(P),a.hasMonth?(this.fillMonths(),i.removeClass(P),this.place()):this.showView(2);break;default:e.addClass(P),i.addClass(P),a.hasDay?(this.fillDays(),s.removeClass(P),this.place()):this.showView(1)}},hideView:function(){this.options.autoHide&&this.hide()},place:function(){var t=this.options,e=this.$element,i=this.$picker,s=p.outerWidth(),a=p.outerHeight(),n=e.outerWidth(),h=e.outerHeight(),r=i.width(),l=i.height(),o=e.offset(),d=o.left,u=o.top,c=parseFloat(t.offset)||10,f=V;u>l&&u+h+l>a?(u-=l+c,f=T):u+=h+c,d+r>s&&(d=d+n-r,f=f.replace("left","right")),i.removeClass(A).addClass(f).css({top:u,left:d,zIndex:parseInt(t.zIndex,10)})},trigger:function(e,i){var s=t.Event(e,i);return this.$element.trigger(s),s},createItem:function(e){var i=this.options,s=i.itemTag,a={text:"",view:"",muted:!1,picked:!1,disabled:!1,highlighted:!1},n=[];return t.extend(a,e),a.muted&&n.push(i.mutedClass),a.highlighted&&n.push(i.highlightedClass),a.picked&&n.push(i.pickedClass),a.disabled&&n.push(i.disabledClass),"<"+s+' class="'+n.join(" ")+'"'+(a.view?' data-view="'+a.view+'"':"")+">"+a.text+""},fillAll:function(){this.fillYears(),this.fillMonths(),this.fillDays()},fillWeek:function(){var e,i=this.options,s=parseInt(i.weekStart,10)%7,a=i.daysMin,n="";for(a=t.merge(a.slice(s),a.slice(0,s)),e=0;e<=6;e++)n+=this.createItem({text:a[e]});this.$week.html(n)},fillYears:function(){var e,i=this.options,s=i.disabledClass||"",a=i.yearSuffix||"",n=t.isFunction(i.filter)&&i.filter,h=this.startDate,r=this.endDate,l=this.viewDate,o=l.getFullYear(),d=l.getMonth(),u=l.getDate(),c=this.date,f=c.getFullYear(),p=!1,g=!1,w=!1,y=!1,m=!1,v="",D=-5,k=6;for(e=D;e<=k;e++)c=new Date(o+e,d,u),m=e===D||e===k,y=o+e===f,w=!1,h&&(w=c.getFullYear()r.getFullYear(),e===k&&(g=w)),!w&&n&&(w=n.call(this.$element,c)===!1),v+=this.createItem({text:o+e,view:w?"year disabled":y?"year picked":"year",muted:m,picked:y,disabled:w});this.$yearsPrev.toggleClass(s,p),this.$yearsNext.toggleClass(s,g),this.$yearsCurrent.toggleClass(s,!0).html(o+D+a+" - "+(o+k)+a),this.$years.html(v)},fillMonths:function(){var e,i=this.options,s=i.disabledClass||"",a=i.monthsShort,n=t.isFunction(i.filter)&&i.filter,h=this.startDate,r=this.endDate,l=this.viewDate,o=l.getFullYear(),d=l.getDate(),u=this.date,c=u.getFullYear(),f=u.getMonth(),p=!1,g=!1,w=!1,y=!1,m="";for(e=0;e<=11;e++)u=new Date(o,e,d),y=o===c&&e===f,w=!1,h&&(p=u.getFullYear()===h.getFullYear(),w=p&&u.getMonth()r.getMonth()),!w&&n&&(w=n.call(this.$element,u)===!1),m+=this.createItem({index:e,text:a[e],view:w?"month disabled":y?"month picked":"month",picked:y,disabled:w});this.$yearPrev.toggleClass(s,p),this.$yearNext.toggleClass(s,g),this.$yearCurrent.toggleClass(s,p&&g).html(o+i.yearSuffix||""),this.$months.html(m)},fillDays:function(){var e,i,s,a=this.options,n=a.disabledClass||"",h=a.yearSuffix||"",r=a.monthsShort,l=parseInt(a.weekStart,10)%7,d=t.isFunction(a.filter)&&a.filter,u=this.startDate,c=this.endDate,f=this.viewDate,p=f.getFullYear(),g=f.getMonth(),w=p,y=g,m=p,v=new Date,D=v.getFullYear(),k=v.getMonth(),b=v.getDate(),$=g,x=this.date,C=x.getFullYear(),F=x.getMonth(),S=x.getDate(),M=!1,V=!1,I=!1,T=!1,Y=[],A=[],P=[],N=42;for(0===g?(w-=1,y=11):y-=1,e=o(w,y),x=new Date(p,g,1),s=x.getDay()-l,s<=0&&(s+=7),u&&(M=x.getTime()<=u.getTime()),i=e-(s-1);i<=e;i++)x=new Date(w,y,i),I=!1,u&&(I=x.getTime()=c.getTime()),i=1;i<=s;i++)x=new Date(m,$,i),I=!1,c&&(I=x.getTime()>c.getTime()),!I&&d&&(I=d.call(this.$element,x)===!1),A.push(this.createItem({text:i,view:"day next",muted:!0,disabled:I,highlighted:m===D&&$===k&&x.getDate()===b}));for(i=1;i<=e;i++)x=new Date(p,g,i),T=p===C&&g===F&&i===S,I=!1,u&&(I=x.getTime()c.getTime()),!I&&d&&(I=d.call(this.$element,x)===!1),P.push(this.createItem({text:i,view:I?"day disabled":T?"day picked":"day",picked:T,disabled:I,highlighted:p===D&&g===k&&x.getDate()===b}));this.$monthPrev.toggleClass(n,M),this.$monthNext.toggleClass(n,V),this.$monthCurrent.toggleClass(n,M&&V).html(a.yearFirst?p+h+" "+r[g]:r[g]+" "+p+h),this.$days.html(Y.join("")+P.join(" ")+A.join(""))},click:function(e){var i,s,a,n,h,r,l=t(e.target),o=this.viewDate;if(e.stopPropagation(),e.preventDefault(),!l.hasClass("disabled"))switch(i=o.getFullYear(),s=o.getMonth(),a=o.getDate(),r=l.data("view")){case"years prev":case"years next":i="years prev"===r?i-10:i+10,h=l.text(),n=F.test(h),n&&(i=parseInt(h,10),this.date=new Date(i,s,N(a,28))),this.viewDate=new Date(i,s,N(a,28)),this.fillYears(),n&&(this.showView(1),this.pick("year"));break;case"year prev":case"year next":i="year prev"===r?i-1:i+1,this.viewDate=new Date(i,s,N(a,28)),this.fillMonths();break;case"year current":this.format.hasYear&&this.showView(2);break;case"year picked":this.format.hasMonth?this.showView(1):this.hideView();break;case"year":i=parseInt(l.text(),10),this.date=new Date(i,s,N(a,28)),this.viewDate=new Date(i,s,N(a,28)),this.format.hasMonth?this.showView(1):this.hideView(),this.pick("year");break;case"month prev":case"month next":s="month prev"===r?s-1:"month next"===r?s+1:s,this.viewDate=new Date(i,s,N(a,28)),this.fillDays();break;case"month current":this.format.hasMonth&&this.showView(1);break;case"month picked":this.format.hasDay?this.showView(0):this.hideView();break;case"month":s=t.inArray(l.text(),this.options.monthsShort),this.date=new Date(i,s,N(a,28)),this.viewDate=new Date(i,s,N(a,28)),this.format.hasDay?this.showView(0):this.hideView(),this.pick("month");break;case"day prev":case"day next":case"day":s="day prev"===r?s-1:"day next"===r?s+1:s,a=parseInt(l.text(),10),this.date=new Date(i,s,a),this.viewDate=new Date(i,s,a),this.fillDays(),"day"===r&&this.hideView(),this.pick("day");break;case"day picked":this.hideView(),this.pick("day")}},clickDoc:function(t){for(var e,i=t.target,s=this.$trigger[0];i!==f;){if(i===s){e=!0;break}i=i.parentNode}e||this.hide()},keyup:function(){this.update()},getValue:function(){var t=this.$element,e="";return this.isInput?e=t.val():this.isInline?this.options.container&&(e=t.text()):e=t.text(),e},setValue:function(t){var e=this.$element;t=i(t)?t:"",this.isInput?e.val(t):this.isInline?this.options.container&&e.text(t):e.text(t)},show:function(){this.isBuilt||this.build(),this.isShown||this.trigger(k).isDefaultPrevented()||(this.isShown=!0,this.$picker.removeClass(P).on(y,t.proxy(this.click,this)),this.showView(this.options.startView),this.isInline||(c.on(D,this._place=r(this.place,this)),p.on(y,this._clickDoc=r(this.clickDoc,this)),this.place()))},hide:function(){this.isShown&&(this.trigger(b).isDefaultPrevented()||(this.isShown=!1,this.$picker.addClass(P).off(y,this.click),this.isInline||(c.off(D,this._place),p.off(y,this._clickDoc))))},update:function(){var t=this.getValue();t!==this.oldValue&&(this.setDate(t,!0),this.oldValue=t)},pick:function(t){var e=this.$element,i=this.date;this.trigger($,{view:t||"",date:i}).isDefaultPrevented()||(this.setValue(i=this.formatDate(this.date)),this.isInput&&e.trigger("change"))},reset:function(){this.setDate(this.initialDate,!0),this.setValue(this.initialValue),this.isShown&&this.showView(this.options.startView)},getMonthName:function(e,i){var n=this.options,h=n.months;return t.isNumeric(e)?e=g(e):a(i)&&(i=e),i===!0&&(h=n.monthsShort),h[s(e)?e:this.date.getMonth()]},getDayName:function(e,i,n){var h=this.options,r=h.days;return t.isNumeric(e)?e=g(e):(a(n)&&(n=i),a(i)&&(i=e)),r=n===!0?h.daysMin:i===!0?h.daysShort:r,r[s(e)?e:this.date.getDay()]},getDate:function(t){var e=this.date;return t?this.formatDate(e):new Date(e)},setDate:function(e,s){var a=this.options.filter;if(n(e)||i(e)){if(e=this.parseDate(e),t.isFunction(a)&&a.call(this.$element,e)===!1)return;this.date=e,this.viewDate=new Date(e),s||this.pick(),this.isBuilt&&this.fillAll()}},setStartDate:function(t){(n(t)||i(t))&&(this.startDate=this.parseDate(t),this.isBuilt&&this.fillAll())},setEndDate:function(t){(n(t)||i(t))&&(this.endDate=this.parseDate(t),this.isBuilt&&this.fillAll())},parseDate:function(t){var e,s,a,h,r,l,o=this.format,d=[];if(n(t))return new Date(t.getFullYear(),t.getMonth(),t.getDate());if(i(t)&&(d=t.match(C)||[]),t=new Date,s=t.getFullYear(),a=t.getDate(),h=t.getMonth(),e=o.parts.length,d.length===e)for(l=0;l
                  ',offset:10,zIndex:1e3,filter:null,show:null,hide:null,pick:null},u.setDefaults=function(e){e=t.isPlainObject(e)?e:{},e.language&&(e=t.extend({},u.LANGUAGES[e.language],e)),t.extend(u.DEFAULTS,e)},u.other=t.fn.datepicker,t.fn.datepicker=function(e){var s,n=h(arguments,1);return this.each(function(){var a,h,r=t(this),l=r.data(w);if(!l){if(/destroy/.test(e))return;a=t.extend({},r.data(),t.isPlainObject(e)&&e),r.data(w,l=new u(this,a))}i(e)&&t.isFunction(h=l[e])&&(s=h.apply(l,n))}),a(s)?this:s},t.fn.datepicker.Constructor=u,t.fn.datepicker.languages=u.LANGUAGES,t.fn.datepicker.setDefaults=u.setDefaults,t.fn.datepicker.noConflict=function(){return t.fn.datepicker=u.other,this}}); \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index d17e28f..9eed351 100644 --- a/docs/index.html +++ b/docs/index.html @@ -37,7 +37,7 @@