]> git.0d.be Git - panikweb.git/commitdiff
add page slug as body class, and update it during ajax navigation
authorFrédéric Péters <fpeters@0d.be>
Thu, 16 Nov 2023 17:25:26 +0000 (18:25 +0100)
committerFrédéric Péters <fpeters@0d.be>
Thu, 16 Nov 2023 17:25:26 +0000 (18:25 +0100)
panikweb/base/static/js/specifics.js
panikweb/base/templates/base.html

index d4f5e67ed81071cdcd30c8dccfc76de37c3df905..08f22e553fbf1d6e946b451f21aa0f16c0ecdf2a 100644 (file)
@@ -91,6 +91,14 @@ $(function() {
                        var newTitle = html?html.match(/<title>(.*?)<\/title>/):'';
                        if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
 
+                       /* update body class */
+                       var body_class_match = html ? html.match(/<body.*class="(.*?)"/) : '';
+                       if (body_class_match) {
+                               document.body.setAttribute('class', body_class_match[1]);
+                       } else {
+                               document.body.setAttribute('class', '');
+                       }
+
                        if (push_state !== false) {
                                if (document.location.hash && $(document.location.hash).length) {
                                        $.scrollTo(document.location.hash, 1000, {offset: 0});
index 152359687d2ac6e22318fbef09c6f123cb2df6c1..51257c3f05ea1e747b228935a3e7cdc77d6627d6 100644 (file)
@@ -51,7 +51,7 @@
     {% block extrascripts %}{% endblock %}
   </head>
 
-  <body {% block bodyattr %}{% endblock %}>
+  <body {% block bodyattr %}{% if page %}class="page-{{ page.slug }}"{% endif %}{% endblock %}>
     <div id="All">
       {% block meta %}<div id="metaNav">{% include "includes/metaNav.html" %}</div>{% endblock %}
       <div id="Commons">