diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-11-03 06:47:51 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-11-03 06:47:51 +1300 |
commit | f97cba3ce4bac8b1e5df62e31b082bc68c7ac320 (patch) | |
tree | 63b24ca7f9fd2885314867d2d5e52d82ecdd1c5e | |
parent | a0a618d2cc0f5a6a8423d9eeb6fca54fcf8b41ff (diff) | |
download | trackermap-web-f97cba3ce4bac8b1e5df62e31b082bc68c7ac320.tar.gz trackermap-web-f97cba3ce4bac8b1e5df62e31b082bc68c7ac320.tar.bz2 trackermap-web-f97cba3ce4bac8b1e5df62e31b082bc68c7ac320.zip |
Refactor web app loading
-rw-r--r-- | web/debug.html | 14 | ||||
-rw-r--r-- | web/load.js | 125 | ||||
-rw-r--r-- | web/locale.js | 81 | ||||
-rw-r--r-- | web/release.html | 13 |
4 files changed, 127 insertions, 106 deletions
diff --git a/web/debug.html b/web/debug.html index a865e667..bafdd3c4 100644 --- a/web/debug.html +++ b/web/debug.html @@ -4,22 +4,10 @@ <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title>Traccar</title> -<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/theme-crisp/resources/theme-crisp-all.css"> -<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/ol3/3.18.2/ol.css"> -<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"> -<link rel="stylesheet" href="app.css"> </head> <body> <div id="spinner"></div> <div id="attribution">Powered by <a href="https://www.traccar.org/">Traccar GPS Tracking System</a></div> -<script src="//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/ext-all-debug.js"></script> -<script src="//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/theme-crisp/theme-crisp.js"></script> -<script src="//cdnjs.cloudflare.com/ajax/libs/ol3/3.18.2/ol-debug.js"></script> -<script src="arrow.js"></script> -<script type="text/javascript"> -Ext.Loader.setConfig({ disableCaching: false }); -</script> -<script src="locale.js"></script> -<script src="app.js"></script> +<script id="loadScript" mode="debug" src="load.js"></script> </body> </html> diff --git a/web/load.js b/web/load.js new file mode 100644 index 00000000..ea3ae530 --- /dev/null +++ b/web/load.js @@ -0,0 +1,125 @@ +(function () { + + function addStyleFile(file) { + var link = document.createElement('link'); + link.setAttribute('rel', 'stylesheet'); + link.setAttribute('type', 'text/css'); + link.setAttribute('href', file); + document.head.appendChild(link) + } + + function addScriptFile(file) { + var script = document.createElement('script'); + script.setAttribute('src', file); + script.async = false + document.head.appendChild(script); + } + + var debugMode = document.getElementById('loadScript').getAttribute('mode') === 'debug'; + var touchMode = 'ontouchstart' in window || navigator.maxTouchPoints; + + var locale = {}; + window.Locale = locale; + + locale.languages = { + 'ar': { name: 'العربية', code: 'en' }, + 'bg': { name: 'Български', code: 'bg' }, + 'cs': { name: 'Čeština', code: 'cs' }, + 'de': { name: 'Deutsch', code: 'de' }, + 'da': { name: 'Dansk', code: 'da' }, + 'el': { name: 'Ελληνικά', code: 'el' }, + 'en': { name: 'English', code: 'en' }, + 'es': { name: 'Español', code: 'es' }, + 'fa': { name: 'فارسی', code: 'fa' }, + 'fi': { name: 'Suomi', code: 'fi' }, + 'fr': { name: 'Français', code: 'fr' }, + 'he': { name: 'עברית', code: 'he' }, + 'hi': { name: 'हिन्दी', code: 'en' }, + 'hu': { name: 'Magyar', code: 'hu' }, + 'id': { name: 'Bahasa Indonesia', code: 'id' }, + 'it': { name: 'Italiano', code: 'it' }, + 'ka': { name: 'ქართული', code: 'en' }, + 'lo': { name: 'ລາວ', code: 'en' }, + 'lt': { name: 'Lietuvių', code: 'lt' }, + 'ml': { name: 'മലയാളം', code: 'en' }, + 'ms': { name: 'بهاس ملايو', code: 'en' }, + 'nb': { name: 'Norsk bokmål', code: 'no_NB' }, + 'ne': { name: 'नेपाली', code: 'en' }, + 'nl': { name: 'Nederlands', code: 'nl' }, + 'nn': { name: 'Norsk nynorsk', code: 'no_NN' }, + 'pl': { name: 'Polski', code: 'pl' }, + 'pt': { name: 'Português', code: 'pt' }, + 'pt_BR': { name: 'Português (Brasil)', code: 'pt_BR' }, + 'ro': { name: 'Română', code: 'ro' }, + 'ru': { name: 'Русский', code: 'ru' }, + 'si': { name: 'සිංහල', code: 'en' }, + 'sk': { name: 'Slovenčina', code: 'sk' }, + 'sl': { name: 'Slovenščina', code: 'sl' }, + 'sq': { name: 'Shqipëria', code: 'en' }, + 'sr': { name: 'Srpski', code: 'sr' }, + 'ta': { name: 'தமிழ்', code: 'en' }, + 'th': { name: 'ไทย', code: 'th' }, + 'tr': { name: 'Türkçe', code: 'tr' }, + 'uk': { name: 'Українська', code: 'ukr' }, + 'vi': { name: 'Tiếng Việt', code: 'en' }, + 'zh': { name: '中文', code: 'zh_CN' } + }; + + var localeParameter = window.location.search.match(/locale=([^&#]+)/); + locale.language = localeParameter && localeParameter[1]; + if (locale.language === undefined) { + locale.language = window.navigator.userLanguage || window.navigator.language; + locale.language = locale.language.substr(0, 2); + } + + if (!(locale.language in locale.languages)) { + locale.language = 'en'; // default + } + + window.addEventListener("load", function (event) { + + if (debugMode) { + Ext.Loader.setConfig({ + disableCaching: false + }); + } + + Ext.Ajax.request({ + url: 'l10n/' + Locale.language + '.json', + callback: function (options, success, response) { + window.Strings = Ext.decode(response.responseText); + + if (debugMode) { + addScriptFile('app.js'); + } else { + addScriptFile('app.min.js'); + } + } + }); + + }); + + if (debugMode) { + addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/ext-all-debug.js'); + } else { + addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/ext-all.js'); + } + addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/locale/locale-' + locale.languages[locale.language].code + '.js'); + + if (touchMode) { + addStyleFile('//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/theme-crisp-touch/resources/theme-crisp-touch-all.css'); + addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/theme-crisp-touch/theme-crisp-touch.js'); + } else { + addStyleFile('//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/theme-crisp/resources/theme-crisp-all.css'); + addScriptFile('//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/theme-crisp/theme-crisp.js'); + } + + addStyleFile('//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css'); + + addStyleFile('//cdnjs.cloudflare.com/ajax/libs/ol3/3.18.2/ol.css'); + addScriptFile('//cdnjs.cloudflare.com/ajax/libs/ol3/3.18.2/ol-debug.js'); + + addStyleFile('app.css'); + addScriptFile('arrow.js'); + +})(); diff --git a/web/locale.js b/web/locale.js deleted file mode 100644 index 0cc7f4b2..00000000 --- a/web/locale.js +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2015 Anton Tananaev (anton@traccar.org) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -var Locale = {}; - -Locale.languages = { - 'ar': { name: 'العربية', code: 'en' }, - 'bg': { name: 'Български', code: 'bg' }, - 'cs': { name: 'Čeština', code: 'cs' }, - 'de': { name: 'Deutsch', code: 'de' }, - 'da': { name: 'Dansk', code: 'da' }, - 'el': { name: 'Ελληνικά', code: 'el' }, - 'en': { name: 'English', code: 'en' }, - 'es': { name: 'Español', code: 'es' }, - 'fa': { name: 'فارسی', code: 'fa' }, - 'fi': { name: 'Suomi', code: 'fi' }, - 'fr': { name: 'Français', code: 'fr' }, - 'he': { name: 'עברית', code: 'he' }, - 'hi': { name: 'हिन्दी', code: 'en' }, - 'hu': { name: 'Magyar', code: 'hu' }, - 'id': { name: 'Bahasa Indonesia', code: 'id' }, - 'it': { name: 'Italiano', code: 'it' }, - 'ka': { name: 'ქართული', code: 'en' }, - 'lo': { name: 'ລາວ', code: 'en' }, - 'lt': { name: 'Lietuvių', code: 'lt' }, - 'ml': { name: 'മലയാളം', code: 'en' }, - 'ms': { name: 'بهاس ملايو', code: 'en' }, - 'nb': { name: 'Norsk bokmål', code: 'no_NB' }, - 'ne': { name: 'नेपाली', code: 'en' }, - 'nl': { name: 'Nederlands', code: 'nl' }, - 'nn': { name: 'Norsk nynorsk', code: 'no_NN' }, - 'pl': { name: 'Polski', code: 'pl' }, - 'pt': { name: 'Português', code: 'pt' }, - 'pt_BR': { name: 'Português (Brasil)', code: 'pt_BR' }, - 'ro': { name: 'Română', code: 'ro' }, - 'ru': { name: 'Русский', code: 'ru' }, - 'si': { name: 'සිංහල', code: 'en' }, - 'sk': { name: 'Slovenčina', code: 'sk' }, - 'sl': { name: 'Slovenščina', code: 'sl' }, - 'sq': { name: 'Shqipëria', code: 'en' }, - 'sr': { name: 'Srpski', code: 'sr' }, - 'ta': { name: 'தமிழ்', code: 'en' }, - 'th': { name: 'ไทย', code: 'th' }, - 'tr': { name: 'Türkçe', code: 'tr' }, - 'uk': { name: 'Українська', code: 'ukr' }, - 'vi': { name: 'Tiếng Việt', code: 'en' }, - 'zh': { name: '中文', code: 'zh_CN' } -}; - -Locale.language = Ext.Object.fromQueryString(window.location.search.substring(1)).locale; -if (Locale.language === undefined) { - Locale.language = window.navigator.userLanguage || window.navigator.language; - Locale.language = Locale.language.substr(0, 2); -} - -if (!(Locale.language in Locale.languages)) { - Locale.language = 'en'; // default -} - -Ext.Ajax.request({ - url: 'l10n/' + Locale.language + '.json', - callback: function (options, success, response) { - Strings = Ext.decode(response.responseText); - } -}); - -Ext.Loader.loadScript('//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/locale/locale-' + Locale.languages[Locale.language].code + '.js'); diff --git a/web/release.html b/web/release.html index 1824669e..3113f36c 100644 --- a/web/release.html +++ b/web/release.html @@ -4,21 +4,10 @@ <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title>Traccar</title> -<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/theme-crisp/resources/theme-crisp-all.css"> -<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/ol3/3.18.2/ol.css"> -<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"> -<link rel="stylesheet" href="app.css"> </head> <body> <div id="spinner"></div> <div id="attribution">Powered by <a href="https://www.traccar.org/">Traccar GPS Tracking System</a></div> -<script src="//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/ext-all.js"></script> -<script src="//cdnjs.cloudflare.com/ajax/libs/extjs/6.0.1/classic/theme-crisp/theme-crisp.js"></script> -<script src="//cdnjs.cloudflare.com/ajax/libs/ol3/3.18.2/ol-debug.js"></script> -<script src="arrow.js"></script> -<script src="locale.js"></script> -<script type="text/javascript"> -Ext.Loader.loadScript('app.min.js'); -</script> +<script id="loadScript" src="load.js"></script> </body> </html> |