Skip to content

Refactor js #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions debug_toolbar/static/debug_toolbar/js/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
isReady: false,
init: function() {
$('#djDebug').show();
$('#djDebugPanelList').on('click', 'li a', function() {
$('#djDebugPanelList').on('click', 'li a', function(event) {
event.preventDefault();
if (!this.className) {
return false;
return;
}
var current = $('#djDebug #' + this.className);
if (current.is(':visible')) {
Expand Down Expand Up @@ -40,12 +41,11 @@
$('#djDebugToolbar li').removeClass('djdt-active');
$(this).parent().addClass('djdt-active');
}
return false;
});
$('#djDebug').on('click', 'a.djDebugClose', function() {
$('#djDebug').on('click', 'a.djDebugClose', function(event) {
event.preventDefault();
$(document).trigger('close.djDebug');
$('#djDebugToolbar li').removeClass('djdt-active');
return false;
});
$('#djDebug').on('click', '.djDebugPanelButton input[type=checkbox]', function() {
djdt.cookie.set($(this).attr('data-cookie'), $(this).prop('checked') ? 'on' : 'off', {
Expand All @@ -55,7 +55,9 @@
});

// Used by the SQL and template panels
$('#djDebug').on('click', '.remoteCall', function() {
$('#djDebug').on('click', '.remoteCall', function(event) {
event.preventDefault();

var self = $(this);
var name = self[0].tagName.toLowerCase();
var ajax_data = {};
Expand All @@ -81,17 +83,15 @@
$('#djDebugWindow').html(message).show();
});

$('#djDebugWindow').on('click', 'a.djDebugBack', function() {
$('#djDebugWindow').on('click', 'a.djDebugBack', function(event) {
event.preventDefault();
$(this).parent().parent().hide();
return false;
});

return false;
});

// Used by the cache, profiling and SQL panels
$('#djDebug').on('click', 'a.djToggleSwitch', function(e) {
e.preventDefault();
$('#djDebug').on('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');
Expand All @@ -115,21 +115,21 @@
$this.find('.djToggleSwitch').text(btn.text());
}
});
return;
});

$('#djHideToolBarButton').click(function() {
$('#djHideToolBarButton').on('click', function(event) {
event.preventDefault();
djdt.hide_toolbar(true);
return false;
});
$('#djShowToolBarButton').click(function() {
$('#djShowToolBarButton').on('click', function(event) {
event.preventDefault();
if (!djdt.handleDragged) {
djdt.show_toolbar();
}
return false;
});
var handle = $('#djDebugToolbarHandle');
$('#djShowToolBarButton').on('mousedown', function (event) {
event.preventDefault();
var startPageY = event.pageY;
var baseY = handle.offset().top - startPageY;
var windowHeight = $(window).height();
Expand All @@ -150,11 +150,11 @@
djdt.handleDragged = true;
}
});
return false;
});
$(document).on('mouseup', function () {
$(document).on('mouseup', function (event) {
$(document).off('mousemove.djDebug');
if (djdt.handleDragged) {
event.preventDefault();
var top = handle.offset().top - window.pageYOffset;
djdt.cookie.set('djdttop', top, {
path: '/',
Expand All @@ -163,10 +163,9 @@
setTimeout(function () {
djdt.handleDragged = false;
}, 10);
return false;
}
});
$(document).bind('close.djDebug', function() {
$(document).on('close.djDebug', function() {
// If a sub-panel is open, close that
if ($('#djDebugWindow').is(':visible')) {
$('#djDebugWindow').hide();
Expand All @@ -189,7 +188,7 @@
} else {
djdt.show_toolbar(false);
}
$('#djDebug .djDebugHoverable').hover(function(){
$('#djDebug .djDebugHoverable').on('hover', function(){
$(this).addClass('djDebugHover');
}, function(){
$(this).removeClass('djDebugHover');
Expand Down Expand Up @@ -220,7 +219,7 @@
handle.css({top: handleTop + 'px'});
}
// Unbind keydown
$(document).unbind('keydown.djDebug');
$(document).off('keydown.djDebug');
if (setCookie) {
djdt.cookie.set('djdt', 'hide', {
path: '/',
Expand All @@ -230,7 +229,7 @@
},
show_toolbar: function(animate) {
// Set up keybindings
$(document).bind('keydown.djDebug', function(e) {
$(document).on('keydown.djDebug', function(e) {
if (e.keyCode == 27) {
djdt.close();
}
Expand Down
22 changes: 2 additions & 20 deletions debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
(function ($) {
function getSubcalls(row) {
var id = row.attr('id');
return $('.djDebugProfileRow[id^="'+id+'_"]');
}
function getDirectSubcalls(row) {
var subcalls = getSubcalls(row);
var depth = parseInt(row.attr('depth'), 10) + 1;
return subcalls.filter('[depth='+depth+']');
}
$('.djDebugProfileRow .djDebugProfileToggle').on('click', function(){
var row = $(this).closest('.djDebugProfileRow');
var subcalls = getSubcalls(row);
if (subcalls.css('display') == 'none') {
getDirectSubcalls(row).show();
} else {
subcalls.hide();
}
});
(function () {
djdt.applyStyle('padding-left');
})(djdt.jQuery);
})();
4 changes: 2 additions & 2 deletions debug_toolbar/static/debug_toolbar/js/toolbar.sql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function ($) {
$('#djDebug a.djDebugToggle').on('click', function(e) {
e.preventDefault();
$('#djDebug a.djDebugToggle').on('click', function(event) {
event.preventDefault();
$(this).parent().find('.djDebugCollapsed').toggle();
$(this).parent().find('.djDebugUncollapsed').toggle();
});
Expand Down
4 changes: 2 additions & 2 deletions debug_toolbar/static/debug_toolbar/js/toolbar.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
var uarr = String.fromCharCode(0x25b6),
darr = String.fromCharCode(0x25bc);

$('a.djTemplateShowContext').on('click', function() {
$('a.djTemplateShowContext').on('click', function(event) {
event.preventDefault();
var arrow = $(this).children('.toggleArrow');
arrow.html(arrow.html() == uarr ? darr : uarr);
$(this).parent().next().toggle();
return false;
});
})(djdt.jQuery);
6 changes: 3 additions & 3 deletions debug_toolbar/static/debug_toolbar/js/toolbar.timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var $row = $('<tr class="' + ((rowCount % 2) ? 'djDebugOdd' : 'djDebugEven') + '"></tr>');
if (endStat) {
// Render a start through end bar
$row.html('<td>' + stat.replace('Start', '') + '</td>' +
$row.html('<td>' + stat.replace('Start', '') + '</td>' +
'<td class="djdt-timeline"><div class="djDebugTimeline"><div class="djDebugLineChart"><strong>&#160;</strong></div></div></td>' +
'<td>' + (perf.timing[stat] - timingOffset) + ' (+' + (perf.timing[endStat] - perf.timing[stat]) + ')</td>');
$row.find('strong').css({width: getCSSWidth(stat, endStat)});
Expand All @@ -34,7 +34,7 @@
'<td>' + (perf.timing[stat] - timingOffset) + '</td>');
$row.find('strong').css({width: 2});
}
$row.find('djDebugLineChart').css({left: getLeft(stat) + '%'});
$row.find('.djDebugLineChart').css({left: getLeft(stat) + '%'});
$('#djDebugBrowserTimingTableBody').append($row);
}

Expand All @@ -47,5 +47,5 @@
addRow('domInteractive');
addRow('domContentLoadedEventStart', 'domContentLoadedEventEnd');
addRow('loadEventStart', 'loadEventEnd');
$('#djDebugBrowserTiming').css("display", "block");
$('#djDebugBrowserTiming').show();
})(djdt.jQuery);