2020-02-16 19:39:44 +01:00
|
|
|
export default class UrlParam
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
this.url = document.location.toString();
|
|
|
|
this.params = UrlParam.getParamsFromUrl(this.url);
|
|
|
|
}
|
|
|
|
|
|
|
|
get(name)
|
|
|
|
{
|
|
|
|
return this.params[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
static getParamsFromUrl(url)
|
|
|
|
{
|
|
|
|
let urlParts = url.split('?');
|
|
|
|
|
|
|
|
if (urlParts.length !== 2) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
let params = urlParts[1].split('&');
|
|
|
|
|
|
|
|
if (params.length === 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
let pairs = [];
|
|
|
|
|
|
|
|
params.forEach(
|
|
|
|
(param) => {
|
|
|
|
let parts = param.split('=');
|
|
|
|
|
|
|
|
if (parts.length !== 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pairs[parts[0]] = parts[1];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return pairs;
|
|
|
|
}
|
|
|
|
|
|
|
|
getInt(name)
|
|
|
|
{
|
2023-09-17 14:18:21 +02:00
|
|
|
const value = parseInt(this.get(name));
|
2020-02-16 19:39:44 +01:00
|
|
|
|
2023-09-17 14:18:21 +02:00
|
|
|
return isNaN(value) ? 0 : value;
|
2020-02-16 19:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getFloat(name)
|
|
|
|
{
|
2023-09-17 14:18:21 +02:00
|
|
|
const value = parseFloat(this.get(name));
|
2020-02-16 19:39:44 +01:00
|
|
|
|
2023-09-17 14:18:21 +02:00
|
|
|
return isNaN(value) ? 0.0 : value;
|
2020-02-16 19:39:44 +01:00
|
|
|
}
|
2023-09-17 14:18:21 +02:00
|
|
|
}
|