function appendToMobileMenu() { const mobileMenu = document.querySelector('#mobile-menu .main-menu'); if (mobileMenu) { mobileMenu.insertAdjacentHTML('beforeend', ` `); } } window.onload = appendToMobileMenu; document.addEventListener("DOMContentLoaded", function () { if (document.body.classList.contains("switch2_on")) { let attempts = 0; const maxAttempts = 20; const interval = setInterval(() => { const counters = document.querySelectorAll(".counter"); counters.forEach(counter => { const nextElement = counter.nextElementSibling; if (nextElement && nextElement.classList.contains("s-block--best-offers")) { const targetDiv = nextElement.querySelector(".s-slider-block__title > div"); if (targetDiv) { targetDiv.appendChild(counter); nextElement.classList.add('counter-parent'); } } }); if (++attempts >= maxAttempts) { clearInterval(interval); } }, 250); } }); /* solar features */ if (window.customCardProps?.custom_pc) { window.run_product_card = function (_this) { try { let lang = document.documentElement.getAttribute("lang"); const remained = salla.lang.get("pages.products.remained"); const donationPH = salla.lang.get("pages.products.donation_placeholder"); const startingPrice = salla.lang.get("pages.products.starting_price"); const outOfStock = salla.lang.get("pages.products.out_of_stock"); const calories = salla.lang.get("pages.products.calories"); // Custom props _this.product_preview_down = window.customCardProps?.product_preview_down; _this.p_atc_btn_hidden = window.customCardProps?.p_atc_btn_hidden; _this.product_preview_icon_hide = window.customCardProps?.product_preview_icon_hide; _this.preview_text = window.customCardProps?.preview_text; _this.is_price_ratio_on = window.customCardProps?.is_price_ratio_on; _this.price_ratio_place = window.customCardProps?.price_ratio_place; _this.price_ratio_word = window.customCardProps?.price_ratio_word; _this.small_atc = window.customCardProps?.small_atc; _this.show_pc_ratings = window.customCardProps?.show_pc_ratings; let hasBrand = false; if (_this?.product?.brand) { if (_this?.product?.brand?.name) { hasBrand = true; } } let most_popular_count = 350; let title_3 = getComputedStyle(document.body).getPropertyValue("--custom-title3").slice(1, -1); if (title_3) { // if num console.log(!isNaN(most_popular_count)); if (!isNaN(most_popular_count)) { most_popular_count = parseInt(title_3); console.log("found"); } } if (_this.show_pc_ratings === "hide") { _this.show_pc_ratings = false; } _this.classList.add("custom-pc"); let product_ration_html; if (_this?.product?.is_on_sale) { _this.product_ratio_percent = Math.round( ((_this.product?.regular_price - _this.product?.sale_price) / _this.product?.regular_price) * 100 ); product_ration_html = `
${_this.price_ratio_word}${_this.product_ratio_percent}%${_this.price_ratio_place === "down" ? "-" : "" }
`; } _this.innerHTML = `
${_this.product.sold_quantity > most_popular_count ? ` الأكثر رواجا` : ` ${_this.is_price_ratio_on && _this.price_ratio_place === "over-promotion" && !window.revert_last_update_on ? `${_this.product_ration_html || ""}` : ` ${_this.product.promotion_title && !_this.product_badge_off ? `${_this.product.promotion_title}` : _this.showQuantity && _this.product.quantity ? `${remained} ${_this.product.quantity}` : _this.showQuantity && _this.product.is_out_of_stock ? `
${outOfStock}
` : "" } ` } ` } ${_this.product.image.alt}
${_this.showWishlist ? `` : "" }
${_this.product.rating && _this.show_pc_ratings ? ` ${_this.product.rating.stars} (${_this.product.rating.count}) ` : "" }
${_this.product.brand ? ` ${_this.product.brand.name ? `

${_this.product.brand.name}

` : ` ` } ` : "" }

${_this.product.name}

${_this.product.calories ? `
${_this.product.calories} ${calories}
` : "" } ${_this.product.is_donation ? `
${_this.product.can_donate ? `` : "" }
` : "" }
${_this.product.is_on_sale ? `${salla.money( _this.product.sale_price )}${salla.money( _this.product.regular_price )}` : _this.product.starting_price ? `${startingPrice}${salla.money(_this.product.starting_price)}` : `${salla.money(_this.product.price)}` } ${_this.product?.is_on_sale && _this.is_price_ratio_on && _this.price_ratio_place === "down" ? product_ration_html || "" : "" }
${!_this.hideAddBtn ? `
${ // _this.product.add_to_cart_label || "" ` ` }
` : "" }
`; } catch (error) { console.log(error); } }; } // function all() { // adding notification icon function addNotificationIcon() { // log console.log("adding notification icon"); // create icon wrapper let icon_wrapper = document.createElement("div"); icon_wrapper.classList.add("noti-icon-wrapper"); // check if sign in or user using is_guest clas of body let is_guest = document.body.classList.contains("is_guest"); let ele_node = "a"; if (is_guest) { ele_node = "button"; } // create icon HTML let icon = ` <${ele_node} ${is_guest ? `onclick="salla.event.dispatch('login::open')"` : `href="/notifications"` } class="notification-icon-outer text-xl text-center w-12 h-12 justify-center flex p-4 pt-3 rtl:pl-2 ltr:pr-2"> `; icon_wrapper.innerHTML = icon; return icon_wrapper; } function BurderIconSVG() { return ` `; } function changeBurgerIconPlaceToBottomHeader() { // log console.log("changeBurgerIconPlaceToBottomHeader"); // get burger icon let burger_icon = document.querySelector(".store-header .mburger"); if (burger_icon) { burger_icon.innerHTML = BurderIconSVG(); } // get headerBottom let headerBottom = document.querySelector(".top-navbar .container"); if (burger_icon && headerBottom) { // set position headerBottom.prepend(burger_icon); if (addNotificationIcon()) { headerBottom.appendChild(addNotificationIcon()); } } } function addHeaderPromotionTitle() { // log console.log("addHeaderPromotionTitle"); // get header left side let header_left = document.querySelector(".store-header .header-innerLeft"); // get title from var(--custom-title2) from body] let header_promotion = getComputedStyle(document.body).getPropertyValue("--custom-title2")?.trim().slice(1, -1); // wrap it in a div called hdr-promotion let hdr_promotion = document.createElement("div"); hdr_promotion.classList.add("hdr-promotion", "rtl:mr-4", "ltr:ml-4", "flex", "justify-center", "items-center"); hdr_promotion.innerHTML = ` ${header_promotion} `; if (header_left) { header_left.prepend(hdr_promotion); } } // set it for mobile and ipad screens if (window.innerWidth < 768) { setTimeout(() => { addHeaderPromotionTitle(); changeBurgerIconPlaceToBottomHeader(); document.body.classList.add("new-styles"); }, 10); // desktop } else { document.body.classList.add("styles-desktop"); } } // on dom content loaded if (document.readyState === "complete") { all(); } else { document.addEventListener("DOMContentLoaded", all); } /* Header */ document.addEventListener('DOMContentLoaded', function () { if (document.body.classList.contains('switch4_on') && window.innerWidth >= 1024) { const mobileMenu = document.querySelector('#mobile-menu'); const storeHeader = document.querySelector('.store-header'); if (mobileMenu && storeHeader) { storeHeader.appendChild(mobileMenu); } } });