Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b4905e

Browse files
author
Santiago Barragan
committed
🐛 Version anchors now can be selected and triggers the onclick function
1 parent 3ba584b commit 7b4905e

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

.github/actions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def update(pkg_name, version):
136136
original_div = soup.find('section', class_='versions').findAll('div')[-1]
137137
new_div = copy.copy(original_div)
138138
anchor = new_div.find('a')
139-
anchor['onclick'] = f"load_readme('{version}', scroll_to_div=true)"
139+
new_div['onclick'] = f"load_readme('{version}', scroll_to_div=true);"
140140
new_div['id'] = norm_version
141141
new_div['class'] = ""
142142
if not is_stable(version):

pkg_template.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
_author
8080
</p>
8181
<section class="versions" id="versions">
82-
<div id="_version">
83-
<a href="_link" onclick="load_readme('_version', scroll_to_div=true)">
82+
<div id="_version" onclick="load_readme('_version', scroll_to_div=true)">
83+
<a href="_link">
8484
_version
8585
</a>
8686
</div>

static/package_page.js

+27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function load_readme(version, scroll_to_div=false){
2+
addDynamicClickDelegation(`${version}`);
3+
24
let urlVersion = url_readme_main.replace('main', version);
35
fetch(urlVersion)
46
.then(response => {
@@ -35,4 +37,29 @@ function redirectToIndex() {
3537
window.location.href = "../index.html";
3638
}
3739

40+
function addDynamicClickDelegation(parentId) {
41+
const parentDiv = document.getElementById(parentId);
42+
43+
if (parentDiv) {
44+
parentDiv.addEventListener('click', function (event) {
45+
if (event.target !== this) {
46+
event.stopPropagation();
47+
this.click(); // Trigger the parent div's onclick function
48+
}
49+
});
50+
}
51+
}
52+
53+
function removeHrefFromAnchors() {
54+
var versionsSection = document.getElementById('versions');
55+
if (versionsSection) {
56+
var anchors = versionsSection.getElementsByTagName('a');
57+
for (var i = 0; i < anchors.length; i++) {
58+
anchors[i].removeAttribute('href');
59+
}
60+
}
61+
}
3862

63+
window.onload = function() {
64+
removeHrefFromAnchors();
65+
};

0 commit comments

Comments
 (0)