Add popover positioning on right bottom
Browse files- demo/scripts/demo.js +3 -3
- src/core/popover.js +20 -0
demo/scripts/demo.js
CHANGED
@@ -8,21 +8,21 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
8 |
title: 'Before we start',
|
9 |
description: 'This is just one use-case, make sure to check out the rest of the docs below.',
|
10 |
nextBtnText: 'Okay, Start!',
|
11 |
-
position: 'right-
|
12 |
},
|
13 |
}, {
|
14 |
element: '#logo_img',
|
15 |
popover: {
|
16 |
title: 'Focus Anything',
|
17 |
description: 'You can use it to highlight literally anything, images, text, div, span, li etc.',
|
18 |
-
position: 'right-
|
19 |
},
|
20 |
}, {
|
21 |
element: '#name_driver',
|
22 |
popover: {
|
23 |
title: 'Why Driver?',
|
24 |
description: 'Because it lets you drive the user across the page',
|
25 |
-
position: 'right-
|
26 |
}
|
27 |
}, {
|
28 |
element: '#driver-demo-head',
|
|
|
8 |
title: 'Before we start',
|
9 |
description: 'This is just one use-case, make sure to check out the rest of the docs below.',
|
10 |
nextBtnText: 'Okay, Start!',
|
11 |
+
position: 'right-bottom'
|
12 |
},
|
13 |
}, {
|
14 |
element: '#logo_img',
|
15 |
popover: {
|
16 |
title: 'Focus Anything',
|
17 |
description: 'You can use it to highlight literally anything, images, text, div, span, li etc.',
|
18 |
+
position: 'right-bottom',
|
19 |
},
|
20 |
}, {
|
21 |
element: '#name_driver',
|
22 |
popover: {
|
23 |
title: 'Why Driver?',
|
24 |
description: 'Because it lets you drive the user across the page',
|
25 |
+
position: 'right-bottom'
|
26 |
}
|
27 |
}, {
|
28 |
element: '#driver-demo-head',
|
src/core/popover.js
CHANGED
@@ -143,6 +143,9 @@ export default class Popover extends Element {
|
|
143 |
case 'right-center':
|
144 |
this.positionOnRightCenter(position);
|
145 |
break;
|
|
|
|
|
|
|
146 |
case 'top':
|
147 |
this.positionOnTop(position);
|
148 |
break;
|
@@ -292,6 +295,23 @@ export default class Popover extends Element {
|
|
292 |
this.tipNode.classList.add('left', 'position-center');
|
293 |
}
|
294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
/**
|
296 |
* Shows the popover on the top of the given position
|
297 |
* @param {Position} elementPosition
|
|
|
143 |
case 'right-center':
|
144 |
this.positionOnRightCenter(position);
|
145 |
break;
|
146 |
+
case 'right-bottom':
|
147 |
+
this.positionOnRightBottom(position);
|
148 |
+
break;
|
149 |
case 'top':
|
150 |
this.positionOnTop(position);
|
151 |
break;
|
|
|
295 |
this.tipNode.classList.add('left', 'position-center');
|
296 |
}
|
297 |
|
298 |
+
/**
|
299 |
+
* Shows the popover on the right of the given position
|
300 |
+
* @param {Position} elementPosition
|
301 |
+
* @private
|
302 |
+
*/
|
303 |
+
positionOnRightBottom(elementPosition) {
|
304 |
+
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
305 |
+
const popoverDimensions = this.getSize();
|
306 |
+
|
307 |
+
this.node.style.left = `${elementPosition.right + popoverMargin}px`;
|
308 |
+
this.node.style.top = `${(elementPosition.bottom + this.options.padding) - popoverDimensions.height}px`;
|
309 |
+
this.node.style.bottom = '';
|
310 |
+
this.node.style.right = '';
|
311 |
+
|
312 |
+
this.tipNode.classList.add('left', 'position-bottom');
|
313 |
+
}
|
314 |
+
|
315 |
/**
|
316 |
* Shows the popover on the top of the given position
|
317 |
* @param {Position} elementPosition
|