|
1 | 1 | /** |
2 | | - * SimpleCalendarJs v3.0.5 |
| 2 | + * SimpleCalendarJs v3.0.6 |
3 | 3 | * A clean, modern, and feature-rich JavaScript calendar component with zero dependencies |
4 | 4 | * |
5 | 5 | * @author Pedro Lopes <simplecalendarjs@gmail.com> |
|
372 | 372 | showViewSwitcher: true, |
373 | 373 | showTooltips: true, |
374 | 374 | showBorder: true, |
375 | | - maxEventsPerCell: 3, |
| 375 | + maxEventsPerCell: -1, |
376 | 376 | listDaysForward: 30, |
377 | 377 | enabledViews: ['month', 'week', 'day'], |
378 | 378 | enableDragDrop: false, |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 |
|
| 446 | + // Build the shell once during initialization |
| 447 | + this._root.innerHTML = this._buildShell(); |
| 448 | + |
446 | 449 | this._fetchAndRender(); |
447 | 450 | this._startNowUpdater(); |
448 | 451 | } |
|
555 | 558 | } |
556 | 559 |
|
557 | 560 | async _fetchAndRender() { |
558 | | - // Build the shell immediately (updates toolbar title + clears view) |
559 | | - this._root.innerHTML = this._buildShell(); |
| 561 | + // Update toolbar only (don't rebuild entire shell) |
| 562 | + this._updateToolbar(); |
560 | 563 |
|
561 | 564 | if (!this._opts.fetchEvents) { |
562 | 565 | this._renderView(); |
|
630 | 633 | this._root.classList.add('uc-unlimited-events'); |
631 | 634 | // Remove cell min-height override for unlimited mode |
632 | 635 | this._root.style.removeProperty('--cal-cell-min-height'); |
| 636 | + } else if (this._opts.maxEventsPerCell === -1) { |
| 637 | + this._root.classList.remove('uc-unlimited-events'); |
| 638 | + // Auto-calculate mode: use default CSS value, don't override |
| 639 | + this._root.style.removeProperty('--cal-cell-min-height'); |
633 | 640 | } else { |
634 | 641 | this._root.classList.remove('uc-unlimited-events'); |
635 | 642 | // Set cell min-height based on maxEventsPerCell to match maximum row height |
|
685 | 692 | `; |
686 | 693 | } |
687 | 694 |
|
| 695 | + _updateToolbar() { |
| 696 | + const toolbar = this._root.querySelector('.uc-toolbar'); |
| 697 | + if (toolbar) { |
| 698 | + const temp = document.createElement('div'); |
| 699 | + temp.innerHTML = this._buildToolbar(); |
| 700 | + const newToolbar = temp.firstElementChild; |
| 701 | + if (newToolbar) { |
| 702 | + toolbar.replaceWith(newToolbar); |
| 703 | + } |
| 704 | + } |
| 705 | + } |
| 706 | + |
688 | 707 | _buildToolbar() { |
689 | 708 | if (!this._opts.showToolbar) return ''; |
690 | 709 |
|
|
857 | 876 |
|
858 | 877 | _buildWeekRow(weekDates, allEvents) { |
859 | 878 | const curMonth = this._date.getMonth(); |
860 | | - const MAX = this._opts.maxEventsPerCell === 0 ? Infinity : this._opts.maxEventsPerCell; |
| 879 | + |
| 880 | + // Calculate MAX based on maxEventsPerCell option |
| 881 | + let MAX; |
| 882 | + if (this._opts.maxEventsPerCell === 0) { |
| 883 | + MAX = Infinity; // Show all events |
| 884 | + } else if (this._opts.maxEventsPerCell === -1) { |
| 885 | + // Auto-calculate based on cell height |
| 886 | + // Get the computed cell min-height (default is 112px from CSS) |
| 887 | + const computedStyle = getComputedStyle(this._root); |
| 888 | + const cellMinHeight = parseInt(computedStyle.getPropertyValue('--cal-cell-min-height') || '112'); |
| 889 | + // Formula: (cellHeight - headerHeight - moreLink) / eventHeightWithGap |
| 890 | + // cellHeight - 30 (header) - 28 (+N more space) / 24 (event + gap) |
| 891 | + MAX = Math.floor((cellMinHeight - 30 - 28) / 24); |
| 892 | + // Ensure at least 1 event is shown |
| 893 | + MAX = Math.max(1, MAX); |
| 894 | + } else { |
| 895 | + MAX = this._opts.maxEventsPerCell; // Use specified number |
| 896 | + } |
861 | 897 |
|
862 | 898 | // Separate multi-day from single-day events |
863 | 899 | const multiDay = allEvents.filter(isMultiDay); |
|
1146 | 1182 | style="left:calc(${left}% + 2px);width:calc(${width}% - 4px);top:${topCss};background:${esc(color)};border-radius:${rl} ${rr} ${rr} ${rl};" |
1147 | 1183 | data-event-id="${esc(event.id)}" data-action="event-click" |
1148 | 1184 | ${tooltipAttr}> |
1149 | | - ${isStart ? `<span class="uc-event-title">${esc(event.title)}</span>` : ' '} |
| 1185 | + <span class="uc-event-title">${esc(event.title)}</span> |
1150 | 1186 | ${resizeHandle} |
1151 | 1187 | </div>`; |
1152 | 1188 | } |
|
0 commit comments