mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-23 12:09:30 -07:00
add "share" link
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
|||||||
message as navMessage, isPlaying, resize, resetStatuses, latLonReceived, stopAutoRefreshTimer, registerRefreshData,
|
message as navMessage, isPlaying, resize, resetStatuses, latLonReceived, stopAutoRefreshTimer, registerRefreshData,
|
||||||
} from './modules/navigation.mjs';
|
} from './modules/navigation.mjs';
|
||||||
import { round2 } from './modules/utils/units.mjs';
|
import { round2 } from './modules/utils/units.mjs';
|
||||||
|
import { createLink, readLink } from './modules/share.mjs';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
init();
|
init();
|
||||||
|
|||||||
40
server/scripts/modules/share.mjs
Normal file
40
server/scripts/modules/share.mjs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
document.addEventListener('DOMContentLoaded', () => init());
|
||||||
|
|
||||||
|
const init = () => {
|
||||||
|
// add action to existing link
|
||||||
|
document.querySelector('#share-link').addEventListener('click', createLink);
|
||||||
|
};
|
||||||
|
|
||||||
|
const createLink = (e) => {
|
||||||
|
// cancel default event (click on hyperlink)
|
||||||
|
e.preventDefault();
|
||||||
|
// get all checkboxes on page
|
||||||
|
const checkboxes = document.querySelectorAll('input[type=checkbox]');
|
||||||
|
|
||||||
|
// list to receive checkbox statuses
|
||||||
|
const queryStringElements = {};
|
||||||
|
|
||||||
|
[...checkboxes].forEach((elem) => {
|
||||||
|
if (elem?.id) {
|
||||||
|
queryStringElements[elem.id] = elem?.checked ?? false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// add the location string
|
||||||
|
queryStringElements.txtAddress = document.querySelector('#txtAddress')?.value ?? '';
|
||||||
|
|
||||||
|
const queryString = (new URLSearchParams(queryStringElements)).toString();
|
||||||
|
|
||||||
|
const url = new URL(`?${queryString}`, document.location.href);
|
||||||
|
|
||||||
|
console.log(queryStringElements);
|
||||||
|
console.log(queryString);
|
||||||
|
console.log(url.toString());
|
||||||
|
};
|
||||||
|
|
||||||
|
const readLink = false;
|
||||||
|
|
||||||
|
export {
|
||||||
|
createLink,
|
||||||
|
readLink,
|
||||||
|
};
|
||||||
@@ -151,6 +151,10 @@
|
|||||||
<div id='settings'>
|
<div id='settings'>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class='info'>
|
||||||
|
<a href='' id='share-link'>Share this configuration</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="divInfo">
|
<div id="divInfo">
|
||||||
Location: <span id="spanCity"></span> <span id="spanState"></span><br />
|
Location: <span id="spanCity"></span> <span id="spanState"></span><br />
|
||||||
Station Id: <span id="spanStationId"></span><br />
|
Station Id: <span id="spanStationId"></span><br />
|
||||||
|
|||||||
Reference in New Issue
Block a user