Skip to content

Commit 87364f7

Browse files
committed
Remove unnecessary JavaScript function applyStyle()
This function iterated over elements and converted data-* attributes to style attributes of the same name. Instead of using JavaScript, simply assign these values as style attributes to begin with. This removes the JavaScript execution time and reduces the number of JavaScript files included with the project as well as downloaded at runtime.
1 parent 1948d33 commit 87364f7

File tree

8 files changed

+6
-31
lines changed

8 files changed

+6
-31
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,13 @@
312312
return value;
313313
}
314314
},
315-
applyStyle: function(name) {
316-
var selector = '#djDebug [data-' + name + ']';
317-
document.querySelectorAll(selector).forEach(function(element) {
318-
element.style[name] = element.getAttribute('data-' + name);
319-
});
320-
}
321315
};
322316
window.djdt = {
323317
show_toolbar: djdt.show_toolbar,
324318
hide_toolbar: djdt.hide_toolbar,
325319
init: djdt.init,
326320
close: djdt.hide_one_level,
327321
cookie: djdt.cookie,
328-
applyStyle: djdt.applyStyle
329322
};
330323
document.addEventListener('DOMContentLoaded', djdt.init);
331324
})();

debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

debug_toolbar/static/debug_toolbar/js/toolbar.sql.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

debug_toolbar/templates/debug_toolbar/panels/profiling.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{% for call in func_list %}
1515
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %} djDebugProfileRow{% for parent_id in call.parent_ids %} djToggleDetails_{{ parent_id }}{% endfor %}" depth="{{ call.depth }}" id="profilingMain_{{ call.id }}">
1616
<td>
17-
<div data-padding-left="{{ call.indent }}px">
17+
<div style="padding-left:{{ call.indent }}px">
1818
{% if call.has_subfuncs %}
1919
<a class="djProfileToggleDetails djToggleSwitch" data-toggle-name="profilingMain" data-toggle-id="{{ call.id }}" data-toggle-open="+" data-toggle-close="-" href>-</a>
2020
{% else %}
@@ -32,5 +32,3 @@
3232
{% endfor %}
3333
</tbody>
3434
</table>
35-
36-
<script src="{% static 'debug_toolbar/js/toolbar.profiling.js' %}" defer></script>

debug_toolbar/templates/debug_toolbar/panels/sql.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ul class="djdt-stats">
44
{% for alias, info in databases %}
55
<li>
6-
<strong class="djdt-label"><span data-background-color="rgb({{ info.rgb_color|join:", " }})" class="djdt-color">&#160;</span> {{ alias }}</strong>
6+
<strong class="djdt-label"><span style="background-color:rgb({{ info.rgb_color|join:', ' }})" class="djdt-color">&#160;</span> {{ alias }}</strong>
77
<span class="djdt-info">{{ info.time_spent|floatformat:"2" }} ms ({% blocktrans count info.num_queries as num %}{{ num }} query{% plural %}{{ num }} queries{% endblocktrans %}
88
{% if info.similar_count %}
99
{% blocktrans with count=info.similar_count trimmed %}
@@ -34,7 +34,7 @@
3434
<tbody>
3535
{% for query in queries %}
3636
<tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}{% if query.is_slow %} djDebugRowWarning{% endif %}{% if query.starts_trans %} djDebugStartTransaction{% endif %}{% if query.ends_trans %} djDebugEndTransaction{% endif %}{% if query.in_trans %} djDebugInTransaction{% endif %}" id="sqlMain_{{ forloop.counter }}">
37-
<td class="djdt-color"><span data-background-color="rgb({{ query.rgb_color|join:", " }})">&#160;</span></td>
37+
<td class="djdt-color"><span style="background-color:rgb({{ query.rgb_color|join:', '}})">&#160;</span></td>
3838
<td class="djdt-toggle">
3939
<a class="djToggleSwitch" data-toggle-name="sqlMain" data-toggle-id="{{ forloop.counter }}" data-toggle-open="+" data-toggle-close="-" href="">+</a>
4040
</td>
@@ -44,19 +44,19 @@
4444
</div>
4545
{% if query.similar_count %}
4646
<strong>
47-
<span data-background-color="{{ query.similar_color }}">&#160;</span>
47+
<span style="background-color:{{ query.similar_color }}">&#160;</span>
4848
{% blocktrans with count=query.similar_count %}{{ count }} similar queries.{% endblocktrans %}
4949
</strong>
5050
{% endif %}
5151
{% if query.duplicate_count %}
5252
<strong>
53-
<span data-background-color="{{ query.duplicate_color }}">&#160;</span>
53+
<span style="background-color:{{ query.duplicate_color }}">&#160;</span>
5454
{% blocktrans with dupes=query.duplicate_count %}Duplicated {{ dupes }} times.{% endblocktrans %}
5555
</strong>
5656
{% endif %}
5757
</td>
5858
<td class="djdt-timeline">
59-
<div class="djDebugTimeline"><div class="djDebugLineChart{% if query.is_slow %} djDebugLineChartWarning{% endif %}" data-left="{{ query.start_offset|unlocalize }}%"><strong data-width="{{ query.width_ratio_relative|unlocalize }}%" data-background-color="{{ query.trace_color }}">{{ query.width_ratio }}%</strong></div></div>
59+
<div class="djDebugTimeline"><div class="djDebugLineChart{% if query.is_slow %} djDebugLineChartWarning{% endif %}" style="left:{{ query.start_offset|unlocalize }}%"><strong style="width:{{ query.width_ratio_relative|unlocalize }}%;background-color:{{ query.trace_color }}">{{ query.width_ratio }}%</strong></div></div>
6060
</td>
6161
<td class="djdt-time">
6262
{{ query.duration|floatformat:"2" }}
@@ -113,5 +113,3 @@
113113
{% else %}
114114
<p>{% trans "No SQL queries were recorded during this request." %}</p>
115115
{% endif %}
116-
117-
<script src="{% static 'debug_toolbar/js/toolbar.sql.js' %}" defer></script>

debug_toolbar/templates/debug_toolbar/panels/sql_explain.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,3 @@ <h3>{% trans "SQL explained" %}</h3>
3333
</table>
3434
</div>
3535
</div>
36-
37-
<script src="{% static 'debug_toolbar/js/toolbar.sql.js' %}" defer></script>

debug_toolbar/templates/debug_toolbar/panels/sql_profile.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,3 @@ <h3>{% trans "SQL profiled" %}</h3>
4040
{% endif %}
4141
</div>
4242
</div>
43-
44-
<script src="{% static 'debug_toolbar/js/toolbar.sql.js' %}" defer></script>

debug_toolbar/templates/debug_toolbar/panels/sql_select.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@ <h3>{% trans "SQL selected" %}</h3>
3737
{% endif %}
3838
</div>
3939
</div>
40-
41-
<script src="{% static 'debug_toolbar/js/toolbar.sql.js' %}" defer></script>

0 commit comments

Comments
 (0)