Skip to content

Commit 905e572

Browse files
committed
Apply inline styles via data-djdt-styles attribute.
1 parent 763a008 commit 905e572

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ const djdt = {
4444
inner.previousElementSibling.remove(); // Remove AJAX loader
4545
inner.innerHTML = data.content;
4646
$$.executeScripts(data.scripts);
47-
$$.applyStyle("padding-left");
48-
$$.applyStyle("background-color");
47+
$$.applyStyles(inner);
4948
});
5049
}
5150
}

debug_toolbar/static/debug_toolbar/js/utils.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,25 @@ const $$ = {
3232
document.head.appendChild(el);
3333
});
3434
},
35-
applyStyle(name) {
36-
const selector = "#djDebug [data-" + name + "]";
37-
document.querySelectorAll(selector).forEach(function (element) {
38-
element.style[name] = element.getAttribute("data-" + name);
39-
});
35+
applyStyles(container) {
36+
/*
37+
* Given a container element, apply styles set via data-djdt-styles attribute.
38+
* The format is data-djdt-styles="styleName1:value;styleName2:value2"
39+
* The style names should use the CSSStyleDeclaration camel cased names.
40+
*/
41+
container
42+
.querySelectorAll("[data-djdt-styles]")
43+
.forEach(function (element) {
44+
const styles = element.dataset.djdtStyles || "";
45+
styles.split(";").forEach(function (styleText) {
46+
const styleKeyPair = styleText.split(":");
47+
if (styleKeyPair.length === 2) {
48+
const name = styleKeyPair[0].trim();
49+
const value = styleKeyPair[1].trim();
50+
element.style[name] = value;
51+
}
52+
});
53+
});
4054
},
4155
};
4256

debug_toolbar/templates/debug_toolbar/panels/profiling.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{% for call in func_list %}
1515
<tr class="{% for parent_id in call.parent_ids %} djToggleDetails_{{ parent_id }}{% endfor %}" id="profilingMain_{{ call.id }}">
1616
<td>
17-
<div data-padding-left="{{ call.indent }}px">
17+
<div data-djdt-styles="paddingLeft:{{ call.indent }}px">
1818
{% if call.has_subfuncs %}
1919
<button type="button" class="djProfileToggleDetails djToggleSwitch" data-toggle-name="profilingMain" data-toggle-id="{{ call.id }}">-</button>
2020
{% else %}

debug_toolbar/templates/debug_toolbar/panels/sql.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<ul>
33
{% for alias, info in databases %}
44
<li>
5-
<strong><span class="djdt-color" data-background-color="rgb({{ info.rgb_color|join:', ' }})"></span> {{ alias }}</strong>
5+
<strong><span class="djdt-color" data-djdt-styles="backgroundColor:rgb({{ info.rgb_color|join:', ' }})"></span> {{ alias }}</strong>
66
{{ info.time_spent|floatformat:"2" }} ms ({% blocktrans count info.num_queries as num %}{{ num }} query{% plural %}{{ num }} queries{% endblocktrans %}
77
{% if info.similar_count %}
88
{% blocktrans with count=info.similar_count trimmed %}
@@ -40,21 +40,21 @@
4040
<tbody>
4141
{% for query in queries %}
4242
<tr class="{% if query.is_slow %} djDebugRowWarning{% endif %}" id="sqlMain_{{ forloop.counter }}">
43-
<td><span class="djdt-color" data-background-color="rgb({{ query.rgb_color|join:', '}})"></span></td>
43+
<td><span class="djdt-color" data-djdt-styles="backgroundColor:rgb({{ query.rgb_color|join:', '}})"></span></td>
4444
<td class="djdt-toggle">
4545
<button type="button" class="djToggleSwitch" data-toggle-name="sqlMain" data-toggle-id="{{ forloop.counter }}">+</button>
4646
</td>
4747
<td>
4848
<div class="djDebugSql">{{ query.sql|safe }}</div>
4949
{% if query.similar_count %}
5050
<strong>
51-
<span class="djdt-color" data-background-color="{{ query.similar_color }}"></span>
51+
<span class="djdt-color" data-djdt-styles="backgroundColor:{{ query.similar_color }}"></span>
5252
{% blocktrans with count=query.similar_count %}{{ count }} similar queries.{% endblocktrans %}
5353
</strong>
5454
{% endif %}
5555
{% if query.duplicate_count %}
5656
<strong>
57-
<span class="djdt-color" data-background-color="{{ query.duplicate_color }}"></span>
57+
<span class="djdt-color" data-djdt-styles="backgroundColor:{{ query.duplicate_color }}"></span>
5858
{% blocktrans with dupes=query.duplicate_count %}Duplicated {{ dupes }} times.{% endblocktrans %}
5959
</strong>
6060
{% endif %}

0 commit comments

Comments
 (0)