Skip to content

Commit 076ffdf

Browse files
committed
Updated browser timing javascript to use jQuery, tidied up wording and formatting, and minified js
1 parent 36e7a76 commit 076ffdf

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

+13-21
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ window.djdt = (function(window, document, jQuery) {
232232
}(window, document, $djdtjq));
233233

234234

235-
(function(window, document) {
235+
(function(window, document, $) {
236236
function _renderPerf() {
237237
// Browser timing remains hidden unless we can successfully access the performance object
238238
var perf = window.performance || window.msPerformance ||
@@ -253,46 +253,38 @@ window.djdt = (function(window, document, jQuery) {
253253
}
254254
function addRow(stat, endStat) {
255255
rowCount++;
256-
var row = document.createElement('tr'),
257-
keyCell = document.createElement('td'),
258-
timelineCell = document.createElement('td'),
259-
valueCell = document.createElement('td');
260-
row.className = (rowCount % 2) ? 'djDebugOdd' : 'djDebugEven';
261-
timelineCell.className = 'timeline';
256+
var $row = $('<tr class="' + ((rowCount % 2) ? 'djDebugOdd' : 'djDebugEven') + '"></tr>');
262257
if (endStat) {
263258
// Render a start through end bar
264-
keyCell.innerHTML = stat.replace('Start', '');;
265-
timelineCell.innerHTML = '<div class="djDebugTimeline"><div class="djDebugLineChart" style="left:' + getLeft(stat) + '%;"><strong style="width:' + getCSSWidth(stat, endStat) + ';">&nbsp;</strong></div></div>';
266-
valueCell.innerHTML = (perf.timing[stat] - timingOffset) + ' (+' + (perf.timing[endStat] - perf.timing[stat]) + ')';
259+
$row.html('<td>' + stat.replace('Start', '') + '</td>' +
260+
'<td class="timeline"><div class="djDebugTimeline"><div class="djDebugLineChart" style="left:' + getLeft(stat) + '%;"><strong style="width:' + getCSSWidth(stat, endStat) + ';">&nbsp;</strong></div></div></td>' +
261+
'<td>' + (perf.timing[stat] - timingOffset) + ' (+' + (perf.timing[endStat] - perf.timing[stat]) + ')</td>');
267262
} else {
268263
// Render a point in time
269-
keyCell.innerHTML = stat;
270-
timelineCell.innerHTML = '<div class="djDebugTimeline"><div class="djDebugLineChart" style="left:' + getLeft(stat) + '%;"><strong style="width:2px;">&nbsp;</strong></div></div>';
271-
valueCell.innerHTML = (perf.timing[stat] - timingOffset);
264+
$row.html('<td>' + stat + '</td>' +
265+
'<td class="timeline"><div class="djDebugTimeline"><div class="djDebugLineChart" style="left:' + getLeft(stat) + '%;"><strong style="width:2px;">&nbsp;</strong></div></div></td>' +
266+
'<td>' + (perf.timing[stat] - timingOffset) + '</td>');
272267
}
273-
row.appendChild(keyCell);
274-
row.appendChild(timelineCell);
275-
row.appendChild(valueCell);
276-
document.getElementById('djDebugBrowserTimingTableBody').appendChild(row);
268+
$('#djDebugBrowserTimingTableBody').append($row);
277269
}
278270

279271
// This is a reasonably complete and ordered set of timing periods (2 params) and events (1 param)
280272
addRow('domainLookupStart', 'domainLookupEnd');
281273
addRow('connectStart', 'connectEnd');
282-
addRow('requestStart', 'responseEnd') // There is no requestStart
274+
addRow('requestStart', 'responseEnd') // There is no requestEnd
283275
addRow('responseStart', 'responseEnd');
284276
addRow('domLoading', 'domComplete'); // Spans the events below
285277
addRow('domInteractive');
286278
addRow('domContentLoadedEventStart', 'domContentLoadedEventEnd');
287279
addRow('loadEventStart', 'loadEventEnd');
288-
document.getElementById('djDebugBrowserTiming').style.display = "block";
280+
$('#djDebugBrowserTiming').css("display", "block");
289281
}
290282
}
291283

292284
function renderPerf() {
293285
setTimeout(_renderPerf, 1000);
294286
}
295287

296-
if (window.addEventListener) { window.addEventListener("load", renderPerf, false); }
297-
else if (window.attachEvent) { window.attachEvent("onload", renderPerf); }
288+
$(window).bind('load', renderPerf);
289+
298290
}(window, document, $djdtjq));

debug_toolbar/static/debug_toolbar/js/toolbar.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

debug_toolbar/templates/debug_toolbar/panels/timer.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ <h4>{% trans 'Browser Timing' %}</h4>
2727
<table>
2828
<colgroup>
2929
<col style="width:20%"/>
30-
<col/>
30+
<col style="width:60%"/>
31+
<col style="width:20%"/>
3132
</colgroup>
3233
<thead>
3334
<tr>
3435
<th>{% trans "Timing Attribute" %}</th>
3536
<th class="timeline">{% trans 'Timeline' %}</th>
36-
<th class="time">{% trans "Time since navigation start (+length, msec)" %}</th>
37+
<th class="time">{% trans "Milliseconds since navigation start (+length)" %}</th>
3738
</tr>
3839
</thead>
3940
<tbody id="djDebugBrowserTimingTableBody">

0 commit comments

Comments
 (0)