Skip to content

Commit

Permalink
add custom js support to params
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Larkin committed Jul 31, 2024
1 parent 5db3d64 commit 846e669
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 66 deletions.
49 changes: 21 additions & 28 deletions assets/js/custom.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
console.log('Custom script loaded');

function smoothScroll(e) {
const href = this.getAttribute('href');
console.log('Clicked link:', href);

if (href.startsWith('/#')) {
window.addEventListener('load', function() {
console.log('Custom script loaded');

function smoothScroll(e) {
const href = this.getAttribute('href');
console.log('Clicked link:', href);

if (href.startsWith('/#')) {
e.preventDefault();
console.log('Preventing default behavior for:', href);

const targetId = href.replace('/#', '');
const targetElement = document.getElementById(targetId);

if (targetElement) {
console.log('Scrolling to:', targetId);
targetElement.scrollIntoView({
behavior: 'smooth'
});
console.log('Scrolling to:', targetId);
targetElement.scrollIntoView({
behavior: 'smooth'
});
} else {
console.log('Target element not found:', targetId);
console.log('Target element not found:', targetId);
}
}
}
}

function attachSmoothScroll() {
console.log('Attaching smooth scroll');

const menuLinks = document.querySelectorAll('a[href^="/#"]');
console.log('Found menu links:', menuLinks.length);

menuLinks.forEach(link => {
console.log('Adding listener to:', link.href);
link.addEventListener('click', smoothScroll);
console.log('Adding listener to:', link.href);
link.addEventListener('click', smoothScroll);
});
}

// Try to attach immediately
attachSmoothScroll();

// Also attach when the DOM is fully loaded
document.addEventListener('DOMContentLoaded', attachSmoothScroll);
});
6 changes: 5 additions & 1 deletion config/_default/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ header:
show_search: true
show_theme_chooser: true
logo:
text: "Your Name"
text: "Chris Larkin"

# Site footer
footer:
Expand All @@ -58,3 +58,7 @@ features:
enable: false
privacy_pack:
enable: false

# Append custom JavaScript
plugins_js:
- custom
3 changes: 1 addition & 2 deletions layouts/partials/hooks/head-end.html
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
{{ $custom_js := resources.Get "js/custom.js" | js.Build "custom.js" }}
<script src="{{ $custom_js.RelPermalink }}"></script>
<script>console.log('This is a test');</script>
35 changes: 0 additions & 35 deletions static/js/smooth-scroll.js

This file was deleted.

0 comments on commit 846e669

Please sign in to comment.