From a6573bd508bb351c77fff56a691c7b99fecc2ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Tue, 25 Apr 2017 15:33:07 +0200 Subject: [PATCH] Next button is now always focused when navigating through tutorial steps. [fixes SCI-719] --- app/assets/javascripts/sitewide/utils.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/sitewide/utils.js b/app/assets/javascripts/sitewide/utils.js index 0a005b527..db1a8b507 100644 --- a/app/assets/javascripts/sitewide/utils.js +++ b/app/assets/javascripts/sitewide/utils.js @@ -90,9 +90,11 @@ function initPageTutorialSteps(pageFirstStepN, pageLastStepN, nextPagePath, beforeCb(); // Initialize tutorial for the current pages' steps - var doneLabel = (pageLastStepN === TUTORIAL_STEPS_CNT) ? - 'Start using sciNote' : 'End tutorial'; + var isLastStep = pageLastStepN == TUTORIAL_STEPS_CNT; + var doneLabel = isLastStep ? 'Start using sciNote' : 'End tutorial'; if (_.isUndefined(steps)) { + // This approach (tutorial data separately in ERB) shouldn't be used, + // because it's buggy and inconvenient introJs() .setOptions({ overlayOpacity: '0.2', @@ -121,11 +123,13 @@ function initPageTutorialSteps(pageFirstStepN, pageLastStepN, nextPagePath, }) .start(); } else { - if (pageFirstStepN === pageLastStepN) { - // Only one page step, so add another fake one, so the back and next - // buttons are added to the popup + if (!isLastStep) { + // Add extra fake step, so that next button on last step of current page + // gets focused. Also, if current page has only one step, this adds back + // and next buttons to the popup. steps.push({}); } + introJs() .setOptions({ overlayOpacity: '0.2', @@ -142,20 +146,16 @@ function initPageTutorialSteps(pageFirstStepN, pageLastStepN, nextPagePath, tooltipClass: 'custom next-page-link', steps: steps }) - .onexit(function() { - location.reload(); - }) - .oncomplete(function() { - location.reload(); - }) .goToStep(stepNum - (pageFirstStepN - 1)) .onexit(function() { Cookies.remove('tutorial_data'); Cookies.remove('current_tutorial_step'); + location.reload(); }) .oncomplete(function() { Cookies.remove('tutorial_data'); Cookies.remove('current_tutorial_step'); + location.reload(); }) .start(); }