From 1a9b8dbdcf417fb4c1d4b400c127511c86d242d7 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 01/16] use element for template contexts
not: not supported in edge
https://caniuse.com/#feat=details
---
debug_toolbar/static/debug_toolbar/css/toolbar.css | 11 +----------
.../static/debug_toolbar/js/toolbar.template.js | 11 -----------
.../templates/debug_toolbar/panels/templates.html | 14 ++++++++------
3 files changed, 9 insertions(+), 27 deletions(-)
delete mode 100644 debug_toolbar/static/debug_toolbar/js/toolbar.template.js
diff --git a/debug_toolbar/static/debug_toolbar/css/toolbar.css b/debug_toolbar/static/debug_toolbar/css/toolbar.css
index 6aa4f7156..74528a06d 100644
--- a/debug_toolbar/static/debug_toolbar/css/toolbar.css
+++ b/debug_toolbar/static/debug_toolbar/css/toolbar.css
@@ -314,7 +314,7 @@
padding-right:.5em;
}
-#djDebug .djTemplateHideContextDiv {
+#djDebug .djTemplateContext {
background-color:#fff;
}
@@ -423,15 +423,6 @@
}
-#djDebug a.djTemplateShowContext, #djDebug a.djTemplateShowContext span.toggleArrow {
- color:#999;
-}
-
-#djDebug a.djTemplateShowContext:hover, #djDebug a.djTemplateShowContext:hover span.toggleArrow {
- color:#000;
- cursor:pointer;
-}
-
#djDebug .djDebugSqlWrap {
position:relative;
}
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.template.js b/debug_toolbar/static/debug_toolbar/js/toolbar.template.js
deleted file mode 100644
index fcddc9307..000000000
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.template.js
+++ /dev/null
@@ -1,11 +0,0 @@
-(function ($) {
- var uarr = String.fromCharCode(0x25b6),
- darr = String.fromCharCode(0x25bc);
-
- $('a.djTemplateShowContext').on('click', function(event) {
- event.preventDefault();
- var arrow = $(this).children('.toggleArrow');
- arrow.html(arrow.html() == uarr ? darr : uarr);
- $(this).parent().next().toggle();
- });
-})(djdt.jQuery);
diff --git a/debug_toolbar/templates/debug_toolbar/panels/templates.html b/debug_toolbar/templates/debug_toolbar/panels/templates.html
index a39cede00..fcfa2d6f8 100644
--- a/debug_toolbar/templates/debug_toolbar/panels/templates.html
+++ b/debug_toolbar/templates/debug_toolbar/panels/templates.html
@@ -18,8 +18,10 @@ {% blocktrans count templates|length as template_count %}Template{% plural %
{{ template.template.origin_name|addslashes }}
{% if template.context %}
-
- {{ template.context }}
+
+ {% trans "Toggle context" %}
+ {{ template.context }}
+
{% endif %}
{% endfor %}
@@ -34,13 +36,13 @@ {% blocktrans count context_processors|length as context_processors_count %}
{% for key, value in context_processors.items %}
{{ key|escape }}
-
- {{ value|escape }}
+
+ {% trans "Toggle context" %}
+ {{ value|escape }}
+
{% endfor %}
{% else %}
{% trans "None" %}
{% endif %}
-
-
From ef9ac33a6a11d69d1b1220da5514609524ebb0bd Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 02/16] rm .djDebugToggle
This is duplicated functionality. You can already toggle the entries
using .djToggleSwitch
---
debug_toolbar/panels/sql/utils.py | 4 ++--
debug_toolbar/static/debug_toolbar/js/toolbar.sql.js | 5 -----
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/debug_toolbar/panels/sql/utils.py b/debug_toolbar/panels/sql/utils.py
index c0bd4f4e0..197e4849c 100644
--- a/debug_toolbar/panels/sql/utils.py
+++ b/debug_toolbar/panels/sql/utils.py
@@ -30,8 +30,8 @@ def reformat_sql(sql):
def swap_fields(sql):
expr = r'SELECT (...........*?) FROM'
subs = (r'SELECT '
- r'••• '
- r'\1 '
+ r'••• '
+ r'\1 '
r'FROM')
return re.sub(expr, subs, sql)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js b/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js
index aec16d510..959f39a2d 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js
@@ -1,9 +1,4 @@
(function ($) {
- $('#djDebug a.djDebugToggle').on('click', function(event) {
- event.preventDefault();
- $(this).parent().find('.djDebugCollapsed').toggle();
- $(this).parent().find('.djDebugUncollapsed').toggle();
- });
djdt.applyStyle('background-color');
djdt.applyStyle('left');
djdt.applyStyle('width');
From 16259c46206d18485397114de47d700a2773400b Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 03/16] rm djDebugHoverable
AFAIU it is never used because the background-color is always
overwritten by applyStyle
---
debug_toolbar/static/debug_toolbar/css/toolbar.css | 7 -------
debug_toolbar/static/debug_toolbar/js/toolbar.js | 5 -----
debug_toolbar/templates/debug_toolbar/panels/cache.html | 2 +-
debug_toolbar/templates/debug_toolbar/panels/sql.html | 4 ++--
4 files changed, 3 insertions(+), 15 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/css/toolbar.css b/debug_toolbar/static/debug_toolbar/css/toolbar.css
index 74528a06d..34b143b8a 100644
--- a/debug_toolbar/static/debug_toolbar/css/toolbar.css
+++ b/debug_toolbar/static/debug_toolbar/css/toolbar.css
@@ -532,13 +532,6 @@
#djDebug .djDebugEndTransaction div.djDebugLineChart strong {
border-right: 1px solid #94b24d;
}
-#djDebug .djDebugHover div.djDebugLineChart strong {
- background-color: #000;
-}
-#djDebug .djDebugInTransaction.djDebugHover div.djDebugLineChart strong {
- background-color: #94b24d;
-}
-
#djDebug .djdt-panelContent ul.djdt-stats {
position: relative;
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 678192f8c..7a158deef 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -188,11 +188,6 @@
} else {
djdt.show_toolbar(false);
}
- $('#djDebug .djDebugHoverable').on('hover', function(){
- $(this).addClass('djDebugHover');
- }, function(){
- $(this).removeClass('djDebugHover');
- });
djdt.isReady = true;
$.each(djdt.events.ready, function(_, callback){
callback(djdt);
diff --git a/debug_toolbar/templates/debug_toolbar/panels/cache.html b/debug_toolbar/templates/debug_toolbar/panels/cache.html
index 014e5f621..39c9089b8 100644
--- a/debug_toolbar/templates/debug_toolbar/panels/cache.html
+++ b/debug_toolbar/templates/debug_toolbar/panels/cache.html
@@ -59,7 +59,7 @@ {% trans "Calls" %}
{{ call.kwargs|escape }}
{{ call.backend }}
-
+
{{ call.trace }}
diff --git a/debug_toolbar/templates/debug_toolbar/panels/sql.html b/debug_toolbar/templates/debug_toolbar/panels/sql.html
index c8e93f0a6..37074a4c6 100644
--- a/debug_toolbar/templates/debug_toolbar/panels/sql.html
+++ b/debug_toolbar/templates/debug_toolbar/panels/sql.html
@@ -33,7 +33,7 @@
{% for query in queries %}
-
+
+
@@ -79,7 +79,7 @@
{% endif %}
-
+
From 25066dd6e396ebe4a8703ffbcc981e48f8e0db61 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 04/16] do not close debugwindow twice
this is already handled in the close.djDebug event listener
---
debug_toolbar/static/debug_toolbar/js/toolbar.js | 5 -----
1 file changed, 5 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 7a158deef..3cdb5b269 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -82,11 +82,6 @@
var message = ''+xhr.status+': '+xhr.statusText+' ';
$('#djDebugWindow').html(message).show();
});
-
- $('#djDebugWindow').on('click', 'a.djDebugBack', function(event) {
- event.preventDefault();
- $(this).parent().parent().hide();
- });
});
// Used by the cache, profiling and SQL panels
From 0e4c5b5a0ab04f4ba8677b493739c4311dfde0e1 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 05/16] do not remove .djdt-active twice
already done in close.djDebug handler
---
debug_toolbar/static/debug_toolbar/js/toolbar.js | 2 --
1 file changed, 2 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 3cdb5b269..a6ed95112 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -15,7 +15,6 @@
var current = $('#djDebug #' + this.className);
if (current.is(':visible')) {
$(document).trigger('close.djDebug');
- $(this).parent().removeClass('djdt-active');
} else {
$('.djdt-panelContent').hide(); // Hide any that are already open
var inner = current.find('.djDebugPanelContent .djdt-scroll'),
@@ -45,7 +44,6 @@
$('#djDebug').on('click', 'a.djDebugClose', function(event) {
event.preventDefault();
$(document).trigger('close.djDebug');
- $('#djDebugToolbar li').removeClass('djdt-active');
});
$('#djDebug').on('click', '.djDebugPanelButton input[type=checkbox]', function() {
djdt.cookie.set($(this).attr('data-cookie'), $(this).prop('checked') ? 'on' : 'off', {
From 261bfbd3f59d8cd7e68ad4956afa21e900ecb0d8 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 06/16] more explicit closing
---
.../static/debug_toolbar/js/toolbar.js | 58 +++++++++----------
1 file changed, 26 insertions(+), 32 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index a6ed95112..296e1b4bc 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -14,9 +14,13 @@
}
var current = $('#djDebug #' + this.className);
if (current.is(':visible')) {
- $(document).trigger('close.djDebug');
+ djdt.hide_panels();
} else {
- $('.djdt-panelContent').hide(); // Hide any that are already open
+ djdt.hide_panels();
+
+ current.show();
+ $(this).parent().addClass('djdt-active');
+
var inner = current.find('.djDebugPanelContent .djdt-scroll'),
store_id = $('#djDebug').data('store-id');
if (store_id && inner.children().length === 0) {
@@ -36,14 +40,11 @@
$('#djDebugWindow').html(message).show();
});
}
- current.show();
- $('#djDebugToolbar li').removeClass('djdt-active');
- $(this).parent().addClass('djdt-active');
}
});
$('#djDebug').on('click', 'a.djDebugClose', function(event) {
event.preventDefault();
- $(document).trigger('close.djDebug');
+ djdt.hide_one_level();
});
$('#djDebug').on('click', '.djDebugPanelButton input[type=checkbox]', function() {
djdt.cookie.set($(this).attr('data-cookie'), $(this).prop('checked') ? 'on' : 'off', {
@@ -159,22 +160,7 @@
}
});
$(document).on('close.djDebug', function() {
- // If a sub-panel is open, close that
- if ($('#djDebugWindow').is(':visible')) {
- $('#djDebugWindow').hide();
- return;
- }
- // If a panel is open, close that
- if ($('.djdt-panelContent').is(':visible')) {
- $('.djdt-panelContent').hide();
- $('#djDebugToolbar li').removeClass('djdt-active');
- return;
- }
- // Otherwise, just minimize the toolbar
- if ($('#djDebugToolbar').is(':visible')) {
- djdt.hide_toolbar(true);
- return;
- }
+ djdt.hide_one_level();
});
if (djdt.cookie.get('djdt') == 'hide') {
djdt.hide_toolbar(false);
@@ -186,18 +172,15 @@
callback(djdt);
});
},
- close: function() {
- $(document).trigger('close.djDebug');
- return false;
- },
- hide_toolbar: function(setCookie) {
- // close any sub panels
+ hide_panels: function() {
$('#djDebugWindow').hide();
- // close all panels
$('.djdt-panelContent').hide();
$('#djDebugToolbar li').removeClass('djdt-active');
- // finally close toolbar
+ },
+ hide_toolbar: function(setCookie) {
+ djdt.hide_panels();
$('#djDebugToolbar').hide('fast');
+
var handle = $('#djDebugToolbarHandle');
handle.show();
// set handle position
@@ -206,8 +189,10 @@
handleTop = Math.min(handleTop, window.innerHeight - handle.outerHeight() - 10);
handle.css({top: handleTop + 'px'});
}
+
// Unbind keydown
$(document).off('keydown.djDebug');
+
if (setCookie) {
djdt.cookie.set('djdt', 'hide', {
path: '/',
@@ -215,11 +200,20 @@
});
}
},
+ hide_one_level: function() {
+ if ($('#djDebugWindow').is(':visible')) {
+ $('#djDebugWindow').hide();
+ } else if ($('.djdt-panelContent').is(':visible')) {
+ djdt.hide_panels();
+ } else {
+ djdt.hide_toolbar(true);
+ }
+ },
show_toolbar: function(animate) {
// Set up keybindings
$(document).on('keydown.djDebug', function(e) {
if (e.keyCode == 27) {
- djdt.close();
+ djdt.hide_one_level();
}
});
$('#djDebugToolbarHandle').hide();
@@ -284,7 +278,7 @@
$.extend(publicAPI, {
show_toolbar: djdt.show_toolbar,
hide_toolbar: djdt.hide_toolbar,
- close: djdt.close,
+ close: djdt.hide_one_level,
cookie: djdt.cookie,
applyStyle: djdt.applyStyle
});
From 3abf62fd6949921e717a6414fa68dff560582800 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 07/16] port timer
---
.../static/debug_toolbar/js/toolbar.timer.js | 29 ++++++++++---------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js b/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js
index 4b8428a79..b6959948e 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js
@@ -1,4 +1,4 @@
-(function ($) {
+(function () {
// Browser timing remains hidden unless we can successfully access the performance object
var perf = window.performance || window.msPerformance ||
window.webkitPerformance || window.mozPerformance;
@@ -20,22 +20,23 @@
}
function addRow(stat, endStat) {
rowCount++;
- var $row = $(' ');
+ var row = document.createElement('tr');
+ row.className = (rowCount % 2) ? 'djDebugOdd' : 'djDebugEven';
if (endStat) {
// Render a start through end bar
- $row.html('' + stat.replace('Start', '') + ' ' +
- ' ' +
- '' + (perf.timing[stat] - timingOffset) + ' (+' + (perf.timing[endStat] - perf.timing[stat]) + ') ');
- $row.find('strong').css({width: getCSSWidth(stat, endStat)});
+ row.innerHTML = '' + stat.replace('Start', '') + ' ' +
+ ' ' +
+ '' + (perf.timing[stat] - timingOffset) + ' (+' + (perf.timing[endStat] - perf.timing[stat]) + ') ';
+ row.querySelector('strong').style.width = getCSSWidth(stat, endStat);
} else {
// Render a point in time
- $row.html('' + stat + ' ' +
- ' ' +
- '' + (perf.timing[stat] - timingOffset) + ' ');
- $row.find('strong').css({width: 2});
+ row.innerHTML = '' + stat + ' ' +
+ ' ' +
+ '' + (perf.timing[stat] - timingOffset) + ' ';
+ row.querySelector('strong').style.width = '2px';
}
- $row.find('.djDebugLineChart').css({left: getLeft(stat) + '%'});
- $('#djDebugBrowserTimingTableBody').append($row);
+ row.querySelector('.djDebugLineChart').style.left = getLeft(stat) + '%';
+ document.querySelector('#djDebugBrowserTimingTableBody').appendChild(row);
}
// This is a reasonably complete and ordered set of timing periods (2 params) and events (1 param)
@@ -47,5 +48,5 @@
addRow('domInteractive');
addRow('domContentLoadedEventStart', 'domContentLoadedEventEnd');
addRow('loadEventStart', 'loadEventEnd');
- $('#djDebugBrowserTiming').show();
-})(djdt.jQuery);
+ document.querySelector('#djDebugBrowserTiming').classList.remove('djdt-hidden');
+})();
From 6e71e03a94c72e663a992d8653c938b9117da380 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 08/16] split onMouseMove
---
.../static/debug_toolbar/js/toolbar.js | 42 ++++++++++---------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 296e1b4bc..11b66fb53 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -121,29 +121,31 @@
djdt.show_toolbar();
}
});
+ var startPageY, baseY, windowHeight;
var handle = $('#djDebugToolbarHandle');
- $('#djShowToolBarButton').on('mousedown', function (event) {
- event.preventDefault();
- var startPageY = event.pageY;
- var baseY = handle.offset().top - startPageY;
- var windowHeight = $(window).height();
- $(document).on('mousemove.djDebug', function (event) {
- // Chrome can send spurious mousemove events, so don't do anything unless the
- // cursor really moved. Otherwise, it will be impossible to expand the toolbar
- // due to djdt.handleDragged being set to true.
- if (djdt.handleDragged || event.pageY != startPageY) {
- var top = baseY + event.clientY;
+ var onMouseMove = function(event) {
+ // Chrome can send spurious mousemove events, so don't do anything unless the
+ // cursor really moved. Otherwise, it will be impossible to expand the toolbar
+ // due to djdt.handleDragged being set to true.
+ if (djdt.handleDragged || event.pageY != startPageY) {
+ var top = baseY + event.clientY;
- if (top < 0) {
- top = 0;
- } else if (top + handle.height() > windowHeight) {
- top = windowHeight - handle.height();
- }
-
- handle.css({top: top});
- djdt.handleDragged = true;
+ if (top < 0) {
+ top = 0;
+ } else if (top + handle.height() > windowHeight) {
+ top = windowHeight - handle.height();
}
- });
+
+ handle.css({top: top});
+ djdt.handleDragged = true;
+ }
+ };
+ $('#djShowToolBarButton').on('mousedown', function (event) {
+ event.preventDefault();
+ startPageY = event.pageY;
+ baseY = handle.offset().top - startPageY;
+ windowHeight = $(window).height();
+ $(document).on('mousemove.djDebug', onMouseMove);
});
$(document).on('mouseup', function (event) {
$(document).off('mousemove.djDebug');
From 663238299dab97a92098015a59ed790393720088 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 09/16] split out onKeyDown
---
debug_toolbar/static/debug_toolbar/js/toolbar.js | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 11b66fb53..1d0b86a23 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -1,4 +1,10 @@
(function ($, publicAPI) {
+ var onKeyDown = function(event) {
+ if (event.keyCode == 27) {
+ djdt.hide_one_level();
+ }
+ };
+
var djdt = {
handleDragged: false,
events: {
@@ -213,11 +219,7 @@
},
show_toolbar: function(animate) {
// Set up keybindings
- $(document).on('keydown.djDebug', function(e) {
- if (e.keyCode == 27) {
- djdt.hide_one_level();
- }
- });
+ $(document).on('keydown.djDebug', onKeyDown);
$('#djDebugToolbarHandle').hide();
if (animate) {
$('#djDebugToolbar').show('fast');
From 7162816568c3b17c9b664fb6d0b734d82c8a04b6 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:32 +0200
Subject: [PATCH 10/16] port event handling
NOTE: removes custom event
---
.../static/debug_toolbar/js/toolbar.js | 43 +++++++++++--------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 1d0b86a23..b424da9b3 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -1,4 +1,15 @@
(function ($, publicAPI) {
+ var $$ = {
+ on: function(root, eventName, selector, fn) {
+ root.addEventListener(eventName, function(event) {
+ var target = event.target.closest(selector);
+ if (root.contains(target)) {
+ fn.call(target, event);
+ }
+ });
+ },
+ };
+
var onKeyDown = function(event) {
if (event.keyCode == 27) {
djdt.hide_one_level();
@@ -12,8 +23,9 @@
},
isReady: false,
init: function() {
- $('#djDebug').show();
- $('#djDebugPanelList').on('click', 'li a', function(event) {
+ var djDebug = document.querySelector('#djDebug');
+ djDebug.classList.remove('djdt-hidden');
+ $$.on(djDebug.querySelector('#djDebugPanelList'), 'click', 'li a', function(event) {
event.preventDefault();
if (!this.className) {
return;
@@ -48,11 +60,11 @@
}
}
});
- $('#djDebug').on('click', 'a.djDebugClose', function(event) {
+ $$.on(djDebug, 'click', 'a.djDebugClose', function(event) {
event.preventDefault();
djdt.hide_one_level();
});
- $('#djDebug').on('click', '.djDebugPanelButton input[type=checkbox]', function() {
+ $$.on(djDebug, 'click', '.djDebugPanelButton input[type=checkbox]', function() {
djdt.cookie.set($(this).attr('data-cookie'), $(this).prop('checked') ? 'on' : 'off', {
path: '/',
expires: 10
@@ -60,7 +72,7 @@
});
// Used by the SQL and template panels
- $('#djDebug').on('click', '.remoteCall', function(event) {
+ $$.on(djDebug, 'click', '.remoteCall', function(event) {
event.preventDefault();
var self = $(this);
@@ -90,7 +102,7 @@
});
// Used by the cache, profiling and SQL panels
- $('#djDebug').on('click', 'a.djToggleSwitch', function(event) {
+ $$.on(djDebug, 'click', 'a.djToggleSwitch', function(event) {
event.preventDefault();
var btn = $(this);
var id = btn.attr('data-toggle-id');
@@ -117,11 +129,11 @@
});
});
- $('#djHideToolBarButton').on('click', function(event) {
+ djDebug.querySelector('#djHideToolBarButton').addEventListener('click', function(event) {
event.preventDefault();
djdt.hide_toolbar(true);
});
- $('#djShowToolBarButton').on('click', function(event) {
+ djDebug.querySelector('#djShowToolBarButton').addEventListener('click', function(event) {
event.preventDefault();
if (!djdt.handleDragged) {
djdt.show_toolbar();
@@ -146,15 +158,15 @@
djdt.handleDragged = true;
}
};
- $('#djShowToolBarButton').on('mousedown', function (event) {
+ djDebug.querySelector('#djShowToolBarButton').addEventListener('mousedown', function(event) {
event.preventDefault();
startPageY = event.pageY;
baseY = handle.offset().top - startPageY;
windowHeight = $(window).height();
- $(document).on('mousemove.djDebug', onMouseMove);
+ document.addEventListener('mousemove', onMouseMove);
});
- $(document).on('mouseup', function (event) {
- $(document).off('mousemove.djDebug');
+ document.addEventListener('mouseup', function(event) {
+ document.removeEventListener('mousemove', onMouseMove);
if (djdt.handleDragged) {
event.preventDefault();
var top = handle.offset().top - window.pageYOffset;
@@ -167,9 +179,6 @@
}, 10);
}
});
- $(document).on('close.djDebug', function() {
- djdt.hide_one_level();
- });
if (djdt.cookie.get('djdt') == 'hide') {
djdt.hide_toolbar(false);
} else {
@@ -199,7 +208,7 @@
}
// Unbind keydown
- $(document).off('keydown.djDebug');
+ document.removeEventListener('keydown', onKeyDown);
if (setCookie) {
djdt.cookie.set('djdt', 'hide', {
@@ -219,7 +228,7 @@
},
show_toolbar: function(animate) {
// Set up keybindings
- $(document).on('keydown.djDebug', onKeyDown);
+ document.addEventListener('keydown', onKeyDown);
$('#djDebugToolbarHandle').hide();
if (animate) {
$('#djDebugToolbar').show('fast');
From 1ed21d56aae41b92edf9630e1e4860acf6673525 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:33 +0200
Subject: [PATCH 11/16] port applyStyle
---
debug_toolbar/static/debug_toolbar/js/toolbar.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index b424da9b3..852b45573 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -281,10 +281,9 @@
}
},
applyStyle: function(name) {
- $('#djDebug [data-' + name + ']').each(function() {
- var css = {};
- css[name] = $(this).data(name);
- $(this).css(css);
+ var selector = '#djDebug [data-' + name + ']';
+ document.querySelectorAll(selector).forEach(function(element) {
+ element.style[name] = element.getAttribute('data-' + name);
});
}
};
From c78e474bd79af6ac12bb824b9e97aca5e0cda9b7 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:33 +0200
Subject: [PATCH 12/16] port handle movement
---
.../static/debug_toolbar/js/toolbar.js | 34 +++++++++----------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 852b45573..81d94b6bf 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -139,38 +139,36 @@
djdt.show_toolbar();
}
});
- var startPageY, baseY, windowHeight;
- var handle = $('#djDebugToolbarHandle');
- var onMouseMove = function(event) {
+ var startPageY, baseY;
+ var handle = document.querySelector('#djDebugToolbarHandle');
+ var onHandleMove = function(event) {
// Chrome can send spurious mousemove events, so don't do anything unless the
// cursor really moved. Otherwise, it will be impossible to expand the toolbar
// due to djdt.handleDragged being set to true.
if (djdt.handleDragged || event.pageY != startPageY) {
- var top = baseY + event.clientY;
+ var top = baseY + event.pageY;
if (top < 0) {
top = 0;
- } else if (top + handle.height() > windowHeight) {
- top = windowHeight - handle.height();
+ } else if (top + handle.offsetHeight > window.innerHeight) {
+ top = window.innerHeight - handle.offsetHeight;
}
- handle.css({top: top});
+ handle.style.top = top + 'px';
djdt.handleDragged = true;
}
};
djDebug.querySelector('#djShowToolBarButton').addEventListener('mousedown', function(event) {
event.preventDefault();
startPageY = event.pageY;
- baseY = handle.offset().top - startPageY;
- windowHeight = $(window).height();
- document.addEventListener('mousemove', onMouseMove);
+ baseY = handle.offsetTop - startPageY;
+ document.addEventListener('mousemove', onHandleMove);
});
- document.addEventListener('mouseup', function(event) {
- document.removeEventListener('mousemove', onMouseMove);
+ document.addEventListener('mouseup', function (event) {
+ document.removeEventListener('mousemove', onHandleMove);
if (djdt.handleDragged) {
event.preventDefault();
- var top = handle.offset().top - window.pageYOffset;
- djdt.cookie.set('djdttop', top, {
+ djdt.cookie.set('djdttop', handle.offsetTop, {
path: '/',
expires: 10
});
@@ -198,13 +196,13 @@
djdt.hide_panels();
$('#djDebugToolbar').hide('fast');
- var handle = $('#djDebugToolbarHandle');
- handle.show();
+ var handle = document.querySelector('#djDebugToolbarHandle');
+ $(handle).show();
// set handle position
var handleTop = djdt.cookie.get('djdttop');
if (handleTop) {
- handleTop = Math.min(handleTop, window.innerHeight - handle.outerHeight() - 10);
- handle.css({top: handleTop + 'px'});
+ handleTop = Math.min(handleTop, window.innerHeight - handle.offsetHeight);
+ handle.style.top = handleTop + 'px';
}
// Unbind keydown
From 1e511e0c02d35d175bf4b5ddae2c8ba9aee5d2de Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:33 +0200
Subject: [PATCH 13/16] port most code
Note: removes animations
---
.../static/debug_toolbar/js/toolbar.js | 154 +++++++++++-------
1 file changed, 92 insertions(+), 62 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 81d94b6bf..84f92a326 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -8,6 +8,30 @@
}
});
},
+ show: function(element) {
+ element.style.display = 'block';
+ },
+ hide: function(element) {
+ element.style.display = 'none';
+ },
+ toggle: function(element, value) {
+ if (value) {
+ $$.show(element);
+ } else {
+ $$.hide(element);
+ }
+ },
+ visible: function(element) {
+ style = getComputedStyle(element);
+ return style.display !== 'none';
+ },
+ executeScripts: function(root) {
+ root.querySelectorAll('script').forEach(function(e) {
+ var clone = document.createElement('script');
+ clone.src = e.src;
+ root.appendChild(clone);
+ });
+ },
};
var onKeyDown = function(event) {
@@ -24,38 +48,40 @@
isReady: false,
init: function() {
var djDebug = document.querySelector('#djDebug');
- djDebug.classList.remove('djdt-hidden');
+ $$.show(djDebug);
$$.on(djDebug.querySelector('#djDebugPanelList'), 'click', 'li a', function(event) {
event.preventDefault();
if (!this.className) {
return;
}
- var current = $('#djDebug #' + this.className);
- if (current.is(':visible')) {
+ var current = djDebug.querySelector('#' + this.className);
+ if ($$.visible(current)) {
djdt.hide_panels();
} else {
djdt.hide_panels();
- current.show();
- $(this).parent().addClass('djdt-active');
+ $$.show(current);
+ this.parentElement.classList.add('djdt-active');
- var inner = current.find('.djDebugPanelContent .djdt-scroll'),
- store_id = $('#djDebug').data('store-id');
- if (store_id && inner.children().length === 0) {
+ var inner = current.querySelector('.djDebugPanelContent .djdt-scroll'),
+ store_id = djDebug.getAttribute('data-store-id');
+ if (store_id && inner.children.length === 0) {
var ajax_data = {
data: {
store_id: store_id,
panel_id: this.className
},
type: 'GET',
- url: $('#djDebug').data('render-panel-url')
+ url: djDebug.getAttribute('data-render-panel-url')
};
$.ajax(ajax_data).done(function(data){
- inner.prev().remove(); // Remove AJAX loader
- inner.html(data);
+ inner.previousElementSibling.remove(); // Remove AJAX loader
+ inner.innerHTML = body;
+ $$.executeScripts(inner);
}).fail(function(xhr){
- var message = ''+xhr.status+': '+xhr.statusText+' ';
- $('#djDebugWindow').html(message).show();
+ var win = document.querySelector('#djDebugWindow');
+ win.innerHTML = ''+xhr.status+': '+xhr.statusText+' ';
+ $$.show(win);
});
}
}
@@ -65,7 +91,7 @@
djdt.hide_one_level();
});
$$.on(djDebug, 'click', '.djDebugPanelButton input[type=checkbox]', function() {
- djdt.cookie.set($(this).attr('data-cookie'), $(this).prop('checked') ? 'on' : 'off', {
+ djdt.cookie.set(this.getAttribute('data-cookie'), this.checked ? 'on' : 'off', {
path: '/',
expires: 10
});
@@ -75,56 +101,62 @@
$$.on(djDebug, 'click', '.remoteCall', function(event) {
event.preventDefault();
- var self = $(this);
- var name = self[0].tagName.toLowerCase();
+ var name = this.tagName.toLowerCase();
var ajax_data = {};
if (name == 'button') {
- var form = self.parents('form:eq(0)');
- ajax_data.url = self.attr('formaction');
+ var form = this.closest('form');
+ ajax_data.url = this.getAttribute('formaction');
- if (form.length) {
- ajax_data.data = form.serialize();
- ajax_data.type = form.attr('method') || 'POST';
+ if (form) {
+ ajax_data.data = $(form).serialize();
+ ajax_data.method = form.getAttribute('method') || 'POST';
}
}
if (name == 'a') {
- ajax_data.url = self.attr('href');
+ ajax_data.url = this.getAttribute('href');
}
$.ajax(ajax_data).done(function(data){
- $('#djDebugWindow').html(data).show();
+ var win = djDebug.querySelector('#djDebugWindow');
+ win.innerHTML = body;
+ $$.executeScripts(win);
}).fail(function(xhr){
- var message = ''+xhr.status+': '+xhr.statusText+' ';
- $('#djDebugWindow').html(message).show();
+ var win = document.querySelector('#djDebugWindow');
+ win.innerHTML = ''+xhr.status+': '+xhr.statusText+' ';
+ $$.show(win);
});
});
// Used by the cache, profiling and SQL panels
$$.on(djDebug, 'click', 'a.djToggleSwitch', function(event) {
event.preventDefault();
- var btn = $(this);
- var id = btn.attr('data-toggle-id');
- var open_me = btn.text() == btn.attr('data-toggle-open');
+ var self = this;
+ var id = this.getAttribute('data-toggle-id');
+ var open_me = this.textContent == this.getAttribute('data-toggle-open');
if (id === '' || !id) {
return;
}
- var name = btn.attr('data-toggle-name');
- btn.parents('.djDebugPanelContent').find('#' + name + '_' + id).find('.djDebugCollapsed').toggle(open_me);
- btn.parents('.djDebugPanelContent').find('#' + name + '_' + id).find('.djDebugUncollapsed').toggle(!open_me);
- $(this).parents('.djDebugPanelContent').find('.djToggleDetails_' + id).each(function(){
- var $this = $(this);
+ var name = this.getAttribute('data-toggle-name');
+ var container = this.closest('.djDebugPanelContent').querySelector('#' + name + '_' + id);
+ container.querySelectorAll('.djDebugCollapsed').forEach(function(e) {
+ $$.toggle(e, open_me);
+ });
+ container.querySelectorAll('.djDebugUncollapsed').forEach(function(e) {
+ $$.toggle(e, !open_me);
+ });
+ this.closest('.djDebugPanelContent').querySelectorAll('.djToggleDetails_' + id).forEach(function(e) {
if (open_me) {
- $this.addClass('djSelected');
- $this.removeClass('djUnselected');
- btn.text(btn.attr('data-toggle-close'));
- $this.find('.djToggleSwitch').text(btn.text());
+ e.classList.add('djSelected');
+ e.classList.remove('djUnselected');
+ self.textContent = self.getAttribute('data-toggle-close');
+ e.querySelector('.djToggleSwitch').textContent = self.textContent;
} else {
- $this.removeClass('djSelected');
- $this.addClass('djUnselected');
- btn.text(btn.attr('data-toggle-open'));
- $this.find('.djToggleSwitch').text(btn.text());
+ e.classList.remove('djSelected');
+ e.classList.add('djUnselected');
+ self.textContent = self.getAttribute('data-toggle-open');
+ e.querySelector('.djToggleSwitch').textContent = self.textContent;
}
});
});
@@ -180,24 +212,28 @@
if (djdt.cookie.get('djdt') == 'hide') {
djdt.hide_toolbar(false);
} else {
- djdt.show_toolbar(false);
+ djdt.show_toolbar();
}
djdt.isReady = true;
- $.each(djdt.events.ready, function(_, callback){
+ djdt.events.ready.forEach(function(callback) {
callback(djdt);
});
},
hide_panels: function() {
- $('#djDebugWindow').hide();
- $('.djdt-panelContent').hide();
- $('#djDebugToolbar li').removeClass('djdt-active');
+ $$.hide(djDebug.querySelector('#djDebugWindow'));
+ djDebug.querySelectorAll('.djdt-panelContent').forEach(function(e) {
+ $$.hide(e);
+ });
+ djDebug.querySelectorAll('#djDebugToolbar li').forEach(function(e) {
+ e.classList.remove('djdt-active');
+ });
},
hide_toolbar: function(setCookie) {
djdt.hide_panels();
- $('#djDebugToolbar').hide('fast');
+ $$.hide(djDebug.querySelector('#djDebugToolbar'));
var handle = document.querySelector('#djDebugToolbarHandle');
- $(handle).show();
+ $$.show(handle);
// set handle position
var handleTop = djdt.cookie.get('djdttop');
if (handleTop) {
@@ -205,7 +241,6 @@
handle.style.top = handleTop + 'px';
}
- // Unbind keydown
document.removeEventListener('keydown', onKeyDown);
if (setCookie) {
@@ -215,24 +250,19 @@
});
}
},
- hide_one_level: function() {
- if ($('#djDebugWindow').is(':visible')) {
- $('#djDebugWindow').hide();
- } else if ($('.djdt-panelContent').is(':visible')) {
+ hide_one_level: function(skipDebugWindow) {
+ if ($$.visible(djDebug.querySelector('#djDebugWindow'))) {
+ $$.hide(djDebug.querySelector('#djDebugWindow'));
+ } else if (djDebug.querySelector('#djDebugToolbar li.djdt-active')) {
djdt.hide_panels();
} else {
djdt.hide_toolbar(true);
}
},
- show_toolbar: function(animate) {
- // Set up keybindings
+ show_toolbar: function() {
document.addEventListener('keydown', onKeyDown);
- $('#djDebugToolbarHandle').hide();
- if (animate) {
- $('#djDebugToolbar').show('fast');
- } else {
- $('#djDebugToolbar').show();
- }
+ $$.hide(djDebug.querySelector('#djDebugToolbarHandle'));
+ $$.show(djDebug.querySelector('#djDebugToolbar'));
djdt.cookie.set('djdt', 'show', {
path: '/',
expires: 10
@@ -292,5 +322,5 @@
cookie: djdt.cookie,
applyStyle: djdt.applyStyle
});
- $(document).ready(djdt.init);
+ document.addEventListener('DOMContentLoaded', djdt.init);
})(djdt.jQuery, djdt);
From f7fafffa6426774d402078fa2a8c1dd97717b1f0 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:33 +0200
Subject: [PATCH 14/16] port ajax
---
.../static/debug_toolbar/js/toolbar.js | 40 ++++++++++---------
1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js
index 84f92a326..028c71cbd 100644
--- a/debug_toolbar/static/debug_toolbar/js/toolbar.js
+++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js
@@ -40,6 +40,20 @@
}
};
+ var ajax = function(url, init) {
+ init = Object.assign({credentials: 'same-origin'}, init);
+ return fetch(url, init).then(function(response) {
+ if (response.ok) {
+ return response.text();
+ } else {
+ var win = document.querySelector('#djDebugWindow');
+ win.innerHTML = ''+response.status+': '+response.statusText+' ';
+ $$.show(win);
+ return Promise.reject();
+ }
+ });
+ };
+
var djdt = {
handleDragged: false,
events: {
@@ -66,22 +80,15 @@
var inner = current.querySelector('.djDebugPanelContent .djdt-scroll'),
store_id = djDebug.getAttribute('data-store-id');
if (store_id && inner.children.length === 0) {
- var ajax_data = {
- data: {
- store_id: store_id,
- panel_id: this.className
- },
- type: 'GET',
- url: djDebug.getAttribute('data-render-panel-url')
- };
- $.ajax(ajax_data).done(function(data){
+ var url = djDebug.getAttribute('data-render-panel-url');
+ url += '?' + new URLSearchParams({
+ store_id: store_id,
+ panel_id: this.className
+ })
+ ajax(url).then(function(body) {
inner.previousElementSibling.remove(); // Remove AJAX loader
inner.innerHTML = body;
$$.executeScripts(inner);
- }).fail(function(xhr){
- var win = document.querySelector('#djDebugWindow');
- win.innerHTML = ''+xhr.status+': '+xhr.statusText+' ';
- $$.show(win);
});
}
}
@@ -109,7 +116,7 @@
ajax_data.url = this.getAttribute('formaction');
if (form) {
- ajax_data.data = $(form).serialize();
+ ajax_data.body = new FormData(form);
ajax_data.method = form.getAttribute('method') || 'POST';
}
}
@@ -118,13 +125,10 @@
ajax_data.url = this.getAttribute('href');
}
- $.ajax(ajax_data).done(function(data){
+ ajax(ajax_data.url, ajax_data).then(function(body) {
var win = djDebug.querySelector('#djDebugWindow');
win.innerHTML = body;
$$.executeScripts(win);
- }).fail(function(xhr){
- var win = document.querySelector('#djDebugWindow');
- win.innerHTML = ''+xhr.status+': '+xhr.statusText+' ';
$$.show(win);
});
});
From 94db2f0912b11c212c959227860de028251b0241 Mon Sep 17 00:00:00 2001
From: Tobias Bengfort
Date: Wed, 5 Sep 2018 23:08:33 +0200
Subject: [PATCH 15/16] rm JQUERY_URL setting
---
debug_toolbar/settings.py | 1 -
debug_toolbar/static/debug_toolbar/js/jquery_existing.js | 1 -
debug_toolbar/templates/debug_toolbar/base.html | 7 +------
docs/configuration.rst | 8 --------
docs/tips.rst | 4 ----
5 files changed, 1 insertion(+), 20 deletions(-)
delete mode 100644 debug_toolbar/static/debug_toolbar/js/jquery_existing.js
diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py
index c5e213101..d22bf343e 100644
--- a/debug_toolbar/settings.py
+++ b/debug_toolbar/settings.py
@@ -17,7 +17,6 @@
# Toolbar options
'DISABLE_PANELS': {'debug_toolbar.panels.redirects.RedirectsPanel'},
'INSERT_BEFORE': '
',
- 'JQUERY_URL': '//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js',
'RENDER_PANELS': None,
'RESULTS_CACHE_SIZE': 10,
'ROOT_TAG_EXTRA_ATTRS': '',
diff --git a/debug_toolbar/static/debug_toolbar/js/jquery_existing.js b/debug_toolbar/static/debug_toolbar/js/jquery_existing.js
deleted file mode 100644
index 085495a65..000000000
--- a/debug_toolbar/static/debug_toolbar/js/jquery_existing.js
+++ /dev/null
@@ -1 +0,0 @@
-var djdt = {jQuery: jQuery};
diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html
index 5d4b24aa3..8c8eafa70 100644
--- a/debug_toolbar/templates/debug_toolbar/base.html
+++ b/debug_toolbar/templates/debug_toolbar/base.html
@@ -1,14 +1,9 @@
{% load i18n %}{% load static %}
-{% if toolbar.config.JQUERY_URL %}
-
-
+
-{% else %}
-
-{% endif %}