From 0e00679a564b31a8b53464a918e279b7ef4266b9 Mon Sep 17 00:00:00 2001 From: Adam Zapletal Date: Fri, 20 Dec 2024 17:00:01 -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. Refs #1827 --- djangoproject/static/js/djangoproject.js | 6 ++++++ djangoproject/static/js/main.js | 4 ---- djangoproject/static/js/mod/doc-switcher.js | 24 --------------------- djangoproject/templates/base.html | 1 + 4 files changed, 7 insertions(+), 28 deletions(-) create mode 100644 djangoproject/static/js/djangoproject.js delete mode 100644 djangoproject/static/js/mod/doc-switcher.js diff --git a/djangoproject/static/js/djangoproject.js b/djangoproject/static/js/djangoproject.js new file mode 100644 index 000000000..474231d6d --- /dev/null +++ b/djangoproject/static/js/djangoproject.js @@ -0,0 +1,6 @@ +// 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'); + }); +}); 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..896483b61 100644 --- a/djangoproject/templates/base.html +++ b/djangoproject/templates/base.html @@ -165,6 +165,7 @@ }; + {% block body_extra %}{% endblock body_extra %}