Refactored and added back button for tutorial for step 18. Tutorial function now also works with one page step.

This commit is contained in:
Matej Zrimšek 2016-11-16 14:31:50 +01:00
parent 00ed91e856
commit 47c1308ba6
2 changed files with 44 additions and 81 deletions

View file

@ -16,6 +16,31 @@
var checkedReports = []; var checkedReports = [];
/**
* Initializes page
*/
function init() {
// Initialize selectors
newReportModal = $('#new-report-modal');
newReportModalBody = newReportModal.find('.modal-body');
newReportCreateButton = $('#create-new-report-btn');
deleteReportsModal = $('#delete-reports-modal');
deleteReportsInput = $('#report-ids');
newReportButton = $('#new-report-btn');
editReportButton = $('#edit-report-btn');
deleteReportsButton = $('#delete-reports-btn');
checkAll = $('.check-all-reports');
allChecks = $('.check-report');
allRows = $('.report-row');
initNewReportModal();
initCheckboxesAndEditing();
updateButtons();
initEditReport();
initDeleteReports();
initTutorial();
}
/** /**
* Initialize the new report modal. * Initialize the new report modal.
*/ */
@ -138,88 +163,21 @@
}); });
} }
/* Initilize first-time tutorial if needed */ /**
* Initializes tutorial
*/
function initTutorial() { function initTutorial() {
var currentStep = Cookies.get('current_tutorial_step'); var nextPage = $('#new-report-btn').attr('href');
if (showTutorial() && (currentStep > 17 && currentStep < 20)) { var steps = [
var reportsClickNewReportTutorial = $("#content").attr("data-reports-click-new-report-step-text"); {
introJs() element: $('#new-report-btn')[0],
.setOptions({ intro: $('#content').attr('data-reports-click-new-report-step-text'),
steps: [ position: 'right'
{}, }
{ ];
element: document.getElementById("new-report-btn"), initPageTutorialSteps(18, 18, nextPage, function() {}, function() {},
intro: reportsClickNewReportTutorial, steps);
position: 'right',
tooltipClass: "custom next-page-link"
}
],
overlayOpacity: '0.1',
nextLabel: 'Next',
doneLabel: 'End tutorial',
skipLabel: 'End tutorial',
showBullets: false,
showStepNumbers: false,
exitOnOverlayClick: false,
exitOnEsc: false,
tooltipClass: 'custom'
})
.onafterchange(function (tarEl) {
Cookies.set('current_tutorial_step', this._currentStep + 18);
if (this._currentStep == 1) {
setTimeout(function() {
$('.next-page-link a.introjs-nextbutton')
.removeClass('introjs-disabled')
.attr('href', tarEl.href);
}, 500);
}
})
.goToStep(2)
.start();
// Destroy first-time tutorial cookies when skip tutorial
// or end tutorial is clicked
$(".introjs-skipbutton").each(function (){
$(this).click(function (){
Cookies.remove('tutorial_data');
Cookies.remove('current_tutorial_step');
});
});
}
} }
function showTutorial() { $(document).ready(init);
var tutorialData;
if (Cookies.get('tutorial_data'))
tutorialData = JSON.parse(Cookies.get('tutorial_data'));
else
return false;
var tutorialProjectId = tutorialData[0].project;
var currentProjectId = $(".report-table").attr("data-project-id");
return tutorialProjectId == currentProjectId;
}
$(document).ready(function() {
// Initialize selectors
newReportModal = $("#new-report-modal");
newReportModalBody = newReportModal.find(".modal-body");
newReportCreateButton = $("#create-new-report-btn");
deleteReportsModal = $("#delete-reports-modal");
deleteReportsInput = $("#report-ids");
newReportButton = $("#new-report-btn");
editReportButton = $("#edit-report-btn");
deleteReportsButton = $("#delete-reports-btn");
checkAll = $(".check-all-reports");
allChecks = $(".check-report");
allRows = $(".report-row");
initNewReportModal();
initCheckboxesAndEditing();
updateButtons();
initEditReport();
initDeleteReports();
initTutorial();
});
}()); }());

View file

@ -104,6 +104,11 @@ function initPageTutorialSteps(pageFirstStep, pageLastStep, nextPagePath,
.goToStep(stepNum - (pageFirstStep - 1)) .goToStep(stepNum - (pageFirstStep - 1))
.start(); .start();
} else { } else {
if (pageFirstStep === pageLastStep) {
// Only one page step, so add another fake one, so the back and next
// buttons are added to the popup
steps.push({});
}
introJs() introJs()
.setOptions({ .setOptions({
overlayOpacity: '0.2', overlayOpacity: '0.2',