Gustavo Luigi 2023-10-21 01:44:42 -03:00
parent 7f748127b8
commit 6ab9c53fe8
4 changed files with 11 additions and 52 deletions

View File

@ -18,7 +18,7 @@ export async function sync() {
let ids = items.map(obj => obj.id);

if (ids.length > 0) {
let products = await fetch(document.querySelector('meta[name="get-contents"]').getAttribute('content') + "/" + ids.join(","));
let products = await fetch(url("contents/" + ids.join(",")));
products = await products.json();

products.contents.forEach(product => {

View File

@ -1,4 +1,5 @@
import * as Cart from './modules/cart.js';
import { url } from './utils.js';

document.addEventListener("DOMContentLoaded", async () => {
let productId = document.querySelector('meta[name="product-id"]').getAttribute('content');
@ -26,7 +27,7 @@ document.addEventListener("DOMContentLoaded", async () => {
btnCheckOut.addEventListener("click", () => {
let productId = btnCheckOut.getAttribute("data-id");
Cart.addItem(productId);
window.location.replace(document.querySelector('meta[name="checkout"]').getAttribute('content'));
window.location.replace(url("/checkout"));
});

let btnAddToBag = document.querySelector('#btn-add-to-bag');

View File

@ -15,40 +15,8 @@ export function isEncoded(string) {
return true;
}

export function fetchData(method = null, url, data = null) {

const csrf = $('meta[name="csrf-token"]').attr('content');
const urlBase = document.querySelector('meta[name="url-base"]').getAttribute("content");

const urlPattern = /^(https?:\/\/|ftp:\/\/)[^\s/$.?#].[^\s]*$/i;
const pathPattern = /^(\/|[^\/\s]+\/)[^\s]*$/;

if (pathPattern.test(url)) url = urlBase + (url.startsWith('/') ? "" : "/") + url;
else if (!urlPattern.test(url)) throw new Error("Invalid URL.");

return fetch(url, {
method: method ?? 'GET',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': csrf
},
body: JSON.stringify(data ?? {})
})
.then(response => response.json())
.catch(error => console.error("Error fetching data:", error));
}

export function url(path = "") {
let protocol = window.location.protocol;
let host = window.location.hostname;
let port = window.location.port;
let pathk = window.location.pathname;

let baseUrl = protocol + "//" + host + (port ? ':' + port : '');

let pathArray = pathk.split('/');
pathArray.pop();
let directoryOnly = pathArray.join('/');

return baseUrl + directoryOnly + '/' + path;
const baseUrlElement = document.getElementById("base-url");
const baseUrl = baseUrlElement ? baseUrlElement.getAttribute("content") : "";
return baseUrl + path;
}

View File

@ -5,17 +5,16 @@
<meta name="viewport" content="width=device-width">
<meta name="Generator" content="Lumino CMS" />
<title>{{config('settings.name')}}</title>
@include('template.'.config('settings.template').'.content.includes.css')

<meta name="csrf-token" content="{{csrf_token()}}"/>
<meta name="url-base" content="{{url('/')}}">
<meta name="checkout" content="{{url('/checkout')}}">
<meta name="get-contents" content="{{url('/contents')}}">

<link rel="apple-touch-icon" sizes="180x180" href="{{$favicon['180']}}">
<link rel="icon" type="image/png" sizes="32x32" href="{{$favicon['32']}}">
<link rel="icon" type="image/png" sizes="16x16" href="{{$favicon['16']}}">

@include('template.'.config('settings.template').'.content.includes.css')

@yield('head')
</head>
<body>
@ -47,15 +46,11 @@
</picture>
</a>


@if(!Request::is('checkout'))


@if(!request()->is('checkout'))
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>


<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav fs-5">
<a class="nav-item nav-link {{request()->is('produkt*')?'active':''}}" href="{{url('/produkte')}}">Produkte</a>
@ -76,12 +71,9 @@
</a>
</li>
@endif

</ul>
</div>
@endif


</div>
</nav>

@ -137,18 +129,16 @@
</div>
<div class="row mt-3" id="modal-buttons">
<div class="col-6">
<button class="btn btn-light text-muted text-decoration-none" data-bs-toggle="modal" data-bs-target="#share-cart">
<button class="btn btn-transparent text-muted text-decoration-none border" data-bs-toggle="modal" data-bs-target="#share-cart">
Warenkorb teilen
<svg style="fill: currentColor; width: 19px; margin-left: 4px; margin-bottom: 4px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M564.907 196.35L388.91 12.366C364.216-13.45 320 3.746 320 40.016v88.154C154.548 130.155 0 160.103 0 331.19c0 94.98 55.84 150.231 89.13 174.571 24.233 17.722 58.021-4.992 49.68-34.51C100.937 336.887 165.575 321.972 320 320.16V408c0 36.239 44.19 53.494 68.91 27.65l175.998-184c14.79-15.47 14.79-39.83-.001-55.3zm-23.127 33.18l-176 184c-4.933 5.16-13.78 1.73-13.78-5.53V288c-171.396 0-295.313 9.707-243.98 191.7C72 453.36 32 405.59 32 331.19 32 171.18 194.886 160 352 160V40c0-7.262 8.851-10.69 13.78-5.53l176 184a7.978 7.978 0 0 1 0 11.06z"/></svg>
</button>

</div>
<div class="col-6 text-end">
<a href="{{url('/checkout')}}" type="button" class="btn btn-primary">Angebot unverbindlich anfragen</a>
</div>
</div>
</div>

</div>
</div>
</div>