Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-99196

Changing the Event Color in Team Calendars won't affect the Event Icon if using Dark or Light Themes.

XMLWordPrintable

      Issue Summary

      This is reproducible on Data Center: Yes

      When using Dark or Light Themes and changing the Event Color in Team Calendars, the Event Icon does not change color as it should. The Event color-code used to help identify events in the calendar. 

      Steps to Reproduce

      1. Set to use Dark or Light Theme
      2. Create a new Calendar
      3. Add an Event to the Calendar
      4. Change the Event color in the three-doted menu next to the Event icon

      Expected Results

      The event background in the calendar and the event icon in the event list side panel change color.

      Actual Results

      The event background in the calendar changes color and the event icon in the event list side panel remains unchanged.

      Workaround

      How to apply the script:

      1. As a Confluence admin Go to Confluence Administration > Under Look and Feel > Custom HTML
      2. Click Edit > Paste the script under At end of the HEAD and then Save
      3. Go back to the page with the Calendar. Check the legend icon colors, they should now match with the events.
        • Make sure to test all event types and also add custom events and try.
      Disclaimer
      • This script is officially not supported and its purely based on Best effort basis. 
      • We recommend to first try this in test environment and then proceed with production. 
      <script>
      // Wait for the DOM to load before running the script
      document.addEventListener('DOMContentLoaded', function() {
          // Ensure jQuery is available (supports window.jQuery, window.$, or AJS.$)
          var $ = window.jQuery || window.$ || AJS.$;
          if (!$) return;
      
          // Function to sync legend icon colors with event bar colors
          function syncLegendColors() {
              // Loop through each legend item
              $('li.child-subcalendar').each(function() {
                  var legendItem = $(this);
                  var subCalendarId = legendItem.attr('data-sub-calendar-id');
                  var eventBar;
      
                  // Try to match the legend item to an event bar using data-subcalendar-id
                  if (subCalendarId) {
                      eventBar = $('.fc-event[data-subcalendar-id="' + subCalendarId + '"]');
                  }
      
                  // If no match found, fall back to class-based matching
                  if (!eventBar || !eventBar.length) {
                      var legendType;
                      // Handle custom event types using their unique class
                      if (legendItem.attr('data-custom-event-type-id')) {
                          legendType = legendItem.attr('class').split(' ').find(cls => 
                              cls !== 'child-subcalendar' && !cls.startsWith('subcalendar-')
                          );
                      } else {
                          // Handle default event types (Events, Leave, Travel, Birthdays)
                          if (legendItem.hasClass('other')) legendType = 'other';
                          else if (legendItem.hasClass('leaves')) legendType = 'leaves';
                          else if (legendItem.hasClass('travel')) legendType = 'travel';
                          else if (legendItem.hasClass('birthdays')) legendType = 'birthdays';
                      }
                      // Find the event bar using the identified class
                      if (legendType) {
                          eventBar = $('.fc-event.' + legendType);
                      }
                  }
      
                  // If a matching event bar is found, apply its background color to the legend icon
                  if (eventBar && eventBar.length) {
                      var eventColor = eventBar.css('background-color');
                      if (eventColor) {
                          legendItem.find('.subcalendar-icon-container svg path').css('fill', eventColor);
                      }
                  }
              });
          }
      
          // Run the sync 10 seconds after page load to ensure the calendar is rendered
          setTimeout(syncLegendColors, 10000);
      
          // Periodically re-sync every 15 seconds to handle color changes
          setInterval(syncLegendColors, 15000);
      
          // Observe DOM changes in the calendar to re-sync dynamically
          var calendarContainer = document.querySelector('.fc-event-container') || document.body;
          var observer = new MutationObserver(function() {
              syncLegendColors();
          });
          observer.observe(calendarContainer, { childList: true, subtree: true });
      });
      </script>
      

              e8288ea86ca1 Saba Taseer
              c8aa498493f3 Marcos Junior
              Votes:
              19 Vote for this issue
              Watchers:
              28 Start watching this issue

                Created:
                Updated:
                Resolved: