@@ -22,6 +22,7 @@ function Calendar(id, size, labelSettings, colors, options) {
2222 var listPlaceholder = document . createElement ( "LI" ) ;
2323 listPlaceholder . className = "cjslib-list-placeholder" ;
2424 listPlaceholder . appendChild ( document . createTextNode ( "No events on this day" ) ) ;
25+ listPlaceholder . style = "text-align: center; padding: 20px 0px;" ;
2526
2627 this . placeholder = listPlaceholder . outerHTML ;
2728 if ( options . placeholder != undefined ) this . placeholder = options . placeholder ;
@@ -48,6 +49,8 @@ function Calendar(id, size, labelSettings, colors, options) {
4849 this . date = new Date ( ) ;
4950 this . today = new Date ( ) ;
5051
52+ this . history = [ ] ;
53+
5154 this . draw ( ) ;
5255 this . update ( ) ;
5356
@@ -105,6 +108,9 @@ Calendar.prototype = {
105108
106109 return true ;
107110 } else this . date . setDate ( theDay ) ;
111+ } ,
112+ getDateString : function getDateString ( ) {
113+ return this . months [ this . date . getMonth ( ) ] + " " + this . date . getDate ( ) + ", " + this . date . getFullYear ( ) ;
108114 }
109115} ;
110116
@@ -329,6 +335,8 @@ function Organizer(id, calendar, data) {
329335 this . setOnClickListener ( 'day-slider' ) ;
330336 this . setOnClickListener ( 'month-slider' ) ;
331337 this . setOnClickListener ( 'year-slider' ) ;
338+
339+ this . setOnLongClickListener ( 'days-blocks' ) ;
332340}
333341
334342Organizer . prototype = {
@@ -394,6 +402,22 @@ Organizer.prototype = {
394402 }
395403 } ,
396404 changeDateTo : function changeDateTo ( theDay , theBlock ) {
405+ this . clearHistory ( ) ;
406+
407+ var changedMonth = this . calendar . changeDateTo ( theDay , theBlock ) ;
408+
409+ var organizerInstance = this ;
410+ setTimeout ( function ( ) {
411+ if ( changedMonth ) {
412+ organizerInstance . onMonthChange ( function ( ) {
413+ organizerInstance . indicateEvents ( ) ;
414+ } ) ;
415+ } else organizerInstance . update ( ) ;
416+ } , 1 ) ;
417+ } ,
418+ addDate : function changeDateTo ( theDay , theBlock ) {
419+ this . showHistory ( ) ;
420+
397421 var changedMonth = this . calendar . changeDateTo ( theDay , theBlock ) ;
398422
399423 var organizerInstance = this ;
@@ -435,12 +459,18 @@ Organizer.prototype.draw = function () {
435459
436460 var theRows = document . createElement ( "DIV" ) ;
437461 theRows . className = "cjslib-rows" ;
462+ theRows . id = this . id + "-list-container" ;
438463
439464 var theList = document . createElement ( "OL" ) ;
440465 theList . className = "cjslib-list" ;
441466 theList . id = this . id + "-list" ;
442467
468+ var theHistory = document . createElement ( "OL" ) ;
469+ theHistory . className = "cjslib-list" ;
470+ theHistory . id = this . id + "-history" ;
471+
443472 theRows . appendChild ( theList . cloneNode ( true ) ) ;
473+ theRows . appendChild ( theHistory . cloneNode ( true ) ) ;
444474
445475 theOrganizer . appendChild ( theDate . cloneNode ( true ) ) ;
446476 theOrganizer . appendChild ( theRows . cloneNode ( true ) ) ;
@@ -456,9 +486,7 @@ Organizer.prototype.update = function () {
456486} ;
457487
458488Organizer . prototype . list = function ( data ) {
459- document . getElementById ( this . id + "-list" ) . innerHTML = "" ;
460-
461- var content = document . createElement ( "UL" ) ;
489+ var container = document . createElement ( "UL" ) ;
462490 for ( var i = 0 ; i < data . length ; i ++ ) {
463491 var listItem = document . createElement ( "LI" ) ;
464492 listItem . id = this . id + "-list-item-" + i ;
@@ -479,22 +507,55 @@ Organizer.prototype.list = function (data) {
479507 listItem . appendChild ( division ) ;
480508 listItem . appendChild ( paragraph ) ;
481509
482- content . appendChild ( listItem ) ;
510+ container . appendChild ( listItem ) ;
483511 }
484512
485- document . getElementById ( this . id + "-list" ) . innerHTML = content . innerHTML ;
513+ return container . innerHTML
514+ } ;
515+
516+ Organizer . prototype . remember = function ( date , content ) {
517+ if ( content . startsWith ( "<div class=\"cjslib-list-placeholder\">" ) )
518+ return "" ;
519+
520+ var dateTitle = this . calendar . getDateString ( ) ;
521+ this . calendar . history . unshift ( dateTitle ) ;
522+
523+ var container = document . createElement ( "UL" ) ;
524+ container . className = "cjslib-list cjslib-list-history"
486525
487- if ( data . length == 0 )
488- this . showPlaceholder ( ) ;
526+ var title = document . createElement ( "LI" ) ;
527+ title . appendChild ( document . createTextNode ( dateTitle ) ) ;
528+ title . className = "cjslib-list-history-title cjslib-date" ;
529+ title . style . backgroundColor = this . calendar . colors [ 1 ] ;
530+ title . style . color = this . calendar . colors [ 3 ] ;
531+
532+ container . appendChild ( title ) ;
533+
534+ container . innerHTML += content ;
535+
536+ return container . outerHTML ;
489537} ;
490538
539+ Organizer . prototype . clearHistory = function ( ) {
540+ this . calendar . history = [ ] ;
541+ document . getElementById ( this . id + "-history" ) . innerHTML = "" ;
542+ }
543+
491544Organizer . prototype . setupBlock = function ( blockId , organizerInstance , callback ) {
492545 var calendarInstance = organizerInstance . calendar ;
493546
494547 document . getElementById ( calendarInstance . id + "-day-" + blockId ) . onclick = function ( ) {
495548 if ( document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . innerHTML . length > 0 ) {
496- organizerInstance . changeDateTo ( document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . innerHTML , blockId ) ;
497- callback ( ) ;
549+ if ( document . getElementById ( calendarInstance . id + "-day-radio-" + blockId ) . checked )
550+ return ;
551+
552+ var longPressed = "" + document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . dataset . longpressed ;
553+ document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . dataset . longpressed = false ;
554+
555+ if ( longPressed != "true" ) {
556+ organizerInstance . changeDateTo ( document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . innerHTML , blockId ) ;
557+ callback ( ) ;
558+ }
498559 }
499560 } ;
500561} ;
@@ -503,16 +564,44 @@ Organizer.prototype.showEvents = function (data) {
503564 data = data || this . data ;
504565 var date = this . calendar . date ;
505566
567+ var content = "" ;
568+ var history = "" ;
506569 try {
507- this . list ( data [ date . getFullYear ( ) ] [ date . getMonth ( ) + 1 ] [ date . getDate ( ) ] ) ;
570+ var historyIndex = this . calendar . history . indexOf ( this . calendar . getDateString ( ) ) ;
571+ if ( historyIndex > - 1 ) {
572+ this . calendar . history . splice ( historyIndex , 1 ) ;
573+ document . getElementById ( this . id + "-history" ) . children [ historyIndex ] . remove ( ) ;
574+ }
575+
576+ history +=
577+ history += document . getElementById ( this . id + "-list" ) . innerHTML ;
578+
579+ content = this . list ( data [ date . getFullYear ( ) ] [ date . getMonth ( ) + 1 ] [ date . getDate ( ) ] ) ;
508580 } catch ( e ) {
509- this . showPlaceholder ( ) ;
581+ content = this . showPlaceholder ( ) ;
510582 }
583+
584+ document . getElementById ( this . id + "-list" ) . innerHTML = content ;
585+ } ;
586+
587+ Organizer . prototype . showHistory = function ( data ) {
588+ data = data || this . data ;
589+ var date = this . calendar . date ;
590+
591+ var content = this . remember ( date , document . getElementById ( this . id + "-list" ) . innerHTML ) ;
592+ var history = document . getElementById ( this . id + "-history" ) . innerHTML ;
593+
594+ document . getElementById ( this . id + "-history" ) . innerHTML = content + history ;
511595} ;
512596
513597Organizer . prototype . showPlaceholder = function ( data ) {
514- document . getElementById ( this . id + "-list" ) . innerHTML = this . calendar . placeholder ;
515- }
598+ var container = document . createElement ( "DIV" ) ;
599+ container . className = "cjslib-list-placeholder" ;
600+
601+ container . innerHTML = this . calendar . placeholder ;
602+
603+ return container . outerHTML ;
604+ } ;
516605
517606Organizer . prototype . indicateEvents = function ( data ) {
518607 data = data || this . data ;
@@ -588,4 +677,47 @@ Organizer.prototype.setOnClickListener = function (theCase, backCallback, nextCa
588677 } ;
589678 break ;
590679 }
591- } ;
680+ } ;
681+
682+ Organizer . prototype . setupLongClickBlock = function ( blockId , organizerInstance , callback ) {
683+ var calendarInstance = organizerInstance . calendar ;
684+
685+ var mouseDownEvent = function ( ) {
686+ document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . dataset . longpressed = "-" ;
687+
688+ window . setTimeout ( function ( ) {
689+ if ( document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . innerHTML . length > 0 ) {
690+ if ( document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . dataset . longpressed == "false" )
691+ return ;
692+ else document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . dataset . longpressed = true ;
693+
694+ if ( document . getElementById ( calendarInstance . id + "-day-radio-" + blockId ) . checked )
695+ return ;
696+
697+ organizerInstance . addDate ( document . getElementById ( calendarInstance . id + "-day-num-" + blockId ) . innerHTML , blockId ) ;
698+ callback ( ) ;
699+ }
700+ } , 1000 ) ;
701+ } ;
702+
703+ document . getElementById ( calendarInstance . id + "-day-" + blockId ) . onmousedown = mouseDownEvent ;
704+ document . getElementById ( calendarInstance . id + "-day-" + blockId ) . ontouchstart = mouseDownEvent ;
705+ } ;
706+
707+ Organizer . prototype . setOnLongClickListener = function ( theCase , backCallback , nextCallback ) {
708+ var calendarId = this . calendar . id ;
709+ var organizerId = this . id ;
710+
711+ backCallback = backCallback || function ( ) { } ;
712+ nextCallback = nextCallback || function ( ) { } ;
713+
714+ var organizerInstance = this ;
715+
716+ switch ( theCase ) {
717+ case "days-blocks" :
718+ for ( var i = 1 ; i <= 42 ; i ++ ) {
719+ organizerInstance . setupLongClickBlock ( i , organizerInstance , backCallback ) ;
720+ }
721+ break ;
722+ }
723+ }
0 commit comments