Skip to content

Commit f429eb2

Browse files
committed
Refactor toggleQuickOrCustom function from export.js
Uses the d-none CSS class to hide the elements and removes the jQuery code. This removes the flickering when the page loads since the elements are already hidden. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 526bfe4 commit f429eb2

4 files changed

Lines changed: 56 additions & 26 deletions

File tree

js/src/export.js

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -698,25 +698,55 @@ window.AJAX.registerOnload('export.js', function () {
698698
/**
699699
* Toggles display of options when quick and custom export are selected
700700
*/
701-
Export.toggleQuickOrCustom = function () {
702-
if ($('input[name=\'quick_or_custom\']').length === 0 // custom_no_form option
703-
|| $('#radio_custom_export').prop('checked') // custom
704-
) {
705-
$('#databases_and_tables').show();
706-
$('#rows').show();
707-
$('#output').show();
708-
$('#format_specific_opts').show();
709-
$('#output_quick_export').addClass('d-none');
710-
var selectedPluginName = $('#plugins').find('option:selected').val();
711-
$('#' + selectedPluginName + '_options').removeClass('d-none');
712-
} else { // quick
713-
$('#databases_and_tables').hide();
714-
$('#rows').hide();
715-
$('#output').hide();
716-
$('#format_specific_opts').hide();
717-
$('#output_quick_export').removeClass('d-none');
701+
function toggleQuickOrCustom () {
702+
const isCustomNoFormOption = ! document.getElementById('quick_or_custom');
703+
const radioCustomExportElement = document.getElementById('radio_custom_export');
704+
const isCustomExport = isCustomNoFormOption
705+
|| radioCustomExportElement instanceof HTMLInputElement
706+
&& radioCustomExportElement.checked;
707+
708+
const databasesAndTablesElement = document.getElementById('databases_and_tables');
709+
if (databasesAndTablesElement) {
710+
databasesAndTablesElement.classList.toggle('d-none', ! isCustomExport);
711+
}
712+
713+
const rowsElement = document.getElementById('rows');
714+
if (rowsElement) {
715+
rowsElement.classList.toggle('d-none', ! isCustomExport);
716+
}
717+
718+
const outputElement = document.getElementById('output');
719+
if (outputElement) {
720+
outputElement.classList.toggle('d-none', ! isCustomExport);
721+
}
722+
723+
const formatSpecificOptionsElement = document.getElementById('format_specific_opts');
724+
if (formatSpecificOptionsElement) {
725+
formatSpecificOptionsElement.classList.toggle('d-none', ! isCustomExport);
726+
}
727+
728+
const outputQuickExportElement = document.getElementById('output_quick_export');
729+
if (outputQuickExportElement) {
730+
outputQuickExportElement.classList.toggle('d-none', isCustomExport);
718731
}
719-
};
732+
733+
if (! isCustomExport) {
734+
return;
735+
}
736+
737+
const selectedPluginElement = document.querySelector('#plugins > option[selected]');
738+
const selectedPluginName = selectedPluginElement instanceof HTMLOptionElement ? selectedPluginElement.value : null;
739+
if (selectedPluginName === null) {
740+
return;
741+
}
742+
743+
const pluginOptionsElement = document.getElementById(selectedPluginName + '_options');
744+
if (! pluginOptionsElement) {
745+
return;
746+
}
747+
748+
pluginOptionsElement.classList.remove('d-none');
749+
}
720750

721751
var timeOut;
722752

@@ -835,13 +865,13 @@ Export.addAlias = function (type, name, field, value) {
835865
};
836866

837867
window.AJAX.registerOnload('export.js', function () {
838-
$('input[type=\'radio\'][name=\'quick_or_custom\']').on('change', Export.toggleQuickOrCustom);
839-
868+
$('input[type=\'radio\'][name=\'quick_or_custom\']').on('change', toggleQuickOrCustom);
840869
$('#format_specific_opts').find('div.format_specific_options')
841870
.addClass('d-none')
842871
.find('h3')
843872
.remove();
844-
Export.toggleQuickOrCustom();
873+
toggleQuickOrCustom();
874+
845875
Export.toggleStructureDataOpts();
846876
Export.toggleSqlIncludeComments();
847877
Export.checkTableSelectAll();

templates/database/export/index.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
{% block selection_options %}
1212
{% if export_type != 'raw' %}
13-
<div class="card mb-3" id="databases_and_tables">
13+
<div class="card mb-3 d-none" id="databases_and_tables">
1414
<div class="card-header">{% trans 'Tables:' %}</div>
1515
<div class="card-body" style="overflow-y: scroll; max-height: 20em;">
1616
<input type="hidden" name="structure_or_data_forced" value="{{ structure_or_data_forced }}">

templates/export.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
{% block selection_options %}{% endblock %}
134134

135135
{% if rows is not empty %}
136-
<div class="card mb-3" id="rows">
136+
<div class="card mb-3 d-none" id="rows">
137137
<div class="card-header">{% trans 'Rows:' %}</div>
138138
<div class="card-body">
139139
<div class="form-check">
@@ -328,7 +328,7 @@
328328
</div>
329329
</div>
330330

331-
<div class="card mb-3" id="output">
331+
<div class="card mb-3 d-none" id="output">
332332
<div class="card-header">{% trans 'Output:' %}</div>
333333
<ul class="list-group list-group-flush">
334334
<li class="list-group-item">
@@ -478,7 +478,7 @@
478478
</ul>
479479
</div>
480480

481-
<div class="card mb-3" id="format_specific_opts">
481+
<div class="card mb-3 d-none" id="format_specific_opts">
482482
<div class="card-header">{% trans 'Format-specific options:' %}</div>
483483
<div class="card-body">
484484
{{ options|raw }}

templates/server/export/index.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% block title %}{% trans 'Exporting databases from the current server' %}{% endblock %}
44

55
{% block selection_options %}
6-
<div class="card mb-3" id="databases_and_tables">
6+
<div class="card mb-3 d-none" id="databases_and_tables">
77
<div class="card-header">{% trans 'Databases' %}</div>
88
<div class="card-body">
99
<div class="mb-3">

0 commit comments

Comments
 (0)