Skip to content

Commit

Permalink
* remove old internal link handling
Browse files Browse the repository at this point in the history
* add support for anchors (xy2z#157)
  • Loading branch information
Mylloon committed Jul 12, 2022
1 parent 50e6c81 commit 0ed3bfa
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions public/js/PineDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,25 @@ $(function() {
return // continue.
}

// Add the correct link if needed
const url = self.get_asset_path(data.relative_path, block.attributes.href.value)
if (url != '#') {
block.href = '#' + self.get_asset_path(data.relative_path, block.attributes.href.value)
// Check if link refer to a header
if (block.attributes.href.value.startsWith('#')) {
// If header exists
const header = document.getElementById(decodeURIComponent(block.attributes.href.value.slice(1)))
if (header != null) {
block.addEventListener("click", function (e) {
e.preventDefault()
header.scrollIntoView({ behavior: 'smooth' })
})
}
} else {
// Add the correct link if internal
const url = self.get_asset_path(data.relative_path, block.attributes.href.value)
if (url != '#') {
block.href = '#' + self.get_asset_path(data.relative_path, block.attributes.href.value)
}
}

return // continue
return // continue.
}

if ($(block).attr('src') === undefined || $(block).attr('src').length === 0) {
Expand Down Expand Up @@ -335,23 +347,6 @@ $(function() {
$(this).find('i.fa').toggleClass('fa-folder-open')
})


// Click on internal link. (links to other files)
self.elements.file_content.on('click', 'a', function(event) {
self.click_hashchange = true

if ($(this).attr('href').substr(0,1) == '#') {
// Find the link in the menu and trigger a click on it.
var link = self.elements.menu.find('a[href="' + $(this).attr('href') + '"]')
if (link.length) {
link.click()
} else {
// Try loading a hidden file.
self.render_hidden_file($(this).attr('href').substr(1));
}
}
})

// URL Hashtag change (user probably went back or forward in browser history)
$(window).bind('hashchange', function(e) {
if (self.click_hashchange) {
Expand Down

0 comments on commit 0ed3bfa

Please sign in to comment.