Add position on right center
Browse files- demo/scripts/demo.js +3 -3
- src/core/popover.js +27 -2
- src/driver.scss +9 -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: '
|
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: '
|
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: '
|
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-center'
|
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-center',
|
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-center'
|
26 |
}
|
27 |
}, {
|
28 |
element: '#driver-demo-head',
|
src/core/popover.js
CHANGED
@@ -127,6 +127,7 @@ export default class Popover extends Element {
|
|
127 |
// Position the popover around the given position
|
128 |
switch (this.options.position) {
|
129 |
case 'left':
|
|
|
130 |
this.positionOnLeft(position);
|
131 |
break;
|
132 |
case 'left-center':
|
@@ -136,8 +137,12 @@ export default class Popover extends Element {
|
|
136 |
this.positionOnLeftBottom(position);
|
137 |
break;
|
138 |
case 'right':
|
|
|
139 |
this.positionOnRight(position);
|
140 |
break;
|
|
|
|
|
|
|
141 |
case 'top':
|
142 |
this.positionOnTop(position);
|
143 |
break;
|
@@ -238,9 +243,7 @@ export default class Popover extends Element {
|
|
238 |
const popoverCenter = popoverHeight / 2;
|
239 |
|
240 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
241 |
-
|
242 |
const elementCenter = (elementPosition.bottom - elementPosition.top) / 2;
|
243 |
-
|
244 |
const centerPosition = (elementPosition.top - popoverCenter) + elementCenter;
|
245 |
|
246 |
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
@@ -267,6 +270,28 @@ export default class Popover extends Element {
|
|
267 |
this.tipNode.classList.add('left');
|
268 |
}
|
269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
/**
|
271 |
* Shows the popover on the top of the given position
|
272 |
* @param {Position} elementPosition
|
|
|
127 |
// Position the popover around the given position
|
128 |
switch (this.options.position) {
|
129 |
case 'left':
|
130 |
+
case 'left-top':
|
131 |
this.positionOnLeft(position);
|
132 |
break;
|
133 |
case 'left-center':
|
|
|
137 |
this.positionOnLeftBottom(position);
|
138 |
break;
|
139 |
case 'right':
|
140 |
+
case 'right-top':
|
141 |
this.positionOnRight(position);
|
142 |
break;
|
143 |
+
case 'right-center':
|
144 |
+
this.positionOnRightCenter(position);
|
145 |
+
break;
|
146 |
case 'top':
|
147 |
this.positionOnTop(position);
|
148 |
break;
|
|
|
243 |
const popoverCenter = popoverHeight / 2;
|
244 |
|
245 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
|
|
246 |
const elementCenter = (elementPosition.bottom - elementPosition.top) / 2;
|
|
|
247 |
const centerPosition = (elementPosition.top - popoverCenter) + elementCenter;
|
248 |
|
249 |
this.node.style.left = `${elementPosition.left - popoverWidth - popoverMargin}px`;
|
|
|
270 |
this.tipNode.classList.add('left');
|
271 |
}
|
272 |
|
273 |
+
/**
|
274 |
+
* Shows the popover on the right of the given position
|
275 |
+
* @param {Position} elementPosition
|
276 |
+
* @private
|
277 |
+
*/
|
278 |
+
positionOnRightCenter(elementPosition) {
|
279 |
+
const popoverDimensions = this.getSize();
|
280 |
+
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
281 |
+
|
282 |
+
const popoverHeight = popoverDimensions.height;
|
283 |
+
const popoverCenter = popoverHeight / 2;
|
284 |
+
const elementCenter = (elementPosition.bottom - elementPosition.top) / 2;
|
285 |
+
const centerPosition = (elementPosition.top - popoverCenter) + elementCenter;
|
286 |
+
|
287 |
+
this.node.style.left = `${elementPosition.right + popoverMargin}px`;
|
288 |
+
this.node.style.top = `${centerPosition}px`;
|
289 |
+
this.node.style.right = '';
|
290 |
+
this.node.style.bottom = '';
|
291 |
+
|
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
|
src/driver.scss
CHANGED
@@ -47,6 +47,15 @@ div#driver-popover-item {
|
|
47 |
border-right-color: $popover-bg;
|
48 |
border-bottom-color: transparent;
|
49 |
border-left-color: transparent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
}
|
51 |
|
52 |
&.right {
|
|
|
47 |
border-right-color: $popover-bg;
|
48 |
border-bottom-color: transparent;
|
49 |
border-left-color: transparent;
|
50 |
+
|
51 |
+
&.position-center {
|
52 |
+
top: 46%;
|
53 |
+
}
|
54 |
+
|
55 |
+
&.position-bottom {
|
56 |
+
top: auto;
|
57 |
+
bottom: 20px;
|
58 |
+
}
|
59 |
}
|
60 |
|
61 |
&.right {
|