kamrify commited on
Commit
1d58af6
·
1 Parent(s): 88df282

Position on bottom center

Browse files
demo/scripts/demo.js CHANGED
@@ -7,14 +7,15 @@ document.addEventListener('DOMContentLoaded', function () {
7
  popover: {
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
  },
12
  }, {
13
  element: '#logo_img',
14
  popover: {
15
  title: 'Focus Anything',
16
  description: 'You can use it to highlight literally anything, images, text, div, span, li etc.',
17
- position: 'bottom'
18
  },
19
  }, {
20
  element: '#name_driver',
 
7
  popover: {
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: 'bottom-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: 'bottom-center',
19
  },
20
  }, {
21
  element: '#name_driver',
src/core/element.js CHANGED
@@ -111,6 +111,7 @@ export default class Element {
111
  * Gets the calculated position on screen, around which
112
  * we need to draw
113
  * @public
 
114
  */
115
  getCalculatedPosition() {
116
  const body = this.document.body;
 
111
  * Gets the calculated position on screen, around which
112
  * we need to draw
113
  * @public
114
+ * @return {Position}
115
  */
116
  getCalculatedPosition() {
117
  const body = this.document.body;
src/core/popover.js CHANGED
@@ -136,8 +136,12 @@ export default class Popover extends Element {
136
  this.positionOnTop(position);
137
  break;
138
  case 'bottom':
 
139
  this.positionOnBottom(position);
140
  break;
 
 
 
141
  case 'auto':
142
  default:
143
  this.autoPosition(position);
@@ -242,6 +246,25 @@ export default class Popover extends Element {
242
  this.tipNode.classList.add('top');
243
  }
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  /**
246
  * Automatically positions the popover around the given position
247
  * such that the element and popover remain in view
 
136
  this.positionOnTop(position);
137
  break;
138
  case 'bottom':
139
+ case 'bottom-left':
140
  this.positionOnBottom(position);
141
  break;
142
+ case 'bottom-center':
143
+ this.positionOnBottomCenter(position);
144
+ break;
145
  case 'auto':
146
  default:
147
  this.autoPosition(position);
 
246
  this.tipNode.classList.add('top');
247
  }
248
 
249
+ /**
250
+ * Shows the popover on the bottom-center of the given position
251
+ * @param {Position} elementPosition
252
+ * @private
253
+ */
254
+ positionOnBottomCenter(elementPosition) {
255
+ const popoverWidth = this.getSize().width / 2;
256
+ const nodeCenter = elementPosition.left + ((elementPosition.right - elementPosition.left) / 2);
257
+ const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
258
+
259
+ this.node.style.top = `${elementPosition.bottom + popoverMargin}px`;
260
+ this.node.style.left = `${nodeCenter - popoverWidth - this.options.padding}px`;
261
+ this.node.style.right = '';
262
+ this.node.style.bottom = '';
263
+
264
+ // Add the tip at the top center
265
+ this.tipNode.classList.add('top', 'center');
266
+ }
267
+
268
  /**
269
  * Automatically positions the popover around the given position
270
  * such that the element and popover remain in view
src/driver.scss CHANGED
@@ -65,6 +65,10 @@ div#driver-popover-item {
65
  border-bottom-color: $popover-bg;
66
  border-left-color: transparent;
67
  }
 
 
 
 
68
  }
69
 
70
  .driver-popover-footer {
 
65
  border-bottom-color: $popover-bg;
66
  border-left-color: transparent;
67
  }
68
+
69
+ &.center {
70
+ left: 49%;
71
+ }
72
  }
73
 
74
  .driver-popover-footer {