diff --git a/README.md b/README.md index d4c798ce8..8ca245cb5 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,23 @@ ![DateTimePicker](http://i.imgur.com/nfnvh5g.png) -### [⇢ Manual and demo](http://eonasdan.github.io/bootstrap-datetimepicker/) +### [⇢ View the manual and demos](http://eonasdan.github.io/bootstrap-datetimepicker/) -## Quick installation using [bower](http://bower.io): +## Quick installation using + +## [bower](http://bower.io): Run the following command: ```` bower install eonasdan-bootstrap-datetimepicker#latest --save ```` +## [Nuget](https://www.nuget.org/packages/Bootstrap.v3.Datetimepicker/): +```` +PM> Install-Package Bootstrap.v3.Datetimepicker +```` + +## See the [Change Log](#change-log) for important changes and updates Include necessary scripts and styles: ````html @@ -19,7 +27,7 @@ Include necessary scripts and styles: - + @@ -32,7 +40,7 @@ Done! [Now take a look at the manual](http://eonasdan.github.io/bootstrap-dateti ## Manual installation ### [Moment.js](https://github.com/moment/moment) -Datetimepicker requires moment.js in version 2.3.1 (we're working on supporting higher versions). This allows for better support for various date formats and locales. See [documentation](http://eonasdan.github.io/bootstrap-datetimepicker/) for examples. Check [Momentjs' homepage](http://momentjs.com/) for documentation on date formats. If you can't use moment.js there's still older version of datetimewidget [available here](https://github.com/Eonasdan/bootstrap-datetimepicker/tree/version1). +Datetimepicker requires moment.js. This allows for better support for various date formats and locales. See [documentation](http://eonasdan.github.io/bootstrap-datetimepicker/) for examples. Check [Momentjs' homepage](http://momentjs.com/) for documentation on date formats. If you can't use moment.js there's still older version of datetimewidget [available here](https://github.com/Eonasdan/bootstrap-datetimepicker/tree/version1). ````html @@ -75,13 +83,16 @@ Finally include the main javascript file. ```` -#### Installation using Nuget +# Change Log -````` -PM> Install-Package Bootstrap.v3.Datetimepicker -````` -More information: https://www.nuget.org/packages/Bootstrap.v3.Datetimepicker/ +## New features (2.1.20)! +* Fix for #83: Changes to the picker should fire native `change` event for knockout and the like as well as `change.dp` which contains the old date and the new date +* Fix for #78: Script has been update for breaking changes in Moment 2.4.0 +* Fix for #73: IE8 should be working now +* Enhancement for #79: `minuteStepping` option takes a number (default is 1). Changing the minutes in the time picker will step by this number. +* Enhancement for #74 and #65: `useMinutes` and `useSeconds` are now options. Disabling seconds will hide the seconds spinner. Disabling minutes will display `00` and hide the arrows +* Enhancement for #67: Picker will now attempt to convert all `data-OPTION` into its appropriate option ## New features (2.1.11)! * Fix for #51, #60 diff --git a/build/js/bootstrap-datetimepicker.min.js b/build/js/bootstrap-datetimepicker.min.js index 3bc74fcbb..0b1c8b6f1 100644 --- a/build/js/bootstrap-datetimepicker.min.js +++ b/build/js/bootstrap-datetimepicker.min.js @@ -1,5 +1,5 @@ /** - * version 2.1.11 + * version 2.1.20 * @license * ========================================================= * bootstrap-datetimepicker.js @@ -25,4 +25,4 @@ * 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"),Q=a.weekdaysMin(),R;if(a()._lang._week.dow==0){for(R=0;R<7;R++){S.append(''+Q[R]+"")}}else{for(R=1;R<8;R++){if(R==7){S.append(''+Q[0]+"")}else{S.append(''+Q[R]+"")}}}l.widget.find(".datepicker-days thead").append(S)},u=function(){a.lang(l.options.language);var R="",Q=0,S=a.monthsShort();while(Q<12){R+=''+S[Q++]+""}l.widget.find(".datepicker-months td").append(R)},n=function(){a.lang(l.options.language);var ab=l.viewDate.year(),Z=l.viewDate.month(),aa=l.options.startDate.year(),ad=l.options.startDate.month(),ae=l.options.endDate.year(),X=l.options.endDate.month(),T,W,V=[],af,S,U,ac,R,Y,Q=a.months();l.widget.find(".datepicker-days").find(".disabled").removeClass("disabled");l.widget.find(".datepicker-months").find(".disabled").removeClass("disabled");l.widget.find(".datepicker-years").find(".disabled").removeClass("disabled");l.widget.find(".datepicker-days th:eq(1)").text(Q[Z]+" "+ab);T=a(l.viewDate).subtract("months",1);ac=T.daysInMonth();T.date(ac).startOf("week");if((ab==aa&&Z<=ad)||ab=X)||ab>ae){l.widget.find(".datepicker-days th:eq(2)").addClass("disabled")}W=a(T).add(42,"d");while(T.isBefore(W)){if(T.weekday()===a().startOf("week").weekday()){af=d("");V.push(af)}S="";if(T.year()ab||(T.year()==ab&&T.month()>Z)){S+=" new"}}if(T.isSame(a({y:l.date.year(),M:l.date.month(),d:l.date.date()}))){S+=" active"}if((a(T).add(1,"d")<=l.options.startDate)||(T>l.options.endDate)||O(T)||!s(T)){S+=" disabled"}af.append(''+T.date()+"");T.add(1,"d")}l.widget.find(".datepicker-days tbody").empty().append(V);Y=a().year(),Q=l.widget.find(".datepicker-months").find("th:eq(1)").text(ab).end().find("span").removeClass("active");if(Y===ab){Q.eq(a().month()).addClass("active")}if(Y-1ae){l.widget.find(".datepicker-months th:eq(2)").addClass("disabled")}for(U=0;U<12;U++){if((ab==aa&&ad>U)||(abae)){d(Q[U]).addClass("disabled")}}}V="";ab=parseInt(ab/10,10)*10;R=l.widget.find(".datepicker-years").find("th:eq(1)").text(ab+"-"+(ab+9)).end().find("td");l.widget.find(".datepicker-years").find("th").removeClass("disabled");if(aa>ab){l.widget.find(".datepicker-years").find("th:eq(0)").addClass("disabled")}if(aeae)?" disabled":"")+'">'+ab+"";ab+=1}R.html(V)},v=function(){a.lang(l.options.language);var T=l.widget.find(".timepicker .timepicker-hours table"),S="",U,R,Q;T.parent().hide();if(l.options.use24hours){U=0;for(R=0;R<6;R+=1){S+="";for(Q=0;Q<4;Q+=1){S+=''+N(U.toString())+"";U++}S+=""}}else{U=1;for(R=0;R<3;R+=1){S+="";for(Q=0;Q<4;Q+=1){S+=''+N(U.toString())+"";U++}S+=""}}T.html(S)},t=function(){var T=l.widget.find(".timepicker .timepicker-minutes table"),S="",U=0,R,Q;T.parent().hide();for(R=0;R<5;R++){S+="";for(Q=0;Q<4;Q+=1){S+=''+N(U.toString())+"";U+=3}S+=""}T.html(S)},h=function(){var T=l.widget.find(".timepicker .timepicker-seconds table"),S="",U=0,R,Q;T.parent().hide();for(R=0;R<5;R++){S+="";for(Q=0;Q<4;Q+=1){S+=''+N(U.toString())+"";U+=3}S+=""}T.html(S)},k=function(){if(!l.date){return}var S=l.widget.find(".timepicker span[data-time-component]"),Q=l.date.hours(),R="AM";if(!l.options.use24hours){if(Q>=12){R="PM"}if(Q===0){Q=12}else{if(Q!=12){Q=Q%12}}l.widget.find(".timepicker [data-action=togglePeriod]").text(R)}S.filter("[data-time-component=hours]").text(N(Q));S.filter("[data-time-component=minutes]").text(N(l.date.minutes()));S.filter("[data-time-component=seconds]").text(N(l.date.second()))},A=function(W){W.stopPropagation();W.preventDefault();l.unset=false;var V=d(W.target).closest("span, td, th"),U,S,T,Q,R=a(l.date);if(V.length===1){if(!V.is(".disabled")){switch(V[0].nodeName.toLowerCase()){case"th":switch(V[0].className){case"switch":g(1);break;case"prev":case"next":T=w.modes[l.viewMode].navStep;if(V[0].className==="prev"){T=T*-1}l.viewDate.add(T,w.modes[l.viewMode].navFnc);n();break}break;case"span":if(V.is(".month")){U=V.parent().find("span").index(V);l.viewDate.month(U)}else{S=parseInt(V.text(),10)||0;l.viewDate.year(S)}if(l.viewMode!==0){l.date=a({y:l.viewDate.year(),M:l.viewDate.month(),d:l.viewDate.date(),h:l.date.hours(),m:l.date.minutes()});p(R,W.type)}g(-1);n();break;case"td":if(V.is(".day")){Q=parseInt(V.text(),10)||1;U=l.viewDate.month();S=l.viewDate.year();if(V.is(".old")){if(U===0){U=11;S-=1}else{U-=1}}else{if(V.is(".new")){if(U==11){U=0;S+=1}else{U+=1}}}l.date=a({y:S,M:U,d:Q,h:l.date.hours(),m:l.date.minutes()});l.viewDate=a({y:S,M:U,d:Math.min(28,Q)});n();r();p(R,W.type)}break}}}},D={incrementHours:function(){m("add","hours",1)},incrementMinutes:function(){m("add","minutes",l.options.minuteStepping)},incrementSeconds:function(){m("add","seconds",1)},decrementHours:function(){m("subtract","hours",1)},decrementMinutes:function(){m("subtract","minutes",l.options.minuteStepping)},decrementSeconds:function(){m("subtract","seconds",1)},togglePeriod:function(){var Q=l.date.hours();if(Q>=12){Q-=12}else{Q+=12}l.date.hours(Q)},showPicker:function(){l.widget.find(".timepicker > div:not(.timepicker-picker)").hide();l.widget.find(".timepicker .timepicker-picker").show()},showHours:function(){l.widget.find(".timepicker .timepicker-picker").hide();l.widget.find(".timepicker .timepicker-hours").show()},showMinutes:function(){l.widget.find(".timepicker .timepicker-picker").hide();l.widget.find(".timepicker .timepicker-minutes").show()},showSeconds:function(){l.widget.find(".timepicker .timepicker-picker").hide();l.widget.find(".timepicker .timepicker-seconds").show()},selectHour:function(Q){l.date.hours(parseInt(d(Q.target).text(),10));D.showPicker.call(l)},selectMinute:function(Q){l.date.minutes(parseInt(d(Q.target).text(),10));D.showPicker.call(l)},selectSecond:function(Q){l.date.seconds(parseInt(d(Q.target).text(),10));D.showPicker.call(l)}},x=function(S){var Q=a(l.date),R=d(S.currentTarget).data("action"),T=D[R].apply(l,arguments);K(S);if(!l.date){l.date=a({y:1970})}r();k();p(Q);return T},K=function(Q){Q.stopPropagation();Q.preventDefault()},i=function(S){a.lang(l.options.language);var Q=d(S.target),R=a(l.date),T=a(Q.val(),l.format,l.options.useStrict);if(T.isValid()){y();l.setValue(T);p(R);r()}else{l.viewDate=R;p(R);C(T);l.unset=true;Q.val("")}},g=function(Q){if(Q){l.viewMode=Math.max(l.minViewMode,Math.min(2,l.viewMode+Q))}l.widget.find(".datepicker > div").hide().filter(".datepicker-"+w.modes[l.viewMode].clsName).show()},J=function(){var U,T,R,Q,S;l.widget.on("click",".datepicker *",d.proxy(A,this));l.widget.on("click","[data-action]",d.proxy(x,this));l.widget.on("mousedown",d.proxy(K,this));if(l.options.pickDate&&l.options.pickTime){l.widget.on("click.togglePicker",".accordion-toggle",function(V){V.stopPropagation();U=d(this);T=U.closest("ul");R=T.find(".in");Q=T.find(".collapse:not(.in)");if(R&&R.length){S=R.data("collapse");if(S&&S.transitioning){return}R.collapse("hide");Q.collapse("show");U.find("span").toggleClass(l.options.icons.time+" "+l.options.icons.date);l.element.find(".input-group-addon span").toggleClass(l.options.icons.time+" "+l.options.icons.date)}})}if(l.isInput){l.element.on({focus:d.proxy(l.show,this),change:d.proxy(i,this),blur:d.proxy(l.hide,this)})}else{l.element.on({change:d.proxy(i,this)},"input");if(l.component){l.component.on("click",d.proxy(l.show,this))}else{l.element.on("click",d.proxy(l.show,this))}}},L=function(){d(window).on("resize.datetimepicker"+l.id,d.proxy(j,this));if(!l.isInput){d(document).on("mousedown.datetimepicker"+l.id,d.proxy(l.hide,this))}},F=function(){l.widget.off("click",".datepicker *",l.click);l.widget.off("click","[data-action]");l.widget.off("mousedown",l.stopEvent);if(l.options.pickDate&&l.options.pickTime){l.widget.off("click.togglePicker")}if(l.isInput){l.element.off({focus:l.show,change:l.change})}else{l.element.off({change:l.change},"input");if(l.component){l.component.off("click",l.show)}else{l.element.off("click",l.show)}}},E=function(){d(window).off("resize.datetimepicker"+l.id);if(!l.isInput){d(document).off("mousedown.datetimepicker"+l.id)}},B=function(){if(l.element){var R=l.element.parents(),Q=false,S;for(S=0;S=2){return Q}else{return"0"+Q}},P=function(R,Q,S){if(R&&Q){return('")}else{if(Q){return('")}else{return('")}}},w={modes:[{clsName:"days",navFnc:"month",navStep:1},{clsName:"months",navFnc:"year",navStep:1},{clsName:"years",navFnc:"year",navStep:10}],headTemplate:'‹›',contTemplate:''},G={hourTemplate:'',minuteTemplate:'',secondTemplate:''};w.template='
'+w.headTemplate+'
'+w.headTemplate+w.contTemplate+'
'+w.headTemplate+w.contTemplate+"
";G.getTemplate=function(){return('
"+(l.options.useSeconds?'':"")+(l.options.use24hours?"":'')+" "+(l.options.useSeconds?'":"")+(l.options.use24hours?"":'')+'"+(l.options.useSeconds?'':"")+(l.options.use24hours?"":'')+'
'+(l.options.useMinutes?'':"")+"
"+G.hourTemplate+' :'+(l.options.useMinutes?G.minuteTemplate:'00')+":'+G.secondTemplate+"
'+(l.options.useMinutes?'':"")+"
'+(l.options.useSeconds?'
':""))};l.destroy=function(){F();E();l.widget.remove();l.element.removeData("DateTimePicker");if(l.component){l.component.removeData("DateTimePicker")}};l.show=function(Q){l.widget.show();l.height=l.component?l.component.outerHeight():l.element.outerHeight();j();l.element.trigger({type:"show.dp",date:a(l.date)});L();if(Q){K(Q)}},l.disable=function(){var Q=l.element.find("input");if(!Q.prop("disabled")){return}Q.prop("disabled",true);F()},l.enable=function(){var Q=l.element.find("input");if(!Q.prop("disabled")){return}Q.prop("disabled",true);J()},l.hide=function(S){if(S&&d(S.target).is(l.element.attr("id"))){return}var T=l.widget.find(".collapse"),Q,R;for(Q=0;Q=1.8.3", "bootstrap" : ">=3.0", - "moment": ">=2.3.1" + "moment": ">=2.4.0" } } diff --git a/package.json b/package.json index cda414837..099626cdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-datetimepicker", - "version": "2.1.11", + "version": "2.1.20", "repository": { "type": "git", "url": "git://github.com/eonasdan/bootstrap-datetimepicker.git" diff --git a/src/js/bootstrap-datetimepicker.js b/src/js/bootstrap-datetimepicker.js index 83c71f382..201234eb4 100644 --- a/src/js/bootstrap-datetimepicker.js +++ b/src/js/bootstrap-datetimepicker.js @@ -1,5 +1,5 @@ /** - * version 2.1.11 + * version 2.1.20 * @license * ========================================================= * bootstrap-datetimepicker.js @@ -39,7 +39,9 @@ factory(jQuery, moment); } } -}(function ($, moment) { +} + +(function ($, moment) { if (typeof moment === 'undefined') { alert("momentjs is requried"); throw new Error('momentjs is requried'); @@ -54,13 +56,16 @@ var defaults = { pickDate: true, pickTime: true, + useMinutes: true, + useSeconds: false, + minuteStepping: 1, startDate: new pMoment({ y: 1970 }), endDate: new pMoment().add(50, "y"), collapse: true, language: "en", defaultDate: "", disabledDates: [], - enabledDates: false, // array + enabledDates: false, icons: {}, useStrict: false }, @@ -79,14 +84,17 @@ var icon = false, i, dDate, longDateFormat; picker.options = $.extend({}, defaults, options); picker.options.icons = $.extend({}, icons, picker.options.icons); - + + picker.element = $(element); + + dataToOptions(); + 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; @@ -110,10 +118,18 @@ picker.format = (picker.options.pickDate ? longDateFormat.L : ''); if (picker.options.pickDate && picker.options.pickTime) picker.format += ' '; picker.format += (picker.options.pickTime ? longDateFormat.LT : ''); + if (picker.options.useSeconds) { + if (~longDateFormat.LT.indexOf(' A')) { + picker.format = picker.format.split(" A")[0] + ":ss A"; + } + else { + picker.format += ':ss'; + } + } } } - picker.use24hours = picker.format.toLowerCase().indexOf("a") < 1; + picker.options.use24hours = picker.format.toLowerCase().indexOf("a") < 1; if (picker.component) icon = picker.component.find('span'); @@ -172,7 +188,6 @@ if (!dDate.isValid()) dDate = pMoment(picker.options.startDate).subtract(1, "day"); picker.options.enabledDates[i] = dDate.format("L"); } - picker.startViewMode = picker.viewMode; picker.setStartDate(picker.options.startDate || picker.element.data('date-startdate')); picker.setEndDate(picker.options.endDate || picker.element.data('date-enddate')); @@ -180,11 +195,30 @@ fillMonths(); fillHours(); fillMinutes(); + fillSeconds(); update(); showMode(); attachDatePickerEvents(); if (picker.options.defaultDate !== "") picker.setValue(picker.options.defaultDate); }, + + dataToOptions = function () { + var eData = picker.element.data(); + if (eData.pickdate !== undefined) picker.options.pickDate = eData.pickdate; + if (eData.picktime !== undefined) picker.options.pickTime = eData.picktime; + if (eData.useminutes !== undefined) picker.options.useMinutes = eData.useminutes; + if (eData.useseconds !== undefined) picker.options.useSeconds = eData.useseconds; + if (eData.minutestepping !== undefined) picker.options.minuteStepping = eData.minutestepping; + if (eData.startdate !== undefined) picker.options.startDate = eData.startdate; + if (eData.enddate !== undefined) picker.options.endDate = eData.enddate; + if (eData.collapse !== undefined) picker.options.collapse = eData.collapse; + if (eData.language !== undefined) picker.options.language = eData.language; + if (eData.defaultdate !== undefined) picker.options.defaultDate = eData.defaultdate; + if (eData.disableddates !== undefined) picker.options.disabledDates = eData.disableddates; + if (eData.enableddates !== undefined) picker.options.enabledDates = eData.enableddates; + if (eData.icons !== undefined) picker.options.icons = eData.icons; + if (eData.usestrict !== undefined) picker.options.useStrict = eData.usestrict; + }, place = function () { var position = 'absolute', @@ -226,18 +260,21 @@ }); }, - notifyChange = function (oldDate) { + notifyChange = function (oldDate, eventType) { picker.element.trigger({ type: 'change.dp', - date: picker.getDate(), - oldDate: oldDate + date: pMoment(picker.date), + oldDate: pMoment(oldDate) }); + + if (eventType !== 'change') + picker.element.change(); }, notifyError = function (date) { picker.element.trigger({ type: 'error.dp', - date: date + date: pMoment(date) }); }, @@ -377,7 +414,7 @@ pMoment.lang(picker.options.language); var table = picker.widget.find('.timepicker .timepicker-hours table'), html = '', current, i, j; table.parent().hide(); - if (picker.use24hours) { + if (picker.options.use24hours) { current = 0; for (i = 0; i < 6; i += 1) { html += ''; @@ -415,13 +452,27 @@ } table.html(html); }, + + fillSeconds = function () { + var table = picker.widget.find('.timepicker .timepicker-seconds 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 (!picker.options.use24hours) { if (hour >= 12) period = 'PM'; if (hour === 0) hour = 12; else if (hour != 12) hour = hour % 12; @@ -429,13 +480,14 @@ } timeComponents.filter('[data-time-component=hours]').text(padLeft(hour)); timeComponents.filter('[data-time-component=minutes]').text(padLeft(picker.date.minutes())); + timeComponents.filter('[data-time-component=seconds]').text(padLeft(picker.date.second())); }, 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; + var target = $(e.target).closest('span, td, th'), month, year, step, day, oldDate = pMoment(picker.date); if (target.length === 1) { if (!target.is('.disabled')) { switch (target[0].nodeName.toLowerCase()) { @@ -469,7 +521,7 @@ h: picker.date.hours(), m: picker.date.minutes() }); - notifyChange(oldDate); + notifyChange(oldDate, e.type); } showMode(-1); fillDate(); @@ -507,7 +559,7 @@ }); fillDate(); set(); - notifyChange(oldDate); + notifyChange(oldDate, e.type); } break; } @@ -517,19 +569,27 @@ actions = { incrementHours: function () { - checkDate("add", "hours"); + checkDate("add", "hours", 1); }, incrementMinutes: function () { - checkDate("add", "minutes"); + checkDate("add", "minutes", picker.options.minuteStepping); + }, + + incrementSeconds: function () { + checkDate("add", "seconds", 1); }, decrementHours: function () { - checkDate("subtract", "hours"); + checkDate("subtract", "hours", 1); }, decrementMinutes: function () { - checkDate("subtract", "minutes"); + checkDate("subtract", "minutes", picker.options.minuteStepping); + }, + + decrementSeconds: function () { + checkDate("subtract", "seconds", 1); }, togglePeriod: function () { @@ -554,6 +614,11 @@ picker.widget.find('.timepicker .timepicker-minutes').show(); }, + showSeconds: function () { + picker.widget.find('.timepicker .timepicker-picker').hide(); + picker.widget.find('.timepicker .timepicker-seconds').show(); + }, + selectHour: function (e) { picker.date.hours(parseInt($(e.target).text(), 10)); actions.showPicker.call(picker); @@ -562,11 +627,16 @@ selectMinute: function (e) { picker.date.minutes(parseInt($(e.target).text(), 10)); actions.showPicker.call(picker); + }, + + selectSecond: function (e) { + picker.date.seconds(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; + var oldDate = pMoment(picker.date), action = $(e.currentTarget).data('action'), rv = actions[action].apply(picker, arguments); stopEvent(e); if (!picker.date) picker.date = pMoment({ y: 1970 }); set(); @@ -582,7 +652,7 @@ change = function (e) { pMoment.lang(picker.options.language); - var input = $(e.target), oldDate = picker.date, d = pMoment(input.val(), picker.format, picker.options.useStrict); + var input = $(e.target), oldDate = pMoment(picker.date), d = pMoment(input.val(), picker.format, picker.options.useStrict); if (d.isValid()) { update(); picker.setValue(d); @@ -720,27 +790,27 @@ if (!picker.options.pickTime) picker.hide(); }, - checkDate = function (direction, unit) { + checkDate = function (direction, unit, amount) { pMoment.lang(picker.options.language); var newDate; if (direction == "add") { newDate = pMoment(picker.date); - if (newDate.hours() == 23) newDate.add(1, unit); - newDate.add(1, unit); + if (newDate.hours() == 23) newDate.add(amount, unit); + newDate.add(amount, unit); } else { - newDate = pMoment(picker.date).subtract(1, unit); + newDate = pMoment(picker.date).subtract(amount, unit); } - if (newDate.isAfter(picker.options.endDate) || newDate.subtract(1, unit).isBefore(picker.options.startDate) || isInDisableDates(newDate) || !isInEnableDates(newDate)) { + if (newDate.isAfter(picker.options.endDate) || pMoment(newDate.subtract(amount, unit)).isBefore(picker.options.startDate) || isInDisableDates(newDate)) { notifyError(newDate.format(picker.format)); return; } if (direction == "add") { - picker.date.add(1, unit); + picker.date.add(amount, unit); } else { - picker.date.subtract(1, unit); + picker.date.subtract(amount, unit); } }, @@ -768,7 +838,6 @@ } return enabled === false ? true : false; }, - padLeft = function (string) { string = string.toString(); if (string.length >= 2) return string; @@ -833,8 +902,9 @@ }, tpGlobal = { - hourTemplate: '', - minuteTemplate: '' + hourTemplate: '', + minuteTemplate: '', + secondTemplate: '' }; dpGlobal.template = @@ -855,21 +925,27 @@ '' + '' + '' + - '' + - (!picker.use24hours ? '' : '') + + '' + (picker.options.useMinutes ? '' : '') + '' + + (picker.options.useSeconds ? + '' : '') + + (picker.options.use24hours ? '' : '') + '' + '' + '' + tpGlobal.hourTemplate + ' ' + ':' + - '' + tpGlobal.minuteTemplate + ' ' + - (!picker.use24hours ? '' + - '' : '') + + '' + (picker.options.useMinutes ? tpGlobal.minuteTemplate : '00') + ' ' + + (picker.options.useSeconds ? + ':' + tpGlobal.secondTemplate + '' : '') + + (picker.options.use24hours ? '' : '' + + '') + '' + '' + '' + '' + - '' + - (!picker.use24hours ? '' : '') + + '' + (picker.options.useMinutes ? '' : '') + '' + + (picker.options.useSeconds ? + '' : '') + + (picker.options.use24hours ? '' : '') + '' + '' + '' + @@ -878,7 +954,9 @@ '' + '
' + '
' + - '
' + '' + + (picker.options.useSeconds ? + '
' : '') ); }; @@ -897,7 +975,7 @@ place(); picker.element.trigger({ type: 'show.dp', - date: picker.date + date: pMoment(picker.date) }); attachDatePickerGlobalEvents(); if (e) { @@ -906,16 +984,24 @@ }, picker.disable = function () { - picker.element.find('input').prop('disabled', true); + var input = picker.element.find('input'); + if(!input.prop('disabled')) return; + + input.prop('disabled', true); detachDatePickerEvents(); }, picker.enable = function () { - picker.element.find('input').prop('disabled', false); + var input = picker.element.find('input'); + if(!input.prop('disabled')) return; + + input.prop('disabled', true); attachDatePickerEvents(); }, - picker.hide = function () { + picker.hide = function (event) { + if (event && $(event.target).is(picker.element.attr("id"))) + return; // Ignore event if in the middle of a picker transition var collapse = picker.widget.find('.collapse'), i, collapseData; for (i = 0; i < collapse.length; i++) { @@ -928,7 +1014,7 @@ showMode(); picker.element.trigger({ type: 'hide.dp', - date: picker.date + date: pMoment(picker.date) }); detachDatePickerGlobalEvents(); }, @@ -959,6 +1045,7 @@ }, picker.setDate = function (date) { + date = pMoment(date); if (!date) picker.setValue(null); else picker.setValue(date); }, @@ -968,7 +1055,7 @@ else picker.options.enabledDates = dates; if (picker.viewDate) update(); }, - + picker.setEndDate = function (date) { picker.options.endDate = pMoment(date); if (!picker.options.endDate.isValid()) { @@ -994,4 +1081,4 @@ if (!data) $this.data('DateTimePicker', new DateTimePicker(this, options)); }); }; -})); +})); \ No newline at end of file