You already have the right left positions, so you only need to set the correct width.
In pseudo code:
foreach chip chips_siblings = this.parent .allchilds(chip) .filter(this.top <= child.top <= this.bottom && child.left > this.left) this.width = min(chips_siblings.left) - this.left
In JavaScript:
function placeChipsCorrectly() { "use strict" Array.prototype.forEach.call( document.getElementsByClassName('chip'), function(self) { var siblings = Array.prototype.filter.call( self.parentElement.getElementsByClassName('chip'), function(child) { return child.offsetTop >= self.offsetTop-2 && child.offsetTop <= self.offsetTop+self.offsetHeight-3 && child.offsetLeft > self.offsetLeft; }); if (siblings.length > 0) { var minLeft = Math.min.apply(null, Array.prototype.map.call( siblings, function(el) { return el.offsetLeft; })); self.style.width = (minLeft - self.offsetLeft - 2) + "px"; } }); } placeChipsCorrectly();
Regarding change tracking events:
After each data change, you can see "Loading ..." in the upper right corner. After checking how this works, you can see that it changes the style attribute of the container with id lo-c .
Thus, you can track its appearance and disappearance as follows:
(new MutationObserver(placeChipsCorrectly)).observe(document.getElementById('lo-c'),{attributes: true});
When you only change the view, and not the data (for example, by selecting another day or week), then "Loading ..." does not appear. For these events, you can track the global click event:
document.body.addEventListener('click', placeChipsCorrectly);
Keep in mind that both methods will require some overhead. If you want to improve them, start by modifying the observer so that it placeChipsCorrectly only when it disappears and restricting click tracking to specific controls.
user
source share