From 13e43c82bd2ee1127eb0500b7dc8413ca8a56883 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Thu, 30 Jul 2015 21:56:22 +0200 Subject: [PATCH] Replace inefficient jQuery selectors. Signed-off-by: Hugues Peccatte --- js/console.js | 297 ++++++++++++++++++++-------------------- js/pmd/designer_page.js | 6 +- js/pmd/move.js | 4 +- 3 files changed, 154 insertions(+), 153 deletions(-) diff --git a/js/console.js b/js/console.js index f80eb5d4b9..5588018e1a 100644 --- a/js/console.js +++ b/js/console.js @@ -72,10 +72,10 @@ var PMA_console = { } // Vars init - PMA_console.$consoleToolbar = $('#pma_console>.toolbar'); - PMA_console.$consoleContent = $('#pma_console>.content'); - PMA_console.$consoleAllContents = $('#pma_console .content'); - PMA_console.$consoleTemplates = $('#pma_console>.templates'); + PMA_console.$consoleToolbar = $("#pma_console").find(">.toolbar"); + PMA_console.$consoleContent = $("#pma_console").find(">.content"); + PMA_console.$consoleAllContents = $('#pma_console').find('.content'); + PMA_console.$consoleTemplates = $('#pma_console').find('>.templates'); // Generate a from for post PMA_console.$requestForm = $('
' + @@ -99,23 +99,23 @@ var PMA_console = { var tempConfig = JSON.parse($.cookie('pma_console_config')); if (tempConfig) { if (tempConfig.alwaysExpand === true) { - $('#pma_console_options input[name=always_expand]').prop('checked', true); + $('#pma_console_options').find('input[name=always_expand]').prop('checked', true); } if (tempConfig.startHistory === true) { - $('#pma_console_options input[name=start_history]').prop('checked', true); + $('#pma_console_options').find('input[name=start_history]').prop('checked', true); } if (tempConfig.currentQuery === true) { - $('#pma_console_options input[name=current_query]').prop('checked', true); + $('#pma_console_options').find('input[name=current_query]').prop('checked', true); } if (ConsoleEnterExecutes === true) { - $('#pma_console_options input[name=enter_executes]').prop('checked', true); + $('#pma_console_options').find('input[name=enter_executes]').prop('checked', true); } if (tempConfig.darkTheme === true) { - $('#pma_console_options input[name=dark_theme]').prop('checked', true); - $('#pma_console>.content').addClass('console_dark_theme'); + $('#pma_console_options').find('input[name=dark_theme]').prop('checked', true); + $('#pma_console').find('>.content').addClass('console_dark_theme'); } } else { - $('#pma_console_options input[name=current_query]').prop('checked', true); + $('#pma_console_options').find('input[name=current_query]').prop('checked', true); } PMA_console.updateConfig(); @@ -134,24 +134,24 @@ var PMA_console = { } }); - $('#pma_console .toolbar').children().mousedown(function(event) { + $('#pma_console').find('.toolbar').children().mousedown(function(event) { event.preventDefault(); event.stopImmediatePropagation(); }); - $('#pma_console .button.clear').click(function() { + $('#pma_console').find('.button.clear').click(function() { PMA_consoleMessages.clear(); }); - $('#pma_console .button.history').click(function() { + $('#pma_console').find('.button.history').click(function() { PMA_consoleMessages.showHistory(); }); - $('#pma_console .button.options').click(function() { + $('#pma_console').find('.button.options').click(function() { PMA_console.showCard('#pma_console_options'); }); - $('#pma_console .button.debug').click(function() { + $('#pma_console').find('.button.debug').click(function() { PMA_console.showCard('#debug_console'); }); @@ -161,33 +161,33 @@ var PMA_console = { } }); - $('#pma_console .mid_layer').click(function() { + $('#pma_console').find('.mid_layer').click(function() { PMA_console.hideCard($(this).parent().children('.card')); }); - $('#debug_console .switch_button').click(function() { + $('#debug_console').find('.switch_button').click(function() { PMA_console.hideCard($(this).closest('.card')); }); - $('#pma_bookmarks .switch_button').click(function() { + $('#pma_bookmarks').find('.switch_button').click(function() { PMA_console.hideCard($(this).closest('.card')); }); - $('#pma_console_options .switch_button').click(function() { + $('#pma_console_options').find('.switch_button').click(function() { PMA_console.hideCard($(this).closest('.card')); }); - $('#pma_console_options input[type=checkbox]').change(function() { + $('#pma_console_options').find('input[type=checkbox]').change(function() { PMA_console.updateConfig(); }); - $('#pma_console_options .button.default').click(function() { - $('#pma_console_options input[name=always_expand]').prop('checked', false); - $('#pma_console_options input[name=start_history]').prop('checked', false); - $('#pma_console_options input[name=current_query]').prop('checked', true); - $('#pma_console_options input[name=enter_executes]').prop('checked', false); - $('#pma_console_options input[name=dark_theme]').prop('checked', false); + $('#pma_console_options').find('.button.default').click(function() { + $('#pma_console_options').find('input[name=always_expand]').prop('checked', false); + $('#pma_console_options').find('input[name=start_history]').prop('checked', false); + $('#pma_console_options').find('input[name=current_query]').prop('checked', true); + $('#pma_console_options').find('input[name=enter_executes]').prop('checked', false); + $('#pma_console_options').find('input[name=dark_theme]').prop('checked', false); PMA_console.updateConfig(); }); - $('#pma_console_options input[name=enter_executes]').change(function() { + $('#pma_console_options').find('input[name=enter_executes]').change(function() { PMA_consoleMessages.showInstructions(PMA_console.config.enterExecutes); }); @@ -399,8 +399,8 @@ var PMA_console = { */ hideCard: function($targetCard) { if (! $targetCard) { - $('#pma_console .mid_layer').fadeOut(140); - $('#pma_console .card').removeClass('show'); + $('#pma_console').find('.mid_layer').fadeOut(140); + $('#pma_console').find('.card').removeClass('show'); } else if ($targetCard.length > 0) { $targetCard.parent().find('.mid_layer').fadeOut(140); $targetCard.find('.card').removeClass('show'); @@ -414,18 +414,18 @@ var PMA_console = { */ updateConfig: function() { PMA_console.config = { - alwaysExpand: $('#pma_console_options input[name=always_expand]').prop('checked'), - startHistory: $('#pma_console_options input[name=start_history]').prop('checked'), - currentQuery: $('#pma_console_options input[name=current_query]').prop('checked'), - enterExecutes: $('#pma_console_options input[name=enter_executes]').prop('checked'), - darkTheme: $('#pma_console_options input[name=dark_theme]').prop('checked') + alwaysExpand: $('#pma_console_options').find('input[name=always_expand]').prop('checked'), + startHistory: $('#pma_console_options').find('input[name=start_history]').prop('checked'), + currentQuery: $('#pma_console_options').find('input[name=current_query]').prop('checked'), + enterExecutes: $('#pma_console_options').find('input[name=enter_executes]').prop('checked'), + darkTheme: $('#pma_console_options').find('input[name=dark_theme]').prop('checked') }; $.cookie('pma_console_config', JSON.stringify(PMA_console.config)); /*Setting the dark theme of the console*/ if (PMA_console.config.darkTheme) { - $('#pma_console>.content').addClass('console_dark_theme'); + $('#pma_console').find('>.content').addClass('console_dark_theme'); } else { - $('#pma_console>.content').removeClass('console_dark_theme'); + $('#pma_console').find('>.content').removeClass('console_dark_theme'); } }, isSelect: function (queryString) { @@ -503,8 +503,8 @@ var PMA_consoleResizer = { * @return void */ initialize: function() { - $('#pma_console .toolbar').unbind('mousedown'); - $('#pma_console .toolbar').mousedown(PMA_consoleResizer._mousedown); + $('#pma_console').find('.toolbar').unbind('mousedown'); + $('#pma_console').find('.toolbar').mousedown(PMA_consoleResizer._mousedown); } }; @@ -548,7 +548,7 @@ var PMA_consoleInput = { } PMA_consoleInput._inputs = []; if (PMA_consoleInput._codemirror) { - PMA_consoleInput._inputs.console = CodeMirror($('#pma_console .console_query_input')[0], { + PMA_consoleInput._inputs.console = CodeMirror($('#pma_console').find('.console_query_input')[0], { theme: 'pma', mode: 'text/x-sql', lineWrapping: true, @@ -565,7 +565,7 @@ var PMA_consoleInput = { PMA_consoleInput._historyNavigate(event); }); if ($('#pma_bookmarks').length !== 0) { - PMA_consoleInput._inputs.bookmark = CodeMirror($('#pma_console .bookmark_add_input')[0], { + PMA_consoleInput._inputs.bookmark = CodeMirror($('#pma_console').find('.bookmark_add_input')[0], { theme: 'pma', mode: 'text/x-sql', lineWrapping: true, @@ -588,7 +588,7 @@ var PMA_consoleInput = { $('