File tree Expand file tree Collapse file tree 4 files changed +17
-18
lines changed
Expand file tree Collapse file tree 4 files changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ document.addEventListener('DOMContentLoaded', function () {
66 {
77 element : document . getElementById ( 'driver-demo-head' ) ,
88 popover : {
9+ className : 'scoped-driver-popover' ,
910 title : 'Before we start' ,
1011 description : 'This is just one use-case, make sure to check out the rest of the docs below.' ,
1112 nextBtnText : 'Okay, Start!' ,
@@ -102,6 +103,7 @@ document.addEventListener('DOMContentLoaded', function () {
102103 opacity : 0.8 ,
103104 padding : 5 ,
104105 showButtons : true ,
106+ className : 'boring-scope' ,
105107 } ) ;
106108
107109 boringTourDriver . defineSteps ( tourSteps ) ;
@@ -331,6 +333,7 @@ document.addEventListener('DOMContentLoaded', function () {
331333 {
332334 element : '#first-element-introduction' ,
333335 popover : {
336+ className : 'first-step-popover-class' ,
334337 title : 'Title on Popover' ,
335338 description : 'Body of the popover' ,
336339 position : 'top'
Original file line number Diff line number Diff line change 11/**
22 * Turn a string into a node
33 * @param {String } htmlString to convert
4- * @return {Node } Converted node element
4+ * @return {HTMLElement| Node } Converted node element
55 */
6- // eslint-disable-next-line
76export const createNodeFromString = ( htmlString ) => {
87 const div = document . createElement ( 'div' ) ;
98 div . innerHTML = htmlString . trim ( ) ;
Original file line number Diff line number Diff line change @@ -38,14 +38,13 @@ export default class Element {
3838 this . overlay = overlay ;
3939 this . popover = popover ;
4040 this . stage = stage ;
41-
4241 this . animationTimeout = null ;
4342 }
4443
4544 /**
4645 * Checks if the current element is visible in viewport
4746 * @returns {boolean }
48- * @private
47+ * @public
4948 */
5049 isInView ( ) {
5150 let top = this . node . offsetTop ;
@@ -83,10 +82,11 @@ export default class Element {
8382
8483 /**
8584 * Brings the element to middle of the view port if not in view
86- * @private
85+ * @public
8786 */
8887 bringInView ( ) {
89- if ( this . isInView ( ) ) {
88+ // If the node is not there or already is in view
89+ if ( ! this . node || this . isInView ( ) ) {
9090 return ;
9191 }
9292
@@ -196,12 +196,6 @@ export default class Element {
196196 this . addHighlightClasses ( ) ;
197197
198198 const highlightedElement = this ;
199- const popoverElement = this . popover ;
200-
201- if ( popoverElement && ! popoverElement . isInView ( ) ) {
202- popoverElement . bringInView ( ) ;
203- }
204-
205199 if ( ! highlightedElement . isInView ( ) ) {
206200 highlightedElement . bringInView ( ) ;
207201 }
Original file line number Diff line number Diff line change @@ -42,9 +42,6 @@ export default class Popover extends Element {
4242
4343 this . window = window ;
4444 this . document = document ;
45-
46- this . attachNode ( ) ;
47- this . hide ( ) ;
4845 }
4946
5047 /**
@@ -53,11 +50,13 @@ export default class Popover extends Element {
5350 */
5451 attachNode ( ) {
5552 let popover = this . document . getElementById ( ID_POPOVER ) ;
56- if ( ! popover ) {
57- popover = createNodeFromString ( POPOVER_HTML ( this . options . className ) ) ;
58- document . body . appendChild ( popover ) ;
53+ if ( popover ) {
54+ popover . parentElement . removeChild ( popover ) ;
5955 }
6056
57+ popover = createNodeFromString ( POPOVER_HTML ( this . options . className ) ) ;
58+ document . body . appendChild ( popover ) ;
59+
6160 this . node = popover ;
6261 this . tipNode = popover . querySelector ( `.${ CLASS_POPOVER_TIP } ` ) ;
6362 this . titleNode = popover . querySelector ( `.${ CLASS_POPOVER_TITLE } ` ) ;
@@ -117,6 +116,7 @@ export default class Popover extends Element {
117116 * @public
118117 */
119118 show ( position ) {
119+ this . attachNode ( ) ;
120120 this . setInitialState ( ) ;
121121
122122 // Set the title and descriptions
@@ -172,6 +172,9 @@ export default class Popover extends Element {
172172 this . autoPosition ( position ) ;
173173 break ;
174174 }
175+
176+ // Bring the popover in view port once it is displayed
177+ this . bringInView ( ) ;
175178 }
176179
177180 /**
You can’t perform that action at this time.
0 commit comments