Skip to content

Commit

Permalink
Refactored version-switcher.js
Browse files Browse the repository at this point in the history
- Simplified code
- Stopped using jQuery
- Moved refactored code to `djangoproject.js`

This patch should bring no user-facing changes.

Refs #1827
  • Loading branch information
adamzap authored Dec 28, 2024
1 parent 124be99 commit 48b2f81
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 30 deletions.
7 changes: 7 additions & 0 deletions djangoproject/static/js/djangoproject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ document.querySelectorAll('.doc-switcher li.current').forEach(function (el) {
this.parentElement.classList.toggle('open');
});
});

// Propagate the current fragment identifier when switching docs versions
document.querySelectorAll('#doc-versions a').forEach(function (el) {
el.addEventListener('click', function () {
this.href = this.href.split('#')[0] + window.location.hash;
});
});
4 changes: 0 additions & 4 deletions djangoproject/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ define(function () {
mods.push('mod/list-collapsing');
}

if (hasClass('version-switcher')) {
mods.push('mod/version-switcher');
}

if (hasClass('doc-floating-warning')) {
mods.push('mod/floating-warning');
}
Expand Down
25 changes: 0 additions & 25 deletions djangoproject/static/js/mod/version-switcher.js

This file was deleted.

1 change: 0 additions & 1 deletion djangoproject/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
"mod/list-collapsing": extless("{% static 'js/mod/list-collapsing.js' %}"),
"mod/list-feature": extless("{% static 'js/mod/list-feature.js' %}"),
"mod/mobile-menu": extless("{% static 'js/mod/mobile-menu.js' %}"),
"mod/version-switcher": extless("{% static 'js/mod/version-switcher.js' %}"),
"mod/search-key": extless("{% static 'js/mod/search-key.js' %}"),
"mod/stripe-change-card": extless("{% static 'js/mod/stripe-change-card.js' %}"),
"mod/switch-dark-mode": extless("{% static 'js/mod/switch-dark-mode.js' %}"),
Expand Down

0 comments on commit 48b2f81

Please sign in to comment.