Skip to content

Commit 344baae

Browse files
authored
Unify show/hide JS logic through the djdt-hidden class (#1340)
Using a class -- rather than manipulating inline CSS -- is more robust as it doesn't assume the hidden object is styled as 'display: block;'. The djdt-hidden class already existed, so use it for all hide/show code.
1 parent 28eb519 commit 344baae

File tree

7 files changed

+8
-11
lines changed

7 files changed

+8
-11
lines changed

debug_toolbar/panels/sql/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def reformat_sql(sql, with_toggle=False):
2525
return formatted
2626
simple = simplify(parse_sql(sql, aligned_indent=False))
2727
uncollapsed = '<span class="djDebugUncollapsed">{}</span>'.format(simple)
28-
collapsed = '<span class="djDebugCollapsed">{}</span>'.format(formatted)
28+
collapsed = '<span class="djDebugCollapsed djdt-hidden">{}</span>'.format(formatted)
2929
return collapsed + uncollapsed
3030

3131

debug_toolbar/static/debug_toolbar/css/toolbar.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@
191191
}
192192

193193
#djDebug .djdt-panelContent {
194-
display: none;
195194
position: fixed;
196195
margin: 0;
197196
top: 0;
@@ -351,7 +350,6 @@
351350
}
352351

353352
#djDebug .djDebugCollapsed {
354-
display: none;
355353
color: #333;
356354
}
357355

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const $$ = {
88
});
99
},
1010
show: function(element) {
11-
element.style.display = 'block';
11+
element.classList.remove('djdt-hidden');
1212
},
1313
hide: function(element) {
14-
element.style.display = 'none';
14+
element.classList.add('djdt-hidden');
1515
},
1616
toggle: function(element, value) {
1717
if (value) {
@@ -21,8 +21,7 @@ const $$ = {
2121
}
2222
},
2323
visible: function(element) {
24-
const style = getComputedStyle(element);
25-
return style.display !== 'none';
24+
element.classList.contains('djdt-hidden');
2625
},
2726
executeScripts: function(scripts) {
2827
scripts.forEach(function(script) {

debug_toolbar/templates/debug_toolbar/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
{% for panel in toolbar.panels %}
2828
{% include "debug_toolbar/includes/panel_content.html" %}
2929
{% endfor %}
30-
<div id="djDebugWindow" class="djdt-panelContent"></div>
30+
<div id="djDebugWindow" class="djdt-panelContent djdt-hidden"></div>
3131
</div>

debug_toolbar/templates/debug_toolbar/includes/panel_content.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% load static %}
22

33
{% if panel.has_content and panel.enabled %}
4-
<div id="{{ panel.panel_id }}" class="djdt-panelContent">
4+
<div id="{{ panel.panel_id }}" class="djdt-panelContent djdt-hidden">
55
<div class="djDebugPanelTitle">
66
<a href="" class="djDebugClose">×</a>
77
<h3>{{ panel.title }}</h3>

tests/panels/test_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_escapes_panel_title(self):
3131
self.assertContains(
3232
response,
3333
"""
34-
<div id="CustomPanel" class="djdt-panelContent">
34+
<div id="CustomPanel" class="djdt-panelContent djdt-hidden">
3535
<div class="djDebugPanelTitle">
3636
<a href="" class="djDebugClose">×</a>
3737
<h3>Title with special chars &amp;&quot;&#39;&lt;&gt;</h3>

tests/panels/test_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_panel_title(self):
2222
self.assertContains(
2323
response,
2424
"""
25-
<div id="SettingsPanel" class="djdt-panelContent">
25+
<div id="SettingsPanel" class="djdt-panelContent djdt-hidden">
2626
<div class="djDebugPanelTitle">
2727
<a href="" class="djDebugClose">×</a>
2828
<h3>Settings from None</h3>

0 commit comments

Comments
 (0)