Skip to content

Commit b153b89

Browse files
adamcarhedenMarkusBordihn
authored andcommitted
Made tutorial Continue button scroll to next step (#187)
1 parent 91ca946 commit b153b89

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/ui/tutorial/tutorial.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ cwc.ui.Tutorial = function(helper) {
109109

110110
/** @private {cwc.ui.TutorialValidator} */
111111
this.validator_ = null;
112+
113+
/** @private {Element} */
114+
this.rootNode_ = null;
112115
};
113116

114117
/**
@@ -440,7 +443,9 @@ cwc.ui.Tutorial.prototype.startTutorial = function() {
440443
video['youtube_id']
441444
),
442445
})),
443-
});
446+
}
447+
);
448+
this.rootNode_ = goog.dom.getElement(this.prefix + 'container');
444449
}
445450

446451
this.state_ = {
@@ -494,8 +499,8 @@ cwc.ui.Tutorial.prototype.initMediaOverlay_ = function() {
494499
*/
495500
cwc.ui.Tutorial.prototype.initMedia_ = function() {
496501
this.initMediaOverlay_();
497-
let rootNode = goog.dom.getElement(this.prefix + 'container');
498-
let nodeListImages = rootNode.querySelectorAll('.js-project-step-image');
502+
let nodeListImages = this.rootNode_.querySelectorAll(
503+
'.js-project-step-image');
499504
if (this.imagesDb_) {
500505
[].forEach.call(nodeListImages, (image) => {
501506
let imageSrc = image.getAttribute('data-src');
@@ -572,6 +577,7 @@ cwc.ui.Tutorial.prototype.completeCurrentStep_ = function() {
572577
activeStepID: nextStep.id,
573578
inProgressStepID: nextStep.id,
574579
});
580+
this.scrollToStep_();
575581
};
576582

577583
/**
@@ -589,6 +595,29 @@ cwc.ui.Tutorial.prototype.jumpToStep_ = function(stepID) {
589595
}
590596
};
591597

598+
599+
/**
600+
* Scrolls the tutorial to the top of the given step
601+
* @param {number} stepID
602+
* @private
603+
*/
604+
cwc.ui.Tutorial.prototype.scrollToStep_ = function(stepID) {
605+
if (stepID === undefined) {
606+
stepID = this.getActiveStep_().id;
607+
}
608+
let step = goog.dom.getElement(this.prefix + 'step-'+stepID);
609+
if (!(step && this.rootNode_)) {
610+
this.log_.warn('Failed to find root and/or step elements');
611+
return;
612+
}
613+
if (!this.rootNode_.contains(step)) {
614+
this.log_.error('step', stepID, 'isn\'t a child of ',
615+
this.prefix+'container. Can\'t scroll to it.');
616+
return;
617+
}
618+
this.rootNode_.scrollTop = step.offsetTop - this.rootNode_.offsetTop;
619+
};
620+
592621
/**
593622
* @private
594623
* @return {!Object}

0 commit comments

Comments
 (0)