1
1
'use strict' ;
2
2
3
3
var assign = require ( 'object-assign' ) ,
4
+ moment = require ( 'moment' ) ,
4
5
React = require ( 'react' ) ,
5
6
DaysView = require ( './src/DaysView' ) ,
6
7
MonthsView = require ( './src/MonthsView' ) ,
7
8
YearsView = require ( './src/YearsView' ) ,
8
- TimeView = require ( './src/TimeView' ) ,
9
- moment = require ( 'moment' )
9
+ TimeView = require ( './src/TimeView' )
10
10
;
11
11
12
12
var TYPES = React . PropTypes ;
@@ -42,7 +42,7 @@ var Datetime = React.createClass({
42
42
} ,
43
43
44
44
getDefaultProps : function ( ) {
45
- var nof = function ( ) { } ;
45
+ var nof = function ( ) { } ;
46
46
return {
47
47
className : '' ,
48
48
defaultValue : '' ,
@@ -72,7 +72,7 @@ var Datetime = React.createClass({
72
72
return state ;
73
73
} ,
74
74
75
- getStateFromProps : function ( props ) {
75
+ getStateFromProps : function ( props ) {
76
76
var formats = this . getFormats ( props ) ,
77
77
date = props . value || props . defaultValue ,
78
78
selectedDate , viewDate , updateOn , inputValue
@@ -110,36 +110,36 @@ var Datetime = React.createClass({
110
110
} ;
111
111
} ,
112
112
113
- getUpdateOn : function ( formats ) {
114
- if ( formats . date . match ( / [ l L D ] / ) ) {
113
+ getUpdateOn : function ( formats ) {
114
+ if ( formats . date . match ( / [ l L D ] / ) ) {
115
115
return 'days' ;
116
116
}
117
- else if ( formats . date . indexOf ( 'M' ) !== - 1 ) {
117
+ else if ( formats . date . indexOf ( 'M' ) !== - 1 ) {
118
118
return 'months' ;
119
119
}
120
- else if ( formats . date . indexOf ( 'Y' ) !== - 1 ) {
120
+ else if ( formats . date . indexOf ( 'Y' ) !== - 1 ) {
121
121
return 'years' ;
122
122
}
123
123
124
124
return 'days' ;
125
125
} ,
126
126
127
- getFormats : function ( props ) {
127
+ getFormats : function ( props ) {
128
128
var formats = {
129
129
date : props . dateFormat || '' ,
130
130
time : props . timeFormat || ''
131
131
} ,
132
132
locale = this . localMoment ( props . date ) . localeData ( )
133
133
;
134
134
135
- if ( formats . date === true ) {
135
+ if ( formats . date === true ) {
136
136
formats . date = locale . longDateFormat ( 'L' ) ;
137
137
}
138
- else if ( this . getUpdateOn ( formats ) !== 'days' ) {
138
+ else if ( this . getUpdateOn ( formats ) !== 'days' ) {
139
139
formats . time = '' ;
140
140
}
141
141
142
- if ( formats . time === true ) {
142
+ if ( formats . time === true ) {
143
143
formats . time = locale . longDateFormat ( 'LT' ) ;
144
144
}
145
145
@@ -151,7 +151,7 @@ var Datetime = React.createClass({
151
151
return formats ;
152
152
} ,
153
153
154
- componentWillReceiveProps : function ( nextProps ) {
154
+ componentWillReceiveProps : function ( nextProps ) {
155
155
var formats = this . getFormats ( nextProps ) ,
156
156
update = { }
157
157
;
@@ -161,7 +161,7 @@ var Datetime = React.createClass({
161
161
update = this . getStateFromProps ( nextProps ) ;
162
162
}
163
163
164
- if ( update . open === undefined ) {
164
+ if ( update . open === undefined ) {
165
165
update . open = this . state . open ;
166
166
}
167
167
@@ -191,46 +191,46 @@ var Datetime = React.createClass({
191
191
} ) ;
192
192
} ,
193
193
194
- onInputKey : function ( e ) {
195
- if ( e . which === 9 && this . props . closeOnTab ) {
194
+ onInputKey : function ( e ) {
195
+ if ( e . which === 9 && this . props . closeOnTab ) {
196
196
this . closeCalendar ( ) ;
197
197
}
198
198
} ,
199
199
200
- showView : function ( view ) {
200
+ showView : function ( view ) {
201
201
var me = this ;
202
- return function ( ) {
202
+ return function ( ) {
203
203
me . setState ( { currentView : view } ) ;
204
204
} ;
205
205
} ,
206
206
207
- setDate : function ( type ) {
207
+ setDate : function ( type ) {
208
208
var me = this ,
209
209
nextViews = {
210
210
month : 'days' ,
211
211
year : 'months'
212
212
}
213
213
;
214
- return function ( e ) {
214
+ return function ( e ) {
215
215
me . setState ( {
216
216
viewDate : me . state . viewDate . clone ( ) [ type ] ( parseInt ( e . target . getAttribute ( 'data-value' ) , 10 ) ) . startOf ( type ) ,
217
217
currentView : nextViews [ type ]
218
218
} ) ;
219
219
} ;
220
220
} ,
221
221
222
- addTime : function ( amount , type , toSelected ) {
222
+ addTime : function ( amount , type , toSelected ) {
223
223
return this . updateTime ( 'add' , amount , type , toSelected ) ;
224
224
} ,
225
225
226
- subtractTime : function ( amount , type , toSelected ) {
226
+ subtractTime : function ( amount , type , toSelected ) {
227
227
return this . updateTime ( 'subtract' , amount , type , toSelected ) ;
228
228
} ,
229
229
230
- updateTime : function ( op , amount , type , toSelected ) {
230
+ updateTime : function ( op , amount , type , toSelected ) {
231
231
var me = this ;
232
232
233
- return function ( ) {
233
+ return function ( ) {
234
234
var update = { } ,
235
235
date = toSelected ? 'selectedDate' : 'viewDate'
236
236
;
@@ -242,7 +242,7 @@ var Datetime = React.createClass({
242
242
} ,
243
243
244
244
allowedSetTime : [ 'hours' , 'minutes' , 'seconds' , 'milliseconds' ] ,
245
- setTime : function ( type , value ) {
245
+ setTime : function ( type , value ) {
246
246
var index = this . allowedSetTime . indexOf ( type ) + 1 ,
247
247
state = this . state ,
248
248
date = ( state . selectedDate || state . viewDate ) . clone ( ) ,
@@ -257,7 +257,7 @@ var Datetime = React.createClass({
257
257
date [ nextType ] ( date [ nextType ] ( ) ) ;
258
258
}
259
259
260
- if ( ! this . props . value ) {
260
+ if ( ! this . props . value ) {
261
261
this . setState ( {
262
262
selectedDate : date ,
263
263
inputValue : date . format ( state . inputFormat )
@@ -274,7 +274,7 @@ var Datetime = React.createClass({
274
274
date
275
275
;
276
276
277
- if ( target . className . indexOf ( 'rdtDay' ) !== - 1 ) {
277
+ if ( target . className . indexOf ( 'rdtDay' ) !== - 1 ) {
278
278
if ( target . className . indexOf ( 'rdtNew' ) !== - 1 )
279
279
modifier = 1 ;
280
280
else if ( target . className . indexOf ( 'rdtOld' ) !== - 1 )
@@ -283,11 +283,11 @@ var Datetime = React.createClass({
283
283
date = viewDate . clone ( )
284
284
. month ( viewDate . month ( ) + modifier )
285
285
. date ( parseInt ( target . getAttribute ( 'data-value' ) , 10 ) ) ;
286
- } else if ( target . className . indexOf ( 'rdtMonth' ) !== - 1 ) {
286
+ } else if ( target . className . indexOf ( 'rdtMonth' ) !== - 1 ) {
287
287
date = viewDate . clone ( )
288
288
. month ( parseInt ( target . getAttribute ( 'data-value' ) , 10 ) )
289
289
. date ( currentDate . date ( ) ) ;
290
- } else if ( target . className . indexOf ( 'rdtYear' ) !== - 1 ) {
290
+ } else if ( target . className . indexOf ( 'rdtYear' ) !== - 1 ) {
291
291
date = viewDate . clone ( )
292
292
. month ( currentDate . month ( ) )
293
293
. date ( currentDate . date ( ) )
@@ -299,7 +299,7 @@ var Datetime = React.createClass({
299
299
. seconds ( currentDate . seconds ( ) )
300
300
. milliseconds ( currentDate . milliseconds ( ) ) ;
301
301
302
- if ( ! this . props . value ) {
302
+ if ( ! this . props . value ) {
303
303
this . setState ( {
304
304
selectedDate : date ,
305
305
viewDate : date . clone ( ) . startOf ( 'month' ) ,
@@ -329,15 +329,15 @@ var Datetime = React.createClass({
329
329
} ) ;
330
330
} ,
331
331
332
- handleClickOutside : function ( ) {
333
- if ( this . props . input && this . state . open && ! this . props . open ) {
332
+ handleClickOutside : function ( ) {
333
+ if ( this . props . input && this . state . open && ! this . props . open ) {
334
334
this . setState ( { open : false } , function ( ) {
335
335
this . props . onBlur ( this . state . selectedDate || this . state . inputValue ) ;
336
336
} ) ;
337
337
}
338
338
} ,
339
339
340
- localMoment : function ( date , format ) {
340
+ localMoment : function ( date , format ) {
341
341
var momentFn = this . props . utc ? moment . utc : moment ;
342
342
var m = momentFn ( date , format , this . props . strictParsing ) ;
343
343
if ( this . props . locale )
@@ -351,19 +351,19 @@ var Datetime = React.createClass({
351
351
fromThis : [ 'setDate' , 'setTime' , 'showView' , 'addTime' , 'subtractTime' , 'updateSelectedDate' , 'localMoment' ]
352
352
} ,
353
353
354
- getComponentProps : function ( ) {
354
+ getComponentProps : function ( ) {
355
355
var me = this ,
356
356
formats = this . getFormats ( this . props ) ,
357
357
props = { dateFormat : formats . date , timeFormat : formats . time }
358
358
;
359
359
360
- this . componentProps . fromProps . forEach ( function ( name ) {
360
+ this . componentProps . fromProps . forEach ( function ( name ) {
361
361
props [ name ] = me . props [ name ] ;
362
362
} ) ;
363
- this . componentProps . fromState . forEach ( function ( name ) {
363
+ this . componentProps . fromState . forEach ( function ( name ) {
364
364
props [ name ] = me . state [ name ] ;
365
365
} ) ;
366
- this . componentProps . fromThis . forEach ( function ( name ) {
366
+ this . componentProps . fromThis . forEach ( function ( name ) {
367
367
props [ name ] = me [ name ] ;
368
368
} ) ;
369
369
@@ -379,10 +379,10 @@ var Datetime = React.createClass({
379
379
children = [ ]
380
380
;
381
381
382
- if ( this . props . input ) {
382
+ if ( this . props . input ) {
383
383
children = [ DOM . input ( assign ( {
384
384
key : 'i' ,
385
- type :'text' ,
385
+ type : 'text' ,
386
386
className : 'form-control' ,
387
387
onFocus : this . openCalendar ,
388
388
onChange : this . onInputChange ,
0 commit comments