Thanks, sidenotes are floating next to the index so it only happens in unusual cases when the index is at the last/first line or sidenotes have been pushed because the are a few close by. I finally managed to get it working by doing some calculations so when the sidetone is close to the upper/bottom margin the margin top/bottom is removed
// Post layout call to fix sidenote margins
function fixSidenoteMargins(lowestY, uppermostY) {
schedule(fixSidenoteMargins_postlayout,[lowestY,uppermostY]);
}
// function to fix sidenote top and bottom margins
function fixSidenoteMargins_postlayout(fixSidenote_args) {
var lowestYThreshold = fixSidenote_args[0];
var uppermostYThreshold = topt(fixSidenote_args[1]);
// convert to points
lowestYThreshold = convertToPoints(lowestYThreshold);
uppermostYThreshold = convertToPoints(uppermostYThreshold);
// Find all span elements with class "sidenote-lua" or "sidenote-fn"
var elements = document.querySelectorAll("span.sidenote-lua, span.sidenote-fn");
for(var i=0; i<elements.length; i++) {
var boxes = elements[i].getPrinceBoxes();
if (boxes.length > 0) {
if (DEBUG) {
console.log("tagname: ", elements[i].className, " id: ", elements[i].id);
console.log(" x: ", uni(boxes[0].x));
console.log(" y: ", uni(boxes[0].y));
console.log(" width: ", uni(boxes[0].w));
console.log(" height: ", uni(boxes[0].h));
console.log(" page: ", boxes[0].pageNum);
console.log(" margin bottom: ", uni(boxes[0].marginBottom));
console.log(" uppermost y: ", uni(uppermostY));
console.log(" lowest y: ", uni(lowestY));
}
var uppermostY = boxes[0].y;
var lowestY = boxes[0].y - boxes[0].h;
if (lowestY <= lowestYThreshold) {
boxes[0].element.style.marginBottom = "0";
console.log("page: ", boxes[0].pageNum, " id: ", elements[i].id);
console.log("margin bottom set to 0 due to lowestY being", uni(lowestYThreshold), "or less");
if (DEBUG) {
boxes[0].element.style.color="red";
}
}
if (uppermostY >= uppermostYThreshold) {
boxes[0].element.style.marginTop = "0";
console.log("page: ", boxes[0].pageNum, " id: ", elements[i].id);
console.log("margin top set to 0 due to uppermostY being", uni(uppermostYThreshold), "or more");
if (DEBUG) {
boxes[0].element.style.color="red";
}
}
}
}
}