diff options
author | Luciano Iam <lucianito@gmail.com> | 2020-04-11 09:37:00 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2020-04-11 22:30:40 +0200 |
commit | c96e392f0fc252fd6ae8d4d91a950bed146a8d51 (patch) | |
tree | dcb9ec28945e8e6125d8b90f381acf73bc0bcbb9 /share/web_surfaces/index | |
parent | e82171ea1954c3e80040c063c401ceb0913b4dd3 (diff) |
WebSockets: prepare for developing a shared JS API client
Diffstat (limited to 'share/web_surfaces/index')
-rw-r--r-- | share/web_surfaces/index/junge-regular-webfont.ttf | bin | 0 -> 71400 bytes | |||
-rw-r--r-- | share/web_surfaces/index/junge-regular-webfont.woff | bin | 0 -> 30848 bytes | |||
-rw-r--r-- | share/web_surfaces/index/logo.png | bin | 0 -> 36211 bytes | |||
-rw-r--r-- | share/web_surfaces/index/main.css | 81 | ||||
-rw-r--r-- | share/web_surfaces/index/main.js | 80 |
5 files changed, 161 insertions, 0 deletions
diff --git a/share/web_surfaces/index/junge-regular-webfont.ttf b/share/web_surfaces/index/junge-regular-webfont.ttf Binary files differnew file mode 100644 index 0000000000..4e381e9e3f --- /dev/null +++ b/share/web_surfaces/index/junge-regular-webfont.ttf diff --git a/share/web_surfaces/index/junge-regular-webfont.woff b/share/web_surfaces/index/junge-regular-webfont.woff Binary files differnew file mode 100644 index 0000000000..4a74925aa9 --- /dev/null +++ b/share/web_surfaces/index/junge-regular-webfont.woff diff --git a/share/web_surfaces/index/logo.png b/share/web_surfaces/index/logo.png Binary files differnew file mode 100644 index 0000000000..652a6c3e1c --- /dev/null +++ b/share/web_surfaces/index/logo.png diff --git a/share/web_surfaces/index/main.css b/share/web_surfaces/index/main.css new file mode 100644 index 0000000000..3b330fa36f --- /dev/null +++ b/share/web_surfaces/index/main.css @@ -0,0 +1,81 @@ +@font-face { + font-family: 'junge-regular'; + src: url('junge-regular-webfont.woff') format('woff'), + url('junge-regular-webfont.ttf') format('truetype'); + font-weight: normal; + font-style: normal; +} + +html { + height: 100%; +} + +body { + font-family: 'junge-regular'; + font-size: 16px; + height: 100%; + margin: 0; +} + +div { + box-sizing: border-box; +} + +a { + color: #337ab7; + text-decoration: none; +} + +a:visited { + text-decoration: underline; +} + +a:focus, a:hover { + color: #23527c; + text-decoration: underline; +} + +h1, h2 { + font-weight: normal; +} + +h1 { + font-size: 1.8em; + margin: 0 0 2ex 0; + padding-bottom: .8ex; +} + +h2 { + font-size: 1.3em; + margin: 2ex 0 1ex 0; +} + +#top-bar { + background: #212a30; + padding: 4px; +} + +#logo { + height: 36px; + margin: 8px 8px 0 8px; +} + +#content { + padding: 24px; +} + +#index h2 { + border-bottom: 2px solid #ddd; +} + +.surface-list { + margin-bottom: 6ex; +} + +.surface-list > ul { + list-style-type: none; +} + +.surface-list > ul > li { + margin: 4ex 0; +}
\ No newline at end of file diff --git a/share/web_surfaces/index/main.js b/share/web_surfaces/index/main.js new file mode 100644 index 0000000000..9a8e9301a5 --- /dev/null +++ b/share/web_surfaces/index/main.js @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2020 Luciano Iam <lucianito@gmail.com> + * + * 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 2 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +(() => { + + const INDEX_RESOURCE = 'index.json'; + + async function fetchIndex (url) { + const response = await fetch(url); + + if (response.status == 200) { + return await response.json(); + } else { + throw new Error(`HTTP response status ${response.status}`); + } + } + + function buildItem (group, model) { + const li = document.createElement('li'); + li.innerHTML = `<li> + <a href="${group}/${model.id}/">${model.name}</a> + <p>${model.description}</p> + </li>`; + return li; + } + + function printIndex (index) { + ['builtin', 'user'].forEach((group) => { + const ul = document.getElementById(group); + let models = index[group]; + + if (models.length > 0) { + models.sort((a, b) => a.name.localeCompare(b.name)); + for (model of models) { + ul.appendChild(buildItem(group, model)); + } + } else { + ul.parentNode.style.display = 'none'; + } + }); + + document.getElementById('index').style.display = 'inline'; + } + + function printError (message) { + const error = document.getElementById('error'); + error.innerHTML = message; + error.style.display = 'inline'; + } + + async function main () { + try { + const indexUrl = `${location.protocol}//${location.host}/${INDEX_RESOURCE}`; + const index = await fetchIndex (indexUrl); + printIndex(index); + } catch (err) { + printError(`Error loading ${INDEX_RESOURCE}: ${err.message}`); + } + + document.getElementById('loading').style.display = 'none'; + } + + main(); + +})(); |