Patrick Westerhoff
2016-02-18 c3ac10cfe4689a217860d20a3d08171b41368ef0
1
2
3
4
5
6
/*
react-datetime v2.0.3
https://github.com/arqex/react-datetime
MIT: https://github.com/arqex/react-datetime/raw/master/LICENSE
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React"),require("moment"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["React","moment","ReactDOM"],e):"object"==typeof exports?exports.Datetime=e(require("React"),require("moment"),require("ReactDOM")):t.Datetime=e(t.React,t.moment,t.ReactDOM)}(this,function(t,e,s){return function(t){function e(r){if(s[r])return s[r].exports;var n=s[r]={exports:{},id:r,loaded:!1};return t[r].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var s={};return e.m=t,e.c=s,e.p="",e(0)}([function(t,e,s){"use strict";var r=s(1),n=s(2),a=s(3),o=s(5),i=s(6),c=s(7),u=s(4),l=n.PropTypes,p=n.createClass({mixins:[s(8)],viewComponents:{days:a,months:o,years:i,time:c},propTypes:{closeOnSelect:l.bool,onBlur:l.func,onChange:l.func,locale:l.string,input:l.bool,inputProps:l.object,viewMode:l.oneOf(["years","months","days","time"]),isValidDate:l.func,open:l.bool,strictParsing:l.bool},getDefaultProps:function(){var t=function(){};return{className:"",defaultValue:"",viewMode:"days",inputProps:{},input:!0,onBlur:t,onChange:t,timeFormat:!0,dateFormat:!0,strictParsing:!0}},getInitialState:function(){var t=this.getStateFromProps(this.props);return void 0==t.open&&(t.open=!this.props.input),t.currentView=this.props.dateFormat?this.props.viewMode:"time",t},getStateFromProps:function(t){var e,s,r=this.getFormats(t),n=t.value||t.defaultValue;return n&&"string"==typeof n?e=this.localMoment(n,r.datetime):n&&(e=this.localMoment(n)),e&&!e.isValid()&&(e=null),s=e?e.clone().startOf("month"):this.localMoment().startOf("month"),{inputFormat:r.datetime,viewDate:s,selectedDate:e,inputValue:e?e.format(r.datetime):n||"",open:void 0!=t.open?t.open:this.state&&this.state.open}},getFormats:function(t){var e={date:t.dateFormat||"",time:t.timeFormat||""},s=this.localMoment(t.date).localeData();return e.date===!0&&(e.date=s.longDateFormat("L")),e.time===!0&&(e.time=s.longDateFormat("LT")),e.datetime=e.date&&e.time?e.date+" "+e.time:e.date||e.time,e},componentWillReceiveProps:function(t){var e=this.getFormats(t),s={};t.value!=this.props.value&&(s=this.getStateFromProps(t)),e.datetime!==this.getFormats(this.props).datetime&&(s.inputFormat=e.datetime),this.setState(s)},onInputChange:function(t){var e=null==t.target?t:t.target.value,s=this.localMoment(e,this.state.inputFormat),r={inputValue:e};return s.isValid()&&!this.props.value?(r.selectedDate=s,r.viewDate=s.clone().startOf("month")):r.selectedDate=null,this.setState(r,function(){return this.props.onChange(s.isValid()?s:this.state.inputValue)})},showView:function(t){var e=this;return function(s){e.setState({currentView:t})}},setDate:function(t){var e=this,s={month:"days",year:"months"};return function(r){e.setState({viewDate:e.state.viewDate.clone()[t](parseInt(r.target.getAttribute("data-value"))).startOf(t),currentView:s[t]})}},addTime:function(t,e,s){return this.updateTime("add",t,e,s)},subtractTime:function(t,e,s){return this.updateTime("subtract",t,e,s)},updateTime:function(t,e,s,r){var n=this;return function(){var a={},o=r?"selectedDate":"viewDate";a[o]=n.state[o].clone()[t](e,s),n.setState(a)}},allowedSetTime:["hours","minutes","seconds","milliseconds"],setTime:function(t,e){var s,r=this.allowedSetTime.indexOf(t)+1,n=this.state,a=(n.selectedDate||n.viewDate).clone();for(a[t](e);r<this.allowedSetTime.length;r++)s=this.allowedSetTime[r],a[s](a[s]());this.props.value||this.setState({selectedDate:a,inputValue:a.format(n.inputFormat)}),this.props.onChange(a)},updateSelectedDate:function(t,e){var s,r=t.target,n=0,a=this.state.viewDate,o=this.state.selectedDate||a;-1!=r.className.indexOf("rdtNew")?n=1:-1!=r.className.indexOf("rdtOld")&&(n=-1),s=a.clone().month(a.month()+n).date(parseInt(r.getAttribute("data-value"))).hours(o.hours()).minutes(o.minutes()).seconds(o.seconds()).milliseconds(o.milliseconds()),this.props.value||this.setState({selectedDate:s,viewDate:s.clone().startOf("month"),inputValue:s.format(this.state.inputFormat)},function(){this.props.closeOnSelect&&e&&this.closeCalendar()}),this.props.onChange(s)},openCalendar:function(){this.setState({open:!0})},closeCalendar:function(){this.setState({open:!1})},handleClickOutside:function(){this.props.input&&this.state.open&&!this.props.open&&(this.setState({open:!1}),this.props.onBlur(this.state.selectedDate||this.state.inputValue))},localMoment:function(t,e){var s=u(t,e,this.props.strictParsing);return this.props.locale&&s.locale(this.props.locale),s},componentProps:{fromProps:["value","isValidDate","renderDay","renderMonth","renderYear"],fromState:["viewDate","selectedDate"],fromThis:["setDate","setTime","showView","addTime","subtractTime","updateSelectedDate","localMoment"]},getComponentProps:function(){var t=this,e=this.getFormats(this.props),s={dateFormat:e.date,timeFormat:e.time};return this.componentProps.fromProps.forEach(function(e){s[e]=t.props[e]}),this.componentProps.fromState.forEach(function(e){s[e]=t.state[e]}),this.componentProps.fromThis.forEach(function(e){s[e]=t[e]}),s},render:function(){var t=this.viewComponents[this.state.currentView],e=n.DOM,s="rdt "+this.props.className,a=[];return this.props.input?a=[e.input(r({key:"i",type:"text",className:"form-control",onFocus:this.openCalendar,onChange:this.onInputChange,value:this.state.inputValue},this.props.inputProps))]:s+=" rdtStatic",this.state.open&&(s+=" rdtOpen"),e.div({className:s},a.concat(e.div({key:"dt",className:"rdtPicker"},n.createElement(t,this.getComponentProps()))))}});p.moment=u,t.exports=p},function(t,e){"use strict";function s(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function r(t){var e=Object.getOwnPropertyNames(t);return Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(t))),e.filter(function(e){return n.call(t,e)})}var n=Object.prototype.propertyIsEnumerable;t.exports=Object.assign||function(t,e){for(var n,a,o=s(t),i=1;i<arguments.length;i++){n=arguments[i],a=r(Object(n));for(var c=0;c<a.length;c++)o[a[c]]=n[a[c]]}return o}},function(e,s){e.exports=t},function(t,e,s){var r=s(2),n=s(4),a=r.DOM,o=r.createClass({render:function(){var t,e=this.renderFooter(),s=this.props.viewDate,r=s.localeData();return t=[a.thead({key:"th"},[a.tr({key:"h"},[a.th({key:"p",className:"rdtPrev"},a.button({onClick:this.props.subtractTime(1,"months"),type:"button"},"‹")),a.th({key:"s",className:"rdtSwitch",onClick:this.props.showView("months"),colSpan:5,"data-value":this.props.viewDate.month()},r.months(s)+" "+s.year()),a.th({key:"n",className:"rdtNext"},a.button({onClick:this.props.addTime(1,"months"),type:"button"},"›"))]),a.tr({key:"d"},this.getDaysOfWeek(r).map(function(t,e){return a.th({key:t+e,className:"dow"},t)}))]),a.tbody({key:"tb"},this.renderDays())],e&&t.push(e),a.div({className:"rdtDays"},a.table({},t))},getDaysOfWeek:function(t){var e=t._weekdaysMin,s=t.firstDayOfWeek(),r=[],n=0;return e.forEach(function(t){r[(7+n++-s)%7]=t}),r},renderDays:function(){var t,e,s,r,o=this.props.viewDate,i=this.props.selectedDate&&this.props.selectedDate.clone(),c=o.clone().subtract(1,"months"),u=o.year(),l=o.month(),p=[],d=[],h=this.props.renderDay||this.renderDay,m=this.props.isValidDate||this.isValidDate;c.date(c.daysInMonth()).startOf("week");for(var f=c.clone().add(42,"d");c.isBefore(f);)t="rdtDay",r=c.clone(),c.year()==u&&c.month()<l||c.year()<u?t+=" rdtOld":(c.year()==u&&c.month()>l||c.year()>u)&&(t+=" rdtNew"),i&&c.isSame({y:i.year(),M:i.month(),d:i.date()})&&(t+=" rdtActive"),c.isSame(n(),"day")&&(t+=" rdtToday"),e=!m(r,i),e&&(t+=" rdtDisabled"),s={key:c.format("M_D"),"data-value":c.date(),className:t},e||(s.onClick=this.updateSelectedDate),d.push(h(s,r,i)),7==d.length&&(p.push(a.tr({key:c.format("M_D")},d)),d=[]),c.add(1,"d");return p},updateSelectedDate:function(t){this.props.updateSelectedDate(t,!0)},renderDay:function(t,e,s){return a.td(t,e.date())},renderFooter:function(){if(!this.props.timeFormat)return"";var t=this.props.selectedDate||this.props.viewDate;return a.tfoot({key:"tf"},a.tr({},a.td({onClick:this.props.showView("time"),colSpan:7,className:"rdtTimeToggle"},t.format(this.props.timeFormat))))},isValidDate:function(){return 1}});t.exports=o},function(t,s){t.exports=e},function(t,e,s){"use strict";var r=s(2),n=(s(4),r.DOM),a=r.createClass({render:function(){return n.div({className:"rdtMonths"},[n.table({key:"a"},n.thead({},n.tr({},[n.th({key:"prev",className:"rdtPrev"},n.button({onClick:this.props.subtractTime(1,"years"),type:"button"},"‹")),n.th({key:"year",className:"rdtSwitch",onClick:this.props.showView("years"),colSpan:2,"data-value":this.props.viewDate.year()},this.props.viewDate.year()),n.th({key:"next",className:"rdtNext"},n.button({onClick:this.props.addTime(1,"years"),type:"button"},"›"))]))),n.table({key:"months"},n.tbody({key:"b"},this.renderMonths()))])},renderMonths:function(){for(var t,e,s=this.props.selectedDate,r=this.props.viewDate.month(),a=this.props.viewDate.year(),o=[],i=0,c=[],u=this.props.renderMonth||this.renderMonth;12>i;)t="rdtMonth",s&&i===r&&a===s.year()&&(t+=" rdtActive"),e={key:i,"data-value":i,className:t,onClick:this.props.setDate("month")},c.push(u(e,i,a,s&&s.clone())),4==c.length&&(o.push(n.tr({key:r+"_"+o.length},c)),c=[]),i++;return o},renderMonth:function(t,e,s,r){return n.td(t,this.props.viewDate.localeData()._monthsShort[e])}});t.exports=a},function(t,e,s){"use strict";var r=s(2),n=r.DOM,a=r.createClass({render:function(){var t=10*parseInt(this.props.viewDate.year()/10,10);return n.div({className:"rdtYears"},[n.table({key:"a"},n.thead({},n.tr({},[n.th({key:"prev",className:"rdtPrev"},n.button({onClick:this.props.subtractTime(10,"years"),type:"button"},"‹")),n.th({key:"year",className:"rdtSwitch",onClick:this.props.showView("years"),colSpan:2},t+"-"+(t+9)),n.th({key:"next",className:"rdtNext"},n.button({onClick:this.props.addTime(10,"years"),type:"button"},"›"))]))),n.table({key:"years"},n.tbody({},this.renderYears(t)))])},renderYears:function(t){var e,s,r=[],a=-1,o=[],i=this.props.renderYear||this.renderYear,c=this.props.selectedDate;for(t--;11>a;)e="rdtYear",-1===a|10===a&&(e+=" rdtOld"),c&&c.year()===t&&(e+=" rdtActive"),s={key:t,"data-value":t,className:e,onClick:this.props.setDate("year")},r.push(i(s,t,c&&c.clone())),4==r.length&&(o.push(n.tr({key:a},r)),r=[]),t++,a++;return o},renderYear:function(t,e,s){return n.td(t,e)}});t.exports=a},function(t,e,s){"use strict";var r=s(2),n=r.DOM,a=r.createClass({getInitialState:function(){return this.calculateState(this.props)},calculateState:function(t){var e=t.selectedDate||t.viewDate,s=t.timeFormat,r=[];return(-1!=s.indexOf("H")||-1!=s.indexOf("h"))&&(r.push("hours"),-1!=s.indexOf("m")&&(r.push("minutes"),-1!=s.indexOf("s")&&r.push("seconds"))),{hours:e.format("H"),minutes:e.format("mm"),seconds:e.format("ss"),milliseconds:e.format("SSS"),counters:r}},renderCounter:function(t){return n.div({key:t,className:"rdtCounter"},[n.button({key:"up",className:"rdtBtn",onMouseDown:this.onStartClicking("increase",t),type:"button"},"▲"),n.div({key:"c",className:"rdtCount"},this.state[t]),n.button({key:"do",className:"rdtBtn",onMouseDown:this.onStartClicking("decrease",t),type:"button"},"▼")])},render:function(){var t=this,e=[];return this.state.counters.forEach(function(s){e.length&&e.push(n.div({key:"sep"+e.length,className:"rdtCounterSeparator"},":")),e.push(t.renderCounter(s))}),3==this.state.counters.length&&-1!=this.props.timeFormat.indexOf("S")&&(e.push(n.div({className:"rdtCounterSeparator",key:"sep5"},":")),e.push(n.div({className:"rdtCounter rdtMilli",key:"m"},n.input({value:this.state.milliseconds,type:"text",onChange:this.updateMilli})))),n.div({className:"rdtTime"},n.table({},[this.renderHeader(),n.tbody({key:"b"},n.tr({},n.td({},n.div({className:"rdtCounters"},e))))]))},componentWillReceiveProps:function(t,e){this.setState(this.calculateState(t))},updateMilli:function(t){var e=parseInt(t.target.value);e==t.target.value&&e>=0&&1e3>e&&(this.props.setTime("milliseconds",e),this.setState({milliseconds:e}))},renderHeader:function(){if(!this.props.dateFormat)return"";var t=this.props.selectedDate||this.props.viewDate;return n.thead({key:"h"},n.tr({},n.th({className:"rdtSwitch",colSpan:4,onClick:this.props.showView("days")},t.format(this.props.dateFormat))))},onStartClicking:function(t,e){var s=this;this.state[e];return function(){var r={};r[e]=s[t](e),s.setState(r),s.timer=setTimeout(function(){s.increaseTimer=setInterval(function(){r[e]=s[t](e),s.setState(r)},70)},500),s.mouseUpListener=function(){clearTimeout(s.timer),clearInterval(s.increaseTimer),s.props.setTime(e,s.state[e]),document.body.removeEventListener("mouseup",s.mouseUpListener)},document.body.addEventListener("mouseup",s.mouseUpListener)}},maxValues:{hours:23,minutes:59,seconds:59,milliseconds:999},padValues:{hours:1,minutes:2,seconds:2,milliseconds:3},increase:function(t){var e=parseInt(this.state[t])+1;return e>this.maxValues[t]&&(e=0),this.pad(t,e)},decrease:function(t){var e=parseInt(this.state[t])-1;return 0>e&&(e=this.maxValues[t]),this.pad(t,e)},pad:function(t,e){for(var s=e+"";s.length<this.padValues[t];)s="0"+s;return s}});t.exports=a},function(t,e,s){var r=s(2),n=r.version&&r.version.split(".");n&&(n[0]>0||n[1]>13)&&(r=s(9));var a=[],o=[],i="ignore-react-onclickoutside",c=function(t,e){return t===e?!0:t.correspondingElement?t.correspondingElement.classList.contains(i):t.classList.contains(i)};t.exports={componentDidMount:function(){if("function"!=typeof this.handleClickOutside)throw new Error("Component lacks a handleClickOutside(event) function for processing outside click events.");var t=this.__outsideClickHandler=function(t,e){return function(s){s.stopPropagation();for(var r=s.target,n=!1;r.parentNode;){if(n=c(r,t))return;r=r.parentNode}e(s)}}(r.findDOMNode(this),this.handleClickOutside),e=a.length;a.push(this),o[e]=t,this.props.disableOnClickOutside||this.enableOnClickOutside()},componentWillUnmount:function(){this.disableOnClickOutside(),this.__outsideClickHandler=!1;var t=a.indexOf(this);t>-1&&o[t]&&(o.splice(t,1),a.splice(t,1))},enableOnClickOutside:function(){var t=this.__outsideClickHandler;document.addEventListener("mousedown",t),document.addEventListener("touchstart",t)},disableOnClickOutside:function(){var t=this.__outsideClickHandler;document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t)}}},function(t,e){t.exports=s}])});