Skip to content

Commit 0406c5e

Browse files
committed
fixed css
1 parent 0ed0f80 commit 0406c5e

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/widget.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,45 @@
7272
(function(window, document) {
7373
'use strict';
7474

75+
// Detect the script URL to determine CDN base for CSS loading
76+
// This allows the CSS to be loaded from the same location as the widget.js
77+
const SCRIPT_URL = (function() {
78+
try {
79+
// Try document.currentScript first (works in most cases)
80+
if (document.currentScript && document.currentScript.src) {
81+
return document.currentScript.src;
82+
}
83+
// Fallback: find our script by looking for widget.js in script tags
84+
const scripts = document.getElementsByTagName('script');
85+
for (let i = scripts.length - 1; i >= 0; i--) {
86+
const src = scripts[i].src || '';
87+
if (src.includes('widget') && src.includes('.js')) {
88+
return src;
89+
}
90+
}
91+
} catch (e) {
92+
// Ignore errors
93+
}
94+
return null;
95+
})();
96+
97+
// Extract CDN base URL from script source
98+
const CDN_BASE = (function() {
99+
if (SCRIPT_URL) {
100+
try {
101+
const url = new URL(SCRIPT_URL);
102+
return `${url.protocol}//${url.host}`;
103+
} catch (e) {
104+
// Ignore URL parse errors
105+
}
106+
}
107+
return 'https://cdn.ezcontactform.com'; // Default CDN
108+
})();
109+
75110
// Default configuration
76111
const DEFAULT_CONFIG = {
77112
apiBase: 'https://api.ezcontactform.com',
113+
cdnBase: CDN_BASE, // Where to load CSS from (detected from script URL)
78114
theme: 'system', // 'system' will auto-detect light/dark based on user preference
79115
autoInit: true,
80116
disableStyles: false,
@@ -1553,7 +1589,8 @@
15531589
const link = document.createElement('link');
15541590
link.id = 'ezform-styles';
15551591
link.rel = 'stylesheet';
1556-
link.href = `${this.config.apiBase}/widget.css`;
1592+
// Load CSS from CDN (same location as widget.js), not from API
1593+
link.href = `${this.config.cdnBase}/widget.css`;
15571594
document.head.appendChild(link);
15581595
},
15591596

0 commit comments

Comments
 (0)