diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ddcc1..47b4aff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # Changelog +## 0.2.2 (Dec 10, 2015) + +- Fixed the issue of options overriding (#15) +- Fixed the error of next view month + + ## 0.2.1 (Oct 26, 2015) -- Fixed the error of month picker. +- Fixed the error of month picker ## 0.2.0 (Oct 18, 2015) diff --git a/README.md b/README.md index 5bade18..11d8dd8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > A simple jQuery datepicker plugin. -- [Demo](http://fengyuanchen.github.io/datepicker) +- [Homepage](http://fengyuanchen.github.io/datepicker) @@ -11,8 +11,8 @@ - Supports [options](#options) - Supports [methods](#methods) - Supports [events](#events) -- Supports inline -- Supports mobile +- Supports inline mode +- Supports touch (mobile) - Cross-browser support diff --git a/dist/datepicker.css b/dist/datepicker.css index bd2f7f3..21c3757 100644 --- a/dist/datepicker.css +++ b/dist/datepicker.css @@ -1,11 +1,11 @@ /*! - * Datepicker v0.2.1 + * Datepicker v0.2.2 * https://github.com/fengyuanchen/datepicker * * Copyright (c) 2014-2015 Fengyuan Chen * Released under the MIT license * - * Date: 2015-10-26T02:21:31.213Z + * Date: 2015-12-10T13:37:58.037Z */ .datepicker-container { position: fixed; @@ -27,13 +27,13 @@ -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; } -.datepicker-container:before, - .datepicker-container:after { + +.datepicker-container:before, .datepicker-container:after { position: absolute; display: block; width: 0; height: 0; - content: " "; + content: " "; border: 5px solid transparent; } @@ -42,7 +42,7 @@ z-index: 1; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; - 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; @@ -56,20 +56,22 @@ .datepicker-top-right { border-top-color: #39f; } -.datepicker-top-left:before, - .datepicker-top-left:after, - .datepicker-top-right:before, - .datepicker-top-right:after { + +.datepicker-top-left:before, .datepicker-top-left:after, +.datepicker-top-right:before, +.datepicker-top-right:after { top: -5px; left: 10px; border-top: 0; } + .datepicker-top-left:before, - .datepicker-top-right:before { +.datepicker-top-right:before { border-bottom-color: #39f; } + .datepicker-top-left:after, - .datepicker-top-right:after { +.datepicker-top-right:after { top: -4px; border-bottom-color: #fff; } @@ -78,29 +80,30 @@ .datepicker-bottom-right { border-bottom-color: #39f; } -.datepicker-bottom-left:before, - .datepicker-bottom-left:after, - .datepicker-bottom-right:before, - .datepicker-bottom-right:after { + +.datepicker-bottom-left:before, .datepicker-bottom-left:after, +.datepicker-bottom-right:before, +.datepicker-bottom-right:after { bottom: -5px; left: 10px; border-bottom: 0; } + .datepicker-bottom-left:before, - .datepicker-bottom-right:before { +.datepicker-bottom-right:before { border-top-color: #39f; } + .datepicker-bottom-left:after, - .datepicker-bottom-right:after { +.datepicker-bottom-right:after { bottom: -4px; border-top-color: #fff; } -.datepicker-top-right:before, -.datepicker-top-right:after, +.datepicker-top-right:before, .datepicker-top-right:after, .datepicker-bottom-right:before, .datepicker-bottom-right:after { - right: 10px; + right: 10px; left: auto; } @@ -116,9 +119,10 @@ .datepicker-panel > ul { width: 102%; - padding: 0; + padding: 0; margin: 0; } + .datepicker-panel > ul > li { float: left; width: 30px; @@ -127,49 +131,45 @@ margin: 0; text-align: center; list-style: none; - cursor: pointer; + cursor: pointer; background-color: #fff; } + .datepicker-panel > ul > li:hover { background-color: #eee; } -.datepicker-panel > ul > li.muted, - .datepicker-panel > ul > li.muted:hover { + +.datepicker-panel > ul > li.muted, .datepicker-panel > ul > li.muted:hover { color: #999; } -.datepicker-panel > ul > li.picked, - .datepicker-panel > ul > li.picked:hover { + +.datepicker-panel > ul > li.picked, .datepicker-panel > ul > li.picked:hover { color: #39f; } -.datepicker-panel > ul > li.disabled, - .datepicker-panel > ul > li.disabled:hover { + +.datepicker-panel > ul > li.disabled, .datepicker-panel > ul > li.disabled:hover { color: #ccc; - cursor: default; + cursor: default; 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"] { + +.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="years current"], - .datepicker-panel > ul > li[data-view="year current"], - .datepicker-panel > ul > li[data-view="month current"] { + +.datepicker-panel > ul > li[data-view="years current"], .datepicker-panel > ul > li[data-view="year current"], .datepicker-panel > ul > li[data-view="month current"] { width: 150px; } -.datepicker-panel > ul[data-view="years"] > li, - .datepicker-panel > ul[data-view="months"] > li { + +.datepicker-panel > ul[data-view="years"] > li, .datepicker-panel > ul[data-view="months"] > li { width: 52.5px; height: 52.5px; line-height: 52.5px; } + .datepicker-panel > ul[data-view="week"] > li, - .datepicker-panel > ul[data-view="week"] > li:hover { - cursor: default; +.datepicker-panel > ul[data-view="week"] > li:hover { + cursor: default; background-color: #fff; } diff --git a/dist/datepicker.js b/dist/datepicker.js index b60d130..1e4d901 100644 --- a/dist/datepicker.js +++ b/dist/datepicker.js @@ -1,11 +1,11 @@ /*! - * Datepicker v0.2.1 + * Datepicker v0.2.2 * https://github.com/fengyuanchen/datepicker * * Copyright (c) 2014-2015 Fengyuan Chen * Released under the MIT license * - * Date: 2015-10-26T02:21:30.292Z + * Date: 2015-12-10T13:37:57.693Z */ (function (factory) { @@ -154,8 +154,14 @@ } function Datepicker(element, options) { + options = $.isPlainObject(options) ? options : {}; + + if (options.language) { + options = $.extend({}, Datepicker.LANGUAGES[options.language], options); + } + this.$element = $(element); - this.options = $.extend({}, Datepicker.DEFAULTS, $.isPlainObject(options) && options); + this.options = $.extend({}, Datepicker.DEFAULTS, options); this.isBuilt = false; this.isShown = false; this.isInput = false; @@ -170,8 +176,6 @@ Datepicker.prototype = { constructor: Datepicker, - version: '0.2.1', - init: function () { var options = this.options; var $this = this.$element; @@ -179,10 +183,6 @@ var endDate = options.endDate; var date = options.date; - if (options.language) { - $.extend(options, Datepicker.LANGUAGES[options.language]); - } - this.$trigger = $(options.trigger || $this); this.isInput = $this.is('input') || $this.is('textarea'); this.isInline = options.inline && (options.container || !this.isInput); @@ -696,7 +696,7 @@ if (viewMonth === 11) { nextViewYear += 1; - nextViewYear = 0; + nextViewMonth = 0; } else { nextViewMonth += 1; } diff --git a/dist/datepicker.min.css b/dist/datepicker.min.css index 6fd1a03..649f0c0 100644 --- a/dist/datepicker.min.css +++ b/dist/datepicker.min.css @@ -1,9 +1,9 @@ /*! - * Datepicker v0.2.1 + * Datepicker v0.2.2 * https://github.com/fengyuanchen/datepicker * * Copyright (c) 2014-2015 Fengyuan Chen * Released under the MIT license * - * Date: 2015-10-26T02:21:31.213Z + * Date: 2015-12-10T13:37:58.037Z */.datepicker-container{position:fixed;top:0;left:0;z-index:-1;width:210px;font-size:12px;line-height:30px;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-color:#fff;direction:ltr!important;-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%;padding:0;margin:0}.datepicker-panel>ul>li{float:left;width:30px;height:30px;padding:0;margin:0;text-align:center;list-style:none;cursor:pointer;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{color:#ccc;cursor:default;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{width:52.5px;height:52.5px;line-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 668b5be..85c77b0 100644 --- a/dist/datepicker.min.js +++ b/dist/datepicker.min.js @@ -1,10 +1,10 @@ /*! - * Datepicker v0.2.1 + * Datepicker v0.2.2 * https://github.com/fengyuanchen/datepicker * * Copyright (c) 2014-2015 Fengyuan Chen * Released under the MIT license * - * Date: 2015-10-26T02:21:30.292Z + * Date: 2015-12-10T13:37:57.693Z */ -!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"string"==typeof t}function i(t){return"number"==typeof t&&!isNaN(t)}function s(t){return"undefined"==typeof t}function a(t){return"object"!=typeof t||null===t?!1:"[object Date]"===A.call(t)}function n(t,e){var s=[];return i(e)&&s.push(e),s.slice.apply(t,s)}function r(t,e){var i=n(arguments,2);return function(){return t.apply(e,i.concat(n(arguments)))}}function h(t){return t%4===0&&t%100!==0||t%400===0}function o(t,e){return[31,h(t)?29:28,31,30,31,30,31,31,30,31,30,31][e]}function l(t){var e,i,s=String(t).toLowerCase(),a=s.match(b);if(!a||0===a.length)throw new Error("Invalid date format.");for(t={source:s,parts:a},e=a.length,i=0;e>i;i++)switch(a[i]){case"dd":case"d":t.hasDay=!0;break;case"mm":case"m":t.hasMonth=!0;break;case"yyyy":case"yy":t.hasYear=!0}return t}function d(e,i){this.$element=t(e),this.options=t.extend({},d.DEFAULTS,t.isPlainObject(i)&&i),this.isBuilt=!1,this.isShown=!1,this.isInput=!1,this.isInline=!1,this.initialValue="",this.initialDate=null,this.startDate=null,this.endDate=null,this.init()}var u=t(window),c=window.document,f=t(c),p="datepicker",w="click."+p,m="keyup."+p,y="focus."+p,g="resize."+p,v="show."+p,D="hide."+p,k="pick."+p,b=/y+|m+|d+/g,$=/\d+/g,x=/^\d{2,4}$/,C="datepicker-inline",F="datepicker-dropdown",S="datepicker-top-left",I="datepicker-top-right",M="datepicker-bottom-left",V="datepicker-bottom-right",T=[S,I,M,V].join(" "),Y="datepicker-hide",N=Number,P=Math.min,A=Object.prototype.toString;d.prototype={constructor:d,version:"0.2.1",init:function(){var e=this.options,i=this.$element,s=e.startDate,a=e.endDate,n=e.date;e.language&&t.extend(e,d.LANGUAGES[e.language]),this.$trigger=t(e.trigger||i),this.isInput=i.is("input")||i.is("textarea"),this.isInline=e.inline&&(e.container||!this.isInput),this.format=l(e.format),this.initialValue=this.getValue(),n=this.parseDate(n||this.initialValue),s&&(s=this.parseDate(s),n.getTime()a.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(C)):(t(c.body).append(e.addClass(F)),e.addClass(Y)),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(v,e.show),t.isFunction(e.hide)&&i.on(D,e.hide),t.isFunction(e.pick)&&i.on(k,e.pick),this.isInput&&(i.on(m,t.proxy(this.keyup,this)),e.trigger||i.on(y,t.proxy(this.show,this))),this.$trigger.on(w,t.proxy(this.show,this))},unbind:function(){var e=this.options,i=this.$element;t.isFunction(e.show)&&i.off(v,e.show),t.isFunction(e.hide)&&i.off(D,e.hide),t.isFunction(e.pick)&&i.off(k,e.pick),this.isInput&&(i.off(m,this.keyup),e.trigger||i.off(y,this.show)),this.$trigger.off(w,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(N(t)){case 2:case"years":i.addClass(Y),s.addClass(Y),a.hasYear?(this.fillYears(),e.removeClass(Y)):this.showView(0);break;case 1:case"months":e.addClass(Y),s.addClass(Y),a.hasMonth?(this.fillMonths(),i.removeClass(Y)):this.showView(2);break;default:e.addClass(Y),i.addClass(Y),a.hasDay?(this.fillDays(),s.removeClass(Y)):this.showView(1)}},hideView:function(){this.options.autohide&&this.hide()},place:function(){var t=this.options,e=this.$element,i=this.$picker,s=f.outerWidth(),a=f.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,p=S;u>o&&u+r+o>a?(u-=o+c,p=M):u+=r+c,d+h>s&&(d=d+n-h,p=p.replace("left","right")),i.removeClass(T).addClass(p).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;6>=e;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,m=!1,y=!1,g=!1,v="",D=-5,k=6;for(e=D;k>=e;e++)c=new Date(l+e,d,u),g=e===D||e===k,y=l+e===f,m=!1,r&&(m=c.getFullYear()h.getFullYear(),e===k&&(w=m)),!m&&n&&(m=n.call(this.$element,c)===!1),v+=this.createItem({text:l+e,view:m?"year disabled":y?"year picked":"year",muted:g,picked:y,disabled:m});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,m=!1,y=!1,g="";for(e=0;11>=e;e++)u=new Date(l,e,d),y=l===c&&e===f,m=!1,r&&(p=u.getFullYear()===r.getFullYear(),m=p&&u.getMonth()h.getMonth()),!m&&n&&(m=n.call(this.$element,u)===!1),g+=this.createItem({index:e,text:a[e],view:m?"month disabled":y?"month picked":"month",picked:y,disabled:m});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,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(),w=f.getMonth(),m=p,y=w,g=p,v=w,D=this.date,k=D.getFullYear(),b=D.getMonth(),$=D.getDate(),x=!1,C=!1,F=!1,S=!1,I=[],M=[],V=[],T=42;for(0===w?(m-=1,y=11):y-=1,e=o(m,y),D=new Date(p,w,1),s=D.getDay()-l,0>=s&&(s+=7),u&&(x=D.getTime()<=u.getTime()),i=e-(s-1);e>=i;i++)D=new Date(m,y,i),F=!1,u&&(F=D.getTime()=c.getTime()),i=1;s>=i;i++)D=new Date(g,v,i),F=!1,c&&(F=D.getTime()>c.getTime()),!F&&d&&(F=d.call(this.$element,D)===!1),M.push(this.createItem({text:i,view:"day next",muted:!0,disabled:F}));for(i=1;e>=i;i++)D=new Date(p,w,i),S=p===k&&w===b&&i===$,F=!1,u&&(F=D.getTime()c.getTime()),!F&&d&&(F=d.call(this.$element,D)===!1),V.push(this.createItem({text:i,view:F?"day disabled":S?"day picked":"day",picked:S,disabled:F}));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(I.join("")+V.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=x.test(r),n&&(i=parseInt(r,10),this.date=new Date(i,s,P(a,28))),this.viewDate=new Date(i,s,P(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,P(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,P(a,28)),this.viewDate=new Date(i,s,P(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,P(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,P(a,28)),this.viewDate=new Date(i,s,P(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!==c;){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 i=this.$element;t=e(t)?t:"",this.isInput?i.val(t):this.isInline?this.options.container&&i.text(t):i.text(t)},show:function(){this.isBuilt||this.build(),this.isShown||this.trigger(v).isDefaultPrevented()||(this.isShown=!0,this.$picker.removeClass(Y).on(w,t.proxy(this.click,this)),this.showView(this.options.startView),this.isInline||(u.on(g,this._place=r(this.place,this)),f.on(w,this._clickDoc=r(this.clickDoc,this)),this.place()))},hide:function(){this.isShown&&(this.trigger(D).isDefaultPrevented()||(this.isShown=!1,this.$picker.addClass(Y).off(w,this.click),this.isInline||(u.off(g,this._place),f.off(w,this._clickDoc))))},update:function(){this.setDate(this.getValue(),!0)},pick:function(t){var e=this.$element,i=this.date;this.trigger(k,{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,a){var n=this.options,r=n.months;return t.isNumeric(e)?e=N(e):s(a)&&(a=e),a===!0&&(r=n.monthsShort),r[i(e)?e:this.date.getMonth()]},getDayName:function(e,a,n){var r=this.options,h=r.days;return t.isNumeric(e)?e=N(e):(s(n)&&(n=a),s(a)&&(a=e)),h=n===!0?r.daysMin:a===!0?r.daysShort:h,h[i(e)?e:this.date.getDay()]},getDate:function(t){var e=this.date;return t?this.formatDate(e):new Date(e)},setDate:function(i,s){var n=this.options.filter;if(a(i)||e(i)){if(i=this.parseDate(i),t.isFunction(n)&&n.call(this.$element,i)===!1)return;this.date=i,this.viewDate=new Date(i),s||this.pick(),this.isBuilt&&this.fillAll()}},setStartDate:function(t){(a(t)||e(t))&&(this.startDate=this.parseDate(t),this.isBuilt&&this.fillAll())},setEndDate:function(t){(a(t)||e(t))&&(this.endDate=this.parseDate(t),this.isBuilt&&this.fillAll())},parseDate:function(t){var i,s,n,r,h,o,l=this.format,d=[];if(a(t))return new Date(t);if(e(t)&&(d=t.match($)||[]),t=new Date,s=t.getFullYear(),n=t.getDate(),r=t.getMonth(),i=l.parts.length,d.length===i)for(o=0;i>o;o++)switch(h=parseInt(d[o],10)||1,l.parts[o]){case"dd":case"d":n=h;break;case"mm":case"m":r=h-1;break;case"yy":s=2e3+h;break;case"yyyy":s=h}return new Date(s,r,n)},formatDate:function(t){var e,i,s,n,r,h=this.format,o="";if(a(t))for(o=h.source,i=t.getFullYear(),n={d:t.getDate(),m:t.getMonth()+1,yy:i.toString().substring(2),yyyy:i},n.dd=(n.d<10?"0":"")+n.d,n.mm=(n.m<10?"0":"")+n.m,e=h.parts.length,r=0;e>r;r++)s=h.parts[r],o=o.replace(s,n[s]);return o},destroy:function(){this.unbind(),this.unbuild(),this.$element.removeData(p)}},d.LANGUAGES={},d.DEFAULTS={autoshow:!1,autohide:!1,autopick:!1,inline:!1,container:null,trigger:null,language:"",format:"mm/dd/yyyy",date:null,startDate:null,endDate:null,startView:0,weekStart:0,yearFirst:!1,yearSuffix:"",days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],daysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],daysMin:["Su","Mo","Tu","We","Th","Fr","Sa"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],itemTag:"li",mutedClass:"muted",pickedClass:"picked",disabledClass:"disabled",template:'
          ',offset:10,zIndex:1,filter:null,show:null,hide:null,pick:null},d.setDefaults=function(e){t.extend(d.DEFAULTS,t.isPlainObject(e)&&e)},d.other=t.fn.datepicker,t.fn.datepicker=function(i){var a,r=n(arguments,1);return this.each(function(){var s,n,h=t(this),o=h.data(p);if(!o){if(/destroy/.test(i))return;s=t.extend({},h.data(),t.isPlainObject(i)&&i),h.data(p,o=new d(this,s))}e(i)&&t.isFunction(n=o[i])&&(a=n.apply(o,r))}),s(a)?this:a},t.fn.datepicker.Constructor=d,t.fn.datepicker.languages=d.LANGUAGES,t.fn.datepicker.setDefaults=d.setDefaults,t.fn.datepicker.noConflict=function(){return t.fn.datepicker=d.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"string"==typeof t}function i(t){return"number"==typeof t&&!isNaN(t)}function s(t){return"undefined"==typeof t}function a(t){return"object"!=typeof t||null===t?!1:"[object Date]"===A.call(t)}function n(t,e){var s=[];return i(e)&&s.push(e),s.slice.apply(t,s)}function r(t,e){var i=n(arguments,2);return function(){return t.apply(e,i.concat(n(arguments)))}}function h(t){return t%4===0&&t%100!==0||t%400===0}function o(t,e){return[31,h(t)?29:28,31,30,31,30,31,31,30,31,30,31][e]}function l(t){var e,i,s=String(t).toLowerCase(),a=s.match(b);if(!a||0===a.length)throw new Error("Invalid date format.");for(t={source:s,parts:a},e=a.length,i=0;e>i;i++)switch(a[i]){case"dd":case"d":t.hasDay=!0;break;case"mm":case"m":t.hasMonth=!0;break;case"yyyy":case"yy":t.hasYear=!0}return t}function d(e,i){i=t.isPlainObject(i)?i:{},i.language&&(i=t.extend({},d.LANGUAGES[i.language],i)),this.$element=t(e),this.options=t.extend({},d.DEFAULTS,i),this.isBuilt=!1,this.isShown=!1,this.isInput=!1,this.isInline=!1,this.initialValue="",this.initialDate=null,this.startDate=null,this.endDate=null,this.init()}var u=t(window),c=window.document,f=t(c),p="datepicker",w="click."+p,m="keyup."+p,y="focus."+p,g="resize."+p,v="show."+p,D="hide."+p,k="pick."+p,b=/y+|m+|d+/g,$=/\d+/g,x=/^\d{2,4}$/,C="datepicker-inline",F="datepicker-dropdown",S="datepicker-top-left",I="datepicker-top-right",M="datepicker-bottom-left",V="datepicker-bottom-right",T=[S,I,M,V].join(" "),Y="datepicker-hide",N=Number,P=Math.min,A=Object.prototype.toString;d.prototype={constructor:d,init:function(){var e=this.options,i=this.$element,s=e.startDate,a=e.endDate,n=e.date;this.$trigger=t(e.trigger||i),this.isInput=i.is("input")||i.is("textarea"),this.isInline=e.inline&&(e.container||!this.isInput),this.format=l(e.format),this.initialValue=this.getValue(),n=this.parseDate(n||this.initialValue),s&&(s=this.parseDate(s),n.getTime()a.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(C)):(t(c.body).append(e.addClass(F)),e.addClass(Y)),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(v,e.show),t.isFunction(e.hide)&&i.on(D,e.hide),t.isFunction(e.pick)&&i.on(k,e.pick),this.isInput&&(i.on(m,t.proxy(this.keyup,this)),e.trigger||i.on(y,t.proxy(this.show,this))),this.$trigger.on(w,t.proxy(this.show,this))},unbind:function(){var e=this.options,i=this.$element;t.isFunction(e.show)&&i.off(v,e.show),t.isFunction(e.hide)&&i.off(D,e.hide),t.isFunction(e.pick)&&i.off(k,e.pick),this.isInput&&(i.off(m,this.keyup),e.trigger||i.off(y,this.show)),this.$trigger.off(w,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(N(t)){case 2:case"years":i.addClass(Y),s.addClass(Y),a.hasYear?(this.fillYears(),e.removeClass(Y)):this.showView(0);break;case 1:case"months":e.addClass(Y),s.addClass(Y),a.hasMonth?(this.fillMonths(),i.removeClass(Y)):this.showView(2);break;default:e.addClass(Y),i.addClass(Y),a.hasDay?(this.fillDays(),s.removeClass(Y)):this.showView(1)}},hideView:function(){this.options.autohide&&this.hide()},place:function(){var t=this.options,e=this.$element,i=this.$picker,s=f.outerWidth(),a=f.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,p=S;u>o&&u+r+o>a?(u-=o+c,p=M):u+=r+c,d+h>s&&(d=d+n-h,p=p.replace("left","right")),i.removeClass(T).addClass(p).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;6>=e;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,m=!1,y=!1,g=!1,v="",D=-5,k=6;for(e=D;k>=e;e++)c=new Date(l+e,d,u),g=e===D||e===k,y=l+e===f,m=!1,r&&(m=c.getFullYear()h.getFullYear(),e===k&&(w=m)),!m&&n&&(m=n.call(this.$element,c)===!1),v+=this.createItem({text:l+e,view:m?"year disabled":y?"year picked":"year",muted:g,picked:y,disabled:m});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,m=!1,y=!1,g="";for(e=0;11>=e;e++)u=new Date(l,e,d),y=l===c&&e===f,m=!1,r&&(p=u.getFullYear()===r.getFullYear(),m=p&&u.getMonth()h.getMonth()),!m&&n&&(m=n.call(this.$element,u)===!1),g+=this.createItem({index:e,text:a[e],view:m?"month disabled":y?"month picked":"month",picked:y,disabled:m});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,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(),w=f.getMonth(),m=p,y=w,g=p,v=w,D=this.date,k=D.getFullYear(),b=D.getMonth(),$=D.getDate(),x=!1,C=!1,F=!1,S=!1,I=[],M=[],V=[],T=42;for(0===w?(m-=1,y=11):y-=1,e=o(m,y),D=new Date(p,w,1),s=D.getDay()-l,0>=s&&(s+=7),u&&(x=D.getTime()<=u.getTime()),i=e-(s-1);e>=i;i++)D=new Date(m,y,i),F=!1,u&&(F=D.getTime()=c.getTime()),i=1;s>=i;i++)D=new Date(g,v,i),F=!1,c&&(F=D.getTime()>c.getTime()),!F&&d&&(F=d.call(this.$element,D)===!1),M.push(this.createItem({text:i,view:"day next",muted:!0,disabled:F}));for(i=1;e>=i;i++)D=new Date(p,w,i),S=p===k&&w===b&&i===$,F=!1,u&&(F=D.getTime()c.getTime()),!F&&d&&(F=d.call(this.$element,D)===!1),V.push(this.createItem({text:i,view:F?"day disabled":S?"day picked":"day",picked:S,disabled:F}));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(I.join("")+V.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=x.test(r),n&&(i=parseInt(r,10),this.date=new Date(i,s,P(a,28))),this.viewDate=new Date(i,s,P(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,P(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,P(a,28)),this.viewDate=new Date(i,s,P(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,P(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,P(a,28)),this.viewDate=new Date(i,s,P(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!==c;){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 i=this.$element;t=e(t)?t:"",this.isInput?i.val(t):this.isInline?this.options.container&&i.text(t):i.text(t)},show:function(){this.isBuilt||this.build(),this.isShown||this.trigger(v).isDefaultPrevented()||(this.isShown=!0,this.$picker.removeClass(Y).on(w,t.proxy(this.click,this)),this.showView(this.options.startView),this.isInline||(u.on(g,this._place=r(this.place,this)),f.on(w,this._clickDoc=r(this.clickDoc,this)),this.place()))},hide:function(){this.isShown&&(this.trigger(D).isDefaultPrevented()||(this.isShown=!1,this.$picker.addClass(Y).off(w,this.click),this.isInline||(u.off(g,this._place),f.off(w,this._clickDoc))))},update:function(){this.setDate(this.getValue(),!0)},pick:function(t){var e=this.$element,i=this.date;this.trigger(k,{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,a){var n=this.options,r=n.months;return t.isNumeric(e)?e=N(e):s(a)&&(a=e),a===!0&&(r=n.monthsShort),r[i(e)?e:this.date.getMonth()]},getDayName:function(e,a,n){var r=this.options,h=r.days;return t.isNumeric(e)?e=N(e):(s(n)&&(n=a),s(a)&&(a=e)),h=n===!0?r.daysMin:a===!0?r.daysShort:h,h[i(e)?e:this.date.getDay()]},getDate:function(t){var e=this.date;return t?this.formatDate(e):new Date(e)},setDate:function(i,s){var n=this.options.filter;if(a(i)||e(i)){if(i=this.parseDate(i),t.isFunction(n)&&n.call(this.$element,i)===!1)return;this.date=i,this.viewDate=new Date(i),s||this.pick(),this.isBuilt&&this.fillAll()}},setStartDate:function(t){(a(t)||e(t))&&(this.startDate=this.parseDate(t),this.isBuilt&&this.fillAll())},setEndDate:function(t){(a(t)||e(t))&&(this.endDate=this.parseDate(t),this.isBuilt&&this.fillAll())},parseDate:function(t){var i,s,n,r,h,o,l=this.format,d=[];if(a(t))return new Date(t);if(e(t)&&(d=t.match($)||[]),t=new Date,s=t.getFullYear(),n=t.getDate(),r=t.getMonth(),i=l.parts.length,d.length===i)for(o=0;i>o;o++)switch(h=parseInt(d[o],10)||1,l.parts[o]){case"dd":case"d":n=h;break;case"mm":case"m":r=h-1;break;case"yy":s=2e3+h;break;case"yyyy":s=h}return new Date(s,r,n)},formatDate:function(t){var e,i,s,n,r,h=this.format,o="";if(a(t))for(o=h.source,i=t.getFullYear(),n={d:t.getDate(),m:t.getMonth()+1,yy:i.toString().substring(2),yyyy:i},n.dd=(n.d<10?"0":"")+n.d,n.mm=(n.m<10?"0":"")+n.m,e=h.parts.length,r=0;e>r;r++)s=h.parts[r],o=o.replace(s,n[s]);return o},destroy:function(){this.unbind(),this.unbuild(),this.$element.removeData(p)}},d.LANGUAGES={},d.DEFAULTS={autoshow:!1,autohide:!1,autopick:!1,inline:!1,container:null,trigger:null,language:"",format:"mm/dd/yyyy",date:null,startDate:null,endDate:null,startView:0,weekStart:0,yearFirst:!1,yearSuffix:"",days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],daysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],daysMin:["Su","Mo","Tu","We","Th","Fr","Sa"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],itemTag:"li",mutedClass:"muted",pickedClass:"picked",disabledClass:"disabled",template:'
                  ',offset:10,zIndex:1,filter:null,show:null,hide:null,pick:null},d.setDefaults=function(e){t.extend(d.DEFAULTS,t.isPlainObject(e)&&e)},d.other=t.fn.datepicker,t.fn.datepicker=function(i){var a,r=n(arguments,1);return this.each(function(){var s,n,h=t(this),o=h.data(p);if(!o){if(/destroy/.test(i))return;s=t.extend({},h.data(),t.isPlainObject(i)&&i),h.data(p,o=new d(this,s))}e(i)&&t.isFunction(n=o[i])&&(a=n.apply(o,r))}),s(a)?this:a},t.fn.datepicker.Constructor=d,t.fn.datepicker.languages=d.LANGUAGES,t.fn.datepicker.setDefaults=d.setDefaults,t.fn.datepicker.noConflict=function(){return t.fn.datepicker=d.other,this}}); \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index f0c44d9..6294d11 100644 --- a/docs/index.html +++ b/docs/index.html @@ -33,7 +33,7 @@