1/** 2 * @file 3 * Calendar multiple day events behaviors. 4 */ 5 6(function (Drupal, once) { 7 8 const hashAttribute = 'data-calendar-view-hash'; 9 10 /** 11 * Alter multiday events theming. 12 * 13 * This behavior is dependent on preprocess hook. 14 * 15 * @type {Drupal~behavior} 16 * 17 * @prop {Drupal~behaviorAttach} attach 18 * Attaches the behavior. 19 * 20 * @see template_preprocess_calendar_view_day() 21 */ 22 Drupal.behaviors.calendarViewMultiday = { 23 attach(context, settings) { 24 // Find first instance multiday event from the past. 25 let firstInstances = {}; 26 context.querySelectorAll('[' + hashAttribute + ']').forEach(function (el) { 27 if (el.hasAttribute(hashAttribute)) { 28 let hash = el.getAttribute(hashAttribute); 29 if (!firstInstances[hash]) { 30 firstInstances[hash] = el; 31 } 32 } 33 }); 34 35 if (!firstInstances || firstInstances.length < 1) { 36 return; 37 } 38 39 // Alter all other instances of a multiday event. 40 once('calendar-view-multiday', Object.values(firstInstances), context).forEach(function (el) { 41 if (!el.hasAttribute(hashAttribute)) { 42 return; 43 } 44 45 let rowHash = el.getAttribute(hashAttribute); 46 let rowInstances = context.querySelectorAll('[' + hashAttribute + '="' + rowHash + '"]'); 47 if (!rowInstances || rowInstances.length < 1) { 48 return; 49 } 50 51 // Simulate first instance for multiday spanning in the past. 52 if (el.classList.contains('is-multi--middle')) { 53 el.classList.add('is-multi--first'); 54 } 55 56 // Get reference "sizes". 57 let elBound = el.getBoundingClientRect(); 58 59 // Loop on cloned events. 60 rowInstances.forEach(function (instance) { 61 // Hover all at once. 62 instance.addEventListener('mouseover', function (event) { 63 rowInstances.forEach(function (other) { 64 other.classList.add('hover'); 65 }); 66 }); 67 instance.addEventListener('mouseleave', function (event) { 68 rowInstances.forEach(function (other) { 69 other.classList.remove('hover'); 70 }); 71 }); 72 73 // Simulate same size and position in cell. 74 if (instance != el) { 75 instance.style.height = elBound.height + 'px'; 76 77 if (instance.offsetTop < el.offsetTop) { 78 instance.style.marginTop = (el.offsetTop - instance.offsetTop) + 'px'; 79 } 80 } 81 }); 82 }); 83 }, 84 }; 85})(Drupal, once);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.