Firstsource is a leading provider of business process solutions to more than 100 global businesses across varied industry sectors in the US, UK, Philippines and India. With such a wide range of clients, Firstsource brought MaxContact onboard to provide a bespoke, stable solution.
Firstsource’s previous contact centre solution had stability issues, a lack of support and was difficult to customise. They needed a reliable solution that helped them to win new business and could be adapted to meet changing client demands.
(function () {
const READ_WPM = 220; // average words per minute
const $readTime = document.getElementById('read-time');
const $progress = document.getElementById('progress-bar');
// Get all rich text elements from case_studies-sections div
function getAllRichTexts() {
const caseStudySection = document.querySelector('.case_studies-sections');
if (!caseStudySection) return [];
return Array.from(caseStudySection.querySelectorAll('.text-rich-text'));
}
const $articles = getAllRichTexts();
if (!$articles.length) return;
// --- Reading time ---
function computeReadingTime() {
let totalText = '';
// Collect text from all rich text elements
$articles.forEach($article => {
const text = ($article.innerText || $article.textContent || '').trim();
totalText += text + ' ';
});
const words = totalText.length ? totalText.split(/\s+/).length : 0;
const minutes = Math.max(1, Math.ceil(words / READ_WPM));
if ($readTime) $readTime.textContent = `${minutes} MIN READ`;
}
// --- Scroll progress ---
let startY = 0;
let endY = 0;
function clamp01(x) { return Math.max(0, Math.min(1, x)); }
function measure() {
// Calculate bounds based on all articles
let minTop = Infinity;
let maxBottom = -Infinity;
$articles.forEach($article => {
const rect = $article.getBoundingClientRect();
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const docTopToArticleTop = rect.top + scrollY;
const articleHeight = $article.offsetHeight;
minTop = Math.min(minTop, docTopToArticleTop);
maxBottom = Math.max(maxBottom, docTopToArticleTop + articleHeight);
});
const viewportH = window.innerHeight || document.documentElement.clientHeight;
startY = minTop - 16;
endY = maxBottom - viewportH + 16;
if (endY < startY) endY = startY + 1;
}
function onScroll() {
if (!$progress) return;
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const t = clamp01((scrollY - startY) / (endY - startY));
$progress.style.width = (t * 100).toFixed(2) + '%';
}
function watchImages() {
$articles.forEach($article => {
const images = $article.querySelectorAll('img');
images.forEach(img => {
if (!img.complete) {
img.addEventListener('load', () => { measure(); onScroll(); }, { once: true });
img.addEventListener('error', () => { measure(); onScroll(); }, { once: true });
}
});
});
}
computeReadingTime();
measure();
watchImages();
onScroll();
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', () => { measure(); onScroll(); });
// Watch for changes in all articles
const mo = new MutationObserver(() => { computeReadingTime(); measure(); onScroll(); });
$articles.forEach($article => {
mo.observe($article, { childList: true, subtree: true, characterData: true });
});
})();
(() => {
const rich = document.querySelector('#rich-text');
const toc = document.querySelector('#toc');
if (!rich || !toc) return;
// Only H2s inside the Rich Text
const headings = [...rich.querySelectorAll('h2')];
if (!headings.length) { toc.style.display = 'none'; return; }
// Slugify + ensure unique IDs (handles accents like šđčćž)
const slugCounts = {};
const slugify = (str) => {
const base = (str || '')
.trim()
.toLowerCase()
.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // remove diacritics
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-');
const n = (slugCounts[base] = (slugCounts[base] || 0) + 1);
return n > 1 ? `${base}-${n}` : base || `section-${n}`;
};
// Build anchors directly inside #toc
toc.innerHTML = '';
headings.forEach((h, idx) => {
if (!h.id) h.id = slugify(h.textContent || `section-${idx+1}`);
const a = document.createElement('a');
a.href = `#${h.id}`;
a.className = 'content_link';
a.dataset.target = h.id;
a.setAttribute('aria-label', h.textContent || `Section ${idx+1}`);
const p = document.createElement('p');
p.className = 'text-size-small';
p.textContent = h.textContent || `Section ${idx+1}`;
a.appendChild(p);
toc.appendChild(a);
});
// Offset for fixed navs - with extra spacing for visibility
const getOffset = () => {
const nav = document.querySelector('.navbar, .w-nav, [data-nav]');
const navHeight = nav ? nav.getBoundingClientRect().height : 0;
// Add 30px buffer to ensure heading is clearly visible below fixed navbar
return navHeight + 30;
};
toc.addEventListener('click', (e) => {
const link = e.target.closest('a.content_link[href^="#"]');
if (!link) return;
e.preventDefault();
e.stopPropagation(); // Stop other event listeners
const id = link.getAttribute('href').slice(1);
const target = document.getElementById(id);
if (!target) return;
const targetTop = target.getBoundingClientRect().top + window.scrollY;
const finalY = targetTop - 150;
// Use only smooth scroll
window.scrollTo({ top: finalY, behavior: 'smooth' });
history.replaceState(null, '', `#${id}`);
});
})();
After a successful proof of concept, we worked with Firstsource on their preferred migration strategy, carefully reviewing specific campaign requirements to ensure a seamless migration with zero downtime or impact to them or their clients.
Firstsource saw an immediate improvement in stability following a successful post implementation phase for the initial 50 seat campaign. Our team has since migrated many
more campaigns across to MaxContact, each time delivering improved functionality, client satisfaction and of course, stability.
A strong partnership has resulted in our team regularly assisting Firstsource in responding to tenders and winning new business. Working with our platform, Firstsource has been able to provide bespoke functionality to their clients to win new business and as a result, we are their preferred telephony partner.
(function () {
const READ_WPM = 220; // average words per minute
const $readTime = document.getElementById('read-time');
const $progress = document.getElementById('progress-bar');
// Get all rich text elements from case_studies-sections div
function getAllRichTexts() {
const caseStudySection = document.querySelector('.case_studies-sections');
if (!caseStudySection) return [];
return Array.from(caseStudySection.querySelectorAll('.text-rich-text'));
}
const $articles = getAllRichTexts();
if (!$articles.length) return;
// --- Reading time ---
function computeReadingTime() {
let totalText = '';
// Collect text from all rich text elements
$articles.forEach($article => {
const text = ($article.innerText || $article.textContent || '').trim();
totalText += text + ' ';
});
const words = totalText.length ? totalText.split(/\s+/).length : 0;
const minutes = Math.max(1, Math.ceil(words / READ_WPM));
if ($readTime) $readTime.textContent = `${minutes} MIN READ`;
}
// --- Scroll progress ---
let startY = 0;
let endY = 0;
function clamp01(x) { return Math.max(0, Math.min(1, x)); }
function measure() {
// Calculate bounds based on all articles
let minTop = Infinity;
let maxBottom = -Infinity;
$articles.forEach($article => {
const rect = $article.getBoundingClientRect();
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const docTopToArticleTop = rect.top + scrollY;
const articleHeight = $article.offsetHeight;
minTop = Math.min(minTop, docTopToArticleTop);
maxBottom = Math.max(maxBottom, docTopToArticleTop + articleHeight);
});
const viewportH = window.innerHeight || document.documentElement.clientHeight;
startY = minTop - 16;
endY = maxBottom - viewportH + 16;
if (endY < startY) endY = startY + 1;
}
function onScroll() {
if (!$progress) return;
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const t = clamp01((scrollY - startY) / (endY - startY));
$progress.style.width = (t * 100).toFixed(2) + '%';
}
function watchImages() {
$articles.forEach($article => {
const images = $article.querySelectorAll('img');
images.forEach(img => {
if (!img.complete) {
img.addEventListener('load', () => { measure(); onScroll(); }, { once: true });
img.addEventListener('error', () => { measure(); onScroll(); }, { once: true });
}
});
});
}
computeReadingTime();
measure();
watchImages();
onScroll();
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', () => { measure(); onScroll(); });
// Watch for changes in all articles
const mo = new MutationObserver(() => { computeReadingTime(); measure(); onScroll(); });
$articles.forEach($article => {
mo.observe($article, { childList: true, subtree: true, characterData: true });
});
})();
(() => {
const rich = document.querySelector('#rich-text');
const toc = document.querySelector('#toc');
if (!rich || !toc) return;
// Only H2s inside the Rich Text
const headings = [...rich.querySelectorAll('h2')];
if (!headings.length) { toc.style.display = 'none'; return; }
// Slugify + ensure unique IDs (handles accents like šđčćž)
const slugCounts = {};
const slugify = (str) => {
const base = (str || '')
.trim()
.toLowerCase()
.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // remove diacritics
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-');
const n = (slugCounts[base] = (slugCounts[base] || 0) + 1);
return n > 1 ? `${base}-${n}` : base || `section-${n}`;
};
// Build anchors directly inside #toc
toc.innerHTML = '';
headings.forEach((h, idx) => {
if (!h.id) h.id = slugify(h.textContent || `section-${idx+1}`);
const a = document.createElement('a');
a.href = `#${h.id}`;
a.className = 'content_link';
a.dataset.target = h.id;
a.setAttribute('aria-label', h.textContent || `Section ${idx+1}`);
const p = document.createElement('p');
p.className = 'text-size-small';
p.textContent = h.textContent || `Section ${idx+1}`;
a.appendChild(p);
toc.appendChild(a);
});
// Offset for fixed navs - with extra spacing for visibility
const getOffset = () => {
const nav = document.querySelector('.navbar, .w-nav, [data-nav]');
const navHeight = nav ? nav.getBoundingClientRect().height : 0;
// Add 30px buffer to ensure heading is clearly visible below fixed navbar
return navHeight + 30;
};
toc.addEventListener('click', (e) => {
const link = e.target.closest('a.content_link[href^="#"]');
if (!link) return;
e.preventDefault();
e.stopPropagation(); // Stop other event listeners
const id = link.getAttribute('href').slice(1);
const target = document.getElementById(id);
if (!target) return;
const targetTop = target.getBoundingClientRect().top + window.scrollY;
const finalY = targetTop - 150;
// Use only smooth scroll
window.scrollTo({ top: finalY, behavior: 'smooth' });
history.replaceState(null, '', `#${id}`);
});
})();
(function () {
const READ_WPM = 220; // average words per minute
const $readTime = document.getElementById('read-time');
const $progress = document.getElementById('progress-bar');
// Get all rich text elements from case_studies-sections div
function getAllRichTexts() {
const caseStudySection = document.querySelector('.case_studies-sections');
if (!caseStudySection) return [];
return Array.from(caseStudySection.querySelectorAll('.text-rich-text'));
}
const $articles = getAllRichTexts();
if (!$articles.length) return;
// --- Reading time ---
function computeReadingTime() {
let totalText = '';
// Collect text from all rich text elements
$articles.forEach($article => {
const text = ($article.innerText || $article.textContent || '').trim();
totalText += text + ' ';
});
const words = totalText.length ? totalText.split(/\s+/).length : 0;
const minutes = Math.max(1, Math.ceil(words / READ_WPM));
if ($readTime) $readTime.textContent = `${minutes} MIN READ`;
}
// --- Scroll progress ---
let startY = 0;
let endY = 0;
function clamp01(x) { return Math.max(0, Math.min(1, x)); }
function measure() {
// Calculate bounds based on all articles
let minTop = Infinity;
let maxBottom = -Infinity;
$articles.forEach($article => {
const rect = $article.getBoundingClientRect();
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const docTopToArticleTop = rect.top + scrollY;
const articleHeight = $article.offsetHeight;
minTop = Math.min(minTop, docTopToArticleTop);
maxBottom = Math.max(maxBottom, docTopToArticleTop + articleHeight);
});
const viewportH = window.innerHeight || document.documentElement.clientHeight;
startY = minTop - 16;
endY = maxBottom - viewportH + 16;
if (endY < startY) endY = startY + 1;
}
function onScroll() {
if (!$progress) return;
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const t = clamp01((scrollY - startY) / (endY - startY));
$progress.style.width = (t * 100).toFixed(2) + '%';
}
function watchImages() {
$articles.forEach($article => {
const images = $article.querySelectorAll('img');
images.forEach(img => {
if (!img.complete) {
img.addEventListener('load', () => { measure(); onScroll(); }, { once: true });
img.addEventListener('error', () => { measure(); onScroll(); }, { once: true });
}
});
});
}
computeReadingTime();
measure();
watchImages();
onScroll();
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', () => { measure(); onScroll(); });
// Watch for changes in all articles
const mo = new MutationObserver(() => { computeReadingTime(); measure(); onScroll(); });
$articles.forEach($article => {
mo.observe($article, { childList: true, subtree: true, characterData: true });
});
})();
(() => {
const rich = document.querySelector('#rich-text');
const toc = document.querySelector('#toc');
if (!rich || !toc) return;
// Only H2s inside the Rich Text
const headings = [...rich.querySelectorAll('h2')];
if (!headings.length) { toc.style.display = 'none'; return; }
// Slugify + ensure unique IDs (handles accents like šđčćž)
const slugCounts = {};
const slugify = (str) => {
const base = (str || '')
.trim()
.toLowerCase()
.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // remove diacritics
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-');
const n = (slugCounts[base] = (slugCounts[base] || 0) + 1);
return n > 1 ? `${base}-${n}` : base || `section-${n}`;
};
// Build anchors directly inside #toc
toc.innerHTML = '';
headings.forEach((h, idx) => {
if (!h.id) h.id = slugify(h.textContent || `section-${idx+1}`);
const a = document.createElement('a');
a.href = `#${h.id}`;
a.className = 'content_link';
a.dataset.target = h.id;
a.setAttribute('aria-label', h.textContent || `Section ${idx+1}`);
const p = document.createElement('p');
p.className = 'text-size-small';
p.textContent = h.textContent || `Section ${idx+1}`;
a.appendChild(p);
toc.appendChild(a);
});
// Offset for fixed navs - with extra spacing for visibility
const getOffset = () => {
const nav = document.querySelector('.navbar, .w-nav, [data-nav]');
const navHeight = nav ? nav.getBoundingClientRect().height : 0;
// Add 30px buffer to ensure heading is clearly visible below fixed navbar
return navHeight + 30;
};
toc.addEventListener('click', (e) => {
const link = e.target.closest('a.content_link[href^="#"]');
if (!link) return;
e.preventDefault();
e.stopPropagation(); // Stop other event listeners
const id = link.getAttribute('href').slice(1);
const target = document.getElementById(id);
if (!target) return;
const targetTop = target.getBoundingClientRect().top + window.scrollY;
const finalY = targetTop - 150;
// Use only smooth scroll
window.scrollTo({ top: finalY, behavior: 'smooth' });
history.replaceState(null, '', `#${id}`);
});
})();
(function () {
const READ_WPM = 220; // average words per minute
const $readTime = document.getElementById('read-time');
const $progress = document.getElementById('progress-bar');
// Get all rich text elements from case_studies-sections div
function getAllRichTexts() {
const caseStudySection = document.querySelector('.case_studies-sections');
if (!caseStudySection) return [];
return Array.from(caseStudySection.querySelectorAll('.text-rich-text'));
}
const $articles = getAllRichTexts();
if (!$articles.length) return;
// --- Reading time ---
function computeReadingTime() {
let totalText = '';
// Collect text from all rich text elements
$articles.forEach($article => {
const text = ($article.innerText || $article.textContent || '').trim();
totalText += text + ' ';
});
const words = totalText.length ? totalText.split(/\s+/).length : 0;
const minutes = Math.max(1, Math.ceil(words / READ_WPM));
if ($readTime) $readTime.textContent = `${minutes} MIN READ`;
}
// --- Scroll progress ---
let startY = 0;
let endY = 0;
function clamp01(x) { return Math.max(0, Math.min(1, x)); }
function measure() {
// Calculate bounds based on all articles
let minTop = Infinity;
let maxBottom = -Infinity;
$articles.forEach($article => {
const rect = $article.getBoundingClientRect();
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const docTopToArticleTop = rect.top + scrollY;
const articleHeight = $article.offsetHeight;
minTop = Math.min(minTop, docTopToArticleTop);
maxBottom = Math.max(maxBottom, docTopToArticleTop + articleHeight);
});
const viewportH = window.innerHeight || document.documentElement.clientHeight;
startY = minTop - 16;
endY = maxBottom - viewportH + 16;
if (endY < startY) endY = startY + 1;
}
function onScroll() {
if (!$progress) return;
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const t = clamp01((scrollY - startY) / (endY - startY));
$progress.style.width = (t * 100).toFixed(2) + '%';
}
function watchImages() {
$articles.forEach($article => {
const images = $article.querySelectorAll('img');
images.forEach(img => {
if (!img.complete) {
img.addEventListener('load', () => { measure(); onScroll(); }, { once: true });
img.addEventListener('error', () => { measure(); onScroll(); }, { once: true });
}
});
});
}
computeReadingTime();
measure();
watchImages();
onScroll();
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', () => { measure(); onScroll(); });
// Watch for changes in all articles
const mo = new MutationObserver(() => { computeReadingTime(); measure(); onScroll(); });
$articles.forEach($article => {
mo.observe($article, { childList: true, subtree: true, characterData: true });
});
})();
(() => {
const rich = document.querySelector('#rich-text');
const toc = document.querySelector('#toc');
if (!rich || !toc) return;
// Only H2s inside the Rich Text
const headings = [...rich.querySelectorAll('h2')];
if (!headings.length) { toc.style.display = 'none'; return; }
// Slugify + ensure unique IDs (handles accents like šđčćž)
const slugCounts = {};
const slugify = (str) => {
const base = (str || '')
.trim()
.toLowerCase()
.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // remove diacritics
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-');
const n = (slugCounts[base] = (slugCounts[base] || 0) + 1);
return n > 1 ? `${base}-${n}` : base || `section-${n}`;
};
// Build anchors directly inside #toc
toc.innerHTML = '';
headings.forEach((h, idx) => {
if (!h.id) h.id = slugify(h.textContent || `section-${idx+1}`);
const a = document.createElement('a');
a.href = `#${h.id}`;
a.className = 'content_link';
a.dataset.target = h.id;
a.setAttribute('aria-label', h.textContent || `Section ${idx+1}`);
const p = document.createElement('p');
p.className = 'text-size-small';
p.textContent = h.textContent || `Section ${idx+1}`;
a.appendChild(p);
toc.appendChild(a);
});
// Offset for fixed navs - with extra spacing for visibility
const getOffset = () => {
const nav = document.querySelector('.navbar, .w-nav, [data-nav]');
const navHeight = nav ? nav.getBoundingClientRect().height : 0;
// Add 30px buffer to ensure heading is clearly visible below fixed navbar
return navHeight + 30;
};
toc.addEventListener('click', (e) => {
const link = e.target.closest('a.content_link[href^="#"]');
if (!link) return;
e.preventDefault();
e.stopPropagation(); // Stop other event listeners
const id = link.getAttribute('href').slice(1);
const target = document.getElementById(id);
if (!target) return;
const targetTop = target.getBoundingClientRect().top + window.scrollY;
const finalY = targetTop - 150;
// Use only smooth scroll
window.scrollTo({ top: finalY, behavior: 'smooth' });
history.replaceState(null, '', `#${id}`);
});
})();
(function () {
const READ_WPM = 220; // average words per minute
const $readTime = document.getElementById('read-time');
const $progress = document.getElementById('progress-bar');
// Get all rich text elements from case_studies-sections div
function getAllRichTexts() {
const caseStudySection = document.querySelector('.case_studies-sections');
if (!caseStudySection) return [];
return Array.from(caseStudySection.querySelectorAll('.text-rich-text'));
}
const $articles = getAllRichTexts();
if (!$articles.length) return;
// --- Reading time ---
function computeReadingTime() {
let totalText = '';
// Collect text from all rich text elements
$articles.forEach($article => {
const text = ($article.innerText || $article.textContent || '').trim();
totalText += text + ' ';
});
const words = totalText.length ? totalText.split(/\s+/).length : 0;
const minutes = Math.max(1, Math.ceil(words / READ_WPM));
if ($readTime) $readTime.textContent = `${minutes} MIN READ`;
}
// --- Scroll progress ---
let startY = 0;
let endY = 0;
function clamp01(x) { return Math.max(0, Math.min(1, x)); }
function measure() {
// Calculate bounds based on all articles
let minTop = Infinity;
let maxBottom = -Infinity;
$articles.forEach($article => {
const rect = $article.getBoundingClientRect();
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const docTopToArticleTop = rect.top + scrollY;
const articleHeight = $article.offsetHeight;
minTop = Math.min(minTop, docTopToArticleTop);
maxBottom = Math.max(maxBottom, docTopToArticleTop + articleHeight);
});
const viewportH = window.innerHeight || document.documentElement.clientHeight;
startY = minTop - 16;
endY = maxBottom - viewportH + 16;
if (endY < startY) endY = startY + 1;
}
function onScroll() {
if (!$progress) return;
const scrollY = window.pageYOffset || document.documentElement.scrollTop || 0;
const t = clamp01((scrollY - startY) / (endY - startY));
$progress.style.width = (t * 100).toFixed(2) + '%';
}
function watchImages() {
$articles.forEach($article => {
const images = $article.querySelectorAll('img');
images.forEach(img => {
if (!img.complete) {
img.addEventListener('load', () => { measure(); onScroll(); }, { once: true });
img.addEventListener('error', () => { measure(); onScroll(); }, { once: true });
}
});
});
}
computeReadingTime();
measure();
watchImages();
onScroll();
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', () => { measure(); onScroll(); });
// Watch for changes in all articles
const mo = new MutationObserver(() => { computeReadingTime(); measure(); onScroll(); });
$articles.forEach($article => {
mo.observe($article, { childList: true, subtree: true, characterData: true });
});
})();
(() => {
const rich = document.querySelector('#rich-text');
const toc = document.querySelector('#toc');
if (!rich || !toc) return;
// Only H2s inside the Rich Text
const headings = [...rich.querySelectorAll('h2')];
if (!headings.length) { toc.style.display = 'none'; return; }
// Slugify + ensure unique IDs (handles accents like šđčćž)
const slugCounts = {};
const slugify = (str) => {
const base = (str || '')
.trim()
.toLowerCase()
.normalize('NFD').replace(/[\u0300-\u036f]/g, '') // remove diacritics
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-');
const n = (slugCounts[base] = (slugCounts[base] || 0) + 1);
return n > 1 ? `${base}-${n}` : base || `section-${n}`;
};
// Build anchors directly inside #toc
toc.innerHTML = '';
headings.forEach((h, idx) => {
if (!h.id) h.id = slugify(h.textContent || `section-${idx+1}`);
const a = document.createElement('a');
a.href = `#${h.id}`;
a.className = 'content_link';
a.dataset.target = h.id;
a.setAttribute('aria-label', h.textContent || `Section ${idx+1}`);
const p = document.createElement('p');
p.className = 'text-size-small';
p.textContent = h.textContent || `Section ${idx+1}`;
a.appendChild(p);
toc.appendChild(a);
});
// Offset for fixed navs - with extra spacing for visibility
const getOffset = () => {
const nav = document.querySelector('.navbar, .w-nav, [data-nav]');
const navHeight = nav ? nav.getBoundingClientRect().height : 0;
// Add 30px buffer to ensure heading is clearly visible below fixed navbar
return navHeight + 30;
};
toc.addEventListener('click', (e) => {
const link = e.target.closest('a.content_link[href^="#"]');
if (!link) return;
e.preventDefault();
e.stopPropagation(); // Stop other event listeners
const id = link.getAttribute('href').slice(1);
const target = document.getElementById(id);
if (!target) return;
const targetTop = target.getBoundingClientRect().top + window.scrollY;
const finalY = targetTop - 150;
// Use only smooth scroll
window.scrollTo({ top: finalY, behavior: 'smooth' });
history.replaceState(null, '', `#${id}`);
});
})();