From f6426ac15b49be10a60d8293738e6955fd9b9b72 Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:22:21 +0330 Subject: [PATCH] Import source: app/public/embed-loader Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- app/public/embed-loader.js | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/public/embed-loader.js diff --git a/app/public/embed-loader.js b/app/public/embed-loader.js new file mode 100644 index 0000000..f72da0a --- /dev/null +++ b/app/public/embed-loader.js @@ -0,0 +1,42 @@ +// Teknav Embed Loader — paste this script tag on any page to embed a Teknav widget. +// Usage: +// +(function () { + var scripts = document.querySelectorAll('script[src*="embed-loader.js"]'); + var script = scripts[scripts.length - 1]; + if (!script) return; + + var type = script.getAttribute('data-type') || 'glossary'; + var slug = script.getAttribute('data-slug') || ''; + var width = script.getAttribute('data-width') || '480'; + var origin = 'https://www.teknav.ir'; + + if (!slug) { + console.warn('[Teknav] embed-loader: data-slug attribute is required'); + return; + } + + var iframe = document.createElement('iframe'); + iframe.src = origin + '/embed/' + type + '/' + encodeURIComponent(slug); + iframe.style.border = 'none'; + iframe.style.width = isNaN(Number(width)) ? width : width + 'px'; + iframe.style.maxWidth = '100%'; + iframe.style.height = '300px'; + iframe.style.overflow = 'hidden'; + iframe.setAttribute('loading', 'lazy'); + iframe.setAttribute('sandbox', 'allow-scripts allow-popups allow-same-origin'); + iframe.setAttribute('title', 'تکناو — ' + type + ': ' + slug); + + window.addEventListener('message', function (event) { + if (event.origin !== origin) return; + if (event.source !== iframe.contentWindow) return; + if (event.data && event.data.type === 'resize' && typeof event.data.height === 'number') { + iframe.style.height = (event.data.height + 24) + 'px'; + } + }); + + script.parentNode.insertBefore(iframe, script.nextSibling); +})();