提交 33906f6e 编写于 作者: K Kamran Ahmed

Add callbacks for onNext, onPrevious

上级 de8cc320
/* eslint-disable */ /* eslint-disable */
document.addEventListener("DOMContentLoaded", function () { document.addEventListener('DOMContentLoaded', function () {
const tourSteps = [ const tourSteps = [
{ {
...@@ -8,7 +8,7 @@ document.addEventListener("DOMContentLoaded", function () { ...@@ -8,7 +8,7 @@ document.addEventListener("DOMContentLoaded", function () {
title: 'Before we start', title: 'Before we start',
description: 'This is just one use-case, make sure to check out the rest of the docs below.', description: 'This is just one use-case, make sure to check out the rest of the docs below.',
nextBtnText: 'Okay, Start!' nextBtnText: 'Okay, Start!'
} },
}, { }, {
element: '#logo_emoji', element: '#logo_emoji',
popover: { popover: {
...@@ -102,7 +102,7 @@ document.addEventListener("DOMContentLoaded", function () { ...@@ -102,7 +102,7 @@ document.addEventListener("DOMContentLoaded", function () {
animate: false, animate: false,
opacity: 0.8, opacity: 0.8,
padding: 5, padding: 5,
showButtons: true, showButtons: true
}); });
boringTourDriver.defineSteps(tourSteps); boringTourDriver.defineSteps(tourSteps);
...@@ -145,7 +145,7 @@ document.addEventListener("DOMContentLoaded", function () { ...@@ -145,7 +145,7 @@ document.addEventListener("DOMContentLoaded", function () {
///////////////////////////////////////////// /////////////////////////////////////////////
// Form focus examples // Form focus examples
///////////////////////////////////////////// /////////////////////////////////////////////
const focusDriver = new Driver({padding: 0}); const focusDriver = new Driver({ padding: 0 });
const inputIds = ['creation-input', 'creation-input-2', 'creation-input-3', 'creation-input-4']; const inputIds = ['creation-input', 'creation-input-2', 'creation-input-3', 'creation-input-4'];
inputIds.forEach(inputId => { inputIds.forEach(inputId => {
// Highlight the section on focus // Highlight the section on focus
...@@ -375,7 +375,7 @@ document.addEventListener("DOMContentLoaded", function () { ...@@ -375,7 +375,7 @@ document.addEventListener("DOMContentLoaded", function () {
featureIntroductionDriver.start(); featureIntroductionDriver.start();
}); });
const newURL = location.href.split("?")[0]; const newURL = location.href.split('?')[0];
if (newURL !== location.href) { if (newURL !== location.href) {
window.location = newURL; window.location = newURL;
window.location.href = newURL; window.location.href = newURL;
......
...@@ -45,6 +45,10 @@ export default class Driver { ...@@ -45,6 +45,10 @@ export default class Driver {
}, },
onReset: () => { // When overlay is about to be cleared onReset: () => { // When overlay is about to be cleared
}, },
onNext: () => { // When next button is clicked
},
onPrevious: () => { // When previous button is clicked
},
...options, ...options,
}; };
...@@ -166,12 +170,21 @@ export default class Driver { ...@@ -166,12 +170,21 @@ export default class Driver {
* @public * @public
*/ */
movePrevious() { movePrevious() {
this.currentStep -= 1; const currentStep = this.steps[this.currentStep];
if (this.steps[this.currentStep]) { const previousStep = this.steps[this.currentStep - 1];
this.overlay.highlight(this.steps[this.currentStep]);
} else { if (!previousStep) {
this.reset(); this.reset();
return;
} }
// If there is an event binding on the current step
if (currentStep.options.onPrevious) {
currentStep.options.onPrevious();
}
this.overlay.highlight(previousStep);
this.currentStep -= 1;
} }
/** /**
...@@ -180,12 +193,21 @@ export default class Driver { ...@@ -180,12 +193,21 @@ export default class Driver {
* @public * @public
*/ */
moveNext() { moveNext() {
this.currentStep += 1; const currentStep = this.steps[this.currentStep];
if (this.steps[this.currentStep]) { const nextStep = this.steps[this.currentStep + 1];
this.overlay.highlight(this.steps[this.currentStep]);
} else { if (!nextStep) {
this.reset(); this.reset();
return;
}
// If there is an event binding on the current step
if (currentStep.options.onNext) {
currentStep.options.onNext();
} }
this.overlay.highlight(nextStep);
this.currentStep += 1;
} }
/** /**
...@@ -285,12 +307,10 @@ export default class Driver { ...@@ -285,12 +307,10 @@ export default class Driver {
if (isStepDefinition) { if (isStepDefinition) {
querySelector = currentStep.element; querySelector = currentStep.element;
elementOptions = { elementOptions = { ...this.options, ...currentStep };
...this.options,
...currentStep,
};
} }
// If the given element is a query selector or a DOM element?
const domElement = isDomElement(querySelector) ? querySelector : this.document.querySelector(querySelector); const domElement = isDomElement(querySelector) ? querySelector : this.document.querySelector(querySelector);
if (!domElement) { if (!domElement) {
console.warn(`Element to highlight ${querySelector} not found`); console.warn(`Element to highlight ${querySelector} not found`);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册