Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.

Commit fad5321

Browse files
committed
Added Calendar Multi Select Days / History
1 parent 85baa2c commit fad5321

6 files changed

Lines changed: 177 additions & 23 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,22 @@ var data = {
206206
> Do not use this if `organizer` is not declared. Use the [Calendar OnClickListeners](#calendar-onclicklisteners) instead
207207
208208
```javascript
209-
// Days Block click listener
209+
// Days Block Click Listener
210210
organizer.setOnClickListener('days-blocks',
211211
// Called when a day block is clicked
212212
function () {
213213
console.log("Day block clicked");
214214
}
215215
);
216216

217+
// Days Block Long Click Listener
218+
organizer.setOnLongClickListener('days-blocks',
219+
// Called when a day block is long clicked
220+
function () {
221+
console.log("Day block long clicked");
222+
}
223+
);
224+
217225
// Month Slider (Left and Right Arrow) Click Listeners
218226
organizer.setOnClickListener('month-slider',
219227
// Called when the month left arrow is clicked

assets/screenshot1.png

416 KB
Loading

calendarorganizer.css

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,21 +436,28 @@
436436
-webkit-box-direction: normal;
437437
-ms-flex-direction: column;
438438
flex-direction: column;
439-
overflow: hidden !important;
439+
overflow: auto !important;
440440
}
441441

442442
.cjslib-list {
443443
width: 100%;
444-
height: 100%;
445444
position: relative;
446-
-webkit-box-flex: 1;
447-
-ms-flex: 1;
448-
flex: 1;
449-
overflow-y: auto !important;
445+
overflow-y: visible !important;
450446
padding: 0;
451447
margin: 0;
452448
color: rgba(21, 21, 21, 0.94);
449+
padding-bottom: 15px;
453450
}
451+
.cjslib-list-history {
452+
padding-top: 10px;
453+
width: calc(100% - 20px);
454+
margin-left: 10px;
455+
margin-right: 10px;
456+
}
457+
.cjslib-list-history > .cjslib-list-history-title {
458+
padding: 5px 0px;
459+
border-radius: 2px;
460+
}
454461

455462
.cjslib-list-placeholder {
456463
height: 100%;
@@ -465,7 +472,14 @@
465472
align-items: center;
466473
color: #757575;
467474
pointer-events: none;
475+
display: none;
468476
}
477+
.cjslib-list-placeholder * {
478+
pointer-events: all;
479+
}
480+
.cjslib-list .cjslib-list-placeholder:only-child {
481+
display: block !important;
482+
}
469483

470484
.cjslib-list > li {
471485
width: 100%;

calendarorganizer.js

Lines changed: 146 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

334342
Organizer.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

458488
Organizer.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+
491544
Organizer.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

513597
Organizer.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

517606
Organizer.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

Comments
 (0)