提交 88eeb965 编写于 作者: K Kamran Ahmed

Add functionality to position the popover on mid center

上级 ee16ecaa
...@@ -10,6 +10,7 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -10,6 +10,7 @@ document.addEventListener('DOMContentLoaded', function () {
title: 'Before we start', title: 'Before we start',
description: 'This is just one use-case, make sure to check out the rest of the docs below.', description: 'This is just one use-case, make sure to check out the rest of the docs below.',
nextBtnText: 'Okay, Start!', nextBtnText: 'Okay, Start!',
position: 'mid-center',
}, },
}, { }, {
element: '#logo_img', element: '#logo_img',
......
...@@ -167,6 +167,9 @@ export default class Popover extends Element { ...@@ -167,6 +167,9 @@ export default class Popover extends Element {
case 'bottom-right': case 'bottom-right':
this.positionOnBottomRight(position); this.positionOnBottomRight(position);
break; break;
case 'mid-center':
this.positionOnMidCenter(position);
break;
case 'auto': case 'auto':
default: default:
this.autoPosition(position); this.autoPosition(position);
...@@ -434,6 +437,30 @@ export default class Popover extends Element { ...@@ -434,6 +437,30 @@ export default class Popover extends Element {
this.tipNode.classList.add('top', 'position-right'); this.tipNode.classList.add('top', 'position-right');
} }
/**
* Shows the popover on the mid-center of the given position
* @param {Position} elementPosition
* @private
*/
positionOnMidCenter(elementPosition) {
const popoverDimensions = this.getSize();
const popoverHeight = popoverDimensions.height;
const popoverWidth = popoverDimensions.width / 2;
const popoverCenter = popoverHeight / 2;
const elementCenter = (elementPosition.bottom - elementPosition.top) / 2;
const topCenterPosition = (elementPosition.top - popoverCenter) + elementCenter + this.options.offset;
const nodeCenter = this.options.offset + elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
this.node.style.top = `${topCenterPosition}px`;
this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
this.node.style.right = '';
this.node.style.bottom = '';
// Add the tip at the top center
this.tipNode.classList.add('mid-center');
}
/** /**
* Automatically positions the popover around the given position * Automatically positions the popover around the given position
* such that the element and popover remain in view * such that the element and popover remain in view
......
...@@ -99,6 +99,10 @@ div#driver-popover-item { ...@@ -99,6 +99,10 @@ div#driver-popover-item {
right: 20px; right: 20px;
} }
} }
&.mid-center {
display: none;
}
} }
.driver-popover-footer { .driver-popover-footer {
......
...@@ -555,6 +555,12 @@ declare module 'driver.js' { ...@@ -555,6 +555,12 @@ declare module 'driver.js' {
*/ */
private positionOnBottomRight(position: Driver.Position): void; private positionOnBottomRight(position: Driver.Position): void;
/**
* Positions the popover to the middle center of the given element position
* @param {Driver.Position} position
*/
private positionOnMidCenter(position: Driver.Position): void;
/** /**
* Positions the popover automatically around the element position * Positions the popover automatically around the element position
* @param {Driver.Position} position * @param {Driver.Position} position
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册