westdc-zf1/public/static/lib/datepicker/bootstrap-datepicker.min.js

21 lines
14 KiB
JavaScript
Raw Normal View History

/* =========================================================
* bootstrap-datepicker.js
* http://www.eyecon.ro/bootstrap-datepicker
* =========================================================
* Copyright 2012 Stefan Petre
* Improvements by Andrew Rowls
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================= */
!function(e){var m=function(a,b){this.element=e(a);this.language=b.language||this.element.data("date-language")||"en";this.language=this.language in l?this.language:"en";this.format=g.parseFormat(b.format||this.element.data("date-format")||"mm/dd/yyyy");this.picker=e(g.template).appendTo("body").on({click:e.proxy(this.click,this),mousedown:e.proxy(this.mousedown,this)});this.isInput=this.element.is("input");if((this.component=this.element.is(".date")?this.element.find(".add-on"):!1)&&0===this.component.length)this.component= !1;if(this.isInput)this.element.on({focus:e.proxy(this.show,this),blur:e.proxy(this._hide,this),keyup:e.proxy(this.update,this),keydown:e.proxy(this.keydown,this)});else if(this.component)this.component.on("click",e.proxy(this.show,this)),a=this.element.find("input"),a.on({blur:e.proxy(this._hide,this)});else this.element.on("click",e.proxy(this.show,this));this.autoclose=!1;"autoclose"in b?this.autoclose=b.autoclose:"dateAutoclose"in this.element.data()&&(this.autoclose=this.element.data("date-autoclose")); switch(b.startView){case 2:case "decade":this.viewMode=this.startViewMode=2;break;case 1:case "year":this.viewMode=this.startViewMode=1;break;default:this.viewMode=this.startViewMode=0}this.weekStart=(b.weekStart||this.element.data("date-weekstart")||l[this.language].weekStart||0)%7;this.weekEnd=(this.weekStart+6)%7;this.startDate=-Infinity;this.endDate=Infinity;this.setStartDate(b.startDate||this.element.data("date-startdate"));this.setEndDate(b.endDate||this.element.data("date-enddate"));this.fillDow(); this.fillMonths();this.update();this.showMode()};m.prototype={constructor:m,show:function(a){this.picker.show();this.height=this.component?this.component.outerHeight():this.element.outerHeight();this.place();e(window).on("resize",e.proxy(this.place,this));a&&(a.stopPropagation(),a.preventDefault());if(!this.isInput)e(document).on("mousedown",e.proxy(this.hide,this));this.element.trigger({type:"show",date:this.date})},_hide:function(a){if(e.browser.msie){var b=this,c=arguments,f=function(){clearTimeout(j); a.target.focus();b.picker.off("click",f)};this.picker.on("click",f);var j=setTimeout(function(){b.hide.apply(b,c);b.picker.off("click",f)},100)}else return this.hide.apply(this,arguments)},hide:function(a){this.picker.hide();e(window).off("resize",this.place);this.viewMode=this.startViewMode;this.showMode();this.isInput||e(document).off("mousedown",this.hide);a&&a.currentTarget.value&&this.setValue();this.element.trigger({type:"hide",date:this.date})},setValue:function(){var a=g.formatDate(this.date, this.format,this.language);this.isInput?this.element.prop("value",a):(this.component&&this.element.find("input").prop("value",a),this.element.data("date",a))},setStartDate:function(a){this.startDate=a||-Infinity;-Infinity!==this.startDate&&(this.startDate=g.parseDate(this.startDate,this.format,this.language));this.update();this.updateNavArrows()},setEndDate:function(a){this.endDate=a||Infinity;Infinity!==this.endDate&&(this.endDate=g.parseDate(this.endDate,this.format,this.language));this.update(); this.updateNavArrows()},place:function(){var a=this.component?this.component.offset():this.element.offset(),b=e(window).width()-a.left,c=this.component?this.component.outerWidth():0;208>b?this.picker.addClass("dp_right").css({top:a.top+this.height,right:b-c,left:"auto"}):this.picker.css({top:a.top+this.height,left:a.left})},update:function(){this.date=g.parseDate(this.isInput?this.element.prop("value"):this.element.data("date"),this.format,this.language);this.viewDate=this.date<this.startDate?new Date(this.startDate): this.date>this.endDate?new Date(this.endDate):new Date(this.date);this.fill()},fillDow:function(){for(var a=this.weekStart,b="<tr>";a<this.weekStart+7;)b+='<th class="dow">'+l[this.language].daysMin[a++%7]+"</th>";this.picker.find(".datepicker-days thead").append(b+"</tr>")},fillMonths:function(){for(var a="",b=0;12>b;)a+='<span class="month">'+l[this.language].monthsShort[b++]+"</span>";this.picker.find(".datepicker-months td").html(a)},fill:function(){var a=new Date(this.viewDate),b=a.ge