From 6ab9c53fe828edfa7347d657e86275105de63922 Mon Sep 17 00:00:00 2001 From: Gustavo Luigi <=> Date: Sat, 21 Oct 2023 01:44:42 -0300 Subject: [PATCH] . --- assets/js/modules/cart.js | 2 +- assets/js/product.js | 3 ++- assets/js/utils.js | 38 +++----------------------------------- content/master.blade.php | 20 +++++--------------- 4 files changed, 11 insertions(+), 52 deletions(-) diff --git a/assets/js/modules/cart.js b/assets/js/modules/cart.js index e649bea..e290880 100644 --- a/assets/js/modules/cart.js +++ b/assets/js/modules/cart.js @@ -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 => { diff --git a/assets/js/product.js b/assets/js/product.js index da6a74f..2bd3d11 100644 --- a/assets/js/product.js +++ b/assets/js/product.js @@ -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'); diff --git a/assets/js/utils.js b/assets/js/utils.js index 151cdc3..64cb1df 100644 --- a/assets/js/utils.js +++ b/assets/js/utils.js @@ -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; } \ No newline at end of file diff --git a/content/master.blade.php b/content/master.blade.php index 3975349..c205465 100644 --- a/content/master.blade.php +++ b/content/master.blade.php @@ -5,17 +5,16 @@ {{config('settings.name')}} - @include('template.'.config('settings.template').'.content.includes.css') - + - - + @include('template.'.config('settings.template').'.content.includes.css') + @yield('head') @@ -47,15 +46,11 @@ - - @if(!Request::is('checkout')) - - + @if(!request()->is('checkout')) - @endif - - @@ -137,18 +129,16 @@ -