-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69b7a2f
commit 9a41108
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Content Page Shortcuts | ||
const shortcutsTarget = $('#shortcuts'); | ||
if (shortcutsTarget.length > 0) { | ||
$('.content-container h2, .content-container h3').map(function(idx, el) { | ||
const title = el.textContent; | ||
// transforms title into snake-case | ||
const elTitle = title.replace(/\s/g, '-').toLowerCase(); | ||
// Gets the element type (e.g. h2, h3) | ||
const elType = $(el).get(0).tagName; | ||
// Adds snake-case title as an id attribute to target element | ||
$(el).attr('id', elTitle); | ||
shortcutsTarget.append(`<div id="${elTitle}-shortcut" class="shortcuts-${elType}">${title}</div>`); | ||
|
||
$(`#${elTitle}-shortcut`).click(function() { | ||
$([document.documentElement, document.body]).animate({ | ||
scrollTop: $(`#${elTitle}`).offset().top-60 | ||
}, 1000); | ||
}) | ||
}); | ||
} | ||
|
||
// Removes the shortcuts container if no shortcuts exist. | ||
// Also removes the 'Get Help' link. | ||
if ($('#shortcuts div').length < 1) { | ||
$('.shortcuts-container').css('display', 'none'); | ||
} |