Skip to content

Commit 763ac8f

Browse files
authored
Simplify djToggleSwitch HTML (#1360)
Every instance of djToggleSwitch uses the same text to represent open & close. Therefore, parameterizing it adds unnecessary HTML to use. Now, simply assume "-" and "+" will be used. Should new uses of djToggleSwitch be added, this reduces the amount of copy & paste necessary.
1 parent 24df791 commit 763ac8f

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ const djdt = {
9797
event.preventDefault();
9898
const self = this;
9999
const id = this.dataset.toggleId;
100-
const open_me = this.textContent === this.dataset.toggleOpen;
100+
const toggleOpen = "+";
101+
const toggleClose = "-";
102+
const open_me = this.textContent === toggleOpen;
101103
const name = this.dataset.toggleName;
102104
const container = this.closest(
103105
".djDebugPanelContent"
@@ -118,11 +120,11 @@ const djdt = {
118120
if (open_me) {
119121
e.classList.add("djSelected");
120122
e.classList.remove("djUnselected");
121-
self.textContent = self.dataset.toggleClose;
123+
self.textContent = toggleClose;
122124
} else {
123125
e.classList.remove("djSelected");
124126
e.classList.add("djUnselected");
125-
self.textContent = self.dataset.toggleOpen;
127+
self.textContent = toggleOpen;
126128
}
127129
const switch_ = e.querySelector(".djToggleSwitch");
128130
if (switch_) {

debug_toolbar/templates/debug_toolbar/panels/cache.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h4>{% trans "Calls" %}</h4>
5151
{% for call in calls %}
5252
<tr id="cacheMain_{{ forloop.counter }}">
5353
<td class="djdt-toggle">
54-
<a class="djToggleSwitch" data-toggle-name="cacheMain" data-toggle-id="{{ forloop.counter }}" data-toggle-open="+" data-toggle-close="-" href>+</a>
54+
<a class="djToggleSwitch" data-toggle-name="cacheMain" data-toggle-id="{{ forloop.counter }}" href>+</a>
5555
</td>
5656
<td>{{ call.time|floatformat:"4" }}</td>
5757
<td>{{ call.name|escape }}</td>

debug_toolbar/templates/debug_toolbar/panels/history_tr.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<p>{{ store_context.toolbar.stats.HistoryPanel.request_url|truncatechars:100|escape }}</p>
1111
</td>
1212
<td>
13-
<a class="djToggleSwitch" data-toggle-name="historyMain" data-toggle-id="{{ id }}" data-toggle-open="+" data-toggle-close="-" href>+</a>
13+
<a class="djToggleSwitch" data-toggle-name="historyMain" data-toggle-id="{{ id }}" href>+</a>
1414
<div class="djUnselected djToggleDetails_{{ id }}">
1515
<table>
1616
<colgroup>

debug_toolbar/templates/debug_toolbar/panels/profiling.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<td>
1717
<div style="padding-left:{{ call.indent }}px">
1818
{% if call.has_subfuncs %}
19-
<a class="djProfileToggleDetails djToggleSwitch" data-toggle-name="profilingMain" data-toggle-id="{{ call.id }}" data-toggle-open="+" data-toggle-close="-" href>-</a>
19+
<a class="djProfileToggleDetails djToggleSwitch" data-toggle-name="profilingMain" data-toggle-id="{{ call.id }}" href>-</a>
2020
{% else %}
2121
<span class="djNoToggleSwitch"></span>
2222
{% endif %}

debug_toolbar/templates/debug_toolbar/panels/sql.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<tr class="{% if query.is_slow %} djDebugRowWarning{% endif %}" id="sqlMain_{{ forloop.counter }}">
3535
<td><span class="djdt-color" style="background-color:rgb({{ query.rgb_color|join:', '}})"></span></td>
3636
<td class="djdt-toggle">
37-
<a class="djToggleSwitch" data-toggle-name="sqlMain" data-toggle-id="{{ forloop.counter }}" data-toggle-open="+" data-toggle-close="-" href="">+</a>
37+
<a class="djToggleSwitch" data-toggle-name="sqlMain" data-toggle-id="{{ forloop.counter }}" href="">+</a>
3838
</td>
3939
<td class="djdt-query">
4040
<div class="djDebugSqlWrap">

0 commit comments

Comments
 (0)