From 35e8e6ea9ba460a1dae0ef7dd6426aca5fc77cf1 Mon Sep 17 00:00:00 2001 From: Adam Zapletal Date: Wed, 18 Dec 2024 17:11:20 -0600 Subject: [PATCH 1/4] 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 %} From 249c1e65c60b3227691af8681369e7513e8c2ec4 Mon Sep 17 00:00:00 2001 From: Adam Zapletal Date: Wed, 18 Dec 2024 20:22:28 -0600 Subject: [PATCH 2/4] Add comment --- djangoproject/static/js/app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/djangoproject/static/js/app.js b/djangoproject/static/js/app.js index 85b84c5ff..1cf3b5525 100644 --- a/djangoproject/static/js/app.js +++ b/djangoproject/static/js/app.js @@ -1,3 +1,5 @@ +// Toggle persistent display of documentation version and language options if +// the element is clicked document.querySelectorAll('.doc-switcher li.current').forEach(function (el) { el.addEventListener('click', function () { this.parentElement.classList.toggle('open'); From f3ab40d92444e686319d400c4a913c698ce1e195 Mon Sep 17 00:00:00 2001 From: Adam Zapletal Date: Fri, 20 Dec 2024 15:59:31 -0600 Subject: [PATCH 3/4] Rename `app.js` to `djangoproject.js` --- djangoproject/static/js/{app.js => djangoproject.js} | 0 djangoproject/templates/base.html | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename djangoproject/static/js/{app.js => djangoproject.js} (100%) diff --git a/djangoproject/static/js/app.js b/djangoproject/static/js/djangoproject.js similarity index 100% rename from djangoproject/static/js/app.js rename to djangoproject/static/js/djangoproject.js diff --git a/djangoproject/templates/base.html b/djangoproject/templates/base.html index 05acd3a39..896483b61 100644 --- a/djangoproject/templates/base.html +++ b/djangoproject/templates/base.html @@ -165,7 +165,7 @@ }; - + {% block body_extra %}{% endblock body_extra %} From 69b131c4097bb8c18cc8cd77fee797b7442ac3e0 Mon Sep 17 00:00:00 2001 From: Adam Zapletal Date: Fri, 20 Dec 2024 16:45:22 -0600 Subject: [PATCH 4/4] Remove obvious part of comment --- djangoproject/static/js/djangoproject.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/djangoproject/static/js/djangoproject.js b/djangoproject/static/js/djangoproject.js index 1cf3b5525..474231d6d 100644 --- a/djangoproject/static/js/djangoproject.js +++ b/djangoproject/static/js/djangoproject.js @@ -1,5 +1,4 @@ -// Toggle persistent display of documentation version and language options if -// the element is clicked +// Toggle persistent display of documentation version and language options document.querySelectorAll('.doc-switcher li.current').forEach(function (el) { el.addEventListener('click', function () { this.parentElement.classList.toggle('open');