Commit 5309108 1 parent b074110 commit 5309108 Copy full SHA for 5309108
File tree 4 files changed +17
-18
lines changed
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 () {
6
6
{
7
7
element : document . getElementById ( 'driver-demo-head' ) ,
8
8
popover : {
9
+ className : 'scoped-driver-popover' ,
9
10
title : 'Before we start' ,
10
11
description : 'This is just one use-case, make sure to check out the rest of the docs below.' ,
11
12
nextBtnText : 'Okay, Start!' ,
@@ -102,6 +103,7 @@ document.addEventListener('DOMContentLoaded', function () {
102
103
opacity : 0.8 ,
103
104
padding : 5 ,
104
105
showButtons : true ,
106
+ className : 'boring-scope' ,
105
107
} ) ;
106
108
107
109
boringTourDriver . defineSteps ( tourSteps ) ;
@@ -331,6 +333,7 @@ document.addEventListener('DOMContentLoaded', function () {
331
333
{
332
334
element : '#first-element-introduction' ,
333
335
popover : {
336
+ className : 'first-step-popover-class' ,
334
337
title : 'Title on Popover' ,
335
338
description : 'Body of the popover' ,
336
339
position : 'top'
Original file line number Diff line number Diff line change 1
1
/**
2
2
* Turn a string into a node
3
3
* @param {String } htmlString to convert
4
- * @return {Node } Converted node element
4
+ * @return {HTMLElement| Node } Converted node element
5
5
*/
6
- // eslint-disable-next-line
7
6
export const createNodeFromString = ( htmlString ) => {
8
7
const div = document . createElement ( 'div' ) ;
9
8
div . innerHTML = htmlString . trim ( ) ;
Original file line number Diff line number Diff line change @@ -38,14 +38,13 @@ export default class Element {
38
38
this . overlay = overlay ;
39
39
this . popover = popover ;
40
40
this . stage = stage ;
41
-
42
41
this . animationTimeout = null ;
43
42
}
44
43
45
44
/**
46
45
* Checks if the current element is visible in viewport
47
46
* @returns {boolean }
48
- * @private
47
+ * @public
49
48
*/
50
49
isInView ( ) {
51
50
let top = this . node . offsetTop ;
@@ -83,10 +82,11 @@ export default class Element {
83
82
84
83
/**
85
84
* Brings the element to middle of the view port if not in view
86
- * @private
85
+ * @public
87
86
*/
88
87
bringInView ( ) {
89
- if ( this . isInView ( ) ) {
88
+ // If the node is not there or already is in view
89
+ if ( ! this . node || this . isInView ( ) ) {
90
90
return ;
91
91
}
92
92
@@ -196,12 +196,6 @@ export default class Element {
196
196
this . addHighlightClasses ( ) ;
197
197
198
198
const highlightedElement = this ;
199
- const popoverElement = this . popover ;
200
-
201
- if ( popoverElement && ! popoverElement . isInView ( ) ) {
202
- popoverElement . bringInView ( ) ;
203
- }
204
-
205
199
if ( ! highlightedElement . isInView ( ) ) {
206
200
highlightedElement . bringInView ( ) ;
207
201
}
Original file line number Diff line number Diff line change @@ -42,9 +42,6 @@ export default class Popover extends Element {
42
42
43
43
this . window = window ;
44
44
this . document = document ;
45
-
46
- this . attachNode ( ) ;
47
- this . hide ( ) ;
48
45
}
49
46
50
47
/**
@@ -53,11 +50,13 @@ export default class Popover extends Element {
53
50
*/
54
51
attachNode ( ) {
55
52
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 ) ;
59
55
}
60
56
57
+ popover = createNodeFromString ( POPOVER_HTML ( this . options . className ) ) ;
58
+ document . body . appendChild ( popover ) ;
59
+
61
60
this . node = popover ;
62
61
this . tipNode = popover . querySelector ( `.${ CLASS_POPOVER_TIP } ` ) ;
63
62
this . titleNode = popover . querySelector ( `.${ CLASS_POPOVER_TITLE } ` ) ;
@@ -117,6 +116,7 @@ export default class Popover extends Element {
117
116
* @public
118
117
*/
119
118
show ( position ) {
119
+ this . attachNode ( ) ;
120
120
this . setInitialState ( ) ;
121
121
122
122
// Set the title and descriptions
@@ -172,6 +172,9 @@ export default class Popover extends Element {
172
172
this . autoPosition ( position ) ;
173
173
break ;
174
174
}
175
+
176
+ // Bring the popover in view port once it is displayed
177
+ this . bringInView ( ) ;
175
178
}
176
179
177
180
/**
You can’t perform that action at this time.
0 commit comments