From 425da5df2f0cfb0f7cf272861a3c439ae00df8a8 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 7 Aug 2018 16:55:53 +0200 Subject: [PATCH] normalize jQuery usage --- .../static/debug_toolbar/js/toolbar.js | 47 +++++++++---------- .../debug_toolbar/js/toolbar.profiling.js | 22 +-------- .../static/debug_toolbar/js/toolbar.sql.js | 4 +- .../debug_toolbar/js/toolbar.template.js | 4 +- .../static/debug_toolbar/js/toolbar.timer.js | 6 +-- 5 files changed, 32 insertions(+), 51 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 701f4f90a..678192f8c 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -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')) { @@ -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', { @@ -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 = {}; @@ -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'); @@ -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(); @@ -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: '/', @@ -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(); @@ -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'); @@ -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: '/', @@ -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(); } diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js b/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js index 2389bace9..5823cfbcd 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.profiling.js @@ -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); +})(); diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js b/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js index 109a74d0e..aec16d510 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.sql.js @@ -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(); }); diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.template.js b/debug_toolbar/static/debug_toolbar/js/toolbar.template.js index 01ac8a4af..fcddc9307 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.template.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.template.js @@ -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); diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js b/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js index ba2e065b3..4b8428a79 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.timer.js @@ -23,7 +23,7 @@ var $row = $(''); if (endStat) { // Render a start through end bar - $row.html('' + stat.replace('Start', '') + '' + + $row.html('' + stat.replace('Start', '') + '' + '
 
' + '' + (perf.timing[stat] - timingOffset) + ' (+' + (perf.timing[endStat] - perf.timing[stat]) + ')'); $row.find('strong').css({width: getCSSWidth(stat, endStat)}); @@ -34,7 +34,7 @@ '' + (perf.timing[stat] - timingOffset) + ''); $row.find('strong').css({width: 2}); } - $row.find('djDebugLineChart').css({left: getLeft(stat) + '%'}); + $row.find('.djDebugLineChart').css({left: getLeft(stat) + '%'}); $('#djDebugBrowserTimingTableBody').append($row); } @@ -47,5 +47,5 @@ addRow('domInteractive'); addRow('domContentLoadedEventStart', 'domContentLoadedEventEnd'); addRow('loadEventStart', 'loadEventEnd'); - $('#djDebugBrowserTiming').css("display", "block"); + $('#djDebugBrowserTiming').show(); })(djdt.jQuery);