diff --git a/store/plugin/index.html b/store/plugin/index.html index 4450b166..9fabdc24 100644 --- a/store/plugin/index.html +++ b/store/plugin/index.html @@ -29,5 +29,8 @@ + \ No newline at end of file diff --git a/store/plugin/resources/css/styles.css b/store/plugin/resources/css/styles.css index 00d7afb4..44f3fe4d 100644 --- a/store/plugin/resources/css/styles.css +++ b/store/plugin/resources/css/styles.css @@ -19,4 +19,9 @@ html, body { } .hidden { display: none !important; +} +.lab{ + border: none !important; + background-color: transparent !important; + font-size: 15px !important; } \ No newline at end of file diff --git a/store/plugin/scripts/code.js b/store/plugin/scripts/code.js index ddc2e186..a9e385e4 100644 --- a/store/plugin/scripts/code.js +++ b/store/plugin/scripts/code.js @@ -17,6 +17,11 @@ */ (function(window, undefined) { + let isOnline = null; + let isInit = false; + let interval = null; + checkInternet(); + // create iframe const iframe = document.createElement("iframe"); let BFrameReady = false; @@ -28,27 +33,28 @@ // for incognito mode marketplaceURl = localStorage.getItem('DeveloperMarketplaceUrl') || OOMarketplaceUrl; } catch (err) { - marketplaceURl = 'https://onlyoffice.github.io/store/index.html'; + marketplaceURl = OOMarketplaceUrl; } - - document.addEventListener("DOMContentLoaded", function() { - let pageUrl = marketplaceURl; - iframe.src = pageUrl + window.location.search; - document.body.appendChild(iframe); - iframe.onload = function() { - BFrameReady = true; - if (BPluginReady) - postMessage( JSON.stringify( { type: 'PluginReady', version: editorVersion } ) ); - }; - }); - window.Asc.plugin.init = function() { + isInit = true; + if (typeof isOnline === 'boolean') { + initPlugin(); + } + }; + + function postMessage(message) { + iframe.contentWindow.postMessage(message, "*"); + }; + + function initPlugin() { + document.body.appendChild(iframe); // resize window if (marketplaceURl !== OOMarketplaceUrl) document.getElementById('notification').classList.remove('hidden'); window.Asc.plugin.resizeWindow(608, 570, 608, 570, 0, 0); + // todo возможно это надо перенести в проверкку на сеть window.Asc.plugin.executeMethod("GetVersion", null, function(version) { editorVersion = version; BPluginReady = true; @@ -56,10 +62,32 @@ postMessage( JSON.stringify( { type: 'PluginReady', version: editorVersion } ) ); }); - }; - - function postMessage(message) { - iframe.contentWindow.postMessage(message, "*"); + let divNoInt = document.getElementById('div_noIternet'); + // send message that plugin is ready + if (isOnline) { + let style = document.getElementsByTagName('head')[0].lastChild; + let pageUrl = marketplaceURl; + iframe.src = pageUrl + window.location.search; + iframe.onload = function() { + BFrameReady = true; + if (BPluginReady) { + if (!divNoInt.classList.contains('hidden')) { + divNoInt.classList.add('hidden'); + clearInterval(interval); + interval = null; + } + postMessage( JSON.stringify( { type: 'Theme', theme: window.Asc.plugin.theme, style : style.innerHTML } ) ); + postMessage( JSON.stringify( { type: 'PluginReady', version: editorVersion } ) ); + } + }; + } else { + divNoInt.classList.remove('hidden'); + if (!interval) { + interval = setInterval(function() { + checkInternet(); + }, 5000); + } + } }; window.Asc.plugin.button = function(id) { @@ -122,11 +150,44 @@ postMessage( JSON.stringify( { type: 'Theme', theme: theme, style : style.innerHTML } ) ); }; - window.Asc.plugin.onTranslate = function() - { + window.Asc.plugin.onTranslate = function() { let label = document.getElementById('lb_notification'); if (label) - label.innerHTML = window.Asc.plugin.tr('This version of "Plugin Manager" is not official.'); + label.innerHTML = window.Asc.plugin.tr(label.innerHTML); + + label = document.getElementById('lb_noInternet'); + if (label) + label.innerHTML = window.Asc.plugin.tr(label.innerHTML); + }; + + function checkInternet() { + try { + let xhr = new XMLHttpRequest(); + let url = 'https://raw.githubusercontent.com/ONLYOFFICE/onlyoffice.github.io/master/store/translations/langs.json'; + xhr.open('GET', url, true); + + xhr.onload = function () { + if (this.readyState == 4) { + if (this.status >= 200 && this.status < 300) { + isOnline = true; + if (isInit) + initPlugin(); + } + } + }; + + xhr.onerror = function (err) { + isOnline = false; + if (isInit) + initPlugin(); + }; + + xhr.send(null); + } catch (error) { + isOnline = false; + if (isInit) + initPlugin(); + } }; })(window, undefined); diff --git a/store/plugin/translations/cs-CZ.json b/store/plugin/translations/cs-CZ.json index 37986071..88b638bb 100644 --- a/store/plugin/translations/cs-CZ.json +++ b/store/plugin/translations/cs-CZ.json @@ -1,3 +1,4 @@ { - "This version of \"Plugin Manager\" is not official." : "Tato verze \"Správce pluginů\" není oficiální." + "This version of \"Plugin Manager\" is not official." : "Tato verze \"Správce pluginů\" není oficiální.", + "No Internet Connection.": "Žádné Připojení K Internetu." } \ No newline at end of file diff --git a/store/plugin/translations/de-DE.json b/store/plugin/translations/de-DE.json index cf36230f..fd39b9a8 100644 --- a/store/plugin/translations/de-DE.json +++ b/store/plugin/translations/de-DE.json @@ -1,3 +1,4 @@ { - "This version of \"Plugin Manager\" is not official." : "Diese Version von \"Plugin Manager\" ist nicht offiziell." + "This version of \"Plugin Manager\" is not official." : "Diese Version von \"Plugin Manager\" ist nicht offiziell.", + "No Internet Connection.": "Keine Internetverbindung." } \ No newline at end of file diff --git a/store/plugin/translations/es-ES.json b/store/plugin/translations/es-ES.json index 9363272f..7cb5bb99 100644 --- a/store/plugin/translations/es-ES.json +++ b/store/plugin/translations/es-ES.json @@ -1,3 +1,4 @@ { - "This version of \"Plugin Manager\" is not official." : "Esta versión de \"Plugin Manager\" no es oficial." + "This version of \"Plugin Manager\" is not official." : "Esta versión de \"Plugin Manager\" no es oficial.", + "No Internet Connection.": "Sin Conexión a Internet." } \ No newline at end of file diff --git a/store/plugin/translations/fr-FR.json b/store/plugin/translations/fr-FR.json index 91e9dcbb..71616643 100644 --- a/store/plugin/translations/fr-FR.json +++ b/store/plugin/translations/fr-FR.json @@ -1,3 +1,4 @@ { - "This version of \"Plugin Manager\" is not official." : "Cette version de \"Plugin Manager\" n'est pas officielle.." + "This version of \"Plugin Manager\" is not official." : "Cette version de \"Plugin Manager\" n'est pas officielle.", + "No Internet Connection.": "Pas De Connexion Internet." } \ No newline at end of file diff --git a/store/plugin/translations/ru-RU.json b/store/plugin/translations/ru-RU.json index 69ead770..017b154b 100644 --- a/store/plugin/translations/ru-RU.json +++ b/store/plugin/translations/ru-RU.json @@ -1,3 +1,4 @@ { - "This version of \"Plugin Manager\" is not official." : "Эта версия \"Менеджера Плагинов\" не является официальной." + "This version of \"Plugin Manager\" is not official." : "Эта версия \"Менеджера Плагинов\" не является официальной.", + "No Internet Connection.": "Отсутствует соединение с интернетом." } \ No newline at end of file