Dynamic title and descriptions
Browse files- assets/scripts/src/popover.js +17 -5
- assets/scripts/src/sholo.js +6 -3
- index.html +9 -2
assets/scripts/src/popover.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
| 1 |
import Element from './element';
|
| 2 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Popover that is displayed on top of the highlighted element
|
|
@@ -14,11 +21,11 @@ export default class Popover extends Element {
|
|
| 14 |
this.window = window;
|
| 15 |
this.document = document;
|
| 16 |
|
| 17 |
-
this.node = this.
|
| 18 |
this.hide();
|
| 19 |
}
|
| 20 |
|
| 21 |
-
|
| 22 |
let popover = this.document.getElementById(ID_POPOVER);
|
| 23 |
if (popover) {
|
| 24 |
return popover;
|
|
@@ -67,9 +74,14 @@ export default class Popover extends Element {
|
|
| 67 |
show(position) {
|
| 68 |
this.reset();
|
| 69 |
|
| 70 |
-
const pageHeight = this.getFullPageSize().height;
|
| 71 |
-
|
| 72 |
const popoverTip = this.node.querySelector(`.${CLASS_POPOVER_TIP}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
const popoverMargin = this.options.padding + 10;
|
| 74 |
const popoverHeight = this.getHeight();
|
| 75 |
|
|
|
|
| 1 |
import Element from './element';
|
| 2 |
+
import {
|
| 3 |
+
CLASS_POPOVER_DESCRIPTION,
|
| 4 |
+
CLASS_POPOVER_TIP,
|
| 5 |
+
CLASS_POPOVER_TITLE,
|
| 6 |
+
ID_POPOVER,
|
| 7 |
+
OVERLAY_PADDING,
|
| 8 |
+
POPOVER_HTML,
|
| 9 |
+
} from './constants';
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Popover that is displayed on top of the highlighted element
|
|
|
|
| 21 |
this.window = window;
|
| 22 |
this.document = document;
|
| 23 |
|
| 24 |
+
this.node = this.makeNode();
|
| 25 |
this.hide();
|
| 26 |
}
|
| 27 |
|
| 28 |
+
makeNode() {
|
| 29 |
let popover = this.document.getElementById(ID_POPOVER);
|
| 30 |
if (popover) {
|
| 31 |
return popover;
|
|
|
|
| 74 |
show(position) {
|
| 75 |
this.reset();
|
| 76 |
|
|
|
|
|
|
|
| 77 |
const popoverTip = this.node.querySelector(`.${CLASS_POPOVER_TIP}`);
|
| 78 |
+
const popoverTitle = this.node.querySelector(`.${CLASS_POPOVER_TITLE}`);
|
| 79 |
+
const popoverDescription = this.node.querySelector(`.${CLASS_POPOVER_DESCRIPTION}`);
|
| 80 |
+
|
| 81 |
+
popoverTitle.innerText = this.options.title;
|
| 82 |
+
popoverDescription.innerText = this.options.description;
|
| 83 |
+
|
| 84 |
+
const pageHeight = this.getFullPageSize().height;
|
| 85 |
const popoverMargin = this.options.padding + 10;
|
| 86 |
const popoverHeight = this.getHeight();
|
| 87 |
|
assets/scripts/src/sholo.js
CHANGED
|
@@ -176,15 +176,18 @@ export default class Sholo {
|
|
| 176 |
}
|
| 177 |
|
| 178 |
const elementOptions = Object.assign({}, this.options, step);
|
| 179 |
-
const popoverOptions = Object.assign({}, this.options, elementOptions.popover || {});
|
| 180 |
-
|
| 181 |
const domElement = this.document.querySelector(step.element);
|
| 182 |
if (!domElement) {
|
| 183 |
console.warn(`Element to highlight ${step.element} not found`);
|
| 184 |
return;
|
| 185 |
}
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
const element = new Element(domElement, elementOptions, popover, this.overlay, this.window, this.document);
|
| 189 |
|
| 190 |
this.steps.push(element);
|
|
|
|
| 176 |
}
|
| 177 |
|
| 178 |
const elementOptions = Object.assign({}, this.options, step);
|
|
|
|
|
|
|
| 179 |
const domElement = this.document.querySelector(step.element);
|
| 180 |
if (!domElement) {
|
| 181 |
console.warn(`Element to highlight ${step.element} not found`);
|
| 182 |
return;
|
| 183 |
}
|
| 184 |
|
| 185 |
+
let popover = null;
|
| 186 |
+
const popoverOptions = Object.assign({}, this.options, elementOptions.popover || {});
|
| 187 |
+
if (elementOptions.popover && elementOptions.popover.description) {
|
| 188 |
+
popover = new Popover(popoverOptions, this.window, this.document);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
const element = new Element(domElement, elementOptions, popover, this.overlay, this.window, this.document);
|
| 192 |
|
| 193 |
this.steps.push(element);
|
index.html
CHANGED
|
@@ -65,11 +65,18 @@
|
|
| 65 |
|
| 66 |
sholo.defineSteps([
|
| 67 |
{
|
| 68 |
-
element: '.section__header'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
},
|
| 70 |
{
|
| 71 |
element: '.section__how',
|
| 72 |
-
popover: {
|
|
|
|
|
|
|
|
|
|
| 73 |
},
|
| 74 |
{
|
| 75 |
element: '.section__purpose',
|
|
|
|
| 65 |
|
| 66 |
sholo.defineSteps([
|
| 67 |
{
|
| 68 |
+
element: '.section__header',
|
| 69 |
+
popover: {
|
| 70 |
+
title: 'Adding Introductions',
|
| 71 |
+
description: 'You can use it to add popovers on top of the website'
|
| 72 |
+
},
|
| 73 |
},
|
| 74 |
{
|
| 75 |
element: '.section__how',
|
| 76 |
+
popover: {
|
| 77 |
+
title: 'Just Specify the Item',
|
| 78 |
+
description: 'All you have to do is provide the query selector of element to highlight'
|
| 79 |
+
},
|
| 80 |
},
|
| 81 |
{
|
| 82 |
element: '.section__purpose',
|