auto-select the first option for each row

pull/11399/head
Peixuan Ding 2021-05-14 01:40:40 -04:00
parent 28915b0ca2
commit cc0d0652c5
2 changed files with 9 additions and 13 deletions

View File

@ -55,7 +55,7 @@ Click on the buttons that describe your target platform:
{{% /quiz_row %}}
{{% quiz_row base="/macOS/x86-64" name="Installer type" %}}
{{% quiz_button option="Homebrew" %}} {{% quiz_button option="Binary download" %}}
{{% quiz_button option="Binary download" %}} {{% quiz_button option="Homebrew" %}}
{{% /quiz_row %}}
{{% quiz_row base="/macOS/ARM64" name="Installer type" %}}
@ -67,7 +67,7 @@ Click on the buttons that describe your target platform:
{{% /quiz_row %}}
{{% quiz_row base="/Windows/x86-64" name="Installer type" %}}
{{% quiz_button option="Windows Package Manager" %}} {{% quiz_button option="Chocolatey" %}} {{% quiz_button option=".exe download" %}}
{{% quiz_button option=".exe download" %}} {{% quiz_button option="Windows Package Manager" %}} {{% quiz_button option="Chocolatey" %}}
{{% /quiz_row %}}
{{% quiz_instruction id="/Linux/x86-64/Binary download" %}}

View File

@ -21,9 +21,9 @@ function selectQuizOption(selectedId) {
$('.quiz-instruction[data-quiz-id=\'' + selectedId + '\']').removeClass('hide');
const buttons = $('.option-row[data-quiz-id=\'' + selectedId + '\']').find('.option-button');
// if there is only one option, auto-select that option for the user
if (buttons.length === 1) {
const btn = $(buttons[0]);
// auto-select the first option for the user, to reduce the number of clicks
if (buttons.length > 0) {
const btn = buttons.first();
btn.addClass('active');
selectQuizOption(btn.attr('data-quiz-id'));
}
@ -39,15 +39,11 @@ function initQuiz() {
selectQuizOption(dataContainerId);
});
const userOS = getQuizUserOS();
const buttons = $('.option-button[data-quiz-id=\'/' + userOS + '\']');
if (buttons.length === 1) {
const btn = $(buttons[0]);
btn.addClass('active');
selectQuizOption(btn.attr('data-quiz-id'));
}
// auto-select the OS for user
const btn = $('.option-button[data-quiz-id=\'/' + userOS + '\']').first();
btn.addClass('active');
selectQuizOption(btn.attr('data-quiz-id'));
} catch(e) {
console.log(e);
const elements = document.getElementsByClassName("quiz-instruction");
for (let element of elements) {
element.classList.remove("hide");