-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathghl-customizer.js
More file actions
108 lines (99 loc) · 4.07 KB
/
ghl-customizer.js
File metadata and controls
108 lines (99 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(function() {
// Directly use your hosted config JSON URL
const configUrl = 'https://cdn.jsdelivr.net/gh/nicopasion/ghl-customizer@main/agency-config.json';
alert("Customizer script loaded!");
// ---- Helper: Applies branding ----
function applyBranding(branding) {
if (branding.logoUrl) {
const logoImg = document.querySelector('.hl-header-logo img');
if (logoImg) logoImg.src = branding.logoUrl;
}
if (branding.primaryColor) {
document.body.style.setProperty('--agency-primary', branding.primaryColor);
}
if (branding.dashboardTitle) {
const titleEl = document.querySelector('.hl-dashboard-title');
if (titleEl) titleEl.textContent = branding.dashboardTitle;
}
}
// ---- Helper: Add header buttons ----
function applyHeaderButtons(headerButtons) {
const navBar = document.querySelector('.hl-header-nav');
if (!navBar || !headerButtons) return;
headerButtons.forEach(btn => {
const button = document.createElement('a');
button.className = 'custom-header-btn';
button.href = btn.url;
button.innerHTML = `<span class="icon-${btn.icon}"></span> ${btn.label}`;
navBar.appendChild(button);
});
}
// ---- Helper: Add user menu items ----
function applyUserMenu(userMenu) {
const menu = document.querySelector('.hl-user-menu');
if (!menu || !userMenu) return;
userMenu.forEach(item => {
const li = document.createElement('li');
li.innerHTML = `<a href="${item.url}">${item.label}</a>`;
menu.appendChild(li);
});
}
// ---- Helper: Widget display toggles ----
function applyWidgets(widgets) {
widgets.forEach(widget => {
const widgetEl = document.querySelector(`.hl-widget-${widget.name.toLowerCase()}`);
if (widgetEl) widgetEl.style.display = widget.isVisible ? 'block' : 'none';
});
}
// ---- Helper: Feature toggles and UI tweaks ----
function applyDashboardFeatures(cfg) {
if (cfg.autoSave && cfg.autoSave.isEnabled) {
document.body.classList.add('customizer-autosave');
// Implement auto-save logic here...
}
if (cfg.saveButtonMove && cfg.saveButtonMove.isEnabled) {
const saveBtn = document.querySelector('.hl-save-btn');
if (saveBtn) saveBtn.style.position = 'fixed';
}
// Extend for additionalInfoSearch, unreadCounter, etc.
}
// ---- Helper: Feature toggles ----
function applyFeatureToggles(toggles) {
if (toggles.showNotifications === false) {
const notifications = document.querySelector('.hl-notifications');
if (notifications) notifications.style.display = 'none';
}
// Extend for other toggles
}
// ---- Helper: Add integrations (e.g., iframes) ----
function applyIntegrations(integrations) {
integrations.forEach(integration => {
if (integration.type === 'iframe') {
const iframe = document.createElement('iframe');
iframe.src = integration.url;
iframe.style.width = '100%';
iframe.style.height = integration.height || '400px';
if (integration.position === 'sidebar') {
const sidebar = document.querySelector('.hl-sidebar');
if (sidebar) sidebar.appendChild(iframe);
} else {
document.body.appendChild(iframe);
}
}
});
}
// ---- Main: Fetch config and apply customizations ----
fetch(configUrl)
.then(res => res.json())
.then(config => {
if (config.branding) applyBranding(config.branding);
if (config.headerButtons) applyHeaderButtons(config.headerButtons);
if (config.userMenu) applyUserMenu(config.userMenu);
if (config.widgets) applyWidgets(config.widgets);
if (config.dashboardCustomizer) applyDashboardFeatures(config.dashboardCustomizer);
if (config.featureToggles) applyFeatureToggles(config.featureToggles);
if (config.integrations) applyIntegrations(config.integrations);
// ...Add more as needed for your setup
})
.catch(err => console.error('Customizer config fetch failed', err));
})();