From b09bfb15e8f2b3b1c652a61667426197c9ca7045 Mon Sep 17 00:00:00 2001 From: Fady Mondy Date: Fri, 3 Feb 2023 22:28:15 +0200 Subject: [PATCH] add upgrade command and fix lang problem --- publish/resources/js/helpers.js | 221 ++++++++++++++++++-------------- 1 file changed, 125 insertions(+), 96 deletions(-) diff --git a/publish/resources/js/helpers.js b/publish/resources/js/helpers.js index b6effd2..04bdd24 100644 --- a/publish/resources/js/helpers.js +++ b/publish/resources/js/helpers.js @@ -1,100 +1,129 @@ import { provide, ref } from "vue"; export default { - setStorage(key, value = null, set = false) { - if (set) { - if (value === "toggle") { - localStorage.setItem(key, !JSON.parse(localStorage.getItem(key))); - } else { - localStorage.setItem(key, value); - } - } else { - const getStorageByKey = JSON.parse(localStorage.getItem(key)); - if (getStorageByKey !== null && getStorageByKey !== undefined) { - return getStorageByKey; - } else { - localStorage.setItem(key, JSON.stringify(false)); - return false; - } - } - }, - setDarkMode(payload = null) { - this.setStorage("dark", payload !== null ? payload : "toggle", true); - const dark = this.setStorage("dark"); - if (typeof document !== undefined) { - document.body.classList[dark ? "add" : "remove"]("dark-scrollbars"); - document.documentElement.classList[dark ? "add" : "remove"]("dark"); - } - }, - langSwitch(lang = null) { - let htmlEl = document.querySelector("html"); - if (lang) { - if (lang === "ar") { - htmlEl.setAttribute("dir", "rtl"); - } else { - htmlEl.setAttribute("dir", "ltr"); - } - } else { - if (this.setStorage("lang") && this.setStorage("lang").id === "ar") { - htmlEl.setAttribute("dir", "ltr"); - this.setStorage( - "lang", - JSON.stringify({ id: "en", name: "English" }), - true - ); - document.cookie = - "lang=" + - JSON.stringify({ - id: "en", - name: "English", - }) + - ";domain=" + - window.location.hostname + - ";path=/"; - } else { - htmlEl.setAttribute("dir", "rtl"); - this.setStorage( - "lang", - JSON.stringify({ id: "ar", name: "Arabic" }), - true - ); - document.cookie = - "lang=" + - JSON.stringify({ - id: "ar", - name: "Arabic", - }) + - ";domain=" + - window.location.hostname + - ";path=/"; - } - } - }, - setAsideMenuGroup(key, action = false) { - if (action) { - const AsideMenuGroup = this.setStorage("AsideMenuGroup") - ? this.setStorage("AsideMenuGroup") - : {}; - if (AsideMenuGroup) { - AsideMenuGroup[key] = AsideMenuGroup.hasOwnProperty(key) - ? !AsideMenuGroup[key] - : true; - } - this.setStorage("AsideMenuGroup", JSON.stringify(AsideMenuGroup), true); - } else { - if ( - this.setStorage("AsideMenuGroup") !== undefined && - this.setStorage("AsideMenuGroup")[key] !== undefined - ) { - return this.setStorage("AsideMenuGroup")[key]; - } else { - const AsideMenuGroup = this.setStorage("AsideMenuGroup") - ? this.setStorage("AsideMenuGroup") - : {}; - AsideMenuGroup[key] = true; - this.setStorage("AsideMenuGroup", JSON.stringify(AsideMenuGroup), true); + setStorage(key, value = null, set = false) { + if (set) { + if (value === "toggle") { + localStorage.setItem(key, !JSON.parse(localStorage.getItem(key))); + } else { + localStorage.setItem(key, value); + } + } else { + const getStorageByKey = JSON.parse(localStorage.getItem(key)); + if (getStorageByKey !== null && getStorageByKey !== undefined) { + return getStorageByKey; + } else { + localStorage.setItem(key, JSON.stringify(false)); + return false; + } + } + }, + setDarkMode(payload = null) { + this.setStorage("dark", payload !== null ? payload : "toggle", true); + const dark = this.setStorage("dark"); + if (typeof document !== undefined) { + document.body.classList[dark ? "add" : "remove"]("dark-scrollbars"); + document.documentElement.classList[dark ? "add" : "remove"]("dark"); + } + }, + langSwitch(lang = null) { + let htmlEl = document.querySelector("html"); + console.log(lang) + if (lang) { + if (lang === "ar") { + htmlEl.setAttribute("dir", "rtl"); + this.setStorage( + "lang", + JSON.stringify({ id: "ar", name: "Arabic" }), + true + ); + document.cookie = + "lang=" + + JSON.stringify({ + id: "ar", + name: "Arabic", + }) + + ";domain=" + + window.location.hostname + + ";path=/"; + } else { + htmlEl.setAttribute("dir", "ltr"); + this.setStorage( + "lang", + JSON.stringify({ id: "en", name: "English" }), + true + ); + document.cookie = + "lang=" + + JSON.stringify({ + id: "en", + name: "English", + }) + + ";domain=" + + window.location.hostname + + ";path=/"; + } + } else { + if (this.setStorage("lang") && this.setStorage("lang").id === "ar") { + htmlEl.setAttribute("dir", "ltr"); + this.setStorage( + "lang", + JSON.stringify({ id: "en", name: "English" }), + true + ); + document.cookie = + "lang=" + + JSON.stringify({ + id: "en", + name: "English", + }) + + ";domain=" + + window.location.hostname + + ";path=/"; + } else { + htmlEl.setAttribute("dir", "rtl"); + this.setStorage( + "lang", + JSON.stringify({ id: "ar", name: "Arabic" }), + true + ); + document.cookie = + "lang=" + + JSON.stringify({ + id: "ar", + name: "Arabic", + }) + + ";domain=" + + window.location.hostname + + ";path=/"; + } + } + }, + setAsideMenuGroup(key, action = false) { + if (action) { + const AsideMenuGroup = this.setStorage("AsideMenuGroup") + ? this.setStorage("AsideMenuGroup") + : {}; + if (AsideMenuGroup) { + AsideMenuGroup[key] = AsideMenuGroup.hasOwnProperty(key) + ? !AsideMenuGroup[key] + : true; + } + this.setStorage("AsideMenuGroup", JSON.stringify(AsideMenuGroup), true); + } else { + if ( + this.setStorage("AsideMenuGroup") !== undefined && + this.setStorage("AsideMenuGroup")[key] !== undefined + ) { + return this.setStorage("AsideMenuGroup")[key]; + } else { + const AsideMenuGroup = this.setStorage("AsideMenuGroup") + ? this.setStorage("AsideMenuGroup") + : {}; + AsideMenuGroup[key] = true; + this.setStorage("AsideMenuGroup", JSON.stringify(AsideMenuGroup), true); - return false; - } - } - }, + return false; + } + } + }, };