marquex
2015-07-23 8abb28c2b289d7d86d85b4bd24f475775a57a99d
commit | author | age
d76f7b 1 /*
8abb28 2 react-datetime v1.0.0-rc.1
d76f7b 3 https://github.com/arqex/react-datetime
M 4 MIT: https://github.com/arqex/react-datetime/raw/master/LICENSE
5 */
8abb28 6 !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(n){if(s[n])return s[n].exports;var r=s[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var s={};return e.m=t,e.c=s,e.p="",e(0)}([function(t,e,s){"use strict";s(1);var n=s(2),r=s(3),i=s(4),a=s(6),o=s(7),c=s(8),u=s(5),l=r.PropTypes,p=r.createClass({mixins:[s(9)],viewComponents:{days:i,months:a,years:o,time:c},propTypes:{value:l.object,defaultValue:l.object,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,minDate:l.object,maxDate:l.object},getDefaultProps:function(){var t=function(){};return{className:"",value:!1,defaultValue:new Date,viewMode:"days",inputProps:{},input:!0,onBlur:t,onChange:t,timeFormat:!0,dateFormat:!0}},getInitialState:function(){var t=this.getStateFromProps(this.props);return t.open=!this.props.input,t.currentView=this.props.viewMode,t},getStateFromProps:function(t){var e,s=this.getFormats(t),n=t.value||t.defaultValue;return e="string"==typeof n?this.localMoment(n,s.datetime):this.localMoment(n),{inputFormat:s.datetime,viewDate:this.localMoment(n).startOf("month"),selectedDate:this.localMoment(n),inputValue:this.localMoment(n).format(s.datetime)}},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},componentWillReceiveProps:function(t){var e=this.getFormats(t),s={};t.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),n={inputValue:e};return s.isValid()&&!this.props.value&&(n.selectedDate=s,n.viewDate=s.clone().startOf("month")),this.setState(n,function(){return s.isValid()?this.props.onChange(s):void 0})},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(n){e.setState({viewDate:e.state.viewDate.clone()[t](parseInt(n.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,n){var r=this;return function(){var i={},a=n?"selectedDate":"viewDate";i[a]=r.state[a].clone()[t](e,s),r.setState(i)}},allowedSetTime:["hours","minutes","seconds","milliseconds"],setTime:function(t,e){var s,n=this.allowedSetTime.indexOf(t)+1,r=this.state.selectedDate.clone();for(r[t](e);n<this.allowedSetTime.length;n++)s=this.allowedSetTime[n],r[s](r[s]());this.props.value||this.setState({selectedDate:r,inputValue:r.format(this.state.inputFormat)}),this.props.onChange(r)},updateSelectedDate:function(t){var e,s=t.target,n=0,r=this.state.selectedDate;-1!=s.className.indexOf("new")?n=1:-1!=s.className.indexOf("old")&&(n=-1),e=this.state.viewDate.clone().month(this.state.viewDate.month()+n).date(parseInt(s.getAttribute("data-value"))).hours(r.hours()).minutes(r.minutes()).seconds(r.seconds()).milliseconds(r.milliseconds()),this.props.value||this.setState({selectedDate:e,viewDate:e.clone().startOf("month"),inputValue:e.format(this.state.inputFormat)}),this.props.onChange(e)},openCalendar:function(){this.setState({open:!0})},handleClickOutside:function(){this.props.onBlur(this.state.selectedDate),this.props.input&&this.state.open&&this.setState({open:!1})},localMoment:function(t,e){var s=u(t,e);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=r.DOM,s="rdt "+this.props.className,i=[];return this.props.input?i=[e.input(n({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},i.concat(e.div({key:"dt",className:"rdtPicker"},r.createElement(t,this.getComponentProps()))))}});p.moment=u,t.exports=p},function(t,e){"document"in window.self&&("classList"in document.createElement("_")?!function(){"use strict";var t=document.createElement("_");if(t.classList.add("c1","c2"),!t.classList.contains("c2")){var e=function(t){var e=DOMTokenList.prototype[t];DOMTokenList.prototype[t]=function(t){var s,n=arguments.length;for(s=0;n>s;s++)t=arguments[s],e.call(this,t)}};e("add"),e("remove")}if(t.classList.toggle("c3",!1),t.classList.contains("c3")){var s=DOMTokenList.prototype.toggle;DOMTokenList.prototype.toggle=function(t,e){return 1 in arguments&&!this.contains(t)==!e?e:s.call(this,t)}}t=null}():!function(t){"use strict";if("Element"in t){var e="classList",s="prototype",n=t.Element[s],r=Object,i=String[s].trim||function(){return this.replace(/^\s+|\s+$/g,"")},a=Array[s].indexOf||function(t){for(var e=0,s=this.length;s>e;e++)if(e in this&&this[e]===t)return e;return-1},o=function(t,e){this.name=t,this.code=DOMException[t],this.message=e},c=function(t,e){if(""===e)throw new o("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new o("INVALID_CHARACTER_ERR","String contains an invalid character");return a.call(t,e)},u=function(t){for(var e=i.call(t.getAttribute("class")||""),s=e?e.split(/\s+/):[],n=0,r=s.length;r>n;n++)this.push(s[n]);this._updateClassName=function(){t.setAttribute("class",this.toString())}},l=u[s]=[],p=function(){return new u(this)};if(o[s]=Error[s],l.item=function(t){return this[t]||null},l.contains=function(t){return t+="",-1!==c(this,t)},l.add=function(){var t,e=arguments,s=0,n=e.length,r=!1;do t=e[s]+"",-1===c(this,t)&&(this.push(t),r=!0);while(++s<n);r&&this._updateClassName()},l.remove=function(){var t,e,s=arguments,n=0,r=s.length,i=!1;do for(t=s[n]+"",e=c(this,t);-1!==e;)this.splice(e,1),i=!0,e=c(this,t);while(++n<r);i&&this._updateClassName()},l.toggle=function(t,e){t+="";var s=this.contains(t),n=s?e!==!0&&"remove":e!==!1&&"add";return n&&this[n](t),e===!0||e===!1?e:!s},l.toString=function(){return this.join(" ")},r.defineProperty){var d={get:p,enumerable:!0,configurable:!0};try{r.defineProperty(n,e,d)}catch(h){-2146823252===h.number&&(d.enumerable=!1,r.defineProperty(n,e,d))}}else r[s].__defineGetter__&&n.__defineGetter__(e,p)}}(window.self))},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 n(t){var e=Object.getOwnPropertyNames(t);return Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(t))),e.filter(function(e){return r.call(t,e)})}var r=Object.prototype.propertyIsEnumerable;t.exports=Object.assign||function(t,e){for(var r,i,a=s(t),o=1;o<arguments.length;o++){r=arguments[o],i=n(Object(r));for(var c=0;c<i.length;c++)a[i[c]]=r[i[c]]}return a}},function(e,s){e.exports=t},function(t,e,s){var n=s(3),r=s(5),i=n.DOM,a=n.createClass({render:function(){var t,e=this.renderFooter(),s=this.props.viewDate,n=s.localeData();return t=[i.thead({key:"th"},[i.tr({key:"h"},[i.th({key:"p",className:"prev"},i.button({onClick:this.props.subtractTime(1,"months"),type:"button"},"‹")),i.th({key:"s",className:"switch",onClick:this.props.showView("months"),colSpan:5},n.months(s)+" "+s.year()),i.th({key:"n",className:"next"},i.button({onClick:this.props.addTime(1,"months"),type:"button"},"›"))]),i.tr({key:"d"},this.getDaysOfWeek(n).map(function(t){return i.th({key:t,className:"dow"},t)}))]),i.tbody({key:"tb"},this.renderDays())],e&&t.push(e),i.div({className:"rdtDays"},i.table({},t))},getDaysOfWeek:function(t){var e=t._weekdaysMin,s=t.firstDayOfWeek(),n=[],r=0;return e.forEach(function(t){n[(7+r++-s)%7]=t}),n},renderDays:function(){var t,e,s,n,a=this.props.viewDate,o=this.props.selectedDate.clone(),c=a.clone().subtract(1,"months"),u=a.year(),l=a.month(),p={y:o.year(),M:o.month(),d:o.date()},d=(this.props.minDate,this.props.maxDate,[]),h=[],m=this.props.renderDay||this.renderDay,f=this.props.isValidDate||this.isValidDate;c.date(c.daysInMonth()).startOf("week");for(var v=c.clone().add(42,"d");c.isBefore(v);)t="day",n=c.clone(),c.year()<u||c.month()<l?t+=" old":(c.year()>u||c.month()>l)&&(t+=" new"),c.isSame(p)&&(t+=" active"),c.isSame(r(),"day")&&(t+=" today"),e=!f(n,o),e&&(t+=" disabled"),s={key:c.format("M_D"),"data-value":c.date(),className:t},e||(s.onClick=this.props.updateSelectedDate),h.push(m(s,n,o)),7==h.length&&(d.push(i.tr({key:c.format("M_D")},h)),h=[]),c.add(1,"d");return d},renderDay:function(t,e,s){return i.td(t,e.date())},renderFooter:function(){return this.props.timeFormat?i.tfoot({key:"tf"},i.tr({},i.td({onClick:this.props.showView("time"),colSpan:7,className:"timeToggle"},this.props.selectedDate.format(this.props.timeFormat)))):""},isValidDate:function(){return 1}});t.exports=a},function(t,s){t.exports=e},function(t,e,s){"use strict";var n=s(3),r=(s(5),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:"prev"},r.button({onClick:this.props.subtractTime(1,"years"),type:"button"},"‹")),r.th({key:"year",className:"switch",onClick:this.props.showView("years"),colSpan:2},this.props.viewDate.year()),r.th({key:"next",className:"next"},r.button({onClick:this.props.addTime(1,"years"),type:"button"},"›"))]))),r.table({key:"months"},r.tbody({key:"b"},this.renderMonths()))])},renderMonths:function(){for(var t,e,s=this.props.selectedDate,n=s.month(),i=this.props.viewDate.year(),a=[],o=0,c=[],u=this.props.renderMonth||this.renderMonth;12>o;)t="month",o===n&&i===s.year()&&(t+=" active"),e={key:o,"data-value":o,className:t,onClick:this.props.setDate("month")},c.push(u(e,o,i,s.clone())),4==c.length&&(a.push(r.tr({key:n+"_"+a.length},c)),c=[]),o++;return a},renderMonth:function(t,e,s,n){return r.td(t,n.localeData()._monthsShort[e])}});t.exports=i},function(t,e,s){"use strict";var n=s(3),r=n.DOM,i=n.createClass({render:function(){var t=10*parseInt(this.props.viewDate.year()/10,10);return r.div({className:"rdtYears"},[r.table({key:"a"},r.thead({},r.tr({},[r.th({key:"prev",className:"prev"},r.button({onClick:this.props.subtractTime(10,"years"),type:"button"},"‹")),r.th({key:"year",className:"switch",onClick:this.props.showView("years"),colSpan:2},t+"-"+(t+9)),r.th({key:"next",className:"next"},r.button({onClick:this.props.addTime(10,"years"),type:"button"},"›"))]))),r.table({key:"years"},r.tbody({},this.renderYears(t)))])},renderYears:function(t){var e,s,n=[],i=-1,a=[],o=this.props.renderYear||this.renderYear;for(t--;11>i;)e="year",-1===i|10===i&&(e+=" old"),this.props.selectedDate.year()===t&&(e+=" active"),s={key:t,"data-value":t,className:e,onClick:this.props.setDate("year")},n.push(o(s,t,this.props.selectedDate.clone())),4==n.length&&(a.push(r.tr({key:i},n)),n=[]),t++,i++;return a},renderYear:function(t,e,s){return r.td(t,e)}});t.exports=i},function(t,e,s){"use strict";var n=s(3),r=n.DOM,i=n.createClass({getInitialState:function(){return this.calculateState(this.props)},calculateState:function(t){var e=t.selectedDate,s=t.timeFormat,n=[];return(-1!=s.indexOf("H")||-1!=s.indexOf("h"))&&(n.push("hours"),-1!=s.indexOf("m")&&(n.push("minutes"),-1!=s.indexOf("s")&&n.push("seconds"))),{hours:e.format("H"),minutes:e.format("mm"),seconds:e.format("ss"),milliseconds:e.format("SSS"),counters:n}},renderCounter:function(t){return r.div({key:t,className:"rdtCounter"},[r.button({key:"up",className:"btn",onMouseDown:this.onStartClicking("increase",t),type:"button"},"▲"),r.div({key:"c",className:"rdtCount"},this.state[t]),r.button({key:"do",className:"btn",onMouseDown:this.onStartClicking("decrease",t),type:"button"},"▼")])},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))}),3==this.state.counters.length&&-1!=this.props.timeFormat.indexOf("S")&&(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))))]))},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(){return this.props.dateFormat?r.thead({key:"h"},r.tr({},r.th({colSpan:4,onClick:this.props.showView("days")},this.props.selectedDate.format(this.props.dateFormat)))):""},onStartClicking:function(t,e){{var s=this;this.state[e]}return function(){var n={};n[e]=s[t](e),s.setState(n),s.timer=setTimeout(function(){s.increaseTimer=setInterval(function(){n[e]=s[t](e),s.setState(n)},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=i},function(t,e,s){var n,r,i;!function(s,a){r=[],n=a,i="function"==typeof n?n.apply(e,r):n,!(void 0!==i&&(t.exports=i))}(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 n=this.__outsideClickHandler=function(t,e){return function(n){for(var r=n.target,i=!1;r.parentNode;){if(i=r===t||r.classList.contains(s))return;r=r.parentNode}e(n)}}(this.getDOMNode(),this.handleClickOutside),r=t.length;t.push(this),e[r]=n,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)}}})}])});