4b86b2a660
- server-dev start/stop/deploy 및 Gitea push 자동 배포 - local-dev 로컬 개발 환경 Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.6 KiB
JavaScript
86 lines
2.6 KiB
JavaScript
/**
|
|
* ExChatbotBanner — 타 사이트 임베드용 검색 배너 SDK (iframe)
|
|
* @example
|
|
* <div id="ex-chatbot-banner"></div>
|
|
* <script src="https://chatbot.exdev.co.kr/chatbot/banner/embed.js"></script>
|
|
* <script>
|
|
* ExChatbotBanner.init({ container: "#ex-chatbot-banner" });
|
|
* </script>
|
|
*/
|
|
(function (global) {
|
|
"use strict";
|
|
|
|
var DEFAULT_BASE = "https://chatbot.exdev.co.kr/chatbot/banner/";
|
|
|
|
function resolveContainer(el) {
|
|
if (!el) return null;
|
|
if (typeof el === "string") return document.querySelector(el);
|
|
return el;
|
|
}
|
|
|
|
function init(options) {
|
|
options = options || {};
|
|
var container = resolveContainer(options.container);
|
|
if (!container) {
|
|
console.error("[ExChatbotBanner] container not found");
|
|
return null;
|
|
}
|
|
|
|
var baseUrl = (options.baseUrl || DEFAULT_BASE).replace(/\/?$/, "/");
|
|
var params = new URLSearchParams();
|
|
if (options.embed !== false) params.set("embed", "1");
|
|
if (options.placeholder) params.set("placeholder", String(options.placeholder));
|
|
var qs = params.toString();
|
|
var src = baseUrl + (qs ? "?" + qs : "");
|
|
|
|
var minHeight = Number(options.minHeight) || 56;
|
|
var maxHeight = Number(options.maxHeight) || 520;
|
|
var height = Number(options.height) || minHeight;
|
|
|
|
var wrap = document.createElement("div");
|
|
wrap.className = "ex-chatbot-banner-widget";
|
|
wrap.style.cssText =
|
|
"position:relative;width:100%;max-width:" +
|
|
(options.maxWidth || "720px") +
|
|
";margin:0 auto;";
|
|
|
|
var iframe = document.createElement("iframe");
|
|
iframe.src = src;
|
|
iframe.title = options.title || "한국도로공사 AI 검색";
|
|
iframe.setAttribute("allow", "clipboard-write");
|
|
iframe.loading = options.loading || "lazy";
|
|
iframe.style.cssText =
|
|
"display:block;width:100%;border:0;overflow:hidden;min-height:" +
|
|
minHeight +
|
|
"px;height:" +
|
|
height +
|
|
"px;transition:height 0.15s ease;";
|
|
|
|
function onMessage(ev) {
|
|
if (!ev.data || ev.data.type !== "ex-chatbot-banner-resize") return;
|
|
if (ev.source !== iframe.contentWindow) return;
|
|
var h = Number(ev.data.height);
|
|
if (h > 0) {
|
|
iframe.style.height = Math.min(Math.max(h, minHeight), maxHeight) + "px";
|
|
}
|
|
}
|
|
|
|
global.addEventListener("message", onMessage);
|
|
wrap.appendChild(iframe);
|
|
container.appendChild(wrap);
|
|
|
|
return {
|
|
destroy: function () {
|
|
global.removeEventListener("message", onMessage);
|
|
wrap.remove();
|
|
},
|
|
iframe: iframe,
|
|
};
|
|
}
|
|
|
|
global.ExChatbotBanner = {
|
|
init: init,
|
|
version: "1.0.0",
|
|
};
|
|
})(typeof window !== "undefined" ? window : globalThis);
|