Simon Egersand
2017-02-10 be9654c6325a15a8ca282d3fd1245c8fe2ed699e
commit | author | age
d76f7b 1 /*
be9654 2 react-datetime v2.8.5
SE 3 https://github.com/YouCanBookMe/react-datetime
4 MIT: https://github.com/YouCanBookMe/react-datetime/raw/master/LICENSE
d76f7b 5 */
be9654 6 !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("moment"),require("React"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["moment","React","ReactDOM"],e):"object"==typeof exports?exports.Datetime=e(require("moment"),require("React"),require("ReactDOM")):t.Datetime=e(t.moment,t.React,t.ReactDOM)}(this,function(t,e,s){return function(t){function e(a){if(s[a])return s[a].exports;var n=s[a]={exports:{},id:a,loaded:!1};return t[a].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 a=s(1),n=s(2),r=s(3),i=s(4),o=s(5),c=s(6),l=s(7),u=r.PropTypes,d=r.createClass({mixins:[s(8)],viewComponents:{days:i,months:o,years:c,time:l},propTypes:{onFocus:u.func,onBlur:u.func,onChange:u.func,locale:u.string,utc:u.bool,input:u.bool,inputProps:u.object,timeConstraints:u.object,viewMode:u.oneOf(["years","months","days","time"]),isValidDate:u.func,open:u.bool,strictParsing:u.bool,closeOnSelect:u.bool,closeOnTab:u.bool},getDefaultProps:function(){var t=function(){};return{className:"",defaultValue:"",inputProps:{},input:!0,onFocus:t,onBlur:t,onChange:t,timeFormat:!0,timeConstraints:{},dateFormat:!0,strictParsing:!0,closeOnSelect:!1,closeOnTab:!0,utc:!1}},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||t.updateOn||"days":"time",t},getStateFromProps:function(t){var e,s,a,n,r=this.getFormats(t),i=t.value||t.defaultValue;return i&&"string"==typeof i?e=this.localMoment(i,r.datetime):i&&(e=this.localMoment(i)),e&&!e.isValid()&&(e=null),s=e?e.clone().startOf("month"):this.localMoment().startOf("month"),a=this.getUpdateOn(r),n=e?e.format(r.datetime):i.isValid&&!i.isValid()?"":i||"",{updateOn:a,inputFormat:r.datetime,viewDate:s,selectedDate:e,inputValue:n,open:t.open}},getUpdateOn:function(t){return t.date.match(/[lLD]/)?"days":t.date.indexOf("M")!==-1?"months":t.date.indexOf("Y")!==-1?"years":"days"},getFormats:function(t){var e={date:t.dateFormat||"",time:t.timeFormat||""},s=this.localMoment(t.date,null,t).localeData();return e.date===!0?e.date=s.longDateFormat("L"):"days"!==this.getUpdateOn(e)&&(e.time=""),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={};if(t.value===this.props.value&&e.datetime===this.getFormats(this.props).datetime||(s=this.getStateFromProps(t)),void 0===s.open&&(s.open=this.state.open),this.props.closeOnSelect===!1&&(s.open=!0),t.viewMode!==this.props.viewMode&&(s.currentView=t.viewMode),t.locale!==this.props.locale){if(this.state.viewDate){var a=this.state.viewDate.clone().locale(t.locale);s.viewDate=a}if(this.state.selectedDate){var n=this.state.selectedDate.clone().locale(t.locale);s.selectedDate=n,s.inputValue=n.format(e.datetime)}}t.utc!==this.props.utc&&(t.utc?(this.state.viewDate&&(s.viewDate=this.state.viewDate.clone().utc()),this.state.selectedDate&&(s.selectedDate=this.state.selectedDate.clone().utc(),s.inputValue=s.selectedDate.format(e.datetime))):(this.state.viewDate&&(s.viewDate=this.state.viewDate.clone().local()),this.state.selectedDate&&(s.selectedDate=this.state.selectedDate.clone().local(),s.inputValue=s.selectedDate.format(e.datetime)))),this.setState(s)},onInputChange:function(t){var e=null===t.target?t:t.target.value,s=this.localMoment(e,this.state.inputFormat),a={inputValue:e};return s.isValid()&&!this.props.value?(a.selectedDate=s,a.viewDate=s.clone().startOf("month")):a.selectedDate=null,this.setState(a,function(){return this.props.onChange(s.isValid()?s:this.state.inputValue)})},onInputKey:function(t){9===t.which&&this.props.closeOnTab&&this.closeCalendar()},showView:function(t){var e=this;return function(){e.setState({currentView:t})}},setDate:function(t){var e=this,s={month:"days",year:"months"};return function(a){e.setState({viewDate:e.state.viewDate.clone()[t](parseInt(a.target.getAttribute("data-value"),10)).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,a){var n=this;return function(){var r={},i=a?"selectedDate":"viewDate";r[i]=n.state[i].clone()[t](e,s),n.setState(r)}},allowedSetTime:["hours","minutes","seconds","milliseconds"],setTime:function(t,e){var s,a=this.allowedSetTime.indexOf(t)+1,n=this.state,r=(n.selectedDate||n.viewDate).clone();for(r[t](e);a<this.allowedSetTime.length;a++)s=this.allowedSetTime[a],r[s](r[s]());this.props.value||this.setState({selectedDate:r,inputValue:r.format(n.inputFormat)}),this.props.onChange(r)},updateSelectedDate:function(t,e){var s,a=t.target,n=0,r=this.state.viewDate,i=this.state.selectedDate||r;a.className.indexOf("rdtDay")!==-1?(a.className.indexOf("rdtNew")!==-1?n=1:a.className.indexOf("rdtOld")!==-1&&(n=-1),s=r.clone().month(r.month()+n).date(parseInt(a.getAttribute("data-value"),10))):a.className.indexOf("rdtMonth")!==-1?s=r.clone().month(parseInt(a.getAttribute("data-value"),10)).date(i.date()):a.className.indexOf("rdtYear")!==-1&&(s=r.clone().month(i.month()).date(i.date()).year(parseInt(a.getAttribute("data-value"),10))),s.hours(i.hours()).minutes(i.minutes()).seconds(i.seconds()).milliseconds(i.milliseconds()),this.props.value?this.props.closeOnSelect&&e&&this.closeCalendar():this.setState({selectedDate:s,viewDate:s.clone().startOf("month"),inputValue:s.format(this.state.inputFormat),open:!(this.props.closeOnSelect&&e)}),this.props.onChange(s)},openCalendar:function(){this.state.open||this.setState({open:!0},function(){this.props.onFocus()})},closeCalendar:function(){this.setState({open:!1},function(){this.props.onBlur(this.state.selectedDate||this.state.inputValue)})},handleClickOutside:function(){this.props.input&&this.state.open&&!this.props.open&&this.setState({open:!1},function(){this.props.onBlur(this.state.selectedDate||this.state.inputValue)})},localMoment:function(t,e,s){s=s||this.props;var a=s.utc?n.utc:n,r=a(t,e,s.strictParsing);return s.locale&&r.locale(s.locale),r},componentProps:{fromProps:["value","isValidDate","renderDay","renderMonth","renderYear","timeConstraints"],fromState:["viewDate","selectedDate","updateOn"],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=r.DOM,s="rdt"+(this.props.className?Array.isArray(this.props.className)?" "+this.props.className.join(" "):" "+this.props.className:""),n=[];return this.props.input?n=[e.input(a({key:"i",type:"text",className:"form-control",onFocus:this.openCalendar,onChange:this.onInputChange,onKeyDown:this.onInputKey,value:this.state.inputValue},this.props.inputProps))]:s+=" rdtStatic",this.state.open&&(s+=" rdtOpen"),e.div({className:s},n.concat(e.div({key:"dt",className:"rdtPicker"},r.createElement(t,this.getComponentProps()))))}});d.moment=n,t.exports=d},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 a(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,r,i=s(t),o=1;o<arguments.length;o++){n=arguments[o],r=a(Object(n));for(var c=0;c<r.length;c++)i[r[c]]=n[r[c]]}return i}},function(e,s){e.exports=t},function(t,s){t.exports=e},function(t,e,s){"use strict";var a=s(3),n=s(2),r=a.DOM,i=a.createClass({render:function(){var t,e=this.renderFooter(),s=this.props.viewDate,a=s.localeData();return t=[r.thead({key:"th"},[r.tr({key:"h"},[r.th({key:"p",className:"rdtPrev"},r.span({onClick:this.props.subtractTime(1,"months")},"‹")),r.th({key:"s",className:"rdtSwitch",onClick:this.props.showView("months"),colSpan:5,"data-value":this.props.viewDate.month()},a.months(s)+" "+s.year()),r.th({key:"n",className:"rdtNext"},r.span({onClick:this.props.addTime(1,"months")},"›"))]),r.tr({key:"d"},this.getDaysOfWeek(a).map(function(t,e){return r.th({key:t+e,className:"dow"},t)}))]),r.tbody({key:"tb"},this.renderDays())],e&&t.push(e),r.div({className:"rdtDays"},r.table({},t))},getDaysOfWeek:function(t){var e=t._weekdaysMin,s=t.firstDayOfWeek(),a=[],n=0;return e.forEach(function(t){a[(7+n++-s)%7]=t}),a},renderDays:function(){var t,e,s,a,i=this.props.viewDate,o=this.props.selectedDate&&this.props.selectedDate.clone(),c=i.clone().subtract(1,"months"),l=i.year(),u=i.month(),d=[],p=[],h=this.props.renderDay||this.renderDay,m=this.props.isValidDate||this.alwaysValidDate;c.date(c.daysInMonth()).startOf("week");for(var f=c.clone().add(42,"d");c.isBefore(f);)t="rdtDay",a=c.clone(),c.year()===l&&c.month()<u||c.year()<l?t+=" rdtOld":(c.year()===l&&c.month()>u||c.year()>l)&&(t+=" rdtNew"),o&&c.isSame(o,"day")&&(t+=" rdtActive"),c.isSame(n(),"day")&&(t+=" rdtToday"),e=!m(a,o),e&&(t+=" rdtDisabled"),s={key:c.format("M_D"),"data-value":c.date(),className:t},e||(s.onClick=this.updateSelectedDate),p.push(h(s,a,o)),7===p.length&&(d.push(r.tr({key:c.format("M_D")},p)),p=[]),c.add(1,"d");return d},updateSelectedDate:function(t){this.props.updateSelectedDate(t,!0)},renderDay:function(t,e){return r.td(t,e.date())},renderFooter:function(){if(!this.props.timeFormat)return"";var t=this.props.selectedDate||this.props.viewDate;return r.tfoot({key:"tf"},r.tr({},r.td({onClick:this.props.showView("time"),colSpan:7,className:"rdtTimeToggle"},t.format(this.props.timeFormat))))},alwaysValidDate:function(){return 1}});t.exports=i},function(t,e,s){"use strict";function a(t){return t.charAt(0).toUpperCase()+t.slice(1)}var n=s(3),r=n.DOM,i=n.createClass({render:function(){return r.div({className:"rdtMonths"},[r.table({key:"a"},r.thead({},r.tr({},[r.th({key:"prev",className:"rdtPrev"},r.span({onClick:this.props.subtractTime(1,"years")},"‹")),r.th({key:"year",className:"rdtSwitch",onClick:this.props.showView("years"),colSpan:2,"data-value":this.props.viewDate.year()},this.props.viewDate.year()),r.th({key:"next",className:"rdtNext"},r.span({onClick:this.props.addTime(1,"years")},"›"))]))),r.table({key:"months"},r.tbody({key:"b"},this.renderMonths()))])},renderMonths:function(){for(var t,e,s,a,n,i,o,c=this.props.selectedDate,l=this.props.viewDate.month(),u=this.props.viewDate.year(),d=[],p=0,h=[],m=this.props.renderMonth||this.renderMonth,f=this.props.isValidDate||this.alwaysValidDate,v=1;p<12;)t="rdtMonth",s=this.props.viewDate.clone().set({year:u,month:p,date:v}),n=s.endOf("month").format("D"),i=Array.from({length:n},function(t,e){return e+1}),o=i.find(function(t){var e=s.clone().set("date",t);return f(e)}),a=void 0===o,a&&(t+=" rdtDisabled"),c&&p===l&&u===c.year()&&(t+=" rdtActive"),e={key:p,"data-value":p,className:t},a||(e.onClick="months"===this.props.updateOn?this.updateSelectedMonth:this.props.setDate("month")),h.push(m(e,p,u,c&&c.clone())),4===h.length&&(d.push(r.tr({key:l+"_"+d.length},h)),h=[]),p++;return d},updateSelectedMonth:function(t){this.props.updateSelectedDate(t,!0)},renderMonth:function(t,e){var s=this.props.viewDate,n=s.localeData().monthsShort(s.month(e)),i=3,o=n.substring(0,i);return r.td(t,a(o))},alwaysValidDate:function(){return 1}});t.exports=i},function(t,e,s){"use strict";var a=s(3),n=a.DOM,r=a.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.span({onClick:this.props.subtractTime(10,"years")},"‹")),n.th({key:"year",className:"rdtSwitch",onClick:this.props.showView("years"),colSpan:2},t+"-"+(t+9)),n.th({key:"next",className:"rdtNext"},n.span({onClick:this.props.addTime(10,"years")},"›"))]))),n.table({key:"years"},n.tbody({},this.renderYears(t)))])},renderYears:function(t){var e,s,a,r,i,o,c,l=[],u=-1,d=[],p=this.props.renderYear||this.renderYear,h=this.props.selectedDate,m=this.props.isValidDate||this.alwaysValidDate,f=0,v=1;for(t--;u<11;)e="rdtYear",a=this.props.viewDate.clone().set({year:t,month:f,date:v}),i=a.endOf("year").format("DDD"),o=Array.from({length:i},function(t,e){return e+1}),c=o.find(function(t){var e=a.clone().dayOfYear(t);return m(e)}),r=void 0===c,r&&(e+=" rdtDisabled"),h&&h.year()===t&&(e+=" rdtActive"),s={key:t,"data-value":t,className:e},r||(s.onClick="years"===this.props.updateOn?this.updateSelectedYear:this.props.setDate("year")),l.push(p(s,t,h&&h.clone())),4===l.length&&(d.push(n.tr({key:u},l)),l=[]),t++,u++;return d},updateSelectedYear:function(t){this.props.updateSelectedDate(t,!0)},renderYear:function(t,e){return n.td(t,e)},alwaysValidDate:function(){return 1}});t.exports=r},function(t,e,s){"use strict";var a=s(3),n=s(1),r=a.DOM,i=a.createClass({getInitialState:function(){return this.calculateState(this.props)},calculateState:function(t){var e=t.selectedDate||t.viewDate,s=t.timeFormat,a=[];s.toLowerCase().indexOf("h")!==-1&&(a.push("hours"),s.indexOf("m")!==-1&&(a.push("minutes"),s.indexOf("s")!==-1&&a.push("seconds")));var n=!1;return null!==this.state&&this.props.timeFormat.toLowerCase().indexOf(" a")!==-1&&(n=this.props.timeFormat.indexOf(" A")!==-1?this.state.hours>=12?"PM":"AM":this.state.hours>=12?"pm":"am"),{hours:e.format("H"),minutes:e.format("mm"),seconds:e.format("ss"),milliseconds:e.format("SSS"),daypart:n,counters:a}},renderCounter:function(t){if("daypart"!==t){var e=this.state[t];return"hours"===t&&this.props.timeFormat.toLowerCase().indexOf(" a")!==-1&&(e=(e-1)%12+1,0===e&&(e=12)),r.div({key:t,className:"rdtCounter"},[r.span({key:"up",className:"rdtBtn",onMouseDown:this.onStartClicking("increase",t)},"▲"),r.div({key:"c",className:"rdtCount"},e),r.span({key:"do",className:"rdtBtn",onMouseDown:this.onStartClicking("decrease",t)},"▼")])}return""},renderDayPart:function(){return r.div({key:"dayPart",className:"rdtCounter"},[r.span({key:"up",className:"rdtBtn",onMouseDown:this.onStartClicking("toggleDayPart","hours")},"▲"),r.div({key:this.state.daypart,className:"rdtCount"},this.state.daypart),r.span({key:"do",className:"rdtBtn",onMouseDown:this.onStartClicking("toggleDayPart","hours")},"▼")])},render:function(){var t=this,e=[];return this.state.counters.forEach(function(s){e.length&&e.push(r.div({key:"sep"+e.length,className:"rdtCounterSeparator"},":")),e.push(t.renderCounter(s))}),this.state.daypart!==!1&&e.push(t.renderDayPart()),3===this.state.counters.length&&this.props.timeFormat.indexOf("S")!==-1&&(e.push(r.div({className:"rdtCounterSeparator",key:"sep5"},":")),e.push(r.div({className:"rdtCounter rdtMilli",key:"m"},r.input({value:this.state.milliseconds,type:"text",onChange:this.updateMilli})))),r.div({className:"rdtTime"},r.table({},[this.renderHeader(),r.tbody({key:"b"},r.tr({},r.td({},r.div({className:"rdtCounters"},e))))]))},componentWillMount:function(){var t=this;t.timeConstraints={hours:{min:0,max:23,step:1},minutes:{min:0,max:59,step:1},seconds:{min:0,max:59,step:1},milliseconds:{min:0,max:999,step:1}},["hours","minutes","seconds","milliseconds"].forEach(function(e){n(t.timeConstraints[e],t.props.timeConstraints[e])}),this.setState(this.calculateState(this.props))},componentWillReceiveProps:function(t){this.setState(this.calculateState(t))},updateMilli:function(t){var e=parseInt(t.target.value,10);e===t.target.value&&e>=0&&e<1e3&&(this.props.setTime("milliseconds",e),this.setState({milliseconds:e}))},renderHeader:function(){if(!this.props.dateFormat)return null;var t=this.props.selectedDate||this.props.viewDate;return r.thead({key:"h"},r.tr({},r.th({className:"rdtSwitch",colSpan:4,onClick:this.props.showView("days")},t.format(this.props.dateFormat))))},onStartClicking:function(t,e){var s=this;return function(){var a={};a[e]=s[t](e),s.setState(a),s.timer=setTimeout(function(){s.increaseTimer=setInterval(function(){a[e]=s[t](e),s.setState(a)},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)}},padValues:{hours:1,minutes:2,seconds:2,milliseconds:3},toggleDayPart:function(t){var e=parseInt(this.state[t],10)+12;return e>this.timeConstraints[t].max&&(e=this.timeConstraints[t].min+(e-(this.timeConstraints[t].max+1))),this.pad(t,e)},increase:function(t){var e=parseInt(this.state[t],10)+this.timeConstraints[t].step;return e>this.timeConstraints[t].max&&(e=this.timeConstraints[t].min+(e-(this.timeConstraints[t].max+1))),this.pad(t,e)},decrease:function(t){var e=parseInt(this.state[t],10)-this.timeConstraints[t].step;return e<this.timeConstraints[t].min&&(e=this.timeConstraints[t].max+1-(this.timeConstraints[t].min-e)),this.pad(t,e)},pad:function(t,e){for(var s=e+"";s.length<this.padValues[t];)s="0"+s;return s}});t.exports=i},function(t,e,s){"use strict";var a=s(3),n=a.version&&a.version.split(".");n&&(n[0]>0||n[1]>13)&&(a=s(9));var r=[],i=[],o="ignore-react-onclickoutside",c=function(t,e){return t===e||(t.correspondingElement?t.correspondingElement.classList.contains(o):t.classList.contains(o))};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 a=s.target,n=!1;a.parentNode;){if(n=c(a,t))return;a=a.parentNode}e(s)}}(a.findDOMNode(this),this.handleClickOutside),e=r.length;r.push(this),i[e]=t,this.props.disableOnClickOutside||this.enableOnClickOutside()},componentWillUnmount:function(){this.disableOnClickOutside(),this.__outsideClickHandler=!1;var t=r.indexOf(this);t>-1&&i[t]&&(i.splice(t,1),r.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}])});
SE 7 //# sourceMappingURL=react-datetime.min.js.map