mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
office: also support slide & cell
This commit is contained in:
1 parent
bcd6ad5b3f
commit
561c4d4175
2 files changed
+67
-10
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/onlyoffice",
|
"name": "@hydrooj/onlyoffice",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
|
|||||||
@@ -3,17 +3,22 @@
|
|||||||
const { $ } = window.node_modules;
|
const { $ } = window.node_modules;
|
||||||
const { request } = window.Hydro.utils;
|
const { request } = window.Hydro.utils;
|
||||||
|
|
||||||
|
let loaded = false;
|
||||||
|
async function load() {
|
||||||
|
if (loaded) return Promise.resolve();
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const scriptElement = document.createElement('script');
|
||||||
|
scriptElement.src = UiContext.onlyofficeApi;
|
||||||
|
scriptElement.async = true;
|
||||||
|
document.head.appendChild(scriptElement);
|
||||||
|
scriptElement.onload = resolve;
|
||||||
|
loaded = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const page = new AutoloadPage('onlyoffice', async () => {
|
const page = new AutoloadPage('onlyoffice', async () => {
|
||||||
const res = $('div[data-doc]');
|
const res = $('div[data-doc]');
|
||||||
if (res.length) {
|
if (res.length) await load();
|
||||||
await new Promise((resolve) => {
|
|
||||||
const scriptElement = document.createElement('script');
|
|
||||||
scriptElement.src = UiContext.onlyofficeApi;
|
|
||||||
scriptElement.async = true;
|
|
||||||
document.head.appendChild(scriptElement);
|
|
||||||
scriptElement.onload = resolve;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
res.get().forEach(async (element) => {
|
res.get().forEach(async (element) => {
|
||||||
const id = `doc-${Math.random().toString()}`;
|
const id = `doc-${Math.random().toString()}`;
|
||||||
$(element).attr('id', id);
|
$(element).attr('id', id);
|
||||||
@@ -38,6 +43,58 @@
|
|||||||
height: '980px',
|
height: '980px',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
res = $('div[data-cell]');
|
||||||
|
if (res.length) await load();
|
||||||
|
res.get().forEach(async (element) => {
|
||||||
|
const id = `cell-${Math.random().toString()}`;
|
||||||
|
$(element).attr('id', id);
|
||||||
|
const url = $(element).text();
|
||||||
|
const t = new URL(url, window.location.href).pathname.split('.');
|
||||||
|
const n = new URL(url, window.location.href).pathname.split('/');
|
||||||
|
const res = await request.get(url);
|
||||||
|
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
window.editor = new DocsAPI.DocEditor(id, {
|
||||||
|
document: {
|
||||||
|
fileType: t[t.length - 1],
|
||||||
|
key: Math.random().toString(16),
|
||||||
|
title: n[n.length - 1],
|
||||||
|
url: new URL(res.url, window.location.href),
|
||||||
|
},
|
||||||
|
editorConfig: {
|
||||||
|
lang,
|
||||||
|
mode: 'cell',
|
||||||
|
},
|
||||||
|
documentType: 'word',
|
||||||
|
height: '980px',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
res = $('div[data-slide]');
|
||||||
|
if (res.length) await load();
|
||||||
|
res.get().forEach(async (element) => {
|
||||||
|
const id = `slide-${Math.random().toString()}`;
|
||||||
|
$(element).attr('id', id);
|
||||||
|
const url = $(element).text();
|
||||||
|
const t = new URL(url, window.location.href).pathname.split('.');
|
||||||
|
const n = new URL(url, window.location.href).pathname.split('/');
|
||||||
|
const res = await request.get(url);
|
||||||
|
const lang = UserContext.viewLang.includes('_') ? UserContext.viewLang.split('_')[0] : UserContext.viewLang;
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
window.editor = new DocsAPI.DocEditor(id, {
|
||||||
|
document: {
|
||||||
|
fileType: t[t.length - 1],
|
||||||
|
key: Math.random().toString(16),
|
||||||
|
title: n[n.length - 1],
|
||||||
|
url: new URL(res.url, window.location.href),
|
||||||
|
},
|
||||||
|
editorConfig: {
|
||||||
|
lang,
|
||||||
|
mode: 'slide',
|
||||||
|
},
|
||||||
|
documentType: 'word',
|
||||||
|
height: '980px',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
window.Hydro.extraPages.push(page);
|
window.Hydro.extraPages.push(page);
|
||||||
|
|||||||
Reference in new issue
Block a user