/* Add custom Js code below */ /* TMS - language-aware copyright, English labels, AR/EN + currency circles next to search */ (function () { var path = location.pathname; var isEn = /^\/en(\/|$)/.test(path) || (document.documentElement.lang || '').indexOf('en') === 0; var link = "https://tms7h.com" + (isEn ? "/en" : "/ar"); var year = new Date().getFullYear(); /* English labels for texts the store settings keep in Arabic */ var EN = { "المدونة": "Blog", "الختم المعدني": "The Metallic Stamp", "عام": "General" }; function setCopyright() { var p = document.querySelector(".copyrights p"); if (!p) return; p.innerHTML = isEn ? 'Crafted with precision by The Metallic Stamp | ' + year : 'صنع بإتقان على الختم المعدني | ' + year; } function translate(root) { if (!isEn || !root || !root.querySelectorAll) return; root.querySelectorAll("a, span, p, li, h2, h3, h4, button").forEach(function (el) { if (el.children.length) return; var t = el.textContent.trim(); if (EN[t]) el.textContent = EN[t]; }); /* blog tags exist in Arabic only: hide them on English pages */ root.querySelectorAll('a[href*="/tag-"]').forEach(function (a) { a.style.display = "none"; }); } function switchUrl() { var target = isEn ? "ar" : "en"; var p = location.pathname; p = /^\/(ar|en)(\/|$)/.test(p) ? p.replace(/^\/(ar|en)/, "/" + target) : "/" + target + (p === "/" ? "" : p); return p + location.search + location.hash; } /* Language + currency circles placed right after the search icon */ function addHeaderButtons() { if (document.querySelector(".tms-hbtns")) return; var search = document.querySelector("header .search-btn"); if (!search) return; var wrap = document.createElement("div"); wrap.className = "tms-hbtns"; /* Language: shows "En" on Arabic pages and "ع" on English pages */ var lang = document.createElement("a"); lang.className = "tms-circle"; lang.href = switchUrl(); lang.textContent = isEn ? "ع" : "En"; lang.setAttribute("aria-label", isEn ? "التبديل إلى العربية" : "Switch to English"); wrap.appendChild(lang); search.parentNode.insertBefore(wrap, search.nextSibling); addCurrency(wrap, 0); } /* Currency: shows the current currency, opens a list of enabled currencies (waits for Salla to load them) */ function addCurrency(wrap, tries) { if (wrap.querySelector(".tms-cur")) return; var cfg = window.salla && salla.config; var list = (cfg && cfg.get && cfg.get("currencies")) || {}; var codes = Object.keys(list).filter(function (c) { return list[c].status !== "disabled"; }); if (codes.length < 2) { if (tries < 40) setTimeout(function () { addCurrency(wrap, tries + 1); }, 250); return; } var cur = cfg.get("user.currency_code") || "SAR"; { var box = document.createElement("div"); box.className = "tms-cur"; var btn = document.createElement("button"); btn.type = "button"; btn.className = "tms-circle"; btn.setAttribute("aria-label", isEn ? "Currency" : "العملة"); btn.innerHTML = cur === "SAR" ? '' : ((list[cur] && list[cur].symbol) || cur).trim(); var menu = document.createElement("div"); menu.className = "tms-cur-menu"; codes.forEach(function (c) { var o = document.createElement("button"); o.type = "button"; if (c === cur) o.className = "active"; o.innerHTML = "" + (isEn ? c : list[c].name) + "" + (list[c].symbol || "").trim() + ""; o.onclick = function () { if (c === cur) { box.classList.remove("open"); return; } try { salla.currency.api.change(c) .then(function () { location.reload(); }) .catch(function () { salla.event.dispatch("localization::open"); }); } catch (e) { salla.event.dispatch("localization::open"); } }; menu.appendChild(o); }); btn.onclick = function (e) { e.stopPropagation(); box.classList.toggle("open"); }; document.addEventListener("click", function () { box.classList.remove("open"); }); box.appendChild(btn); box.appendChild(menu); wrap.appendChild(box); } } function run() { setCopyright(); translate(document.body); addHeaderButtons(); } if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", run); else run(); /* menus and drawers that render later */ if (isEn) { new MutationObserver(function (list) { list.forEach(function (m) { m.addedNodes.forEach(function (n) { if (n.nodeType === 1) translate(n); }); }); }).observe(document.documentElement, { childList: true, subtree: true }); } })();