\n' : '';
return doctype + doc.documentElement.outerHTML;
}
// Скрипт внутри каждой страницы: переход по ссылке на соседнюю страницу просит кабинет открыть её
// по подписанной ссылке (обычная относительная ссылка в закрытое хранилище не сработает)
function presentationBridge(path, pages) {
return '(function(){var here=' + JSON.stringify(path) + ',pages=' + JSON.stringify(pages) + ';' +
'document.addEventListener("click",function(e){' +
'var a=e.target&&e.target.closest?e.target.closest("a[href]"):null;if(!a)return;' +
'var h=a.getAttribute("href");if(!h||/^(?:[a-z][a-z0-9+.-]*:|\\/\\/|\\/|#)/i.test(h))return;' +
'var u;try{u=new URL(h,"http://p/"+encodeURI(here))}catch(x){return}' +
'var p=decodeURIComponent(u.pathname.slice(1));if(pages.indexOf(p)<0)return;' +
'e.preventDefault();var w=window.parent!==window?window.parent:window.opener;' +
'if(w)w.postMessage({type:"syt-open-page",path:p,hash:u.hash,newTab:a.target==="_blank"},"*");' +
'},true);})();';
}
// Файлы архива (не страницы), которые не удалось встроить, но имя которых встречается на страницах:
// скорее всего их загружает скрипт (fetch и т.п.) — в кабинете они не откроются
function bundleWarnings(ctx) {
var text = ctx.sources.join('\n');
return Object.keys(ctx.files).filter(function (p) {
if (ctx.used[p] || ctx.pages.indexOf(p) !== -1) return false;
return text.indexOf(p.split('/').pop()) !== -1;
});
}
api.handlePresentationLinks(function () { return previewUrls; });
// ---------- старт ----------
(async function start() {
if (!api.hasToken()) { location.href = 'cabinet.html'; return; }
var h = location.hash.slice(1);
if (VIEWS[h]) tab = h;
try {
await load();
} catch (e) {
// 401 — не вошёл, 403 — ученик: админка не для него
if (e.status === 401 || e.status === 403) { location.href = 'cabinet.html'; return; }
editorEl.innerHTML = placeholder('bi-exclamation-circle', esc(e.message));
}
})();