// jloadScriptAsync (Promise) ----------------------------
var jloadScriptAsync = function (d, s, id, src) {
return new Promise((resolve, reject) => {
try {
var fjs = d.getElementsByTagName(s)[0];
const scriptEle = d.createElement(s);
scriptEle.id=id;
scriptEle.onload = function () {
//solo quando script caricato:
resolve(scriptEle);
}
scriptEle.onerror = function (ev) {
reject(new Error(`jloadScriptAsync error for ${src}`));
}
scriptEle.src = src;
fjs.parentNode.insertBefore(scriptEle, fjs);
//document.head.append(scriptEle);
} catch (error) {
reject("103 ➔ jloadScriptAsync "+error); // errore interno alla funzione
}
});
};
// fine jloadScriptAsync
// waitForAWN Funzione che attende che un oggetto JavaScript AWN venga definito
function waitForAWN(pollInterval = 100, timeout = 5000) {
return new Promise((resolve, reject) => {
const startTime = Date.now();
function checkAWN() {
if (typeof AWN !== 'undefined' && AWN !== 'undefined') {
resolve(AWN); // L'oggetto AWN è stato trovato, risolvi la Promise
} else if (Date.now() - startTime >= timeout) {
reject(new Error(`Timeout: Oggetto AWN non trovato entro ${timeout}ms`)); // Timeout raggiunto
} else {
setTimeout(checkAWN, pollInterval); // Prova di nuovo dopo l'intervallo di polling
}
}
checkAWN(); // Inizia il polling
});
}
// fine waitForAWN
// waitForIFR Funzione che attende che un oggetto JavaScript iFrameResize venga definito
function waitForIFR(pollInterval = 100, timeout = 5000) {
return new Promise((resolve, reject) => {
const startTime = Date.now();
function checkIFR() {
if (typeof iFrameResize !== 'undefined') {
resolve(iFrameResize); // L'oggetto iFrameResize è stato trovato, risolvi la Promise
} else if (Date.now() - startTime >= timeout) {
reject(new Error(`Timeout: Oggetto iFrameResize non trovato entro ${timeout}ms`)); // Timeout raggiunto
} else {
setTimeout(checkIFR, pollInterval); // Prova di nuovo dopo l'intervallo di polling
}
}
checkIFR(); // Inizia il polling
});
}
// fine waitForIFR
(async () => {
var pfAWN;
var runstep2embedgoskebi_sitia = async function (d, s){
var targetdiv = document.getElementById("skebi_sitia");
if(typeof pfAWN == "undefined"){
pfAWN = new AWN({
position: "top-right",
durations: {
global: 5000,
success: 3000,
warning: 5000,
alert: 0,
info: 4000,
tip: 2000
},
labels: {
success: "SUCCESS",
warning: "EMBEDDING WARNING!",
alert: "EMBEDDING ERROR!",
info: "INFO",
tip: ""
},
icons: {
prefix: ""
}
});
}else{
}
if(targetdiv){
if (!('cliente' in targetdiv.dataset)) {
pfAWN.alert('target [ skebi_sitia ] (div da elaborare) non ha attributo obbligatorio [ data-cliente ]!');
}else{
var c = targetdiv.getAttribute('data-cliente');
if (!('key' in targetdiv.dataset)) {
pfAWN.alert('target [ skebi_sitia ] (div da elaborare) non ha attributo obbligatorio [ data-key ]!');
}else{
var k = targetdiv.getAttribute('data-key');
if (!('host' in targetdiv.dataset)) {
var h = window.location.hostname;
}else{
var h = targetdiv.getAttribute('data-host');
}
let hostnames = h.split('.');
h = hostnames[hostnames.length-2] + '.' + hostnames[hostnames.length-1];
var param_accettati = {'data-autocc':'^cc$','data-anamorfico':'^[a-z0-9_]{3,}$','data-bcolor':'^[A-F0-9]{6}$','data-icolor':'^[A-F0-9]{6}$','data-lang':'^[a-z]{2}$'
};
var optional = {};
for (var att, i = 0, atts = targetdiv.attributes, n = atts.length; i < n; i++){
att = atts[i];
if(Object.keys(param_accettati).indexOf(att.nodeName) != -1){
var regex = new RegExp(Object.values(param_accettati)[Object.keys(param_accettati).indexOf(att.nodeName)]);
if(!regex.test(att.nodeValue)) { // input non accettato
pfAWN.warning('target [ skebi_sitia ] (div da elaborare) ha attributo '+att.nodeName+' non conforme '+Object.values(param_accettati)[Object.keys(param_accettati).indexOf(att.nodeName)]+'!',
{ icons: {
suffix: "' style='width: 36px; filter: invert(36%) sepia(85%) saturate(1988%) hue-rotate(20deg) brightness(94%) contrast(101%);' />"
}}
);
}else{
optional[ att.nodeName ] = att.nodeValue;
}
}
}
var queryString = Object.keys(optional).map(function(key) {
return key.replace('data-', '') + '=' + optional[key]
}).join('&');
if(queryString.length){queryString='/'+queryString};
await jloadScriptAsync(d, s, 'jsskebi_sitia', 'https://skebi.net/3d/skebi_sitia/'+c+'/'+k+'/'+h+'/goembedlist'+queryString );
// remote script has loaded
await runstep3goskebi_sitia(d, s);
}
}
}else{
pfAWN.alert('target [ skebi_sitia ] (div da elaborare) non trovato!');
}
}
var startembedskebi_sitia = async function(d, s, idAWN, idIFR){
try {
if (d.getElementById(idAWN)){
}else{
if (typeof AWN != "undefined") {
}else{
var AWNcss = d.createElement('link');
AWNcss.type = 'text/css';
AWNcss.id = 'pf_AWNcss';
AWNcss.rel = 'stylesheet';
AWNcss.href = "https://skebi.net/3d/css/static/AWN.css";
d.getElementsByTagName('head')[0].appendChild(AWNcss);
await jloadScriptAsync(d, s, idAWN, 'https://skebi.net/3d/libs/static/AWN.js' );
// remote script has loaded
}
}
// attende che oggetto AWN venga definito
await waitForAWN(100, 10000);
if (d.getElementById(idIFR)){
}else{
if (typeof iFrameResize != "undefined") {
}else{
await jloadScriptAsync(d, s, idIFR, 'https://skebi.net/js/iframeResizer.min.js' );
// remote script idIFR has loaded
}
}
// attende che oggetto iFrameResize venga definito
await waitForIFR( 100, 10000);
await runstep2embedgoskebi_sitia(d, s);
} catch (error) {
alert( "392 ➔ "+error);
}
}
await startembedskebi_sitia(document, 'script', 'pf_AWNjs', 'pf_iframeResizerjs');
})();