marquex
2015-06-20 18dc17aa798a8a12785b83a2d6a2ebb916272763
1
2
3
4
5
6
/*
react-datetime v0.1.0
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(void 0),require(void 0)):"function"==typeof define&&define.amd?define([,],e):"object"==typeof exports?exports.Datetime=e(require(void 0),require(void 0)):t.Datetime=e(t.React,t.moment)}(this,function(t,e){return function(t){function e(i){if(s[i])return s[i].exports;var a=s[i]={exports:{},id:i,loaded:!1};return t[i].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var s={};return e.m=t,e.c=s,e.p="",e(0)}([function(t,e,s){"use strict";var i=s(3),a=s(2),n=s(4),r=s(6),o=s(1),c=s(7),d=s(5),u=a.createClass({mixins:[s(8)],viewComponents:{days:n,months:r,years:o,time:c},propTypes:{date:a.PropTypes.string,onChange:a.PropTypes.func,dateFormat:a.PropTypes.string,timeFormat:a.PropTypes.string,inputProps:a.PropTypes.object,defaultText:a.PropTypes.string,viewMode:a.PropTypes.oneOf(["years","months","days","time"]),minDate:a.PropTypes.object,maxDate:a.PropTypes.object},getDefaultProps:function(){return{date:!1,viewMode:"days",inputProps:{},onChange:function(t){console.log(t)}}},getInitialState:function(){var t=this.getFormats(this.props),e=this.props.date||new Date;return{currentView:this.props.viewMode,inputFormat:t.datetime,widgetStyle:{display:"block",position:"absolute",left:-9999,zIndex:"9999 !important"},viewDate:d(e).startOf("month"),selectedDate:d(e),inputValue:"undefined"!=typeof this.props.defaultText?this.props.defaultText:d(e).format(t.datetime)}},getFormats:function(t){var e={date:"",time:"",datetime:""};return t.dateFormat&&(e.date=t.dateFormat),t.timeFormat&&(e.time=t.timeFormat),e.date||e.time?(t.dateFormat&&(e.date=t.dateFormat,e.datetime=e.date),t.timeFormat&&(e.date&&(e.datetime+=" "),e.time=t.timeFormat,e.datetime+=e.time)):(e.date="MM/DD/YY",e.time="H:mm",e.datetime="MM/DD/YY H:mm"),e},componentWillReceiveProps:function(t){var e=this.getFormats(t);return e.datetime!==this.getFormats(this.props).datetime?this.setState({inputFormat:t.inputFormat}):void 0},onChange:function(t){var e=null==t.target?t:t.target.value;return d(e).isValid()&&this.setState({selectedDate:d(e),viewDate:d(e).startOf("month")}),this.setState({inputValue:e},function(){return this.props.onChange(d(this.state.inputValue,this.state.inputFormat,!0).format(this.state.inputFormat))})},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(i){e.setState({viewDate:e.state.viewDate.clone()[t](i.target.innerHTML).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,i){var a=this;return function(){var n={},r=i?"selectedDate":"viewDate";n[r]=a.state[r].clone()[t](e,s),a.setState(n)}},allowedSetTime:["hours","minutes","seconds","milliseconds"],setTime:function(t,e){var s,i=this.allowedSetTime.indexOf(t)+1,a=this.state.selectedDate.clone();for(a[t](e);i<this.allowedSetTime.length;i++)s=this.allowedSetTime[i],a[s](a[s]());this.setState({selectedDate:a,inputValue:a.format(this.state.inputFormat)},this.callOnChange)},callOnChange:function(){this.props.onChange(this.state.selectedDate.format(this.state.inputFormat))},updateDate:function(t){var e,s=t.target,i=0,a=this.state.selectedDate;-1!=s.className.indexOf("new")?i=1:-1!=s.className.indexOf("old")&&(i=-1),e=this.state.viewDate.clone().month(this.state.viewDate.month()+i).date(parseInt(s.innerHTML)).hours(a.hours()).minutes(a.minutes()).seconds(a.seconds()).milliseconds(a.milliseconds()),this.setState({selectedDate:e,viewDate:e.clone().startOf("month"),inputValue:e.format(this.state.inputFormat)})},openCalendar:function(){var t={display:"block",position:"absolute"};this.setState({widgetStyle:t,widgetClasses:"dropdown-menu bottom",showPicker:!0})},handleClickOutside:function(){this.setState({showPicker:!1,widgetStyle:{display:"none"}})},componentProps:{fromProps:["viewMode","minDate","maxDate"],fromState:["viewDate","selectedDate"],fromThis:["setDate","setTime","showView","addTime","subtractTime","updateDate"]},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=i({key:"i",type:"text",className:"form-control",onFocus:this.openCalendar,onChange:this.onChange,value:this.state.inputValue},this.props.inputProps),s=a.DOM;return s.div({className:"datetimePicker"},[s.input(e),s.div({key:"dt",className:this.state.widgetClasses,style:this.state.widgetStyle},a.createElement(t,this.getComponentProps()))])}});t.exports=u},function(t,e,s){"use strict";var i=s(2),a=i.DOM,n=i.createClass({renderYears:function(t){var e,s=[],i=-1,n=[];for(t--;11>i;)e="year",-1===i|10===i&&(e+=" old"),this.props.selectedDate.year()===t&&(e+=" active"),s.push(a.td({key:t,className:e,onClick:this.props.setDate("year")},t)),4==s.length&&(n.push(a.tr({key:i},s)),s=[]),t++,i++;return n},render:function(){var t=10*parseInt(this.props.viewDate.year()/10,10);return a.div({className:"datepicker-years"},[a.table({key:"a"},a.thead({},a.tr({},[a.th({key:"prev",className:"prev",onClick:this.props.subtractTime(10,"years")},"‹"),a.th({key:"year",className:"switch",onClick:this.props.showView("years"),colSpan:5},t+"-"+(t+9)),a.th({key:"next",className:"next",onClick:this.props.addTime(10,"years")},"›")]))),a.table({key:"years"},a.tbody({},this.renderYears(t)))])}});t.exports=n},function(e,s){e.exports=t},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 i(t){var e=Object.getOwnPropertyNames(t);return Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(t))),e.filter(function(e){return a.call(t,e)})}var a=Object.prototype.propertyIsEnumerable;t.exports=Object.assign||function(t,e){for(var a,n,r=s(t),o=1;o<arguments.length;o++){a=arguments[o],n=i(Object(a));for(var c=0;c<n.length;c++)r[n[c]]=a[n[c]]}return r}},function(t,e,s){var i=s(2),a=s(5),n=i.DOM,r=i.createClass({render:function(){var t,e=this.renderFooter(),s=this.props.viewDate;return t=[n.thead({key:"th"},[n.tr({key:"h"},[n.th({key:"p",className:"prev",onClick:this.props.subtractTime(1,"months")},"‹"),n.th({key:"s",className:"switch",onClick:this.props.showView("months"),colSpan:5},a.months()[s.month()]+" "+s.year()),n.th({key:"n",className:"next",onClick:this.props.addTime(1,"months")},"›")]),n.tr({key:"d"},a.weekdaysMin().map(function(t){return n.th({key:t,className:"dow"},t)}))]),n.tbody({key:"tb"},this.renderDays())],e&&t.push(e),n.div({className:"datepicker-days"},n.table({},t))},renderDays:function(){var t,e,s,i=this.props.viewDate,r=this.props.selectedDate,o=i.clone().subtract(1,"months"),c=i.year(),d=i.month(),u={y:r.year(),M:r.month(),d:r.date()},p=this.props.minDate,l=this.props.maxDate,m=[],h=[];o.date(o.daysInMonth()).startOf("week");for(var f=o.clone().add(42,"d");o.isBefore(f);)t="day",o.year()<c||o.month()<d?t+=" old":(o.year()>c||o.month()>d)&&(t+=" new"),o.isSame(u)&&(t+=" active"),o.isSame(a(),"day")&&(t+=" today"),e=p&&o.isBefore(p)||l&&o.isAfter(l),e&&(t+=" disabled"),s={key:o.format("M_D"),className:t},e||(s.onClick=this.props.updateDate),h.push(n.td(s,o.date())),7==h.length&&(m.push(n.tr({key:o.format("M_D")},h)),h=[]),o.add(1,"d");return m},renderFooter:function(){return this.props.timeFormat?n.tfoot({key:"tf"},n.tr({},n.td({onClick:this.props.showView("time"),colSpan:7,className:"timeToggle"},this.props.selectedDate.format(this.props.timeFormat)))):""}});t.exports=r},function(t,s){t.exports=e},function(t,e,s){"use strict";var i=s(2),a=s(5),n=i.DOM,r=i.createClass({renderMonths:function(){for(var t,e=this.props.selectedDate.month(),s=a.monthsShort(),i=[],r=0,o=[];12>r;)t="month",r===e&&this.props.viewDate.year()===this.props.selectedDate.year()&&(t+=" active"),o.push(n.td({key:r,className:t,onClick:this.props.setDate("month")},s[r])),4==o.length&&(i.push(n.tr({key:e+"_"+i.length},o)),o=[]),r++;return i},render:function(){return n.div({className:"datepicker-months"},[n.table({key:"a"},n.thead({},n.tr({},[n.th({key:"prev",className:"prev",onClick:this.props.subtractTime(1,"years")},"‹"),n.th({key:"year",className:"switch",onClick:this.props.showView("years"),colSpan:5},this.props.viewDate.year()),n.th({key:"next",className:"next",onClick:this.props.addTime(1,"years")},"›")]))),n.table({key:"months"},n.tbody({key:"b"},this.renderMonths()))])}});t.exports=r},function(t,e,s){"use strict";var i=s(2),a=i.DOM,n=i.createClass({getInitialState:function(){var t=this.props.selectedDate,e=this.props.timeFormat,s=[];return(-1!=e.indexOf("H")||-1!=e.indexOf("h"))&&(s.push("hours"),-1!=e.indexOf("m")&&(s.push("minutes"),-1!=e.indexOf("s")&&s.push("seconds"))),{hours:t.format("H"),minutes:t.format("mm"),seconds:t.format("ss"),milliseconds:t.format("SSS"),counters:s}},renderCounter:function(t){return a.div({key:t,className:"dtCounter"},[a.div({key:"up",className:"btn",onMouseDown:this.onStartClicking("increase",t)},"▲"),a.div({key:"c",className:"dtCount"},this.state[t]),a.div({key:"do",className:"btn",onMouseDown:this.onStartClicking("increase",t)},"▼")])},render:function(){var t=this,e=[];return this.state.counters.forEach(function(s){e.length&&e.push(a.div({key:"sep"+e.length,className:"dtCounterSeparator"},":")),e.push(t.renderCounter(s))}),3==this.state.counters.length&&-1!=this.props.timeFormat.indexOf("S")&&(e.push(a.div({className:"dtCounterSeparator",key:"sep5"},":")),e.push(a.div({className:"dtCounter dtMilli",key:"m"},a.input({value:this.state.milliseconds,type:"text",onChange:this.updateMilli})))),a.div({className:"timepicker"},a.div({className:"timepicker-picker"},a.table({},[this.renderHeader(),a.tbody({key:"b"},a.tr({},a.td({},a.div({className:"dtCounters"},e))))])))},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(){return this.props.dateFormat?a.thead({key:"h"},a.tr({},a.th({colSpan:4,onClick:this.props.showView("days")},this.props.selectedDate.format(this.props.dateFormat)))):""},onStartClicking:function(t,e){var s=this;return function(){var i={};i[e]=s[t](e),s.setState(i),s.timer=setTimeout(function(){s.increaseTimer=setInterval(function(){i[e]=s[t](e),s.setState(i)},80)},500),document.body.addEventListener("mouseup",function(){clearTimeout(s.timer),clearInterval(s.increaseTimer),s.props.setTime(e,s.state[e])})}},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=n},function(t,e,s){var i,a,n;!function(s,r){a=[],i=r,n="function"==typeof i?i.apply(e,a):i,!(void 0!==n&&(t.exports=n))}(this,function(){"use strict";var t=[],e=[],s="ignore-react-onclickoutside";return{componentDidMount:function(){if(!this.handleClickOutside)throw new Error("Component lacks a handleClickOutside(event) function for processing outside click events.");var i=this.__outsideClickHandler=function(t,e){return function(i){for(var a=i.target,n=!1;a.parentNode;){if(n=a===t||a.classList.contains(s))return;a=a.parentNode}e(i)}}(this.getDOMNode(),this.handleClickOutside),a=t.length;t.push(this),e[a]=i,this.props.disableOnClickOutside||this.enableOnClickOutside()},componentWillUnmount:function(){this.disableOnClickOutside(),this.__outsideClickHandler=!1;var s=t.indexOf(this);s>-1&&e[s]&&(e.splice(s,1),t.splice(s,1))},enableOnClickOutside:function(){var t=this.__outsideClickHandler;document.addEventListener("mousedown",t),document.addEventListener("touchstart",t)},disableOnClickOutside:function(t){var t=this.__outsideClickHandler;document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t)}}})}])});