Skip to content

Commit 83a7dfa

Browse files
committed
Init.
1 parent 570813b commit 83a7dfa

File tree

10 files changed

+147
-8
lines changed

10 files changed

+147
-8
lines changed

build/cjs/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/esm/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

demo/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ Gleap.on("tool-execution", (tool) => {
3535
3636
Gleap.setTicketAttribute("notes", "This is a test value.");*/
3737

38-
Gleap.initialize("ogWhNhuiZcGWrva5nlDS8l7a78OfaLlV");
38+
Gleap.initialize("Vx0SXWPHGU7Af54CabNL07k6HRELKTxu");

package-lock.json

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
},
7272
"dependencies": {
7373
"pick-dom-element": "^0.2.3",
74+
"tippy.js": "^6.3.7",
7475
"unique-selector": "^0.5.0"
7576
}
7677
}

published/13.5.16/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

published/latest/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GleapAdminManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export default class GleapAdminManager {
226226
var elem = document.createElement("div");
227227
elem.className =
228228
"gleap-admin-frame-container";
229-
elem.innerHTML = `<iframe src="https://app.gleap.io/producttourbuilder" class="gleap-admin-frame" scrolling="no" title="Gleap Admin Window" allow="autoplay; encrypted-media; fullscreen;" frameborder="0"></iframe>`;
229+
elem.innerHTML = `<iframe src="http://localhost:4200/${this?.configData?.type === 'tooltips' ? 'tooltipbuilder' : 'producttourbuilder'}" class="gleap-admin-frame" scrolling="no" title="Gleap Admin Window" allow="autoplay; encrypted-media; fullscreen;" frameborder="0"></iframe>`;
230230
document.body.appendChild(elem);
231231

232232
this.gleapFrameContainer = elem;

src/GleapSession.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GleapEventManager, GleapTranslationManager, GleapFrameManager, GleapNotificationManager, GleapStreamedEvent, GleapBannerManager } from "./Gleap";
22
import { eraseGleapCookie, getGleapCookie, loadFromGleapCache, saveToGleapCache, setGleapCookie } from "./GleapHelper";
3+
import GleapTooltipManager from "./GleapTooltipManager";
34

45
export default class GleapSession {
56
apiUrl = "https://api.gleap.io";
@@ -201,6 +202,9 @@ export default class GleapSession {
201202

202203
// Initially track.
203204
GleapStreamedEvent.getInstance().restart();
205+
206+
// Load tooltips.
207+
GleapTooltipManager.getInstance().load();
204208
} catch (exp) { }
205209
} else {
206210
if (http.status !== 429) {
@@ -341,6 +345,8 @@ export default class GleapSession {
341345
// Initially track.
342346
GleapStreamedEvent.getInstance().restart();
343347

348+
// Load tooltips.
349+
GleapTooltipManager.getInstance().load();
344350
resolve(sessionData);
345351
} catch (exp) {
346352
reject(exp);

src/GleapTooltipManager.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import tippy from 'tippy.js';
2+
import 'tippy.js/dist/tippy.css';
3+
import 'tippy.js/themes/light.css';
4+
import { GleapSession } from './Gleap';
5+
6+
export default class GleapTooltipManager {
7+
tooltips = [];
8+
tippyInstances = {};
9+
nextId = 0;
10+
11+
// GleapTooltipManager singleton
12+
static instance;
13+
static getInstance() {
14+
if (!this.instance) {
15+
this.instance = new GleapTooltipManager();
16+
}
17+
return this.instance;
18+
}
19+
20+
linkTooltip = (element, tooltip) => {
21+
if (element.hasAttribute('data-gleap-tooltip')) {
22+
return;
23+
}
24+
25+
const nextId = this.nextId++;
26+
element.setAttribute('data-gleap-tooltip', nextId);
27+
if (element) {
28+
var tooltipElem = null;
29+
30+
if (tooltip.mode === 'hotspot') {
31+
// Create hotspot.
32+
const hotspot = document.createElement('div');
33+
hotspot.style.position = 'absolute';
34+
hotspot.style.width = '22px';
35+
hotspot.style.height = '22px';
36+
hotspot.style.backgroundColor = 'red';
37+
hotspot.style.borderRadius = '22px';
38+
hotspot.style.cursor = 'pointer';
39+
hotspot.style.top = '50%';
40+
hotspot.style.left = '100%';
41+
hotspot.style.transform = 'translate(-50%, -50%)';
42+
hotspot.style.zIndex = '9999';
43+
hotspot.style.display = 'block';
44+
hotspot.style.pointerEvents = 'all';
45+
46+
element.parentNode.insertBefore(hotspot, element.nextSibling);
47+
48+
// Make element position relative.
49+
element.parentNode.style.position = 'relative';
50+
51+
tooltipElem = hotspot;
52+
} else {
53+
// Create tooltip.
54+
tooltipElem = element;
55+
}
56+
57+
const tippyInstance = tippy(tooltipElem, {
58+
content: tooltip.html,
59+
allowHTML: true,
60+
interactive: true,
61+
theme: 'light',
62+
});
63+
64+
this.tippyInstances[nextId] = tippyInstance;
65+
}
66+
}
67+
68+
createTooltips = () => {
69+
for (let i = 0; i < this.tooltips.length; i++) {
70+
const tooltip = this.tooltips[i];
71+
const elements = document.querySelectorAll(tooltip.selector);
72+
73+
for (let j = 0; j < elements.length; j++) {
74+
const element = elements[j];
75+
76+
if (element) {
77+
this.linkTooltip(element, tooltip);
78+
}
79+
}
80+
}
81+
}
82+
83+
load = () => {
84+
const self = this;
85+
const sessionInstance = GleapSession.getInstance();
86+
87+
const http = new XMLHttpRequest();
88+
http.open("GET", sessionInstance.apiUrl + "/config/" + sessionInstance.sdkKey + "/tooltips");
89+
http.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
90+
http.setRequestHeader("Api-Token", sessionInstance.sdkKey);
91+
try {
92+
http.setRequestHeader("Gleap-Id", sessionInstance.session.gleapId);
93+
http.setRequestHeader("Gleap-Hash", sessionInstance.session.gleapHash);
94+
} catch (exp) { }
95+
96+
http.onerror = () => {
97+
console.error("Failed to fetch tooltips");
98+
};
99+
http.onreadystatechange = function (e) {
100+
if (http.readyState === 4) {
101+
if (http.status === 200) {
102+
try {
103+
self.tooltips = JSON.parse(http.responseText);
104+
self.createTooltips();
105+
} catch (exp) {
106+
console.error("Failed to parse tooltips", exp);
107+
}
108+
}
109+
}
110+
};
111+
112+
http.send();
113+
};
114+
}

0 commit comments

Comments
 (0)