@@ -210,6 +210,8 @@ var Events = function () {
210210 return Events ;
211211} ( ) ;
212212
213+ var ESC_KEY = 27 ;
214+
213215var prefix = 'c-datepicker' ;
214216var defaults$$1 = function defaults$$1 ( ) {
215217 return {
@@ -310,18 +312,24 @@ var DateTimePicker = function (_Events) {
310312 // and deal with updating the view only).
311313 // For now this allows us to set the default time using the same quantize
312314 // rules as setting the date explicitly. Setting this.value meets setTime|Date's
313- // expectation that we have a value, and `0` guarantees that we will detect
315+ // expectation that we have a value, and `0` guarantees that we will detect
314316 this . value = moment ( 0 ) ;
315317 this . setDate ( this . options . default ) ;
316318 this . setTime ( this . options . default ) ;
319+ } else {
320+ this . setDate ( this . value ) ;
321+ this . setTime ( this . value ) ;
317322 }
318323
319324 this . initializeRome ( this . $ ( '.' + this . options . styles . container ) , this . options . dateValidator ) ;
325+ this . _listenForCloseEvents ( ) ;
326+
320327 this . _show ( ) ;
321328 }
322329 } , {
323330 key : 'close' ,
324331 value : function close ( ) {
332+ this . _stopListeningForCloseEvents ( ) ;
325333 this . _hide ( ) ;
326334 }
327335 } , {
@@ -352,68 +360,91 @@ var DateTimePicker = function (_Events) {
352360 } ) ;
353361 return this ;
354362 }
363+ } , {
364+ key : '_listenForCloseEvents' ,
365+ value : function _listenForCloseEvents ( ) {
366+ var _this4 = this ;
367+
368+ this . _onWindowKeypress = function ( e ) {
369+ if ( e . which === ESC_KEY ) {
370+ _this4 . close ( ) ;
371+ }
372+ } ;
373+
374+ window . addEventListener ( "keydown" , this . _onWindowKeypress ) ;
375+ }
376+ } , {
377+ key : '_stopListeningForCloseEvents' ,
378+ value : function _stopListeningForCloseEvents ( ) {
379+ window . removeEventListener ( "keydown" , this . _onWindowKeypress ) ;
380+ this . _closeHandler = null ;
381+ }
355382 } , {
356383 key : 'delegateEvents' ,
357384 value : function delegateEvents ( ) {
358- var _this4 = this ;
385+ var _this5 = this ;
359386
360387 this . $ ( '.js-cancel' ) . addEventListener ( 'click' , function ( ) {
361- return _this4 . clickCancel ( ) ;
388+ return _this5 . clickCancel ( ) ;
362389 } , false ) ;
363390 this . $ ( '.js-ok' ) . addEventListener ( 'click' , function ( ) {
364- return _this4 . clickSubmit ( ) ;
391+ return _this5 . clickSubmit ( ) ;
365392 } , false ) ;
366393
367394 this . $ ( '.js-date-hours' ) . addEventListener ( 'click' , function ( e ) {
368- return _this4 . showHourClock ( e ) ;
395+ return _this5 . showHourClock ( e ) ;
369396 } , false ) ;
370397 this . $ ( '.js-date-minutes' ) . addEventListener ( 'click' , function ( e ) {
371- return _this4 . showMinuteClock ( e ) ;
398+ return _this5 . showMinuteClock ( e ) ;
372399 } , false ) ;
373400
374401 this . $ ( '.js-clock-hours' ) . addEventListener ( 'mouseleave' , function ( e ) {
375- return _this4 . mouseOutHourClock ( e ) ;
402+ return _this5 . mouseOutHourClock ( e ) ;
376403 } , false ) ;
377404 this . $ ( '.js-clock-hours .' + this . options . styles . clockNum ) . forEach ( function ( el ) {
378405 el . addEventListener ( 'click' , function ( e ) {
379- return _this4 . clickClickHour ( e ) ;
406+ return _this5 . clickClickHour ( e ) . showMinuteClock ( ) ;
380407 } , false ) ;
381408 el . addEventListener ( 'mouseenter' , function ( e ) {
382- return _this4 . mouseInHourClock ( e ) ;
409+ return _this5 . mouseInHourClock ( e ) ;
383410 } , false ) ;
384411 } ) ;
385412
386413 this . $ ( '.js-clock-minutes' ) . addEventListener ( 'mouseleave' , function ( e ) {
387- return _this4 . mouseOutMinuteClock ( e ) ;
414+ return _this5 . mouseOutMinuteClock ( e ) ;
388415 } , false ) ;
389416 this . $ ( '.js-clock-minutes .' + this . options . styles . clockNum ) . forEach ( function ( el ) {
390417 el . addEventListener ( 'click' , function ( e ) {
391- return _this4 . clickClockMinute ( e ) ;
418+ return _this5 . clickClockMinute ( e ) ;
392419 } , false ) ;
393420 el . addEventListener ( 'mouseenter' , function ( e ) {
394- return _this4 . mouseInMinuteClock ( e ) ;
421+ return _this5 . mouseInMinuteClock ( e ) ;
395422 } , false ) ;
396423 } ) ;
397424
398425 this . $ ( '.c-datepicker__clock--am' ) . addEventListener ( 'click' , function ( e ) {
399- return _this4 . clickAm ( e ) ;
426+ return _this5 . clickAm ( e ) ;
400427 } , false ) ;
401428 this . $ ( '.c-datepicker__clock--pm' ) . addEventListener ( 'click' , function ( e ) {
402- return _this4 . clickPm ( e ) ;
429+ return _this5 . clickPm ( e ) ;
403430 } , false ) ;
404431
405432 this . $ ( '.js-show-calendar' ) . addEventListener ( 'click' , function ( e ) {
406- return _this4 . clickShowCalendar ( e ) ;
433+ return _this5 . clickShowCalendar ( e ) ;
407434 } , false ) ;
408435 this . $ ( '.js-date-day' ) . addEventListener ( 'click' , function ( e ) {
409- return _this4 . clickShowCalendar ( e ) ;
436+ return _this5 . clickShowCalendar ( e ) ;
410437 } , false ) ;
411438 this . $ ( '.js-date-month' ) . addEventListener ( 'click' , function ( e ) {
412- return _this4 . clickShowCalendar ( e ) ;
439+ return _this5 . clickShowCalendar ( e ) ;
413440 } , false ) ;
414441
415442 this . $ ( '.js-show-clock' ) . addEventListener ( 'click' , function ( e ) {
416- return _this4 . clickShowClock ( e ) ;
443+ return _this5 . clickShowClock ( e ) ;
444+ } , false ) ;
445+
446+ this . scrimEl . addEventListener ( 'click' , function ( ) {
447+ return _this5 . close ( ) ;
417448 } , false ) ;
418449
419450 return this ;
0 commit comments