Skip to content

Commit 40300b8

Browse files
committed
v7.0.29
1 parent e7db246 commit 40300b8

File tree

9 files changed

+54
-63
lines changed

9 files changed

+54
-63
lines changed

build/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.

demo/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Gleap = window.Gleap;
33
// Gleap.setFrameUrl("http://localhost:3001");
44
// Gleap.setLanguage("en");
55
// Gleap.setApiUrl("http://localhost:9000");
6-
Gleap.initialize("KProDXhMS0V3UUku2iNnrZ4XsBnAYzxt");
6+
Gleap.initialize("ogWhNhuiZcGWrva5nlDS8l7a78OfaLlV");
77

88
Gleap.identify("user_19283", {
99
name: "Franz",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gleap",
3-
"version": "7.0.28",
3+
"version": "7.0.29",
44
"main": "build/index.js",
55
"scripts": {
66
"start": "webpack serve",

published/7.0.29/index.js

Lines changed: 1 addition & 0 deletions
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/Gleap.js

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { injectStyledCSS } from "./UI";
22
import GleapNetworkIntercepter from "./GleapNetworkIntercepter";
3-
import { gleapDataParser } from "./GleapHelper";
3+
import { gleapDataParser, runFunctionWhenDomIsReady } from "./GleapHelper";
44
import GleapSession from "./GleapSession";
55
import GleapStreamedEvent from "./GleapStreamedEvent";
66
import GleapConfigManager from "./GleapConfigManager";
@@ -117,17 +117,8 @@ class Gleap {
117117
// Run auto configuration.
118118
GleapConfigManager.getInstance().start()
119119
.then(() => {
120-
if (
121-
document.readyState === "complete" ||
122-
document.readyState === "loaded" ||
123-
document.readyState === "interactive"
124-
) {
125-
instance.postInitialization();
126-
} else {
127-
document.addEventListener("DOMContentLoaded", function (event) {
128-
instance.postInitialization();
129-
});
130-
}
120+
// Inject the Gleap frame.
121+
GleapFrameManager.getInstance().injectFrame();
131122
})
132123
.catch(function (err) {
133124
console.warn("Failed to initialize Gleap.");
@@ -333,29 +324,15 @@ class Gleap {
333324
backgroundColor = "#ffffff",
334325
borderRadius = 20,
335326
) {
336-
if (
337-
document.readyState === "complete" ||
338-
document.readyState === "loaded" ||
339-
document.readyState === "interactive"
340-
) {
327+
runFunctionWhenDomIsReady(() => {
341328
injectStyledCSS(
342329
primaryColor,
343330
headerColor,
344331
buttonColor,
345332
borderRadius,
346333
backgroundColor
347334
);
348-
} else {
349-
document.addEventListener("DOMContentLoaded", function (event) {
350-
injectStyledCSS(
351-
primaryColor,
352-
headerColor,
353-
buttonColor,
354-
borderRadius,
355-
backgroundColor
356-
);
357-
});
358-
}
335+
});
359336
}
360337

361338
/**
@@ -476,19 +453,6 @@ class Gleap {
476453
return !isLocalHost;
477454
}
478455

479-
/**
480-
* Post initialization
481-
*/
482-
postInitialization() {
483-
// Load session.
484-
const onGleapReady = function () {
485-
setTimeout(() => {
486-
GleapFrameManager.getInstance().injectFrame();
487-
}, 100);
488-
}
489-
GleapSession.getInstance().setOnSessionReady(onGleapReady.bind(this));
490-
}
491-
492456
softReInitialize() {
493457
GleapFeedbackButtonManager.getInstance().injectedFeedbackButton = false;
494458
GleapFrameManager.getInstance().injectedFrame = false;

src/GleapConfigManager.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ export default class GleapConfigManager {
7575
});
7676
};
7777

78+
applyStylesFromConfig() {
79+
const flowConfig = this.flowConfig;
80+
if (flowConfig && flowConfig.color) {
81+
Gleap.setStyles(
82+
flowConfig.color,
83+
flowConfig.headerColor,
84+
flowConfig.buttonColor,
85+
flowConfig.backgroundColor
86+
? flowConfig.backgroundColor
87+
: "#FFFFFF",
88+
flowConfig.borderRadius,
89+
);
90+
}
91+
}
92+
7893
/**
7994
* Applies the Gleap config.
8095
* @param {*} config
@@ -87,17 +102,8 @@ export default class GleapConfigManager {
87102
this.flowConfig = flowConfig;
88103
this.projectActions = projectActions;
89104

90-
if (flowConfig.color) {
91-
Gleap.setStyles(
92-
flowConfig.color,
93-
flowConfig.headerColor,
94-
flowConfig.buttonColor,
95-
flowConfig.backgroundColor
96-
? flowConfig.backgroundColor
97-
: "#FFFFFF",
98-
flowConfig.borderRadius,
99-
);
100-
}
105+
// Update styles.
106+
this.applyStylesFromConfig();
101107

102108
// Send config update.
103109
GleapFrameManager.getInstance().sendConfigUpdate();

src/GleapFrameManager.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GleapStreamedEvent, GleapPreFillManager, GleapCustomActionManager, GleapEventManager, GleapMarkerManager, GleapFeedback, GleapFeedbackButtonManager, GleapTranslationManager, GleapSession, GleapConfigManager } from "./Gleap";
2+
import { runFunctionWhenDomIsReady } from "./GleapHelper";
23

34
export default class GleapFrameManager {
45
frameUrl = "https://frame.gleap.io";
@@ -55,15 +56,22 @@ export default class GleapFrameManager {
5556
}
5657
this.injectedFrame = true;
5758

58-
var elem = document.createElement("div");
59-
elem.className = "gleap-frame-container gleap-frame-container--hidden gleap-hidden";
60-
elem.innerHTML = `<div class="gleap-frame-container-inner"><iframe src="${this.frameUrl}" class="gleap-frame" scrolling="yes" title="Gleap Widget Window" allow="autoplay; encrypted-media; fullscreen;" frameborder="0"></iframe></div>`;
61-
document.body.appendChild(elem);
59+
// Apply CSS.
60+
GleapConfigManager.getInstance().applyStylesFromConfig();
6261

63-
this.gleapFrameContainer = elem;
64-
this.gleapFrame = document.querySelector(".gleap-frame");
62+
// Inject the frame manager after it has been loaded.
63+
runFunctionWhenDomIsReady(() => {
64+
// Inject widget HTML.
65+
var elem = document.createElement("div");
66+
elem.className = "gleap-frame-container gleap-frame-container--hidden gleap-hidden";
67+
elem.innerHTML = `<div class="gleap-frame-container-inner"><iframe src="${this.frameUrl}" class="gleap-frame" scrolling="yes" title="Gleap Widget Window" allow="autoplay; encrypted-media; fullscreen;" frameborder="0"></iframe></div>`;
68+
document.body.appendChild(elem);
6569

66-
this.updateFrameStyle();
70+
this.gleapFrameContainer = elem;
71+
this.gleapFrame = document.querySelector(".gleap-frame");
72+
73+
this.updateFrameStyle();
74+
});
6775
};
6876

6977
updateFrameStyle = () => {

src/GleapHelper.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,15 @@ export const getDOMElementDescription = (element, html = true) => {
127127

128128
return `${htmlPre}${elementTag}${elementId}${elementClass}${htmlPost}${innerText}${htmlPre}/${elementTag}${htmlPost}`;
129129
}
130+
131+
export const runFunctionWhenDomIsReady = (callback) => {
132+
if (
133+
document.readyState === "complete" ||
134+
document.readyState === "loaded" ||
135+
document.readyState === "interactive"
136+
) {
137+
callback();
138+
} else {
139+
document.addEventListener("DOMContentLoaded", callback);
140+
}
141+
}

0 commit comments

Comments
 (0)