Skip to content

Commit

Permalink
add rough notation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinalcs committed Feb 25, 2025
1 parent 4d341fa commit e066f57
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions assets/js/rough-notation.iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1019,12 +1019,58 @@ function initAnimatePageContent(container = document) {
});
}

function initRoughNotation() {
if (typeof RoughNotation === 'undefined') {
const script = document.createElement('script');
script.src = "/assets/js/rough-notation.iife.js";
script.onload = applyRoughNotation;
document.head.appendChild(script);
} else {
applyRoughNotation();
}

function applyRoughNotation() {
const { annotate } = RoughNotation;
const links = document.querySelectorAll('main a');

// Get the CSS variable value
const computedStyle = getComputedStyle(document.documentElement);
const underlineColor = computedStyle.getPropertyValue('--c').trim() || 'white';

const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const link = entry.target;
const href = link.getAttribute('href');

// Apply only if the link is external (starts with http)
if (href && href.startsWith('http')) {
const annotation = annotate(link, {
type: 'underline',
color: underlineColor,
animationDuration: 800
});
annotation.show();
}
}
});
}, { threshold: 0.1 });

// Observe only external links
links.forEach(link => {
const href = link.getAttribute('href');
if (href && href.startsWith('http')) {
observer.observe(link);
}
});
}
}

// Function to initialize on initial page load
function init() {
initInlineScript(document.body);
initMathJax();
initMermaid();
initMermaid();initRoughNotation();
initFormSubmission();
initLightenseImages();
initPhotoswipe();
Expand Down

0 comments on commit e066f57

Please sign in to comment.