From 35e8e6ea9ba460a1dae0ef7dd6426aca5fc77cf1 Mon Sep 17 00:00:00 2001 From: Adam Zapletal Date: Wed, 18 Dec 2024 17:11:20 -0600 Subject: [PATCH] Refactored `doc-switcher.js` - Simplified code - Stopped using jQuery - Moved refactored code to `app.js` This is the first in a series of patches that will move JavaScript code out of `require.js` modules and into a single file while also refactoring. This patch should bring no user-facing changes. --- djangoproject/static/js/app.js | 5 +++++ djangoproject/static/js/main.js | 4 ---- djangoproject/static/js/mod/doc-switcher.js | 24 --------------------- djangoproject/templates/base.html | 1 + 4 files changed, 6 insertions(+), 28 deletions(-) create mode 100644 djangoproject/static/js/app.js delete mode 100644 djangoproject/static/js/mod/doc-switcher.js diff --git a/djangoproject/static/js/app.js b/djangoproject/static/js/app.js new file mode 100644 index 000000000..85b84c5ff --- /dev/null +++ b/djangoproject/static/js/app.js @@ -0,0 +1,5 @@ +document.querySelectorAll('.doc-switcher li.current').forEach(function (el) { + el.addEventListener('click', function () { + this.parentElement.classList.toggle('open'); + }); +}); diff --git a/djangoproject/static/js/main.js b/djangoproject/static/js/main.js index 983a4918a..8d9dd2797 100644 --- a/djangoproject/static/js/main.js +++ b/djangoproject/static/js/main.js @@ -23,10 +23,6 @@ define(function () { mods.push('mod/version-switcher'); } - if (hasClass('doc-switcher')) { - mods.push('mod/doc-switcher'); - } - if (hasClass('doc-floating-warning')) { mods.push('mod/floating-warning'); } diff --git a/djangoproject/static/js/mod/doc-switcher.js b/djangoproject/static/js/mod/doc-switcher.js deleted file mode 100644 index 081d60664..000000000 --- a/djangoproject/static/js/mod/doc-switcher.js +++ /dev/null @@ -1,24 +0,0 @@ -define([ - 'jquery', //requires jquery -], function ($) { - var DocSwitcher = function (switchers) { - this.switchers = $(switchers); - this.init(); - }; - - DocSwitcher.prototype = { - init: function () { - var self = this; - $(document).ready(function () { - // Make version switcher clickable for touch devices - - self.switchers.find('li.current').on('click', function () { - $(this).closest('ul').toggleClass('open'); - }); - }); - }, - }; - - // Export a single instance of our module: - return new DocSwitcher('.doc-switcher'); -}); diff --git a/djangoproject/templates/base.html b/djangoproject/templates/base.html index d6b0c6071..05acd3a39 100644 --- a/djangoproject/templates/base.html +++ b/djangoproject/templates/base.html @@ -165,6 +165,7 @@ }; + {% block body_extra %}{% endblock body_extra %}