mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-02-10 18:05:06 +08:00
Different scripts in the desktop and online versions
This commit is contained in:
@ -21,18 +21,46 @@
|
||||
<script src="vendor/jquery/jquery-3.7.1.min.js"></script>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
||||
<link rel="stylesheet" href="resources/css/plugin_style.css" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="./../v1/plugins.css"
|
||||
/>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="./../v1/plugins.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="./../v1/plugins-ui.js"
|
||||
></script>
|
||||
<script>
|
||||
const isDesktop = (function () {
|
||||
if (
|
||||
window.navigator &&
|
||||
window.navigator.userAgent
|
||||
.toLowerCase()
|
||||
.indexOf("ascdesktopeditor") < 0
|
||||
)
|
||||
return false;
|
||||
if (window.location && window.location.protocol == "file:") return true;
|
||||
if (
|
||||
window.document &&
|
||||
window.document.currentScript &&
|
||||
0 == window.document.currentScript.src.indexOf("file:///")
|
||||
)
|
||||
return true;
|
||||
return false;
|
||||
})();
|
||||
const scriptPlugins = document.createElement('script');
|
||||
const scriptPluginsUi = document.createElement('script');
|
||||
const stylePlugins = document.createElement('link');
|
||||
scriptPlugins.type = 'text/javascript';
|
||||
scriptPluginsUi.type = 'text/javascript';
|
||||
stylePlugins.rel = 'stylesheet';
|
||||
if (isDesktop) {
|
||||
scriptPlugins.src = '../v1/plugins.js';
|
||||
scriptPluginsUi.src = '../v1/plugins-ui.js';
|
||||
stylePlugins.href = '../v1/plugins.css';
|
||||
} else {
|
||||
scriptPlugins.src = 'https://onlyoffice.github.io/sdkjs-plugins/v1/plugins.js';
|
||||
scriptPluginsUi.src = 'https://onlyoffice.github.io/sdkjs-plugins/v1/plugins-ui.js';
|
||||
stylePlugins.href = 'https://onlyoffice.github.io/sdkjs-plugins/v1/plugins.css';
|
||||
}
|
||||
scriptPlugins.async = false;
|
||||
scriptPluginsUi.async = false;
|
||||
document.head.appendChild(scriptPlugins);
|
||||
document.head.appendChild(scriptPluginsUi);
|
||||
document.head.appendChild(stylePlugins);
|
||||
</script>
|
||||
|
||||
<script src="scripts/thirdparty/fetch.umd.js"></script>
|
||||
<script src="scripts/thirdparty/promise-polyfill.min.js"></script>
|
||||
<script src="scripts/thirdparty/url-polyfill.min.js"></script>
|
||||
@ -48,7 +76,6 @@
|
||||
<script src="scripts/csl/styles/storage.js"></script>
|
||||
|
||||
<script src="scripts/citation-doc-service.js"></script>
|
||||
|
||||
</head>
|
||||
<body id="body" spellcheck="false" class="noselect">
|
||||
<div id="loader" class="cssload-container display-none">
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
(function () {
|
||||
window.addEventListener('load', function() {
|
||||
var counter = 0; // счетчик отправленных запросов (используется чтобы знать показывать "not found" или нет)
|
||||
var displayNoneClass = "display-none";
|
||||
var blurClass = "blur";
|
||||
@ -125,7 +125,7 @@
|
||||
showLoader(true);
|
||||
setTimeout(function () { searchField.focus(); },100);
|
||||
|
||||
sdk = window.Asc.plugin.zotero.api({});
|
||||
sdk = ZoteroSdk();
|
||||
cslStylesManager = new CslStylesManager();
|
||||
addEventListeners();
|
||||
|
||||
@ -178,18 +178,18 @@
|
||||
onlineZoteroElements.forEach(function (element) {
|
||||
element.classList.remove("display-none");
|
||||
});
|
||||
} else {
|
||||
} else {
|
||||
onlineZoteroElements.forEach(function (element) {
|
||||
element.classList.add("display-none");
|
||||
});
|
||||
}
|
||||
if (apis.online && apis.hasKey) {
|
||||
window.Asc.plugin.zotero.isOnlineAvailable = true;
|
||||
sdk.setIsOnlineAvailable(true);
|
||||
switchAuthState("main");
|
||||
resolve(apis);
|
||||
return;
|
||||
} else if (apis.desktop && apis.hasPermission) {
|
||||
window.Asc.plugin.zotero.isOnlineAvailable = false;
|
||||
sdk.setIsOnlineAvailable(false);
|
||||
elements.logoutLink.style.display = "none";
|
||||
switchAuthState("main");
|
||||
showError(false);
|
||||
@ -300,7 +300,7 @@
|
||||
elements.useDesktopApp.onclick = function () {
|
||||
ZoteroApiChecker.checkStatus(sdk).then(function (/** @type {AvailableApis} */ apis) {
|
||||
if (apis.desktop && apis.hasPermission) {
|
||||
window.Asc.plugin.zotero.isOnlineAvailable = false;
|
||||
sdk.setIsOnlineAvailable(false);
|
||||
elements.logoutLink.style.display = "none";
|
||||
switchAuthState("main");
|
||||
showError(false);
|
||||
@ -1461,4 +1461,4 @@
|
||||
// todo now we should make full update (because when we make refresh, we check fields into the document). Fix it in new version (when we change refreshing and updating processes)
|
||||
updateFormatter(true, false, false, true);
|
||||
};
|
||||
})();
|
||||
});
|
||||
|
||||
@ -15,18 +15,15 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
(function () {
|
||||
if (!window.Asc.plugin.zotero) window.Asc.plugin.zotero = {};
|
||||
|
||||
window.Asc.plugin.zotero.isOnlineAvailable = true;
|
||||
|
||||
window.Asc.plugin.zotero.api = function (cfg) {
|
||||
const ZoteroSdk = function () {
|
||||
var apiKey;
|
||||
var userId = 0;
|
||||
var userGroups = [];
|
||||
var isOnlineAvailable = true;
|
||||
|
||||
function getRequestWithOfflineSupport(url) {
|
||||
if (window.Asc.plugin.zotero.isOnlineAvailable) {
|
||||
if (isOnlineAvailable) {
|
||||
return getRequest(url);
|
||||
} else {
|
||||
return getDesktopRequest(url.href);
|
||||
@ -85,7 +82,7 @@
|
||||
|
||||
function buildGetRequest(path, query) {
|
||||
var url = new URL(path, zoteroEnvironment.restApiUrl);
|
||||
if (!window.Asc.plugin.zotero.isOnlineAvailable) {
|
||||
if (!isOnlineAvailable) {
|
||||
url = new URL(path, zoteroEnvironment.desktopApiUrl);
|
||||
}
|
||||
for (var key in query) url.searchParams.append(key, query[key]);
|
||||
@ -110,7 +107,7 @@
|
||||
} else if (itemsID) {
|
||||
props.itemKey = itemsID.join(',');
|
||||
}
|
||||
if (window.Asc.plugin.zotero.isOnlineAvailable) {
|
||||
if (isOnlineAvailable) {
|
||||
parseItemsResponse(buildGetRequest("users/" + userId + "/items", props), resolve, reject, userId);
|
||||
} else {
|
||||
parseDesktopItemsResponse(buildGetRequest("users/" + userId + "/items", props), resolve, reject, userId);
|
||||
@ -129,7 +126,7 @@
|
||||
} else if (itemsID) {
|
||||
props.itemKey = itemsID.join(',');
|
||||
}
|
||||
if (window.Asc.plugin.zotero.isOnlineAvailable) {
|
||||
if (isOnlineAvailable) {
|
||||
parseItemsResponse(buildGetRequest("groups/" + groupId + "/items", props), resolve, reject, groupId);
|
||||
} else {
|
||||
parseDesktopItemsResponse(buildGetRequest("groups/" + groupId + "/items", props), resolve, reject, groupId);
|
||||
@ -139,7 +136,7 @@
|
||||
|
||||
function getLocale(langTag) {
|
||||
let url = zoteroEnvironment.localesPath;
|
||||
if (window.Asc.plugin.zotero.isOnlineAvailable) {
|
||||
if (isOnlineAvailable) {
|
||||
url = zoteroEnvironment.localesUrl;
|
||||
}
|
||||
return fetch(url + "locales-" + langTag + ".xml")
|
||||
@ -300,6 +297,10 @@
|
||||
return links;
|
||||
}
|
||||
|
||||
function setIsOnlineAvailable(isOnline) {
|
||||
isOnlineAvailable = isOnline;
|
||||
}
|
||||
|
||||
return {
|
||||
getItems: getItems,
|
||||
groups: groups,
|
||||
@ -310,6 +311,6 @@
|
||||
setApiKey: setApiKey,
|
||||
getUserId: getUserId,
|
||||
getLocale: getLocale,
|
||||
setIsOnlineAvailable: setIsOnlineAvailable
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user