Import source: app/public/embed-loader
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
// Teknav Embed Loader — paste this script tag on any page to embed a Teknav widget.
|
||||||
|
// Usage:
|
||||||
|
// <script src="https://www.teknav.ir/embed-loader.js"
|
||||||
|
// data-type="glossary"
|
||||||
|
// data-slug="vector-database"
|
||||||
|
// data-width="480"></script>
|
||||||
|
(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);
|
||||||
|
})();
|
||||||
Reference in New Issue
Block a user