commit | author | age
|
d76f7b
|
1 |
/* |
7750ac
|
2 |
react-datetime v2.8.7 |
be9654
|
3 |
https://github.com/YouCanBookMe/react-datetime |
SE |
4 |
MIT: https://github.com/YouCanBookMe/react-datetime/raw/master/LICENSE |
d76f7b
|
5 |
*/ |
M |
6 |
(function webpackUniversalModuleDefinition(root, factory) { |
|
7 |
if(typeof exports === 'object' && typeof module === 'object') |
c5aa9b
|
8 |
module.exports = factory(require("moment"), require("React"), require("ReactDOM")); |
d76f7b
|
9 |
else if(typeof define === 'function' && define.amd) |
c5aa9b
|
10 |
define(["moment", "React", "ReactDOM"], factory); |
d76f7b
|
11 |
else if(typeof exports === 'object') |
c5aa9b
|
12 |
exports["Datetime"] = factory(require("moment"), require("React"), require("ReactDOM")); |
d76f7b
|
13 |
else |
c5aa9b
|
14 |
root["Datetime"] = factory(root["moment"], root["React"], root["ReactDOM"]); |
7750ac
|
15 |
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_10__) { |
d76f7b
|
16 |
return /******/ (function(modules) { // webpackBootstrap |
M |
17 |
/******/ // The module cache |
|
18 |
/******/ var installedModules = {}; |
|
19 |
|
|
20 |
/******/ // The require function |
|
21 |
/******/ function __webpack_require__(moduleId) { |
|
22 |
|
|
23 |
/******/ // Check if module is in cache |
|
24 |
/******/ if(installedModules[moduleId]) |
|
25 |
/******/ return installedModules[moduleId].exports; |
|
26 |
|
|
27 |
/******/ // Create a new module (and put it into the cache) |
|
28 |
/******/ var module = installedModules[moduleId] = { |
|
29 |
/******/ exports: {}, |
|
30 |
/******/ id: moduleId, |
|
31 |
/******/ loaded: false |
|
32 |
/******/ }; |
|
33 |
|
|
34 |
/******/ // Execute the module function |
|
35 |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
|
36 |
|
|
37 |
/******/ // Flag the module as loaded |
|
38 |
/******/ module.loaded = true; |
|
39 |
|
|
40 |
/******/ // Return the exports of the module |
|
41 |
/******/ return module.exports; |
|
42 |
/******/ } |
|
43 |
|
|
44 |
|
|
45 |
/******/ // expose the modules object (__webpack_modules__) |
|
46 |
/******/ __webpack_require__.m = modules; |
|
47 |
|
|
48 |
/******/ // expose the module cache |
|
49 |
/******/ __webpack_require__.c = installedModules; |
|
50 |
|
|
51 |
/******/ // __webpack_public_path__ |
|
52 |
/******/ __webpack_require__.p = ""; |
|
53 |
|
|
54 |
/******/ // Load entry module and return exports |
|
55 |
/******/ return __webpack_require__(0); |
|
56 |
/******/ }) |
|
57 |
/************************************************************************/ |
|
58 |
/******/ ([ |
|
59 |
/* 0 */ |
|
60 |
/***/ function(module, exports, __webpack_require__) { |
|
61 |
|
be9654
|
62 |
'use strict'; |
SE |
63 |
|
|
64 |
var assign = __webpack_require__(1), |
|
65 |
moment = __webpack_require__(2), |
|
66 |
React = __webpack_require__(3), |
7750ac
|
67 |
CalendarContainer = __webpack_require__(4) |
be9654
|
68 |
; |
SE |
69 |
|
|
70 |
var TYPES = React.PropTypes; |
|
71 |
var Datetime = React.createClass({ |
|
72 |
propTypes: { |
|
73 |
// value: TYPES.object | TYPES.string, |
|
74 |
// defaultValue: TYPES.object | TYPES.string, |
|
75 |
onFocus: TYPES.func, |
|
76 |
onBlur: TYPES.func, |
|
77 |
onChange: TYPES.func, |
|
78 |
locale: TYPES.string, |
|
79 |
utc: TYPES.bool, |
|
80 |
input: TYPES.bool, |
|
81 |
// dateFormat: TYPES.string | TYPES.bool, |
|
82 |
// timeFormat: TYPES.string | TYPES.bool, |
|
83 |
inputProps: TYPES.object, |
|
84 |
timeConstraints: TYPES.object, |
|
85 |
viewMode: TYPES.oneOf(['years', 'months', 'days', 'time']), |
|
86 |
isValidDate: TYPES.func, |
|
87 |
open: TYPES.bool, |
|
88 |
strictParsing: TYPES.bool, |
|
89 |
closeOnSelect: TYPES.bool, |
|
90 |
closeOnTab: TYPES.bool |
|
91 |
}, |
|
92 |
|
|
93 |
getDefaultProps: function() { |
|
94 |
var nof = function() {}; |
|
95 |
return { |
|
96 |
className: '', |
|
97 |
defaultValue: '', |
|
98 |
inputProps: {}, |
|
99 |
input: true, |
|
100 |
onFocus: nof, |
|
101 |
onBlur: nof, |
|
102 |
onChange: nof, |
|
103 |
timeFormat: true, |
|
104 |
timeConstraints: {}, |
|
105 |
dateFormat: true, |
|
106 |
strictParsing: true, |
|
107 |
closeOnSelect: false, |
|
108 |
closeOnTab: true, |
|
109 |
utc: false |
|
110 |
}; |
|
111 |
}, |
|
112 |
|
|
113 |
getInitialState: function() { |
|
114 |
var state = this.getStateFromProps( this.props ); |
|
115 |
|
|
116 |
if ( state.open === undefined ) |
|
117 |
state.open = !this.props.input; |
|
118 |
|
|
119 |
state.currentView = this.props.dateFormat ? (this.props.viewMode || state.updateOn || 'days') : 'time'; |
|
120 |
|
|
121 |
return state; |
|
122 |
}, |
|
123 |
|
|
124 |
getStateFromProps: function( props ) { |
|
125 |
var formats = this.getFormats( props ), |
|
126 |
date = props.value || props.defaultValue, |
|
127 |
selectedDate, viewDate, updateOn, inputValue |
|
128 |
; |
|
129 |
|
|
130 |
if ( date && typeof date === 'string' ) |
|
131 |
selectedDate = this.localMoment( date, formats.datetime ); |
|
132 |
else if ( date ) |
|
133 |
selectedDate = this.localMoment( date ); |
|
134 |
|
|
135 |
if ( selectedDate && !selectedDate.isValid() ) |
|
136 |
selectedDate = null; |
|
137 |
|
|
138 |
viewDate = selectedDate ? |
|
139 |
selectedDate.clone().startOf('month') : |
|
140 |
this.localMoment().startOf('month') |
|
141 |
; |
|
142 |
|
|
143 |
updateOn = this.getUpdateOn(formats); |
|
144 |
|
|
145 |
if ( selectedDate ) |
|
146 |
inputValue = selectedDate.format(formats.datetime); |
|
147 |
else if ( date.isValid && !date.isValid() ) |
|
148 |
inputValue = ''; |
|
149 |
else |
|
150 |
inputValue = date || ''; |
|
151 |
|
|
152 |
return { |
|
153 |
updateOn: updateOn, |
|
154 |
inputFormat: formats.datetime, |
|
155 |
viewDate: viewDate, |
|
156 |
selectedDate: selectedDate, |
|
157 |
inputValue: inputValue, |
|
158 |
open: props.open |
|
159 |
}; |
|
160 |
}, |
|
161 |
|
|
162 |
getUpdateOn: function( formats ) { |
|
163 |
if ( formats.date.match(/[lLD]/) ) { |
|
164 |
return 'days'; |
|
165 |
} |
|
166 |
else if ( formats.date.indexOf('M') !== -1 ) { |
|
167 |
return 'months'; |
|
168 |
} |
|
169 |
else if ( formats.date.indexOf('Y') !== -1 ) { |
|
170 |
return 'years'; |
|
171 |
} |
|
172 |
|
|
173 |
return 'days'; |
|
174 |
}, |
|
175 |
|
|
176 |
getFormats: function( props ) { |
|
177 |
var formats = { |
|
178 |
date: props.dateFormat || '', |
|
179 |
time: props.timeFormat || '' |
|
180 |
}, |
|
181 |
locale = this.localMoment( props.date, null, props ).localeData() |
|
182 |
; |
|
183 |
|
|
184 |
if ( formats.date === true ) { |
|
185 |
formats.date = locale.longDateFormat('L'); |
|
186 |
} |
|
187 |
else if ( this.getUpdateOn(formats) !== 'days' ) { |
|
188 |
formats.time = ''; |
|
189 |
} |
|
190 |
|
|
191 |
if ( formats.time === true ) { |
|
192 |
formats.time = locale.longDateFormat('LT'); |
|
193 |
} |
|
194 |
|
|
195 |
formats.datetime = formats.date && formats.time ? |
|
196 |
formats.date + ' ' + formats.time : |
|
197 |
formats.date || formats.time |
|
198 |
; |
|
199 |
|
|
200 |
return formats; |
|
201 |
}, |
|
202 |
|
|
203 |
componentWillReceiveProps: function( nextProps ) { |
|
204 |
var formats = this.getFormats( nextProps ), |
|
205 |
updatedState = {} |
|
206 |
; |
|
207 |
|
|
208 |
if ( nextProps.value !== this.props.value || |
|
209 |
formats.datetime !== this.getFormats( this.props ).datetime ) { |
|
210 |
updatedState = this.getStateFromProps( nextProps ); |
|
211 |
} |
|
212 |
|
|
213 |
if ( updatedState.open === undefined ) { |
a6752b
|
214 |
if ( this.props.closeOnSelect && this.state.currentView !== 'time' ) { |
SE |
215 |
updatedState.open = false; |
7750ac
|
216 |
} else { |
a6752b
|
217 |
updatedState.open = this.state.open; |
SE |
218 |
} |
be9654
|
219 |
} |
SE |
220 |
|
|
221 |
if ( nextProps.viewMode !== this.props.viewMode ) { |
|
222 |
updatedState.currentView = nextProps.viewMode; |
|
223 |
} |
|
224 |
|
|
225 |
if ( nextProps.locale !== this.props.locale ) { |
|
226 |
if ( this.state.viewDate ) { |
|
227 |
var updatedViewDate = this.state.viewDate.clone().locale( nextProps.locale ); |
|
228 |
updatedState.viewDate = updatedViewDate; |
|
229 |
} |
|
230 |
if ( this.state.selectedDate ) { |
|
231 |
var updatedSelectedDate = this.state.selectedDate.clone().locale( nextProps.locale ); |
|
232 |
updatedState.selectedDate = updatedSelectedDate; |
|
233 |
updatedState.inputValue = updatedSelectedDate.format( formats.datetime ); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
if ( nextProps.utc !== this.props.utc ) { |
|
238 |
if ( nextProps.utc ) { |
|
239 |
if ( this.state.viewDate ) |
|
240 |
updatedState.viewDate = this.state.viewDate.clone().utc(); |
|
241 |
if ( this.state.selectedDate ) { |
|
242 |
updatedState.selectedDate = this.state.selectedDate.clone().utc(); |
|
243 |
updatedState.inputValue = updatedState.selectedDate.format( formats.datetime ); |
|
244 |
} |
|
245 |
} else { |
|
246 |
if ( this.state.viewDate ) |
|
247 |
updatedState.viewDate = this.state.viewDate.clone().local(); |
|
248 |
if ( this.state.selectedDate ) { |
|
249 |
updatedState.selectedDate = this.state.selectedDate.clone().local(); |
|
250 |
updatedState.inputValue = updatedState.selectedDate.format(formats.datetime); |
|
251 |
} |
|
252 |
} |
|
253 |
} |
|
254 |
|
|
255 |
this.setState( updatedState ); |
|
256 |
}, |
|
257 |
|
|
258 |
onInputChange: function( e ) { |
|
259 |
var value = e.target === null ? e : e.target.value, |
|
260 |
localMoment = this.localMoment( value, this.state.inputFormat ), |
|
261 |
update = { inputValue: value } |
|
262 |
; |
|
263 |
|
|
264 |
if ( localMoment.isValid() && !this.props.value ) { |
|
265 |
update.selectedDate = localMoment; |
|
266 |
update.viewDate = localMoment.clone().startOf('month'); |
|
267 |
} |
|
268 |
else { |
|
269 |
update.selectedDate = null; |
|
270 |
} |
|
271 |
|
|
272 |
return this.setState( update, function() { |
|
273 |
return this.props.onChange( localMoment.isValid() ? localMoment : this.state.inputValue ); |
|
274 |
}); |
|
275 |
}, |
|
276 |
|
|
277 |
onInputKey: function( e ) { |
|
278 |
if ( e.which === 9 && this.props.closeOnTab ) { |
|
279 |
this.closeCalendar(); |
|
280 |
} |
|
281 |
}, |
|
282 |
|
|
283 |
showView: function( view ) { |
|
284 |
var me = this; |
|
285 |
return function() { |
|
286 |
me.setState({ currentView: view }); |
|
287 |
}; |
|
288 |
}, |
|
289 |
|
|
290 |
setDate: function( type ) { |
|
291 |
var me = this, |
|
292 |
nextViews = { |
|
293 |
month: 'days', |
|
294 |
year: 'months' |
|
295 |
} |
|
296 |
; |
|
297 |
return function( e ) { |
|
298 |
me.setState({ |
|
299 |
viewDate: me.state.viewDate.clone()[ type ]( parseInt(e.target.getAttribute('data-value'), 10) ).startOf( type ), |
|
300 |
currentView: nextViews[ type ] |
|
301 |
}); |
|
302 |
}; |
|
303 |
}, |
|
304 |
|
|
305 |
addTime: function( amount, type, toSelected ) { |
|
306 |
return this.updateTime( 'add', amount, type, toSelected ); |
|
307 |
}, |
|
308 |
|
|
309 |
subtractTime: function( amount, type, toSelected ) { |
|
310 |
return this.updateTime( 'subtract', amount, type, toSelected ); |
|
311 |
}, |
|
312 |
|
|
313 |
updateTime: function( op, amount, type, toSelected ) { |
|
314 |
var me = this; |
|
315 |
|
|
316 |
return function() { |
|
317 |
var update = {}, |
|
318 |
date = toSelected ? 'selectedDate' : 'viewDate' |
|
319 |
; |
|
320 |
|
|
321 |
update[ date ] = me.state[ date ].clone()[ op ]( amount, type ); |
|
322 |
|
|
323 |
me.setState( update ); |
|
324 |
}; |
|
325 |
}, |
|
326 |
|
|
327 |
allowedSetTime: ['hours', 'minutes', 'seconds', 'milliseconds'], |
|
328 |
setTime: function( type, value ) { |
|
329 |
var index = this.allowedSetTime.indexOf( type ) + 1, |
|
330 |
state = this.state, |
|
331 |
date = (state.selectedDate || state.viewDate).clone(), |
|
332 |
nextType |
|
333 |
; |
|
334 |
|
|
335 |
// It is needed to set all the time properties |
|
336 |
// to not to reset the time |
|
337 |
date[ type ]( value ); |
|
338 |
for (; index < this.allowedSetTime.length; index++) { |
|
339 |
nextType = this.allowedSetTime[index]; |
|
340 |
date[ nextType ]( date[nextType]() ); |
|
341 |
} |
|
342 |
|
|
343 |
if ( !this.props.value ) { |
|
344 |
this.setState({ |
|
345 |
selectedDate: date, |
|
346 |
inputValue: date.format( state.inputFormat ) |
|
347 |
}); |
|
348 |
} |
|
349 |
this.props.onChange( date ); |
|
350 |
}, |
|
351 |
|
|
352 |
updateSelectedDate: function( e, close ) { |
|
353 |
var target = e.target, |
|
354 |
modifier = 0, |
|
355 |
viewDate = this.state.viewDate, |
|
356 |
currentDate = this.state.selectedDate || viewDate, |
|
357 |
date |
|
358 |
; |
|
359 |
|
|
360 |
if (target.className.indexOf('rdtDay') !== -1) { |
|
361 |
if (target.className.indexOf('rdtNew') !== -1) |
|
362 |
modifier = 1; |
|
363 |
else if (target.className.indexOf('rdtOld') !== -1) |
|
364 |
modifier = -1; |
|
365 |
|
|
366 |
date = viewDate.clone() |
|
367 |
.month( viewDate.month() + modifier ) |
|
368 |
.date( parseInt( target.getAttribute('data-value'), 10 ) ); |
|
369 |
} else if (target.className.indexOf('rdtMonth') !== -1) { |
|
370 |
date = viewDate.clone() |
|
371 |
.month( parseInt( target.getAttribute('data-value'), 10 ) ) |
|
372 |
.date( currentDate.date() ); |
|
373 |
} else if (target.className.indexOf('rdtYear') !== -1) { |
|
374 |
date = viewDate.clone() |
|
375 |
.month( currentDate.month() ) |
|
376 |
.date( currentDate.date() ) |
|
377 |
.year( parseInt( target.getAttribute('data-value'), 10 ) ); |
|
378 |
} |
|
379 |
|
|
380 |
date.hours( currentDate.hours() ) |
|
381 |
.minutes( currentDate.minutes() ) |
|
382 |
.seconds( currentDate.seconds() ) |
|
383 |
.milliseconds( currentDate.milliseconds() ); |
|
384 |
|
|
385 |
if ( !this.props.value ) { |
7750ac
|
386 |
var open = !( this.props.closeOnSelect && close ); |
JM |
387 |
if ( !open ) { |
|
388 |
this.props.onBlur( date ); |
|
389 |
} |
|
390 |
|
be9654
|
391 |
this.setState({ |
SE |
392 |
selectedDate: date, |
|
393 |
viewDate: date.clone().startOf('month'), |
|
394 |
inputValue: date.format( this.state.inputFormat ), |
7750ac
|
395 |
open: open |
be9654
|
396 |
}); |
SE |
397 |
} else { |
7750ac
|
398 |
if ( this.props.closeOnSelect && close ) { |
be9654
|
399 |
this.closeCalendar(); |
SE |
400 |
} |
|
401 |
} |
|
402 |
|
|
403 |
this.props.onChange( date ); |
|
404 |
}, |
|
405 |
|
|
406 |
openCalendar: function() { |
|
407 |
if (!this.state.open) { |
|
408 |
this.setState({ open: true }, function() { |
|
409 |
this.props.onFocus(); |
|
410 |
}); |
|
411 |
} |
|
412 |
}, |
|
413 |
|
|
414 |
closeCalendar: function() { |
|
415 |
this.setState({ open: false }, function () { |
|
416 |
this.props.onBlur( this.state.selectedDate || this.state.inputValue ); |
|
417 |
}); |
|
418 |
}, |
|
419 |
|
|
420 |
handleClickOutside: function() { |
|
421 |
if ( this.props.input && this.state.open && !this.props.open ) { |
|
422 |
this.setState({ open: false }, function() { |
|
423 |
this.props.onBlur( this.state.selectedDate || this.state.inputValue ); |
|
424 |
}); |
|
425 |
} |
|
426 |
}, |
|
427 |
|
|
428 |
localMoment: function( date, format, props ) { |
|
429 |
props = props || this.props; |
|
430 |
var momentFn = props.utc ? moment.utc : moment; |
|
431 |
var m = momentFn( date, format, props.strictParsing ); |
|
432 |
if ( props.locale ) |
|
433 |
m.locale( props.locale ); |
|
434 |
return m; |
|
435 |
}, |
|
436 |
|
|
437 |
componentProps: { |
|
438 |
fromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear', 'timeConstraints'], |
|
439 |
fromState: ['viewDate', 'selectedDate', 'updateOn'], |
|
440 |
fromThis: ['setDate', 'setTime', 'showView', 'addTime', 'subtractTime', 'updateSelectedDate', 'localMoment'] |
|
441 |
}, |
|
442 |
|
|
443 |
getComponentProps: function() { |
|
444 |
var me = this, |
|
445 |
formats = this.getFormats( this.props ), |
|
446 |
props = {dateFormat: formats.date, timeFormat: formats.time} |
|
447 |
; |
|
448 |
|
|
449 |
this.componentProps.fromProps.forEach( function( name ) { |
|
450 |
props[ name ] = me.props[ name ]; |
|
451 |
}); |
|
452 |
this.componentProps.fromState.forEach( function( name ) { |
|
453 |
props[ name ] = me.state[ name ]; |
|
454 |
}); |
|
455 |
this.componentProps.fromThis.forEach( function( name ) { |
|
456 |
props[ name ] = me[ name ]; |
|
457 |
}); |
|
458 |
|
|
459 |
return props; |
|
460 |
}, |
|
461 |
|
|
462 |
render: function() { |
7750ac
|
463 |
var DOM = React.DOM, |
be9654
|
464 |
className = 'rdt' + (this.props.className ? |
SE |
465 |
( Array.isArray( this.props.className ) ? |
|
466 |
' ' + this.props.className.join( ' ' ) : ' ' + this.props.className) : ''), |
|
467 |
children = [] |
|
468 |
; |
|
469 |
|
|
470 |
if ( this.props.input ) { |
|
471 |
children = [ DOM.input( assign({ |
|
472 |
key: 'i', |
|
473 |
type: 'text', |
|
474 |
className: 'form-control', |
|
475 |
onFocus: this.openCalendar, |
|
476 |
onChange: this.onInputChange, |
|
477 |
onKeyDown: this.onInputKey, |
|
478 |
value: this.state.inputValue |
|
479 |
}, this.props.inputProps ))]; |
|
480 |
} else { |
|
481 |
className += ' rdtStatic'; |
|
482 |
} |
|
483 |
|
|
484 |
if ( this.state.open ) |
|
485 |
className += ' rdtOpen'; |
|
486 |
|
|
487 |
return DOM.div({className: className}, children.concat( |
|
488 |
DOM.div( |
|
489 |
{ key: 'dt', className: 'rdtPicker' }, |
7750ac
|
490 |
React.createElement( CalendarContainer, {view: this.state.currentView, viewProps: this.getComponentProps(), onClickOutside: this.handleClickOutside }) |
be9654
|
491 |
) |
SE |
492 |
)); |
|
493 |
} |
|
494 |
}); |
|
495 |
|
|
496 |
// Make moment accessible through the Datetime class |
|
497 |
Datetime.moment = moment; |
|
498 |
|
|
499 |
module.exports = Datetime; |
|
500 |
|
d76f7b
|
501 |
|
M |
502 |
/***/ }, |
|
503 |
/* 1 */ |
272903
|
504 |
/***/ function(module, exports) { |
d76f7b
|
505 |
|
be9654
|
506 |
'use strict'; |
SE |
507 |
var propIsEnumerable = Object.prototype.propertyIsEnumerable; |
|
508 |
|
|
509 |
function ToObject(val) { |
|
510 |
if (val == null) { |
|
511 |
throw new TypeError('Object.assign cannot be called with null or undefined'); |
|
512 |
} |
|
513 |
|
|
514 |
return Object(val); |
|
515 |
} |
|
516 |
|
|
517 |
function ownEnumerableKeys(obj) { |
|
518 |
var keys = Object.getOwnPropertyNames(obj); |
|
519 |
|
|
520 |
if (Object.getOwnPropertySymbols) { |
|
521 |
keys = keys.concat(Object.getOwnPropertySymbols(obj)); |
|
522 |
} |
|
523 |
|
|
524 |
return keys.filter(function (key) { |
|
525 |
return propIsEnumerable.call(obj, key); |
|
526 |
}); |
|
527 |
} |
|
528 |
|
|
529 |
module.exports = Object.assign || function (target, source) { |
|
530 |
var from; |
|
531 |
var keys; |
|
532 |
var to = ToObject(target); |
|
533 |
|
|
534 |
for (var s = 1; s < arguments.length; s++) { |
|
535 |
from = arguments[s]; |
|
536 |
keys = ownEnumerableKeys(Object(from)); |
|
537 |
|
|
538 |
for (var i = 0; i < keys.length; i++) { |
|
539 |
to[keys[i]] = from[keys[i]]; |
|
540 |
} |
|
541 |
} |
|
542 |
|
|
543 |
return to; |
|
544 |
}; |
|
545 |
|
d76f7b
|
546 |
|
M |
547 |
/***/ }, |
|
548 |
/* 2 */ |
|
549 |
/***/ function(module, exports) { |
|
550 |
|
be9654
|
551 |
module.exports = __WEBPACK_EXTERNAL_MODULE_2__; |
d76f7b
|
552 |
|
M |
553 |
/***/ }, |
|
554 |
/* 3 */ |
c5aa9b
|
555 |
/***/ function(module, exports) { |
d76f7b
|
556 |
|
be9654
|
557 |
module.exports = __WEBPACK_EXTERNAL_MODULE_3__; |
d76f7b
|
558 |
|
M |
559 |
/***/ }, |
|
560 |
/* 4 */ |
7750ac
|
561 |
/***/ function(module, exports, __webpack_require__) { |
JM |
562 |
|
|
563 |
var React = __webpack_require__(3), |
|
564 |
DaysView = __webpack_require__(5), |
|
565 |
MonthsView = __webpack_require__(6), |
|
566 |
YearsView = __webpack_require__(7), |
|
567 |
TimeView = __webpack_require__(8), |
|
568 |
onClickOutside = __webpack_require__(9) |
|
569 |
; |
|
570 |
|
|
571 |
var CalendarContainer = onClickOutside( React.createClass({ |
|
572 |
viewComponents: { |
|
573 |
days: DaysView, |
|
574 |
months: MonthsView, |
|
575 |
years: YearsView, |
|
576 |
time: TimeView |
|
577 |
}, |
|
578 |
|
|
579 |
render: function() { |
|
580 |
return React.createElement( this.viewComponents[ this.props.view ], this.props.viewProps ); |
|
581 |
}, |
|
582 |
|
|
583 |
handleClickOutside: function() { |
|
584 |
this.props.onClickOutside(); |
|
585 |
} |
|
586 |
})); |
|
587 |
|
|
588 |
module.exports = CalendarContainer; |
|
589 |
|
|
590 |
|
|
591 |
/***/ }, |
|
592 |
/* 5 */ |
c5aa9b
|
593 |
/***/ function(module, exports, __webpack_require__) { |
d76f7b
|
594 |
|
be9654
|
595 |
'use strict'; |
SE |
596 |
|
|
597 |
var React = __webpack_require__(3), |
|
598 |
moment = __webpack_require__(2) |
|
599 |
; |
|
600 |
|
|
601 |
var DOM = React.DOM; |
|
602 |
var DateTimePickerDays = React.createClass({ |
|
603 |
render: function() { |
|
604 |
var footer = this.renderFooter(), |
|
605 |
date = this.props.viewDate, |
|
606 |
locale = date.localeData(), |
|
607 |
tableChildren |
|
608 |
; |
|
609 |
|
|
610 |
tableChildren = [ |
|
611 |
DOM.thead({ key: 'th' }, [ |
|
612 |
DOM.tr({ key: 'h' }, [ |
|
613 |
DOM.th({ key: 'p', className: 'rdtPrev' }, DOM.span({ onClick: this.props.subtractTime( 1, 'months' )}, '‹' )), |
|
614 |
DOM.th({ key: 's', className: 'rdtSwitch', onClick: this.props.showView( 'months' ), colSpan: 5, 'data-value': this.props.viewDate.month() }, locale.months( date ) + ' ' + date.year() ), |
|
615 |
DOM.th({ key: 'n', className: 'rdtNext' }, DOM.span({ onClick: this.props.addTime( 1, 'months' )}, '›' )) |
|
616 |
]), |
|
617 |
DOM.tr({ key: 'd'}, this.getDaysOfWeek( locale ).map( function( day, index ) { return DOM.th({ key: day + index, className: 'dow'}, day ); }) ) |
|
618 |
]), |
|
619 |
DOM.tbody({ key: 'tb' }, this.renderDays()) |
|
620 |
]; |
|
621 |
|
|
622 |
if ( footer ) |
|
623 |
tableChildren.push( footer ); |
|
624 |
|
|
625 |
return DOM.div({ className: 'rdtDays' }, |
|
626 |
DOM.table({}, tableChildren ) |
|
627 |
); |
|
628 |
}, |
|
629 |
|
|
630 |
/** |
|
631 |
* Get a list of the days of the week |
|
632 |
* depending on the current locale |
|
633 |
* @return {array} A list with the shortname of the days |
|
634 |
*/ |
|
635 |
getDaysOfWeek: function( locale ) { |
|
636 |
var days = locale._weekdaysMin, |
|
637 |
first = locale.firstDayOfWeek(), |
|
638 |
dow = [], |
|
639 |
i = 0 |
|
640 |
; |
|
641 |
|
|
642 |
days.forEach( function( day ) { |
|
643 |
dow[ (7 + ( i++ ) - first) % 7 ] = day; |
|
644 |
}); |
|
645 |
|
|
646 |
return dow; |
|
647 |
}, |
|
648 |
|
|
649 |
renderDays: function() { |
|
650 |
var date = this.props.viewDate, |
|
651 |
selected = this.props.selectedDate && this.props.selectedDate.clone(), |
|
652 |
prevMonth = date.clone().subtract( 1, 'months' ), |
|
653 |
currentYear = date.year(), |
|
654 |
currentMonth = date.month(), |
|
655 |
weeks = [], |
|
656 |
days = [], |
|
657 |
renderer = this.props.renderDay || this.renderDay, |
|
658 |
isValid = this.props.isValidDate || this.alwaysValidDate, |
|
659 |
classes, isDisabled, dayProps, currentDate |
|
660 |
; |
|
661 |
|
|
662 |
// Go to the last week of the previous month |
|
663 |
prevMonth.date( prevMonth.daysInMonth() ).startOf( 'week' ); |
|
664 |
var lastDay = prevMonth.clone().add( 42, 'd' ); |
|
665 |
|
|
666 |
while ( prevMonth.isBefore( lastDay ) ) { |
|
667 |
classes = 'rdtDay'; |
|
668 |
currentDate = prevMonth.clone(); |
|
669 |
|
|
670 |
if ( ( prevMonth.year() === currentYear && prevMonth.month() < currentMonth ) || ( prevMonth.year() < currentYear ) ) |
|
671 |
classes += ' rdtOld'; |
|
672 |
else if ( ( prevMonth.year() === currentYear && prevMonth.month() > currentMonth ) || ( prevMonth.year() > currentYear ) ) |
|
673 |
classes += ' rdtNew'; |
|
674 |
|
|
675 |
if ( selected && prevMonth.isSame( selected, 'day' ) ) |
|
676 |
classes += ' rdtActive'; |
|
677 |
|
7750ac
|
678 |
if ( prevMonth.isSame( moment(), 'day' ) ) |
be9654
|
679 |
classes += ' rdtToday'; |
SE |
680 |
|
|
681 |
isDisabled = !isValid( currentDate, selected ); |
|
682 |
if ( isDisabled ) |
|
683 |
classes += ' rdtDisabled'; |
|
684 |
|
|
685 |
dayProps = { |
|
686 |
key: prevMonth.format( 'M_D' ), |
|
687 |
'data-value': prevMonth.date(), |
|
688 |
className: classes |
|
689 |
}; |
|
690 |
|
|
691 |
if ( !isDisabled ) |
|
692 |
dayProps.onClick = this.updateSelectedDate; |
|
693 |
|
|
694 |
days.push( renderer( dayProps, currentDate, selected ) ); |
|
695 |
|
|
696 |
if ( days.length === 7 ) { |
|
697 |
weeks.push( DOM.tr({ key: prevMonth.format( 'M_D' )}, days ) ); |
|
698 |
days = []; |
|
699 |
} |
|
700 |
|
|
701 |
prevMonth.add( 1, 'd' ); |
|
702 |
} |
|
703 |
|
|
704 |
return weeks; |
|
705 |
}, |
|
706 |
|
|
707 |
updateSelectedDate: function( event ) { |
|
708 |
this.props.updateSelectedDate( event, true ); |
|
709 |
}, |
|
710 |
|
|
711 |
renderDay: function( props, currentDate ) { |
|
712 |
return DOM.td( props, currentDate.date() ); |
|
713 |
}, |
|
714 |
|
|
715 |
renderFooter: function() { |
|
716 |
if ( !this.props.timeFormat ) |
|
717 |
return ''; |
|
718 |
|
|
719 |
var date = this.props.selectedDate || this.props.viewDate; |
|
720 |
|
|
721 |
return DOM.tfoot({ key: 'tf'}, |
|
722 |
DOM.tr({}, |
|
723 |
DOM.td({ onClick: this.props.showView( 'time' ), colSpan: 7, className: 'rdtTimeToggle' }, date.format( this.props.timeFormat )) |
|
724 |
) |
|
725 |
); |
|
726 |
}, |
|
727 |
|
|
728 |
alwaysValidDate: function() { |
|
729 |
return 1; |
|
730 |
} |
|
731 |
}); |
|
732 |
|
|
733 |
module.exports = DateTimePickerDays; |
|
734 |
|
d76f7b
|
735 |
|
M |
736 |
/***/ }, |
7750ac
|
737 |
/* 6 */ |
272903
|
738 |
/***/ function(module, exports, __webpack_require__) { |
d76f7b
|
739 |
|
be9654
|
740 |
'use strict'; |
SE |
741 |
|
|
742 |
var React = __webpack_require__(3); |
|
743 |
|
|
744 |
var DOM = React.DOM; |
|
745 |
var DateTimePickerMonths = React.createClass({ |
|
746 |
render: function() { |
|
747 |
return DOM.div({ className: 'rdtMonths' }, [ |
|
748 |
DOM.table({ key: 'a' }, DOM.thead( {}, DOM.tr( {}, [ |
|
749 |
DOM.th({ key: 'prev', className: 'rdtPrev' }, DOM.span({ onClick: this.props.subtractTime( 1, 'years' )}, '‹' )), |
|
750 |
DOM.th({ key: 'year', className: 'rdtSwitch', onClick: this.props.showView( 'years' ), colSpan: 2, 'data-value': this.props.viewDate.year() }, this.props.viewDate.year() ), |
|
751 |
DOM.th({ key: 'next', className: 'rdtNext' }, DOM.span({ onClick: this.props.addTime( 1, 'years' )}, '›' )) |
|
752 |
]))), |
|
753 |
DOM.table({ key: 'months' }, DOM.tbody({ key: 'b' }, this.renderMonths())) |
|
754 |
]); |
|
755 |
}, |
|
756 |
|
|
757 |
renderMonths: function() { |
|
758 |
var date = this.props.selectedDate, |
|
759 |
month = this.props.viewDate.month(), |
|
760 |
year = this.props.viewDate.year(), |
|
761 |
rows = [], |
|
762 |
i = 0, |
|
763 |
months = [], |
|
764 |
renderer = this.props.renderMonth || this.renderMonth, |
|
765 |
isValid = this.props.isValidDate || this.alwaysValidDate, |
|
766 |
classes, props, currentMonth, isDisabled, noOfDaysInMonth, daysInMonth, validDay, |
|
767 |
// Date is irrelevant because we're only interested in month |
|
768 |
irrelevantDate = 1 |
|
769 |
; |
|
770 |
|
|
771 |
while (i < 12) { |
|
772 |
classes = 'rdtMonth'; |
|
773 |
currentMonth = |
|
774 |
this.props.viewDate.clone().set({ year: year, month: i, date: irrelevantDate }); |
|
775 |
|
|
776 |
noOfDaysInMonth = currentMonth.endOf( 'month' ).format( 'D' ); |
|
777 |
daysInMonth = Array.from({ length: noOfDaysInMonth }, function( e, i ) { |
|
778 |
return i + 1; |
|
779 |
}); |
|
780 |
|
|
781 |
validDay = daysInMonth.find(function( d ) { |
|
782 |
var day = currentMonth.clone().set( 'date', d ); |
|
783 |
return isValid( day ); |
|
784 |
}); |
|
785 |
|
|
786 |
isDisabled = ( validDay === undefined ); |
|
787 |
|
|
788 |
if ( isDisabled ) |
|
789 |
classes += ' rdtDisabled'; |
|
790 |
|
|
791 |
if ( date && i === month && year === date.year() ) |
|
792 |
classes += ' rdtActive'; |
|
793 |
|
|
794 |
props = { |
|
795 |
key: i, |
|
796 |
'data-value': i, |
|
797 |
className: classes |
|
798 |
}; |
|
799 |
|
|
800 |
if ( !isDisabled ) |
|
801 |
props.onClick = ( this.props.updateOn === 'months' ? |
|
802 |
this.updateSelectedMonth : this.props.setDate( 'month' ) ); |
|
803 |
|
|
804 |
months.push( renderer( props, i, year, date && date.clone() ) ); |
|
805 |
|
|
806 |
if ( months.length === 4 ) { |
|
807 |
rows.push( DOM.tr({ key: month + '_' + rows.length }, months ) ); |
|
808 |
months = []; |
|
809 |
} |
|
810 |
|
|
811 |
i++; |
|
812 |
} |
|
813 |
|
|
814 |
return rows; |
|
815 |
}, |
|
816 |
|
|
817 |
updateSelectedMonth: function( event ) { |
|
818 |
this.props.updateSelectedDate( event, true ); |
|
819 |
}, |
|
820 |
|
|
821 |
renderMonth: function( props, month ) { |
|
822 |
var localMoment = this.props.viewDate; |
|
823 |
var monthStr = localMoment.localeData().monthsShort( localMoment.month( month ) ); |
|
824 |
var strLength = 3; |
|
825 |
// Because some months are up to 5 characters long, we want to |
|
826 |
// use a fixed string length for consistency |
|
827 |
var monthStrFixedLength = monthStr.substring( 0, strLength ); |
|
828 |
return DOM.td( props, capitalize( monthStrFixedLength ) ); |
|
829 |
}, |
|
830 |
|
|
831 |
alwaysValidDate: function() { |
|
832 |
return 1; |
|
833 |
} |
|
834 |
}); |
|
835 |
|
|
836 |
function capitalize( str ) { |
|
837 |
return str.charAt( 0 ).toUpperCase() + str.slice( 1 ); |
|
838 |
} |
|
839 |
|
|
840 |
module.exports = DateTimePickerMonths; |
|
841 |
|
d76f7b
|
842 |
|
M |
843 |
/***/ }, |
7750ac
|
844 |
/* 7 */ |
d76f7b
|
845 |
/***/ function(module, exports, __webpack_require__) { |
M |
846 |
|
be9654
|
847 |
'use strict'; |
SE |
848 |
|
|
849 |
var React = __webpack_require__(3); |
|
850 |
|
|
851 |
var DOM = React.DOM; |
|
852 |
var DateTimePickerYears = React.createClass({ |
|
853 |
render: function() { |
|
854 |
var year = parseInt( this.props.viewDate.year() / 10, 10 ) * 10; |
|
855 |
|
|
856 |
return DOM.div({ className: 'rdtYears' }, [ |
|
857 |
DOM.table({ key: 'a' }, DOM.thead({}, DOM.tr({}, [ |
|
858 |
DOM.th({ key: 'prev', className: 'rdtPrev' }, DOM.span({ onClick: this.props.subtractTime( 10, 'years' )}, '‹' )), |
|
859 |
DOM.th({ key: 'year', className: 'rdtSwitch', onClick: this.props.showView( 'years' ), colSpan: 2 }, year + '-' + ( year + 9 ) ), |
|
860 |
DOM.th({ key: 'next', className: 'rdtNext' }, DOM.span({ onClick: this.props.addTime( 10, 'years' )}, '›' )) |
|
861 |
]))), |
|
862 |
DOM.table({ key: 'years' }, DOM.tbody( {}, this.renderYears( year ))) |
|
863 |
]); |
|
864 |
}, |
|
865 |
|
|
866 |
renderYears: function( year ) { |
|
867 |
var years = [], |
|
868 |
i = -1, |
|
869 |
rows = [], |
|
870 |
renderer = this.props.renderYear || this.renderYear, |
|
871 |
selectedDate = this.props.selectedDate, |
|
872 |
isValid = this.props.isValidDate || this.alwaysValidDate, |
|
873 |
classes, props, currentYear, isDisabled, noOfDaysInYear, daysInYear, validDay, |
|
874 |
// Month and date are irrelevant here because |
|
875 |
// we're only interested in the year |
|
876 |
irrelevantMonth = 0, |
|
877 |
irrelevantDate = 1 |
|
878 |
; |
|
879 |
|
|
880 |
year--; |
|
881 |
while (i < 11) { |
|
882 |
classes = 'rdtYear'; |
|
883 |
currentYear = this.props.viewDate.clone().set( |
|
884 |
{ year: year, month: irrelevantMonth, date: irrelevantDate } ); |
|
885 |
|
|
886 |
// Not sure what 'rdtOld' is for, commenting out for now as it's not working properly |
|
887 |
// if ( i === -1 | i === 10 ) |
|
888 |
// classes += ' rdtOld'; |
|
889 |
|
|
890 |
noOfDaysInYear = currentYear.endOf( 'year' ).format( 'DDD' ); |
|
891 |
daysInYear = Array.from({ length: noOfDaysInYear }, function( e, i ) { |
|
892 |
return i + 1; |
|
893 |
}); |
|
894 |
|
|
895 |
validDay = daysInYear.find(function( d ) { |
|
896 |
var day = currentYear.clone().dayOfYear( d ); |
|
897 |
return isValid( day ); |
|
898 |
}); |
|
899 |
|
|
900 |
isDisabled = ( validDay === undefined ); |
|
901 |
|
|
902 |
if ( isDisabled ) |
|
903 |
classes += ' rdtDisabled'; |
|
904 |
|
|
905 |
if ( selectedDate && selectedDate.year() === year ) |
|
906 |
classes += ' rdtActive'; |
|
907 |
|
|
908 |
props = { |
|
909 |
key: year, |
|
910 |
'data-value': year, |
|
911 |
className: classes |
|
912 |
}; |
|
913 |
|
|
914 |
if ( !isDisabled ) |
|
915 |
props.onClick = ( this.props.updateOn === 'years' ? |
|
916 |
this.updateSelectedYear : this.props.setDate('year') ); |
|
917 |
|
|
918 |
years.push( renderer( props, year, selectedDate && selectedDate.clone() )); |
|
919 |
|
|
920 |
if ( years.length === 4 ) { |
|
921 |
rows.push( DOM.tr({ key: i }, years ) ); |
|
922 |
years = []; |
|
923 |
} |
|
924 |
|
|
925 |
year++; |
|
926 |
i++; |
|
927 |
} |
|
928 |
|
|
929 |
return rows; |
|
930 |
}, |
|
931 |
|
|
932 |
updateSelectedYear: function( event ) { |
|
933 |
this.props.updateSelectedDate( event, true ); |
|
934 |
}, |
|
935 |
|
|
936 |
renderYear: function( props, year ) { |
|
937 |
return DOM.td( props, year ); |
|
938 |
}, |
|
939 |
|
|
940 |
alwaysValidDate: function() { |
|
941 |
return 1; |
|
942 |
} |
|
943 |
}); |
|
944 |
|
|
945 |
module.exports = DateTimePickerYears; |
|
946 |
|
d76f7b
|
947 |
|
M |
948 |
/***/ }, |
7750ac
|
949 |
/* 8 */ |
d76f7b
|
950 |
/***/ function(module, exports, __webpack_require__) { |
M |
951 |
|
be9654
|
952 |
'use strict'; |
SE |
953 |
|
|
954 |
var React = __webpack_require__(3), |
|
955 |
assign = __webpack_require__(1) |
|
956 |
; |
|
957 |
|
|
958 |
var DOM = React.DOM; |
|
959 |
var DateTimePickerTime = React.createClass({ |
|
960 |
getInitialState: function() { |
|
961 |
return this.calculateState( this.props ); |
|
962 |
}, |
|
963 |
|
|
964 |
calculateState: function( props ) { |
|
965 |
var date = props.selectedDate || props.viewDate, |
|
966 |
format = props.timeFormat, |
|
967 |
counters = [] |
|
968 |
; |
|
969 |
|
|
970 |
if ( format.toLowerCase().indexOf('h') !== -1 ) { |
|
971 |
counters.push('hours'); |
|
972 |
if ( format.indexOf('m') !== -1 ) { |
|
973 |
counters.push('minutes'); |
|
974 |
if ( format.indexOf('s') !== -1 ) { |
|
975 |
counters.push('seconds'); |
|
976 |
} |
|
977 |
} |
|
978 |
} |
|
979 |
|
|
980 |
var daypart = false; |
|
981 |
if ( this.state !== null && this.props.timeFormat.toLowerCase().indexOf( ' a' ) !== -1 ) { |
|
982 |
if ( this.props.timeFormat.indexOf( ' A' ) !== -1 ) { |
|
983 |
daypart = ( this.state.hours >= 12 ) ? 'PM' : 'AM'; |
|
984 |
} else { |
|
985 |
daypart = ( this.state.hours >= 12 ) ? 'pm' : 'am'; |
|
986 |
} |
|
987 |
} |
|
988 |
|
|
989 |
return { |
|
990 |
hours: date.format( 'H' ), |
|
991 |
minutes: date.format( 'mm' ), |
|
992 |
seconds: date.format( 'ss' ), |
|
993 |
milliseconds: date.format( 'SSS' ), |
|
994 |
daypart: daypart, |
|
995 |
counters: counters |
|
996 |
}; |
|
997 |
}, |
|
998 |
|
|
999 |
renderCounter: function( type ) { |
|
1000 |
if ( type !== 'daypart' ) { |
|
1001 |
var value = this.state[ type ]; |
|
1002 |
if ( type === 'hours' && this.props.timeFormat.toLowerCase().indexOf( ' a' ) !== -1 ) { |
|
1003 |
value = ( value - 1 ) % 12 + 1; |
|
1004 |
|
|
1005 |
if ( value === 0 ) { |
|
1006 |
value = 12; |
|
1007 |
} |
|
1008 |
} |
|
1009 |
return DOM.div({ key: type, className: 'rdtCounter' }, [ |
|
1010 |
DOM.span({ key: 'up', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'increase', type ) }, 'â–²' ), |
|
1011 |
DOM.div({ key: 'c', className: 'rdtCount' }, value ), |
|
1012 |
DOM.span({ key: 'do', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'decrease', type ) }, 'â–¼' ) |
|
1013 |
]); |
|
1014 |
} |
|
1015 |
return ''; |
|
1016 |
}, |
|
1017 |
|
|
1018 |
renderDayPart: function() { |
|
1019 |
return DOM.div({ key: 'dayPart', className: 'rdtCounter' }, [ |
|
1020 |
DOM.span({ key: 'up', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'toggleDayPart', 'hours') }, 'â–²' ), |
|
1021 |
DOM.div({ key: this.state.daypart, className: 'rdtCount' }, this.state.daypart ), |
|
1022 |
DOM.span({ key: 'do', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'toggleDayPart', 'hours') }, 'â–¼' ) |
|
1023 |
]); |
|
1024 |
}, |
|
1025 |
|
|
1026 |
render: function() { |
|
1027 |
var me = this, |
|
1028 |
counters = [] |
|
1029 |
; |
|
1030 |
|
|
1031 |
this.state.counters.forEach( function( c ) { |
|
1032 |
if ( counters.length ) |
|
1033 |
counters.push( DOM.div({ key: 'sep' + counters.length, className: 'rdtCounterSeparator' }, ':' ) ); |
|
1034 |
counters.push( me.renderCounter( c ) ); |
|
1035 |
}); |
|
1036 |
|
|
1037 |
if ( this.state.daypart !== false ) { |
|
1038 |
counters.push( me.renderDayPart() ); |
|
1039 |
} |
|
1040 |
|
|
1041 |
if ( this.state.counters.length === 3 && this.props.timeFormat.indexOf( 'S' ) !== -1 ) { |
|
1042 |
counters.push( DOM.div({ className: 'rdtCounterSeparator', key: 'sep5' }, ':' ) ); |
|
1043 |
counters.push( |
|
1044 |
DOM.div({ className: 'rdtCounter rdtMilli', key: 'm' }, |
|
1045 |
DOM.input({ value: this.state.milliseconds, type: 'text', onChange: this.updateMilli } ) |
|
1046 |
) |
|
1047 |
); |
|
1048 |
} |
|
1049 |
|
|
1050 |
return DOM.div({ className: 'rdtTime' }, |
|
1051 |
DOM.table({}, [ |
|
1052 |
this.renderHeader(), |
|
1053 |
DOM.tbody({ key: 'b'}, DOM.tr({}, DOM.td({}, |
|
1054 |
DOM.div({ className: 'rdtCounters' }, counters ) |
|
1055 |
))) |
|
1056 |
]) |
|
1057 |
); |
|
1058 |
}, |
|
1059 |
|
|
1060 |
componentWillMount: function() { |
|
1061 |
var me = this; |
|
1062 |
me.timeConstraints = { |
|
1063 |
hours: { |
|
1064 |
min: 0, |
|
1065 |
max: 23, |
|
1066 |
step: 1 |
|
1067 |
}, |
|
1068 |
minutes: { |
|
1069 |
min: 0, |
|
1070 |
max: 59, |
|
1071 |
step: 1 |
|
1072 |
}, |
|
1073 |
seconds: { |
|
1074 |
min: 0, |
|
1075 |
max: 59, |
|
1076 |
step: 1 |
|
1077 |
}, |
|
1078 |
milliseconds: { |
|
1079 |
min: 0, |
|
1080 |
max: 999, |
|
1081 |
step: 1 |
|
1082 |
} |
|
1083 |
}; |
|
1084 |
['hours', 'minutes', 'seconds', 'milliseconds'].forEach( function( type ) { |
|
1085 |
assign(me.timeConstraints[ type ], me.props.timeConstraints[ type ]); |
|
1086 |
}); |
|
1087 |
this.setState( this.calculateState( this.props ) ); |
|
1088 |
}, |
|
1089 |
|
|
1090 |
componentWillReceiveProps: function( nextProps ) { |
|
1091 |
this.setState( this.calculateState( nextProps ) ); |
|
1092 |
}, |
|
1093 |
|
|
1094 |
updateMilli: function( e ) { |
|
1095 |
var milli = parseInt( e.target.value, 10 ); |
|
1096 |
if ( milli === e.target.value && milli >= 0 && milli < 1000 ) { |
|
1097 |
this.props.setTime( 'milliseconds', milli ); |
|
1098 |
this.setState( { milliseconds: milli } ); |
|
1099 |
} |
|
1100 |
}, |
|
1101 |
|
|
1102 |
renderHeader: function() { |
|
1103 |
if ( !this.props.dateFormat ) |
|
1104 |
return null; |
|
1105 |
|
|
1106 |
var date = this.props.selectedDate || this.props.viewDate; |
|
1107 |
return DOM.thead({ key: 'h' }, DOM.tr({}, |
|
1108 |
DOM.th({ className: 'rdtSwitch', colSpan: 4, onClick: this.props.showView( 'days' ) }, date.format( this.props.dateFormat ) ) |
|
1109 |
)); |
|
1110 |
}, |
|
1111 |
|
|
1112 |
onStartClicking: function( action, type ) { |
|
1113 |
var me = this; |
|
1114 |
|
|
1115 |
return function() { |
|
1116 |
var update = {}; |
|
1117 |
update[ type ] = me[ action ]( type ); |
|
1118 |
me.setState( update ); |
|
1119 |
|
|
1120 |
me.timer = setTimeout( function() { |
|
1121 |
me.increaseTimer = setInterval( function() { |
|
1122 |
update[ type ] = me[ action ]( type ); |
|
1123 |
me.setState( update ); |
|
1124 |
}, 70); |
|
1125 |
}, 500); |
|
1126 |
|
|
1127 |
me.mouseUpListener = function() { |
|
1128 |
clearTimeout( me.timer ); |
|
1129 |
clearInterval( me.increaseTimer ); |
|
1130 |
me.props.setTime( type, me.state[ type ] ); |
|
1131 |
document.body.removeEventListener( 'mouseup', me.mouseUpListener ); |
|
1132 |
}; |
|
1133 |
|
|
1134 |
document.body.addEventListener( 'mouseup', me.mouseUpListener ); |
|
1135 |
}; |
|
1136 |
}, |
|
1137 |
|
|
1138 |
padValues: { |
|
1139 |
hours: 1, |
|
1140 |
minutes: 2, |
|
1141 |
seconds: 2, |
|
1142 |
milliseconds: 3 |
|
1143 |
}, |
|
1144 |
|
|
1145 |
toggleDayPart: function( type ) { // type is always 'hours' |
|
1146 |
var value = parseInt( this.state[ type ], 10) + 12; |
|
1147 |
if ( value > this.timeConstraints[ type ].max ) |
|
1148 |
value = this.timeConstraints[ type ].min + ( value - ( this.timeConstraints[ type ].max + 1 ) ); |
|
1149 |
return this.pad( type, value ); |
|
1150 |
}, |
|
1151 |
|
|
1152 |
increase: function( type ) { |
|
1153 |
var value = parseInt( this.state[ type ], 10) + this.timeConstraints[ type ].step; |
|
1154 |
if ( value > this.timeConstraints[ type ].max ) |
|
1155 |
value = this.timeConstraints[ type ].min + ( value - ( this.timeConstraints[ type ].max + 1 ) ); |
|
1156 |
return this.pad( type, value ); |
|
1157 |
}, |
|
1158 |
|
|
1159 |
decrease: function( type ) { |
|
1160 |
var value = parseInt( this.state[ type ], 10) - this.timeConstraints[ type ].step; |
|
1161 |
if ( value < this.timeConstraints[ type ].min ) |
|
1162 |
value = this.timeConstraints[ type ].max + 1 - ( this.timeConstraints[ type ].min - value ); |
|
1163 |
return this.pad( type, value ); |
|
1164 |
}, |
|
1165 |
|
|
1166 |
pad: function( type, value ) { |
|
1167 |
var str = value + ''; |
|
1168 |
while ( str.length < this.padValues[ type ] ) |
|
1169 |
str = '0' + str; |
|
1170 |
return str; |
|
1171 |
} |
|
1172 |
}); |
|
1173 |
|
|
1174 |
module.exports = DateTimePickerTime; |
|
1175 |
|
d76f7b
|
1176 |
|
M |
1177 |
/***/ }, |
7750ac
|
1178 |
/* 9 */ |
d76f7b
|
1179 |
/***/ function(module, exports, __webpack_require__) { |
M |
1180 |
|
7750ac
|
1181 |
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/** |
JM |
1182 |
* A higher-order-component for handling onClickOutside for React components. |
|
1183 |
*/ |
|
1184 |
(function(root) { |
be9654
|
1185 |
|
7750ac
|
1186 |
// administrative |
JM |
1187 |
var registeredComponents = []; |
|
1188 |
var handlers = []; |
|
1189 |
var IGNORE_CLASS = 'ignore-react-onclickoutside'; |
|
1190 |
var DEFAULT_EVENTS = ['mousedown', 'touchstart']; |
be9654
|
1191 |
|
7750ac
|
1192 |
/** |
JM |
1193 |
* Check whether some DOM node is our Component's node. |
|
1194 |
*/ |
|
1195 |
var isNodeFound = function(current, componentNode, ignoreClass) { |
|
1196 |
if (current === componentNode) { |
|
1197 |
return true; |
|
1198 |
} |
|
1199 |
// SVG <use/> elements do not technically reside in the rendered DOM, so |
|
1200 |
// they do not have classList directly, but they offer a link to their |
|
1201 |
// corresponding element, which can have classList. This extra check is for |
|
1202 |
// that case. |
|
1203 |
// See: http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGUseElement |
|
1204 |
// Discussion: https://github.com/Pomax/react-onclickoutside/pull/17 |
|
1205 |
if (current.correspondingElement) { |
|
1206 |
return current.correspondingElement.classList.contains(ignoreClass); |
|
1207 |
} |
|
1208 |
return current.classList.contains(ignoreClass); |
|
1209 |
}; |
be9654
|
1210 |
|
7750ac
|
1211 |
/** |
JM |
1212 |
* Try to find our node in a hierarchy of nodes, returning the document |
|
1213 |
* node as highest noode if our node is not found in the path up. |
|
1214 |
*/ |
|
1215 |
var findHighest = function(current, componentNode, ignoreClass) { |
|
1216 |
if (current === componentNode) { |
|
1217 |
return true; |
|
1218 |
} |
be9654
|
1219 |
|
7750ac
|
1220 |
// If source=local then this event came from 'somewhere' |
JM |
1221 |
// inside and should be ignored. We could handle this with |
|
1222 |
// a layered approach, too, but that requires going back to |
|
1223 |
// thinking in terms of Dom node nesting, running counter |
|
1224 |
// to React's 'you shouldn't care about the DOM' philosophy. |
|
1225 |
while(current.parentNode) { |
|
1226 |
if (isNodeFound(current, componentNode, ignoreClass)) { |
|
1227 |
return true; |
|
1228 |
} |
|
1229 |
current = current.parentNode; |
|
1230 |
} |
|
1231 |
return current; |
|
1232 |
}; |
be9654
|
1233 |
|
7750ac
|
1234 |
/** |
JM |
1235 |
* Check if the browser scrollbar was clicked |
|
1236 |
*/ |
|
1237 |
var clickedScrollbar = function(evt) { |
|
1238 |
return document.documentElement.clientWidth <= evt.clientX; |
|
1239 |
}; |
be9654
|
1240 |
|
7750ac
|
1241 |
/** |
JM |
1242 |
* Generate the event handler that checks whether a clicked DOM node |
|
1243 |
* is inside of, or lives outside of, our Component's node tree. |
|
1244 |
*/ |
|
1245 |
var generateOutsideCheck = function(componentNode, componentInstance, eventHandler, ignoreClass, excludeScrollbar, preventDefault, stopPropagation) { |
|
1246 |
return function(evt) { |
|
1247 |
if (preventDefault) { |
|
1248 |
evt.preventDefault(); |
|
1249 |
} |
|
1250 |
if (stopPropagation) { |
|
1251 |
evt.stopPropagation(); |
|
1252 |
} |
|
1253 |
var current = evt.target; |
|
1254 |
if((excludeScrollbar && clickedScrollbar(evt)) || (findHighest(current, componentNode, ignoreClass) !== document)) { |
|
1255 |
return; |
|
1256 |
} |
|
1257 |
eventHandler(evt); |
|
1258 |
}; |
|
1259 |
}; |
be9654
|
1260 |
|
7750ac
|
1261 |
/** |
JM |
1262 |
* This function generates the HOC function that you'll use |
|
1263 |
* in order to impart onOutsideClick listening to an |
|
1264 |
* arbitrary component. It gets called at the end of the |
|
1265 |
* bootstrapping code to yield an instance of the |
|
1266 |
* onClickOutsideHOC function defined inside setupHOC(). |
|
1267 |
*/ |
|
1268 |
function setupHOC(root, React, ReactDOM) { |
be9654
|
1269 |
|
7750ac
|
1270 |
// The actual Component-wrapping HOC: |
JM |
1271 |
return function onClickOutsideHOC(Component, config) { |
|
1272 |
var wrapComponentWithOnClickOutsideHandling = React.createClass({ |
|
1273 |
statics: { |
|
1274 |
/** |
|
1275 |
* Access the wrapped Component's class. |
|
1276 |
*/ |
|
1277 |
getClass: function() { |
|
1278 |
if (Component.getClass) { |
|
1279 |
return Component.getClass(); |
|
1280 |
} |
|
1281 |
return Component; |
|
1282 |
} |
|
1283 |
}, |
be9654
|
1284 |
|
7750ac
|
1285 |
/** |
JM |
1286 |
* Access the wrapped Component's instance. |
|
1287 |
*/ |
|
1288 |
getInstance: function() { |
|
1289 |
return Component.prototype.isReactComponent ? this.refs.instance : this; |
|
1290 |
}, |
be9654
|
1291 |
|
7750ac
|
1292 |
// this is given meaning in componentDidMount |
JM |
1293 |
__outsideClickHandler: function() {}, |
be9654
|
1294 |
|
7750ac
|
1295 |
/** |
JM |
1296 |
* Add click listeners to the current document, |
|
1297 |
* linked to this component's state. |
|
1298 |
*/ |
|
1299 |
componentDidMount: function() { |
|
1300 |
// If we are in an environment without a DOM such |
|
1301 |
// as shallow rendering or snapshots then we exit |
|
1302 |
// early to prevent any unhandled errors being thrown. |
|
1303 |
if (typeof document === 'undefined' || !document.createElement){ |
|
1304 |
return; |
|
1305 |
} |
be9654
|
1306 |
|
7750ac
|
1307 |
var instance = this.getInstance(); |
JM |
1308 |
var clickOutsideHandler; |
be9654
|
1309 |
|
7750ac
|
1310 |
if(config && typeof config.handleClickOutside === 'function') { |
JM |
1311 |
clickOutsideHandler = config.handleClickOutside(instance); |
|
1312 |
if(typeof clickOutsideHandler !== 'function') { |
|
1313 |
throw new Error('Component lacks a function for processing outside click events specified by the handleClickOutside config option.'); |
|
1314 |
} |
|
1315 |
} else if(typeof instance.handleClickOutside === 'function') { |
|
1316 |
if (React.Component.prototype.isPrototypeOf(instance)) { |
|
1317 |
clickOutsideHandler = instance.handleClickOutside.bind(instance); |
|
1318 |
} else { |
|
1319 |
clickOutsideHandler = instance.handleClickOutside; |
|
1320 |
} |
|
1321 |
} else if(typeof instance.props.handleClickOutside === 'function') { |
|
1322 |
clickOutsideHandler = instance.props.handleClickOutside; |
|
1323 |
} else { |
|
1324 |
throw new Error('Component lacks a handleClickOutside(event) function for processing outside click events.'); |
|
1325 |
} |
|
1326 |
|
|
1327 |
var componentNode = ReactDOM.findDOMNode(instance); |
|
1328 |
if (componentNode === null) { |
|
1329 |
console.warn('Antipattern warning: there was no DOM node associated with the component that is being wrapped by outsideClick.'); |
|
1330 |
console.warn([ |
|
1331 |
'This is typically caused by having a component that starts life with a render function that', |
|
1332 |
'returns `null` (due to a state or props value), so that the component \'exist\' in the React', |
|
1333 |
'chain of components, but not in the DOM.\n\nInstead, you need to refactor your code so that the', |
|
1334 |
'decision of whether or not to show your component is handled by the parent, in their render()', |
|
1335 |
'function.\n\nIn code, rather than:\n\n A{render(){return check? <.../> : null;}\n B{render(){<A check=... />}\n\nmake sure that you', |
|
1336 |
'use:\n\n A{render(){return <.../>}\n B{render(){return <...>{ check ? <A/> : null }<...>}}\n\nThat is:', |
|
1337 |
'the parent is always responsible for deciding whether or not to render any of its children.', |
|
1338 |
'It is not the child\'s responsibility to decide whether a render instruction from above should', |
|
1339 |
'get ignored or not by returning `null`.\n\nWhen any component gets its render() function called,', |
|
1340 |
'that is the signal that it should be rendering its part of the UI. It may in turn decide not to', |
|
1341 |
'render all of *its* children, but it should never return `null` for itself. It is not responsible', |
|
1342 |
'for that decision.' |
|
1343 |
].join(' ')); |
|
1344 |
} |
|
1345 |
|
|
1346 |
var fn = this.__outsideClickHandler = generateOutsideCheck( |
|
1347 |
componentNode, |
|
1348 |
instance, |
|
1349 |
clickOutsideHandler, |
|
1350 |
this.props.outsideClickIgnoreClass || IGNORE_CLASS, |
|
1351 |
this.props.excludeScrollbar || false, |
|
1352 |
this.props.preventDefault || false, |
|
1353 |
this.props.stopPropagation || false |
|
1354 |
); |
|
1355 |
|
|
1356 |
var pos = registeredComponents.length; |
|
1357 |
registeredComponents.push(this); |
|
1358 |
handlers[pos] = fn; |
|
1359 |
|
|
1360 |
// If there is a truthy disableOnClickOutside property for this |
|
1361 |
// component, don't immediately start listening for outside events. |
|
1362 |
if (!this.props.disableOnClickOutside) { |
|
1363 |
this.enableOnClickOutside(); |
|
1364 |
} |
|
1365 |
}, |
|
1366 |
|
|
1367 |
/** |
|
1368 |
* Track for disableOnClickOutside props changes and enable/disable click outside |
|
1369 |
*/ |
|
1370 |
componentWillReceiveProps: function(nextProps) { |
|
1371 |
if (this.props.disableOnClickOutside && !nextProps.disableOnClickOutside) { |
|
1372 |
this.enableOnClickOutside(); |
|
1373 |
} else if (!this.props.disableOnClickOutside && nextProps.disableOnClickOutside) { |
|
1374 |
this.disableOnClickOutside(); |
|
1375 |
} |
|
1376 |
}, |
|
1377 |
|
|
1378 |
/** |
|
1379 |
* Remove the document's event listeners |
|
1380 |
*/ |
|
1381 |
componentWillUnmount: function() { |
|
1382 |
this.disableOnClickOutside(); |
|
1383 |
this.__outsideClickHandler = false; |
|
1384 |
var pos = registeredComponents.indexOf(this); |
|
1385 |
if( pos>-1) { |
|
1386 |
// clean up so we don't leak memory |
|
1387 |
if (handlers[pos]) { handlers.splice(pos, 1); } |
|
1388 |
registeredComponents.splice(pos, 1); |
|
1389 |
} |
|
1390 |
}, |
|
1391 |
|
|
1392 |
/** |
|
1393 |
* Can be called to explicitly enable event listening |
|
1394 |
* for clicks and touches outside of this element. |
|
1395 |
*/ |
|
1396 |
enableOnClickOutside: function() { |
|
1397 |
var fn = this.__outsideClickHandler; |
|
1398 |
if (typeof document !== 'undefined') { |
|
1399 |
var events = this.props.eventTypes || DEFAULT_EVENTS; |
|
1400 |
if (!events.forEach) { |
|
1401 |
events = [events]; |
|
1402 |
} |
|
1403 |
events.forEach(function (eventName) { |
|
1404 |
document.addEventListener(eventName, fn); |
|
1405 |
}); |
|
1406 |
} |
|
1407 |
}, |
|
1408 |
|
|
1409 |
/** |
|
1410 |
* Can be called to explicitly disable event listening |
|
1411 |
* for clicks and touches outside of this element. |
|
1412 |
*/ |
|
1413 |
disableOnClickOutside: function() { |
|
1414 |
var fn = this.__outsideClickHandler; |
|
1415 |
if (typeof document !== 'undefined') { |
|
1416 |
var events = this.props.eventTypes || DEFAULT_EVENTS; |
|
1417 |
if (!events.forEach) { |
|
1418 |
events = [events]; |
|
1419 |
} |
|
1420 |
events.forEach(function (eventName) { |
|
1421 |
document.removeEventListener(eventName, fn); |
|
1422 |
}); |
|
1423 |
} |
|
1424 |
}, |
|
1425 |
|
|
1426 |
/** |
|
1427 |
* Pass-through render |
|
1428 |
*/ |
|
1429 |
render: function() { |
|
1430 |
var passedProps = this.props; |
|
1431 |
var props = {}; |
|
1432 |
Object.keys(this.props).forEach(function(key) { |
|
1433 |
if (key !== 'excludeScrollbar') { |
|
1434 |
props[key] = passedProps[key]; |
|
1435 |
} |
|
1436 |
}); |
|
1437 |
if (Component.prototype.isReactComponent) { |
|
1438 |
props.ref = 'instance'; |
|
1439 |
} |
|
1440 |
props.disableOnClickOutside = this.disableOnClickOutside; |
|
1441 |
props.enableOnClickOutside = this.enableOnClickOutside; |
|
1442 |
return React.createElement(Component, props); |
|
1443 |
} |
|
1444 |
}); |
|
1445 |
|
|
1446 |
// Add display name for React devtools |
|
1447 |
(function bindWrappedComponentName(c, wrapper) { |
|
1448 |
var componentName = c.displayName || c.name || 'Component'; |
|
1449 |
wrapper.displayName = 'OnClickOutside(' + componentName + ')'; |
|
1450 |
}(Component, wrapComponentWithOnClickOutsideHandling)); |
|
1451 |
|
|
1452 |
return wrapComponentWithOnClickOutsideHandling; |
|
1453 |
}; |
|
1454 |
} |
|
1455 |
|
|
1456 |
/** |
|
1457 |
* This function sets up the library in ways that |
|
1458 |
* work with the various modulde loading solutions |
|
1459 |
* used in JavaScript land today. |
|
1460 |
*/ |
|
1461 |
function setupBinding(root, factory) { |
|
1462 |
if (true) { |
|
1463 |
// AMD. Register as an anonymous module. |
|
1464 |
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(3),__webpack_require__(10)], __WEBPACK_AMD_DEFINE_RESULT__ = function(React, ReactDom) { |
|
1465 |
return factory(root, React, ReactDom); |
|
1466 |
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
|
1467 |
} else if (typeof exports === 'object') { |
|
1468 |
// Node. Note that this does not work with strict |
|
1469 |
// CommonJS, but only CommonJS-like environments |
|
1470 |
// that support module.exports |
|
1471 |
module.exports = factory(root, require('react'), require('react-dom')); |
|
1472 |
} else { |
|
1473 |
// Browser globals (root is window) |
|
1474 |
root.onClickOutside = factory(root, React, ReactDOM); |
|
1475 |
} |
|
1476 |
} |
|
1477 |
|
|
1478 |
// Make it all happen |
|
1479 |
setupBinding(root, setupHOC); |
|
1480 |
|
|
1481 |
}(this)); |
be9654
|
1482 |
|
d359eb
|
1483 |
|
M |
1484 |
/***/ }, |
7750ac
|
1485 |
/* 10 */ |
d359eb
|
1486 |
/***/ function(module, exports) { |
M |
1487 |
|
7750ac
|
1488 |
module.exports = __WEBPACK_EXTERNAL_MODULE_10__; |
d76f7b
|
1489 |
|
M |
1490 |
/***/ } |
|
1491 |
/******/ ]) |
|
1492 |
}); |
be9654
|
1493 |
; |