/** * version 2.1.11 * @license * ========================================================= * bootstrap-datetimepicker.js * http://www.eyecon.ro/bootstrap-datepicker * ========================================================= * Copyright 2012 Stefan Petre * * Contributions: * - updated for Bootstrap v3 by Jonathan Peterson (@Eonasdan) and (almost) * completely rewritten to use Momentjs * - based on tarruda's bootstrap-datepicker * * 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($){if(typeof moment==="undefined"){alert("momentjs is requried");throw new Error("momentjs is requried")}var dpgId=0,pMoment=moment,DateTimePicker=function(element,options){var defaults={pickDate:true,pickTime:true,startDate:new pMoment({y:1970}),endDate:(new pMoment).add(50,"y"),collapse:true,language:"en",defaultDate:"",disabledDates:[],icons:{},useStrict:false},icons={time:"glyphicon glyphicon-time",date:"glyphicon glyphicon-calendar",up:"glyphicon glyphicon-chevron-up",down:"glyphicon glyphicon-chevron-down"},picker=this,init=function(){var icon=false,i,dDate,longDateFormat;picker.options=$.extend({},defaults,options);picker.options.icons=$.extend({},icons,picker.options.icons);if(!(picker.options.pickTime||picker.options.pickDate))throw new Error("Must choose at least one picker");picker.id=dpgId++;pMoment.lang(picker.options.language);picker.date=pMoment();picker.element=$(element);picker.unset=false;picker.isInput=picker.element.is("input");picker.component=false;if(picker.element.hasClass("input-group")){if(picker.element.find(".datepickerbutton").size()==0){picker.component=picker.element.find(".input-group-addon")}else{picker.component=picker.element.find(".datepickerbutton")}}picker.format=picker.options.format;longDateFormat=pMoment()._lang._longDateFormat;if(!picker.format){if(picker.isInput)picker.format=picker.element.data("format");else picker.format=picker.element.find("input").data("format");if(!picker.format){picker.format=picker.options.pickDate?longDateFormat.L:"";if(picker.options.pickDate&&picker.options.pickTime)picker.format+=" ";picker.format+=picker.options.pickTime?longDateFormat.LT:""}}picker.use24hours=picker.format.toLowerCase().indexOf("a")<1;if(picker.component)icon=picker.component.find("span");if(picker.options.pickTime){if(icon)icon.addClass(picker.options.icons.time)}if(picker.options.pickDate){if(icon){icon.removeClass(picker.options.icons.time);icon.addClass(picker.options.icons.date)}}picker.widget=$(getTemplate(picker.options.pickDate,picker.options.pickTime,picker.options.collapse)).appendTo("body");picker.minViewMode=picker.options.minViewMode||picker.element.data("date-minviewmode")||0;if(typeof picker.minViewMode==="string"){switch(picker.minViewMode){case"months":picker.minViewMode=1;break;case"years":picker.minViewMode=2;break;default:picker.minViewMode=0;break}}picker.viewMode=picker.options.viewMode||picker.element.data("date-viewmode")||0;if(typeof picker.viewMode==="string"){switch(picker.viewMode){case"months":picker.viewMode=1;break;case"years":picker.viewMode=2;break;default:picker.viewMode=0;break}}for(i=0;i"),weekdaysMin=pMoment.weekdaysMin(),i;if(pMoment()._lang._week.dow==0){for(i=0;i<7;i++){html.append(''+weekdaysMin[i]+"")}}else{for(i=1;i<8;i++){if(i==7){html.append(''+weekdaysMin[0]+"")}else{html.append(''+weekdaysMin[i]+"")}}}picker.widget.find(".datepicker-days thead").append(html)},fillMonths=function(){pMoment.lang(picker.options.language);var html="",i=0,monthsShort=pMoment.monthsShort();while(i<12){html+=''+monthsShort[i++]+""}picker.widget.find(".datepicker-months td").append(html)},fillDate=function(){pMoment.lang(picker.options.language);var year=picker.viewDate.year(),month=picker.viewDate.month(),startYear=picker.options.startDate.year(),startMonth=picker.options.startDate.month(),endYear=picker.options.endDate.year(),endMonth=picker.options.endDate.month(),prevMonth,nextMonth,html=[],row,clsName,i,days,yearCont,currentYear,months=pMoment.months();picker.widget.find(".datepicker-days").find(".disabled").removeClass("disabled");picker.widget.find(".datepicker-months").find(".disabled").removeClass("disabled");picker.widget.find(".datepicker-years").find(".disabled").removeClass("disabled");picker.widget.find(".datepicker-days th:eq(1)").text(months[month]+" "+year);prevMonth=pMoment(picker.viewDate).subtract("months",1);days=prevMonth.daysInMonth();prevMonth.date(days).startOf("week");if(year==startYear&&month<=startMonth||year=endMonth||year>endYear){picker.widget.find(".datepicker-days th:eq(2)").addClass("disabled")}nextMonth=pMoment(prevMonth).add(42,"d");while(prevMonth.isBefore(nextMonth)){if(prevMonth.weekday()===pMoment().startOf("week").weekday()){row=$("");html.push(row)}clsName="";if(prevMonth.year()year||prevMonth.year()==year&&prevMonth.month()>month){clsName+=" new"}if(prevMonth.isSame(pMoment({y:picker.date.year(),M:picker.date.month(),d:picker.date.date()}))){clsName+=" active"}if(pMoment(prevMonth).add(1,"d")<=picker.options.startDate||prevMonth>picker.options.endDate||isInDisableDates(prevMonth)){clsName+=" disabled"}row.append(''+prevMonth.date()+"");prevMonth.add(1,"d")}picker.widget.find(".datepicker-days tbody").empty().append(html);currentYear=pMoment().year(),months=picker.widget.find(".datepicker-months").find("th:eq(1)").text(year).end().find("span").removeClass("active");if(currentYear===year){months.eq(pMoment().month()).addClass("active")}if(currentYear-1endYear){picker.widget.find(".datepicker-months th:eq(2)").addClass("disabled")}for(i=0;i<12;i++){if(year==startYear&&startMonth>i||yearendYear){$(months[i]).addClass("disabled")}}html="";year=parseInt(year/10,10)*10;yearCont=picker.widget.find(".datepicker-years").find("th:eq(1)").text(year+"-"+(year+9)).end().find("td");picker.widget.find(".datepicker-years").find("th").removeClass("disabled");if(startYear>year){picker.widget.find(".datepicker-years").find("th:eq(0)").addClass("disabled")}if(endYearendYear?" disabled":"")+'">'+year+"";year+=1}yearCont.html(html)},fillHours=function(){pMoment.lang(picker.options.language);var table=picker.widget.find(".timepicker .timepicker-hours table"),html="",current,i,j;table.parent().hide();if(picker.use24hours){current=0;for(i=0;i<6;i+=1){html+="";for(j=0;j<4;j+=1){html+=''+padLeft(current.toString())+"";current++}html+=""}}else{current=1;for(i=0;i<3;i+=1){html+="";for(j=0;j<4;j+=1){html+=''+padLeft(current.toString())+"";current++}html+=""}}table.html(html)},fillMinutes=function(){var table=picker.widget.find(".timepicker .timepicker-minutes table"),html="",current=0,i,j;table.parent().hide();for(i=0;i<5;i++){html+="";for(j=0;j<4;j+=1){html+=''+padLeft(current.toString())+"";current+=3}html+=""}table.html(html)},fillTime=function(){if(!picker.date)return;var timeComponents=picker.widget.find(".timepicker span[data-time-component]"),hour=picker.date.hours(),period="AM";if(!picker.use24hours){if(hour>=12)period="PM";if(hour===0)hour=12;else if(hour!=12)hour=hour%12;picker.widget.find(".timepicker [data-action=togglePeriod]").text(period)}timeComponents.filter("[data-time-component=hours]").text(padLeft(hour));timeComponents.filter("[data-time-component=minutes]").text(padLeft(picker.date.minutes()))},click=function(e){e.stopPropagation();e.preventDefault();picker.unset=false;var target=$(e.target).closest("span, td, th"),month,year,step,day,oldDate=picker.date;if(target.length===1){if(!target.is(".disabled")){switch(target[0].nodeName.toLowerCase()){case"th":switch(target[0].className){case"switch":showMode(1);break;case"prev":case"next":step=dpGlobal.modes[picker.viewMode].navStep;if(target[0].className==="prev")step=step*-1;picker.viewDate.add(step,dpGlobal.modes[picker.viewMode].navFnc);fillDate();break}break;case"span":if(target.is(".month")){month=target.parent().find("span").index(target);picker.viewDate.month(month)}else{year=parseInt(target.text(),10)||0;picker.viewDate.year(year)}if(picker.viewMode!==0){picker.date=pMoment({y:picker.viewDate.year(),M:picker.viewDate.month(),d:picker.viewDate.date(),h:picker.date.hours(),m:picker.date.minutes()});notifyChange(oldDate)}showMode(-1);fillDate();break;case"td":if(target.is(".day")){day=parseInt(target.text(),10)||1;month=picker.viewDate.month();year=picker.viewDate.year();if(target.is(".old")){if(month===0){month=11;year-=1}else{month-=1}}else if(target.is(".new")){if(month==11){month=0;year+=1}else{month+=1}}picker.date=pMoment({y:year,M:month,d:day,h:picker.date.hours(),m:picker.date.minutes()});picker.viewDate=pMoment({y:year,M:month,d:Math.min(28,day)});fillDate();set();notifyChange(oldDate)}break}}}},actions={incrementHours:function(){checkDate("add","hours")},incrementMinutes:function(){checkDate("add","minutes")},decrementHours:function(){checkDate("subtract","hours")},decrementMinutes:function(){checkDate("subtract","minutes")},togglePeriod:function(){var hour=picker.date.hours();if(hour>=12)hour-=12;else hour+=12;picker.date.hours(hour)},showPicker:function(){picker.widget.find(".timepicker > div:not(.timepicker-picker)").hide();picker.widget.find(".timepicker .timepicker-picker").show()},showHours:function(){picker.widget.find(".timepicker .timepicker-picker").hide();picker.widget.find(".timepicker .timepicker-hours").show()},showMinutes:function(){picker.widget.find(".timepicker .timepicker-picker").hide();picker.widget.find(".timepicker .timepicker-minutes").show()},selectHour:function(e){picker.date.hours(parseInt($(e.target).text(),10));actions.showPicker.call(picker)},selectMinute:function(e){picker.date.minutes(parseInt($(e.target).text(),10));actions.showPicker.call(picker)}},doAction=function(e){var action=$(e.currentTarget).data("action"),rv=actions[action].apply(picker,arguments),oldDate=picker.date;stopEvent(e);if(!picker.date)picker.date=pMoment({y:1970});set();fillTime();notifyChange(oldDate);return rv},stopEvent=function(e){e.stopPropagation();e.preventDefault()},change=function(e){pMoment.lang(picker.options.language);var input=$(e.target),oldDate=picker.date,d=pMoment(input.val(),picker.format,picker.options.useStrict);if(d.isValid()){update();picker.setValue(d);notifyChange(oldDate);set()}else{picker.viewDate=oldDate;notifyChange(oldDate);notifyError(d);picker.unset=true;input.val("")}},showMode=function(dir){if(dir){picker.viewMode=Math.max(picker.minViewMode,Math.min(2,picker.viewMode+dir))}picker.widget.find(".datepicker > div").hide().filter(".datepicker-"+dpGlobal.modes[picker.viewMode].clsName).show()},attachDatePickerEvents=function(){var $this,$parent,expanded,closed,collapseData;picker.widget.on("click",".datepicker *",$.proxy(click,this));picker.widget.on("click","[data-action]",$.proxy(doAction,this));picker.widget.on("mousedown",$.proxy(stopEvent,this));if(picker.options.pickDate&&picker.options.pickTime){picker.widget.on("click.togglePicker",".accordion-toggle",function(e){e.stopPropagation();$this=$(this);$parent=$this.closest("ul");expanded=$parent.find(".in");closed=$parent.find(".collapse:not(.in)");if(expanded&&expanded.length){collapseData=expanded.data("collapse");if(collapseData&&collapseData.transitioning)return;expanded.collapse("hide");closed.collapse("show");$this.find("span").toggleClass(picker.options.icons.time+" "+picker.options.icons.date);picker.element.find(".input-group-addon span").toggleClass(picker.options.icons.time+" "+picker.options.icons.date)}})}if(picker.isInput){picker.element.on({focus:$.proxy(picker.show,this),change:$.proxy(change,this),blur:$.proxy(picker.hide,this)})}else{picker.element.on({change:$.proxy(change,this)},"input");if(picker.component){picker.component.on("click",$.proxy(picker.show,this))}else{picker.element.on("click",$.proxy(picker.show,this))}}},attachDatePickerGlobalEvents=function(){$(window).on("resize.datetimepicker"+picker.id,$.proxy(place,this));if(!picker.isInput){$(document).on("mousedown.datetimepicker"+picker.id,$.proxy(picker.hide,this))}},detachDatePickerEvents=function(){picker.widget.off("click",".datepicker *",picker.click);picker.widget.off("click","[data-action]");picker.widget.off("mousedown",picker.stopEvent);if(picker.options.pickDate&&picker.options.pickTime){picker.widget.off("click.togglePicker")}if(picker.isInput){picker.element.off({focus:picker.show,change:picker.change})}else{picker.element.off({change:picker.change},"input");if(picker.component){picker.component.off("click",picker.show)}else{picker.element.off("click",picker.show)}}},detachDatePickerGlobalEvents=function(){$(window).off("resize.datetimepicker"+picker.id);if(!picker.isInput){$(document).off("mousedown.datetimepicker"+picker.id)}},isInFixed=function(){if(picker.element){var parents=picker.element.parents(),inFixed=false,i;for(i=0;i=2)return string;else return"0"+string},getTemplate=function(pickDate,pickTime,collapse){if(pickDate&&pickTime){return'"}else if(pickTime){return'"}else{return'"}},dpGlobal={modes:[{clsName:"days",navFnc:"month",navStep:1},{clsName:"months",navFnc:"year",navStep:1},{clsName:"years",navFnc:"year",navStep:10}],headTemplate:""+""+'‹›'+""+"",contTemplate:''},tpGlobal={hourTemplate:'',minuteTemplate:''};dpGlobal.template='
'+''+dpGlobal.headTemplate+"
"+"
"+'
'+''+dpGlobal.headTemplate+dpGlobal.contTemplate+"
"+"
"+'
'+''+dpGlobal.headTemplate+dpGlobal.contTemplate+"
"+"
";tpGlobal.getTemplate=function(){return'
'+''+""+''+''+''+(!picker.use24hours?'':"")+""+""+" "+''+" "+(!picker.use24hours?''+'':"")+""+""+''+''+''+(!picker.use24hours?'':"")+""+"
"+tpGlobal.hourTemplate+":"+tpGlobal.minuteTemplate+"
"+"
"+'
'+'
'+"
"+'
'+'
'+"
"};picker.destroy=function(){detachDatePickerEvents();detachDatePickerGlobalEvents();picker.widget.remove();picker.element.removeData("DateTimePicker");if(picker.component)picker.component.removeData("DateTimePicker")};picker.show=function(e){picker.widget.show();picker.height=picker.component?picker.component.outerHeight():picker.element.outerHeight();place();picker.element.trigger({type:"show.dp",date:picker.date});attachDatePickerGlobalEvents();if(e){stopEvent(e)}},picker.disable=function(){picker.element.find("input").prop("disabled",true);detachDatePickerEvents()},picker.enable=function(){picker.element.find("input").prop("disabled",false);attachDatePickerEvents()},picker.hide=function(){var collapse=picker.widget.find(".collapse"),i,collapseData;for(i=0;i