@@ -109,6 +109,9 @@ cwc.ui.Tutorial = function(helper) {
109
109
110
110
/** @private {cwc.ui.TutorialValidator} */
111
111
this . validator_ = null ;
112
+
113
+ /** @private {Element} */
114
+ this . rootNode_ = null ;
112
115
} ;
113
116
114
117
/**
@@ -440,7 +443,9 @@ cwc.ui.Tutorial.prototype.startTutorial = function() {
440
443
video [ 'youtube_id' ]
441
444
) ,
442
445
} ) ) ,
443
- } ) ;
446
+ }
447
+ ) ;
448
+ this . rootNode_ = goog . dom . getElement ( this . prefix + 'container' ) ;
444
449
}
445
450
446
451
this . state_ = {
@@ -494,8 +499,8 @@ cwc.ui.Tutorial.prototype.initMediaOverlay_ = function() {
494
499
*/
495
500
cwc . ui . Tutorial . prototype . initMedia_ = function ( ) {
496
501
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' ) ;
499
504
if ( this . imagesDb_ ) {
500
505
[ ] . forEach . call ( nodeListImages , ( image ) => {
501
506
let imageSrc = image . getAttribute ( 'data-src' ) ;
@@ -572,6 +577,7 @@ cwc.ui.Tutorial.prototype.completeCurrentStep_ = function() {
572
577
activeStepID : nextStep . id ,
573
578
inProgressStepID : nextStep . id ,
574
579
} ) ;
580
+ this . scrollToStep_ ( ) ;
575
581
} ;
576
582
577
583
/**
@@ -589,6 +595,29 @@ cwc.ui.Tutorial.prototype.jumpToStep_ = function(stepID) {
589
595
}
590
596
} ;
591
597
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
+
592
621
/**
593
622
* @private
594
623
* @return {!Object }
0 commit comments