(function() {
// Google Tag Manager
(function(w,d,s,l,i){
w[l]=w[l]||[];
w[l].push({'gtm.start': new Date().getTime(), event:'gtm.js'});
var f=d.getElementsByTagName(s)[0],
j=d.createElement(s), dl=l!='dataLayer'?'&l='+l:'';
j.async=true;
j.src='https://sscgtm.darlena.com/sdarlena.js?id='+i+dl;
f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-MMCNVPC');
// End Google Tag Manager
var hdrContactsWhats = document.querySelector('header salla-contacts');
var hdrContactsMail = document.querySelector('header salla-contacts a.s-contacts-topnav-link');
hdrContactsWhats.innerHTML = `
whatsapp2
+966597818555
`;
var bottomBar = document.createElement("div");
bottomBar.className = "footerBar";
bottomBar.innerHTML = "
شحن مجانى للطلبات اكثر من 500
التوصيل خلال 1-4 ايام ";
document.querySelector('.store-footer').append(bottomBar);
if (window.matchMedia("(max-width: 1025px)").matches) {
var categoryNav = document.createElement("div");
categoryNav.className = "categoryNav";
categoryNav.innerHTML = ``;
document.querySelector('header > #mainnav > .inner').append(categoryNav);
const slideDown = element => element.style.height = `${element.scrollHeight}px`;
slideDown(categoryNav);
}
var discountCupon = document.createElement("div");
discountCupon.className = "discountCupon";
discountCupon.innerHTML = `
`;
/* ================== Home Page ==================== */
if (document.body.classList.contains('index')) {
var features = document.querySelector('#best-offers-4-slider');
/*features.parentNode.insertBefore(discountCupon, features);*/
/*document.getElementById("copyDiscountCode1").addEventListener("click", function() {
let copybtn1 = document.querySelector("#copyDiscountCode1.copybtn");
let copyInput1 = document.querySelector('#copyvalue1');
copyInput1.select();
document.execCommand("copy");
copybtn1.setAttribute('value','تم نسخ الكود');
copybtn1.classList.add("copybtnCopied");
});
document.getElementById("copyDiscountCode2").addEventListener("click", function() {
let copybtn2 = document.querySelector("#copyDiscountCode2.copybtn");
let copyInput2 = document.querySelector('#copyvalue2');
copyInput2.select();
document.execCommand("copy");
copybtn2.setAttribute('value','تم نسخ الكود');
copybtn2.classList.add("copybtnCopied");
});*/
};
/* ============== home & Product Single & cart =============== */
if (document.body.classList.contains('index') || document.body.classList.contains('product-single')) {
/* ================== FAQ ==================== */
/*var faqHtml = ``;
var faqSec = document.createElement("div");
faqSec.innerHTML = faqHtml;
var ftr = document.querySelector('footer');
ftr.parentNode.insertBefore(faqSec, ftr);*/
/* ================ faq close ================= */
/*var faqCheckboxs = document.querySelectorAll(".faq-container > input[type=checkbox][name=faqs]");
faqCheckboxs.forEach(faqCheckbox => {
faqCheckbox.addEventListener('change', function handleClick(event) {
if (this.checked) {
for (var i = 0; i < faqCheckboxs.length; i++) {
faqCheckboxs[i].checked = false;
}
this.checked = true;
} else {
}
});
});*/
}
/* ============== Product Single =============== */
if (document.body.classList.contains('product-single')) {
var features = document.querySelector('form.form.product-form');
/*features.parentNode.insertBefore(discountCupon, features);*/
/* ======= Tamara & Tabby Cards ======= */
var tabby_tamara_sec = document.createElement("div");
tabby_tamara_sec.className = "tabby_tamara";
tabby_tamara_sec.innerHTML = `
`;
var skuNum = document.querySelector(".product-single .main-content .product__description + .flex.space-x-3 + .mb-4.flex.justify-between.bg-white.rounded-md.px-4.py-2");
features.parentNode.insertBefore(tabby_tamara_sec, features);
var prdPriceText = document.querySelector('.product-single .main-content div.flex.whitespace-nowrap.gap-4.items-center h2');
var prdPrice = prdPriceText.innerText.match(/\d+(?:\.\d+)?/g);
var payByOneTime = (Math.ceil(prdPrice)/4);
tabby_tamara_sec.append(
Object.assign(document.createElement("STYLE"),{
innerText : `.product-single .main-content .tabby_tamara:before {
content: "ادفعي على 4 دفعات بدون فوائد بقيمة ` + payByOneTime + ` ريال سعودي" !important;
}`
})
);
/* ============== */
/*document.getElementById("copyDiscountCode").addEventListener("click", function() {
let copybtn1 = document.querySelector("#copyDiscountCode.copybtn");
let copyInput1 = document.querySelector('#copyvalue');
copyInput1.select();
document.execCommand("copy");
copybtn1.setAttribute('value','تم نسخ الكود');
copybtn1.classList.add("copybtnCopied");
});*/
/* ============== select city ============== */
var skuSec = document.querySelector('.sku.details');
let citiesDropdownList = '{ "citiesList" : [' +
'{ "cityName":"الرياض" , "deliverTime":"خلال 24 ساعة" },' +
'{ "cityName":"جدة" , "deliverTime":"خلال 1-3 أيام" },' +
'{ "cityName":"مكة المكرمة" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"المدينة المنورة" , "deliverTime":"خلال 1-3 أيام" },' +
'{ "cityName":"الدمام" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"الطائف" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"الاحساء" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"تبوك" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"الخبر" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"ابها" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"خميس مشيط" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"الجبيل" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"جازان" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"حائل" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"نجران" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"القطيف" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"بريدة" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"ابها المنهل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ابو عريش" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الداير" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"اضم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"احد مسارحه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"احد رفيده" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العيص" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العارضة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"البدع" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"البشاير" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العيدابي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المدا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المهد" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عمق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عقيق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الشقيق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"اطاولة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بدر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بدر الجنوب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الباحة" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"بلحمر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بللسمر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بلقرن" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بارق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بلجرشي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"برك" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بيش" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بيشة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ضمد" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"درب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ظهران الجنوب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ضبا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"فرسان" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قلوه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حجره" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حالة عمار" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حلي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حقل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حرجه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الحناكية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حبونا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"كرع" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"كربوس" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"خيبر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"خصاويه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ليث" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مهد الدهب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المجاردة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مندق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مخواه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"محايل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المظيلف" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"نماص" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"نمره" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العلا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"القحمة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"القوز" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"القنفذة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مستوره" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"رابغ" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"طارق أملج" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"رجال المع" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سبت العلايا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"صبيا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سعد أل مالك" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سمكه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"صامطة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سراة عبيده" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"شرورة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"صبيخة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"طبلة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تندحة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تنوما" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تثليث" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تيماء" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ذبية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"طريب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"املج" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الواديين" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"وادي بن هشبل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"وادي فرح" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الوجه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ينبع" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"ينبع البحر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ينبع النخيل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"يوتما" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قنا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بحر ابو سكينة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عقول" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حوية/طائف" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الهدى" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المحاني" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عشيرة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الخرمة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الموية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تربه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"رانيا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مويه الجديدة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الجعرانه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الجموم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الشرايع" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الشميسي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"وادي فاطمه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ولي العهد" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"النعيرية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الخفجي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قرية العليا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"صراره" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الموليجه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الجش" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بقيق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بقيق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"نبيه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تاروت" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عنك" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عواميه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الظهران" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"الهفوف" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المبرز" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قاره" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"جفر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العثمانيه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الدهليه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"خضريه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العيون" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"هويه/الدمام" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عين دار" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بطحه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حرض" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سلوى" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عجم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سفنيه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"رحمه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تنجيب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"راس تنورة" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"صفوى" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"راس الخير" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الجبيل الصناعية 2" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سيهات" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ثقبا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عسفان" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بحرا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"دهبان" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"خليص" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الشعيبه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"طيبه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ثول" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مدينة الملك عبدالله الاقتصادية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ديراب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الدرعية" , "deliverTime":"خلال 2-3 أيام" },' +
'{ "cityName":"الدرمه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حريملاء" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المزاحمية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العيينة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"القويعية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"رماح" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الرويضه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سلبوكه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"شفا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تبراك" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ثادق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ابو عجرم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الادري" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"اللقايط" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"النبك ابو قصر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الرديفه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الرفيعة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"السليمانية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الطوير" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"دومة الجندل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"هديب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الجوف" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"كارا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سكاكا" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"صوير" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تبرجل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"زلوم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عرعر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حزم الجلاميد" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"طريف" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العويقيلية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عفيف" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العرجة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"البجادية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الحفيرة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"القرين" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"النافية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الشرائع" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الدوادمي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"رافا الجماش" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ساجر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الذيبيه - حفر الباطن" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"حفر الباطن" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"مدينة الملك خالد العسكرية " , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"نصاب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قيصومه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"رفحاء" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"روضه هباس" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الاجفار" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الحائط" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الحليفة السفلى" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الخطة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الوسيطاء" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"النقرة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الشملي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الشنانه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"باقة الشرقيه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بقعة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"غزالية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"غطي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"موقق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مقيق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"منيفت القيد" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قفار" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سديان" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"شينانة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سيميرا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الضبيعة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الهياثم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الدلم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الحريق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حوطة بني تميم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الخرج" , "deliverTime":"خلال 2-4 أيام" },' +
'{ "cityName":"سحنه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المجمعة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تنيوما" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ثرمادا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"اشيقر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الداهنة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مبايض" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مليح" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قصب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"روضه سودير" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ام الجماجم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الغاط" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الارطاوية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"حوطة سدير" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"جلاجل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مرات" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"شقراء" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تمير" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الزلفي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تويم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ابا الورود" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العامرية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"العاصية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"البترا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الدليميه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الفويلق" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الخشيبي" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المدراج" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"النبهانية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الرس" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الصلبيّة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الشماسية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عين فهيد" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"البدائع" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"البكيرية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ضرية" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"دخنة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ضليع رشيد" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"كحله" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"كبضه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"المذنب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"مذنب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عنيزة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عيون الجوا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"القصيم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قبه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"قصيباء" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"رياض الخبراء" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"سقف" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"شري" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الذيبية - القصيم" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"عقلة الصقور" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الحديثه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"القريات" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"افلج" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"تمرة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"خماسين" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ليلى" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"السليل" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"وادي الدواسر" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"هروب" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"يدمة" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"ظبيه" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"الماضايا" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"بحرة الموجود" , "deliverTime":"خلال 2-5 أيام" },' +
'{ "cityName":"دبي" , "deliverTime":"خلال 4-7 أيام" },' +
'{ "cityName":"ابوظبي" , "deliverTime":"خلال 4-7 أيام" },' +
'{ "cityName":"عجمان" , "deliverTime":"خلال 4-7 أيام" },' +
'{ "cityName":"المنامة" , "deliverTime":"خلال 4-7 أيام" },' +
'{ "cityName":"مسقط" , "deliverTime":"خلال 4-7 أيام" } ]}';
const citiesListObj = JSON.parse(citiesDropdownList);
var citiesList_li = "";
for (var i = 0; i < citiesListObj.citiesList.length; i++) {
citiesList_li += '' + citiesListObj.citiesList[i].cityName + ' '
}
var shippingTimeSecHtml = `
التوصيل خلال 24 ساعة فى الرياض
`;
var shippingTimeSec = document.createElement("div");
shippingTimeSec.className = "shippingTimeSec";
shippingTimeSec.innerHTML = shippingTimeSecHtml;
shippingTimeSec.className = "shippingTimeSec";
// DO NOT MODIFY THIS SELECTOR - essential for shipping time section placement
var mainPrice = document.querySelector('.product-single .main-content div.flex.whitespace-nowrap.gap-4.items-center');
mainPrice.appendChild(shippingTimeSec);
function citiesDropdownFunction() {
document.getElementById("citiesDropdown").classList.toggle("show");
/* document.querySelector('.s-cities-content .dropdown').classList.add("dropActive"); */
}
function filterFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById("citiesInputSearch");
filter = input.value.toUpperCase();
div = document.getElementById("citiesDropdown");
a = div.getElementsByTagName("a");
for (i = 0; i < a.length; i++) {
txtValue = a[i].textContent || a[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
}
}
}
document.querySelector('.dropbtn').addEventListener('click', citiesDropdownFunction);
document.getElementById("citiesInputSearch").addEventListener('keyup', filterFunction);
var citiesListItems = document.querySelector('#citiesDropdown>ul');
citiesListItems.addEventListener('click', function(e) {
if (e.target.tagName === 'A'){
var val = e.target;
document.getElementById("citiesDropdown").classList.remove("show");
document.querySelector(".deliverTime").innerHTML = "التوصيل " + val.getAttribute('data-deliverTime') + " فى " + "" + val.innerHTML + " ";
}
});
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var citiesDropdown = document.getElementById("citiesDropdown");
if (citiesDropdown.classList.contains('show')) {
citiesDropdown.classList.remove('show');
}
/* document.querySelector('.s-cities-content .dropdown').classList.remove("dropActive"); */
}
}
document.getElementById("citiesDropdown").addEventListener('click',function(event){
event.stopPropagation();
});
/* ==================================== */
/* ======= Tamara & Tabby Cards ======= */
/*setTimeout(function() {
var tabbyTamaraSec = document.querySelector('.product-single .main-content salla-installment');
var TamaraSec = document.querySelector('.product-single .main-content salla-installment > .tamara-product-widget');
var tabbySec = document.querySelector('.product-single .main-content salla-installment .styles__tabbySnippet--c10e5');
var nIcon = ` `;
TamaraSec.insertAdjacentHTML( 'beforeend', nIcon );
tabbySec.insertAdjacentHTML( 'beforeend', nIcon );
var prdPriceText = document.querySelector('.product-single .main-content div.flex.whitespace-nowrap.gap-4.items-center h2');
var prdPrice = prdPriceText.innerText.match(/\d+(?:\.\d+)?/g);
var payByOneTime = (Math.ceil(prdPrice)/4);
tabbyTamaraSec.append(
Object.assign(document.createElement("STYLE"),{
innerText : `.product-single .main-content salla-installment:before {
content: "ادفعي على 4 دفعات بدون فوائد بقيمة ` + payByOneTime + ` ريال سعودي" !important;
}`
})
);
document.querySelector("#tabbyPromo > .styles__tabbySnippet--c10e5 > span").shadowRoot.append(
Object.assign(document.createElement("STYLE"),{
innerText : `.styles__tabby-promo-snippet--2ddd6,
.styles__snippetWrapper--d68e9 {
border: 0;
border-radius: 0;
justify-content: center;
padding: 0 16px;
}
.styles__tabby-promo-snippet__content--51d69,
.styles__tabby-promo-snippet__content--c823dv {
font-size: 0 !important;
border: 0 !important;
border-radius: 0 !important;
margin: 0 !important;
}
.styles__tabbyPromoSnippetContent--ef3e6 styles__tabbyPromoSnippetContentRtl--bcbcb {
visibility: hidden;
height: 0;
max-height: 0;
}
.styles__tabby-promo-snippet__text--dfcce,
.styles__tabbyPromoSnippetText--b30d0 {
display: none;
}
.styles__tabby-promo-snippet__content--51d69 + span,
.styles__tabby-promo-snippet__content--c823dv + span,
.styles__tabby-promo-snippet--2ddd6 > span,
.styles__snippetWrapper--d68e9 > span
span.styles__containerPortal--c9f84 {
display: flex;
}`
})
);
}, 4500);*/
/* ==================================== */
setTimeout(function() {
var optionSec = document.querySelector('salla-product-options.s-product-options-wrapper');
if(optionSec) {
var prdOptionSec = document.querySelector('form.form.product-form salla-product-options.s-product-options-wrapper ~ section.flex.bg-white.rounded-md.rounded-b-none');
var replaceNotification = document.createElement('div');
replaceNotification.className = 'replaceNotification';
replaceNotification.innerHTML = ``;
prdOptionSec.parentNode.insertBefore(replaceNotification, prdOptionSec);
}
}, 2500);
var showMoreBtn = document.createElement("a");
showMoreBtn.id = "btn-show-more";
showMoreBtn.setAttribute("href", "javascript:void(0)");
showMoreBtn.innerText = "اقرأ المزيد";
document.querySelector('.product__description').append(showMoreBtn);
document.getElementById("btn-show-more").addEventListener("click", function() {
document.querySelector('.article--main').classList.add("product__description__fullHeight");
showMoreBtn.classList.add("btn-show-more-hidden");
});
var el = document.querySelector('article.article--main');
var wrapper = document.createElement('div');
wrapper.className = 'descWrapper';
el.parentNode.insertBefore(wrapper, el);
Array.prototype.forEach.call(document.querySelectorAll('article.article--main, a#btn-show-more'), function(c){
wrapper.appendChild(c);
});
// Updated to handle both traditional iframes and lazy-loaded placeholders
function positionVideosBelow() {
// Only target placeholders initially, not iframes (let youtube-lazy.js handle those)
var placeholders = document.querySelectorAll('.yt-placeholder:not([data-positioned])');
if (placeholders.length === 0) return;
// Calculate total height needed
var totalVideos = document.querySelectorAll('.yt-placeholder, iframe[src*="youtube"]').length;
if (totalVideos > 0) {
document.querySelector('.product__description').style.marginBottom = ((265 * totalVideos) + 20) + "px";
}
// Position only unpositioned placeholders
for (var i = 0; i < placeholders.length; i++) {
var position = i + 1;
var existing = document.querySelectorAll('.yt-placeholder[data-positioned], iframe[data-position-applied="true"]').length;
position += existing;
placeholders[i].style.position = "absolute";
placeholders[i].style.bottom = "-" + (265 * position) + "px";
placeholders[i].style.display = "block";
placeholders[i].style.width = "100%";
placeholders[i].style.zIndex = "1";
placeholders[i].dataset.positioned = "true";
}
}
// Run initially with delay to ensure youtube-lazy.js has processed iframes
setTimeout(positionVideosBelow, 300);
// Set up efficient MutationObserver to detect only relevant changes
if (typeof MutationObserver !== 'undefined') {
const productDesc = document.querySelector('.product__description');
if (productDesc) {
const observer = new MutationObserver(function(mutations) {
let newElements = false;
// Quickly check if we have relevant mutations before detailed processing
for (let i = 0; i < mutations.length; i++) {
if (mutations[i].type === 'childList' && mutations[i].addedNodes.length > 0) {
newElements = true;
break;
}
}
if (!newElements) return;
// Handle newly created YouTube iframes (from lazy loading clicks)
const newIframes = document.querySelectorAll('iframe[src*="youtube"]:not([data-position-applied])');
for (let i = 0; i < newIframes.length; i++) {
const iframe = newIframes[i];
iframe.dataset.positionApplied = "true";
// Find position index based on nearby positioned elements
let position = document.querySelectorAll('.yt-placeholder[data-positioned], iframe[data-position-applied="true"]').length;
// Apply positioning directly
iframe.style.position = "absolute";
iframe.style.width = "100%";
iframe.style.height = "250px";
iframe.style.left = "0";
iframe.style.right = "0";
iframe.style.zIndex = "1";
iframe.style.display = "block";
iframe.style.bottom = "-" + (265 * position) + "px";
}
// Check for new placeholders
const newPlaceholders = document.querySelectorAll('.yt-placeholder:not([data-positioned])');
if (newPlaceholders.length > 0) {
positionVideosBelow();
}
});
observer.observe(productDesc, {
childList: true,
subtree: true
});
}
}
};
// Comprehensive Product Options Fix - Hybrid Solution
(function() {
// Track active executions to prevent overlapping runs
let isCreatingButtons = false;
let retryAttempts = 0;
const MAX_RETRIES = 5;
// Function to recreate the horizontal buttons from the select options
function recreateOptionButtons() {
// Don't run if already executing or not on a product page
if (isCreatingButtons || !document.querySelector('.product-form')) return;
try {
isCreatingButtons = true;
// First ensure container elements are visible (from old solution)
const optionsWrapper = document.querySelector('.s-product-options-wrapper');
const optionsContainer = optionsWrapper?.querySelector('.s-product-options-option-container') ||
optionsWrapper?.querySelector('salla-conditional-fields');
// Apply visibility fixes from old solution
if (optionsWrapper) {
optionsWrapper.style.display = 'block';
optionsWrapper.style.visibility = 'visible';
optionsWrapper.style.opacity = '1';
optionsWrapper.style.borderColor = '#de9b5d';
}
if (optionsContainer) {
optionsContainer.style.display = 'block';
optionsContainer.style.visibility = 'visible';
optionsContainer.style.opacity = '1';
}
// Find all single-option type selects that should have buttons
const selects = document.querySelectorAll('.s-product-options-option[data-option-type="single-option"] select');
selects.forEach(select => {
// Skip selects that are in the cart page
if (select.closest('.cart-options')) return;
// Skip if buttons already exist and contain elements
const existingContainer = select.parentElement.querySelector('.option-buttons-container');
const hasOptions = select.options.length > 1; // More than just the placeholder
// Only create buttons if (1) select has options and (2) buttons don't exist or are empty
if (hasOptions && (!existingContainer || existingContainer.children.length === 0)) {
// Create container for buttons if it doesn't exist
let container = existingContainer;
if (!container) {
container = document.createElement('div');
container.className = 'option-buttons-container';
container.style.display = 'flex';
container.style.flexWrap = 'wrap';
container.style.gap = '0.5rem';
container.style.marginTop = '0.5rem';
select.parentElement.appendChild(container);
}
// Clear existing buttons
container.innerHTML = '';
// Hide the original select
select.style.display = 'none';
// Create buttons for each option
Array.from(select.options).forEach((option, index) => {
if (index === 0 || !option.value) return; // Skip placeholder option
// Create button element
const button = document.createElement('div');
button.className = 'option-button';
// Style the button
button.style.padding = '0.5rem 1rem';
button.style.border = '1px solid #e5e7eb';
button.style.borderRadius = '0.375rem';
button.style.fontSize = '0.875rem';
button.style.transition = '0.2s';
// Add data attributes
button.dataset.value = option.value;
// Extract stock amount from the option text if available
const stockMatch = option.text.match(/\((\d+)\)/);
const stockAmount = stockMatch ? parseInt(stockMatch[1]) : 3; // Default to 3 if not found
button.dataset.stock = stockAmount;
// Text content should be just the size without stock info
button.textContent = option.text.replace(/ - نفدت الكمية| \(\d+\)/g, '');
// If out of stock, add disabled class and style
if (option.text.includes('نفدت الكمية') || option.disabled) {
button.classList.add('disabled');
button.style.cursor = 'not-allowed';
button.style.opacity = '0.5';
button.style.textDecoration = 'line-through';
} else {
button.style.cursor = 'pointer';
// Handle click to select this option
button.addEventListener('click', () => {
if (button.classList.contains('disabled')) return;
// Update select value
select.value = option.value;
// Trigger change event to update price
select.dispatchEvent(new Event('change', { bubbles: true }));
// Update button states
container.querySelectorAll('.option-button').forEach(btn => {
btn.classList.remove('selected');
btn.style.borderColor = '#e5e7eb';
btn.style.backgroundColor = '';
btn.style.color = '';
});
button.classList.add('selected');
button.style.borderColor = 'var(--color-primary)';
button.style.backgroundColor = 'rgba(var(--color-primary-rgb, 0, 0, 0), 0.05)';
button.style.color = 'var(--color-primary)';
// Show low stock indicator with consistent number for this option
let lowStockIndicator = document.querySelector('.low-stock-indicator');
if (lowStockIndicator) {
lowStockIndicator.querySelector('span').textContent = `متبقي ${stockAmount} قطع فقط من هذا المقاس`;
lowStockIndicator.style.display = 'flex';
}
});
}
container.appendChild(button);
});
} else if (existingContainer) {
// Make sure the existing container is visible
existingContainer.style.display = 'flex';
existingContainer.style.flexWrap = 'wrap';
existingContainer.style.gap = '0.5rem';
existingContainer.style.marginTop = '0.5rem';
}
});
if (retryAttempts > 0) {
console.log(`Product options recreated after ${retryAttempts} attempts`);
}
retryAttempts = 0;
} catch (error) {
console.error('Error creating option buttons:', error);
} finally {
isCreatingButtons = false;
}
}
// 1. Run after DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', recreateOptionButtons);
} else {
recreateOptionButtons();
}
// 2. Run after page is fully loaded
window.addEventListener('load', recreateOptionButtons);
// 3. Listen for Salla's product events
document.addEventListener('salla.product.options.loaded', () => {
setTimeout(recreateOptionButtons, 100);
});
// 4. Watch for price updates (might indicate option changes)
document.addEventListener('salla.product.price.updated', () => {
setTimeout(recreateOptionButtons, 100);
});
// Add missing options.updated event listener
document.addEventListener('salla.product.options.updated', () => {
setTimeout(recreateOptionButtons, 100);
});
// 5. Watch DOM changes with a single MutationObserver
if (typeof MutationObserver !== 'undefined') {
// Wait for product form to be available
const watchForForm = setInterval(() => {
const productForm = document.querySelector('.product-form');
if (productForm) {
clearInterval(watchForForm);
const observer = new MutationObserver((mutations) => {
let shouldRecreate = false;
for (const mutation of mutations) {
// Check if the mutation is relevant to our product options
if (mutation.target.closest('salla-product-options') ||
mutation.target.matches('.s-product-options-wrapper, .s-product-options-container') ||
mutation.type === 'childList' &&
(mutation.addedNodes.length || mutation.removedNodes.length)) {
shouldRecreate = true;
break;
}
}
if (shouldRecreate && !isCreatingButtons) {
if (retryAttempts < MAX_RETRIES) {
retryAttempts++;
setTimeout(recreateOptionButtons, 100);
}
}
});
observer.observe(productForm, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['style', 'class', 'hidden']
});
}
}, 200);
}
// 6. Safety check that runs periodically
let lastCheckTime = Date.now();
// Store interval reference for cleanup
const safetyCheckInterval = setInterval(() => {
if (Date.now() - lastCheckTime > 5000) {
const selects = document.querySelectorAll('.s-product-options-option[data-option-type="single-option"] select');
let needsRecreation = false;
selects.forEach(select => {
if (select.options.length > 1) {
const container = select.parentElement.querySelector('.option-buttons-container');
if (!container || container.children.length === 0) {
needsRecreation = true;
}
}
});
if (needsRecreation) {
console.error('Periodic check: found missing option buttons, recreating...');
recreateOptionButtons();
lastCheckTime = Date.now();
}
}
}, 2000);
// Add cleanup function
const cleanup = () => {
clearInterval(safetyCheckInterval);
if (typeof observer !== 'undefined') {
observer.disconnect();
}
};
// Listen for page navigation in SPAs
document.addEventListener('turbolinks:before-visit', cleanup);
})();
})();
// Fix for availability reminders on out-of-stock variations
(function() {
// Simple function to fix out-of-stock buttons
function fixOutOfStockButtons() {
// Find all out-of-stock buttons
const outOfStockButtons = document.querySelectorAll('.option-button.disabled, .option-button[style*="text-decoration: line-through"]');
outOfStockButtons.forEach(button => {
// Make it clickable but still visually indicate out-of-stock
button.classList.remove('disabled');
button.style.opacity = '0.7';
button.style.cursor = 'pointer';
button.style.textDecoration = 'line-through';
// Reset existing click handlers
const newButton = button.cloneNode(true);
button.parentNode.replaceChild(newButton, button);
// Add click handler to select this option
newButton.addEventListener('click', () => {
// Find the select element and option that matches this button's value
const select = newButton.closest('.s-product-options-option').querySelector('select');
if (!select) return;
// Set the value and trigger change event
select.value = newButton.dataset.value;
select.dispatchEvent(new Event('change', { bubbles: true }));
// Update button states (selected style)
const container = newButton.parentElement;
container.querySelectorAll('.option-button').forEach(btn => {
btn.classList.remove('selected');
btn.style.borderColor = '#e5e7eb';
btn.style.backgroundColor = '';
});
newButton.classList.add('selected');
newButton.style.borderColor = 'var(--color-primary)';
newButton.style.backgroundColor = 'rgba(var(--color-primary-rgb, 0, 0, 0), 0.05)';
});
});
}
// Run initially and after key events
setTimeout(fixOutOfStockButtons, 1000);
// Listen for product option changes
document.addEventListener('salla.product.options.loaded', () => {
setTimeout(fixOutOfStockButtons, 500);
});
// Set up periodic check to catch dynamically added options
setInterval(fixOutOfStockButtons, 3000);
})();
(function(global) {
'use strict';
function injectStyles() {
const styleElement = document.createElement('style');
styleElement.textContent = `
.arabic-notification{position:fixed;top:16px;left:0;right:0;z-index:50;display:flex;justify-content:center;padding:0 16px;pointer-events:none;opacity:0;transform:translateY(-100px);transition:opacity .4s ease-out,transform .4s cubic-bezier(0.175,0.885,0.32,1.275)}
.arabic-notification.visible{opacity:1;transform:translateY(0);pointer-events:auto}
.notification-content{background-color:rgba(255,255,255,0.95);backdrop-filter:blur(8px);box-shadow:0 4px 12px rgba(0,0,0,0.1);border-radius:9999px;padding:10px 16px;display:flex;align-items:center;justify-content:space-between;border:1px solid rgba(212,172,132,0.2);width:fit-content;max-width:90%}
.notification-text{display:flex;align-items:center;gap:8px}
.notification-icon{color:#d4ac84;flex-shrink:0}
.notification-text p{font-size:0.75rem;font-weight:500;color:#1f2937;margin:0;width:auto}
.notification-close{margin-left:8px;color:#6b7280;background:none;border:none;padding:4px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:color .2s;flex-shrink:0}
.notification-close:hover{color:#374151}
@supports not (backdrop-filter:blur(8px)){.notification-content{background-color:rgba(255,255,255,0.98)}}
@media (max-width:640px){.notification-content{padding:8px 12px}}
`;
document.head.appendChild(styleElement);
}
function showArabicNotification(message, delay, duration) {
delay = delay !== undefined ? delay : 1000;
duration = duration !== undefined ? duration : 6000;
if (document.querySelector('.arabic-notification')) {
return null;
}
const notificationContainer = document.createElement('div');
notificationContainer.className = 'arabic-notification';
notificationContainer.innerHTML = `
`;
document.body.appendChild(notificationContainer);
const closeButton = notificationContainer.querySelector('.notification-close');
if (closeButton) {
closeButton.addEventListener('click', function() {
hideNotification(notificationContainer);
}, { passive: true });
}
const showTimer = setTimeout(function() {
notificationContainer.classList.add('visible');
}, delay);
const hideTimer = setTimeout(function() {
hideNotification(notificationContainer);
}, delay + duration);
notificationContainer._timers = {
show: showTimer,
hide: hideTimer
};
return notificationContainer;
}
function hideNotification(notificationElement) {
if (!notificationElement) return;
if (notificationElement._timers) {
clearTimeout(notificationElement._timers.show);
clearTimeout(notificationElement._timers.hide);
}
notificationElement.classList.remove('visible');
function removeElement() {
if (notificationElement.parentNode) {
notificationElement.parentNode.removeChild(notificationElement);
}
}
if (typeof notificationElement.addEventListener === 'function') {
notificationElement.addEventListener('transitionend', removeElement, { once: true });
setTimeout(removeElement, 500);
} else {
setTimeout(removeElement, 400);
}
}
injectStyles();
function initialize() {
showArabicNotification("توصيل فوري في الرياض: 24 ساعة. باقي المدن:1-4 أيام");
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initialize);
} else {
initialize();
}
if (typeof exports !== 'undefined') {
exports.showArabicNotification = showArabicNotification;
}
if (typeof define === 'function' && define.amd) {
define([], function() {
return { showArabicNotification: showArabicNotification };
});
}
global.showArabicNotification = showArabicNotification;
})(typeof window !== 'undefined' ? window : this);
document.addEventListener('DOMContentLoaded', () => {
// Create the coupon element if it doesn't exist
let coupon = document.getElementById('discountCupon');
if (!coupon) {
coupon = document.createElement('div');
coupon.id = 'discountCupon';
coupon.className = 'discountCupon';
}
// Create HTML structure
coupon.innerHTML = `
`;
// Add toast notification if it doesn't exist
if (!document.getElementById('toast')) {
document.body.insertAdjacentHTML('beforeend',
``);
}
// Insert coupon in the appropriate location based on page type
if (document.body.classList.contains('index')) {
// Home page implementation
const features = document.querySelector('#best-offers-4-slider');
if (features) {
coupon.classList.add('homepage-coupon');
features.parentNode.insertBefore(coupon, features);
}
} else if (document.body.classList.contains('product-single')) {
// Product page implementation
const productForm = document.querySelector('form.form.product-form');
if (productForm) {
coupon.classList.add('product-coupon');
productForm.parentNode.insertBefore(coupon, productForm);
}
}
// Cache DOM elements
const btn = document.getElementById('copy-btn'),
code = document.getElementById('coupon-code');
// Copy functionality
btn.addEventListener('click', function() {
// Copy code
const tmp = document.createElement('textarea');
tmp.value = code.textContent;
document.body.appendChild(tmp);
tmp.select();
try {
document.execCommand('copy');
// Show success feedback
btn.classList.add('copied');
btn.innerHTML = ` `;
// Show toast
const toast = document.getElementById('toast');
toast.classList.remove('hidden');
toast.classList.add('show');
// Reset after 2 seconds
setTimeout(() => {
btn.classList.remove('copied');
btn.textContent = 'نسخ';
toast.classList.remove('show');
toast.classList.add('hidden');
}, 2000);
} catch (err) {
console.error('Failed to copy:', err);
alert('فشل نسخ الكود، حاول مرة أخرى');
}
document.body.removeChild(tmp);
});
});
// Size message feature implementation
window.addEventListener('load', function() {
setTimeout(initSizeMessageFeature, 1500);
setTimeout(initSizeMessageFeature, 3000);
setTimeout(initSizeMessageFeature, 5000);
});
function initSizeMessageFeature() {
function parseProductDescription() {
const productDescription = document.querySelector('.product__description');
if (!productDescription) return {};
const paragraphs = productDescription.querySelectorAll('p');
const sizeMessages = {};
paragraphs.forEach((paragraph) => {
const content = paragraph.textContent.trim();
const sizeMessageRegex = /size_message(\d+):(\d+)\/(\d+)/i;
const match = content.match(sizeMessageRegex);
if (match) {
const size = match[1];
const day = match[2];
const month = match[3];
sizeMessages[size] = `${month}/${day}`;
paragraph.style.display = 'none';
}
});
return sizeMessages;
}
function calculateDaysRemaining(dateString) {
const today = new Date();
const [month, day] = dateString.split('/');
let targetDate = new Date(today.getFullYear(), parseInt(month) - 1, parseInt(day));
if (targetDate < today) {
targetDate = new Date(today.getFullYear() + 1, parseInt(month) - 1, parseInt(day));
}
const timeDiff = targetDate - today;
return Math.ceil(timeDiff / (1000 * 60 * 60 * 24));
}
function createSizeMessage(daysRemaining) {
const messageContainer = document.createElement('div');
messageContainer.className = 'size-message';
messageContainer.innerHTML = `
الطلب مرتفع على هذا المقاس! 🔥
سيستغرق شحن هذا المقاس ${daysRemaining} يوم. اطلبيه الآن لضمان حصولكِ عليه
`;
return messageContainer;
}
function createAvailableMessage() {
const messageContainer = document.createElement('div');
messageContainer.className = 'size-message available-message';
messageContainer.innerHTML = `
متوفر
شحن فوري: يصل لباب بيتك خلال 1 الى 4 ايام
`;
return messageContainer;
}
function removeExistingMessage() {
const currentMessage = document.querySelector('.size-message');
if (currentMessage) {
currentMessage.remove();
return true;
}
return false;
}
function setupSizeButtons(sizeMessages) {
const sizeButtons = document.querySelectorAll('.option-button');
if (sizeButtons.length === 0) {
setTimeout(() => setupSizeButtons(sizeMessages), 1000);
return;
}
const markerClass = 'has-size-message-listener';
sizeButtons.forEach(button => {
if (button.classList.contains(markerClass)) return;
button.classList.add(markerClass);
const sizeText = button.textContent.trim();
button.addEventListener('click', function() {
removeExistingMessage();
const isOutOfStock = button.style.textDecoration?.includes('line-through') ||
button.classList.contains('disabled') ||
button.style.opacity === '0.7';
if (!isOutOfStock) {
let hasCustomMessage = false;
Object.entries(sizeMessages).forEach(([size, dateString]) => {
if (sizeText === size) {
hasCustomMessage = true;
const daysRemaining = calculateDaysRemaining(dateString);
const messageElement = createSizeMessage(daysRemaining);
const optionsContainer = document.querySelector('.s-product-options-option-content');
if (optionsContainer) {
optionsContainer.parentNode.insertBefore(messageElement, optionsContainer.nextSibling);
}
}
});
if (!hasCustomMessage) {
const messageElement = createAvailableMessage();
const optionsContainer = document.querySelector('.s-product-options-option-content');
if (optionsContainer) {
optionsContainer.parentNode.insertBefore(messageElement, optionsContainer.nextSibling);
}
}
}
});
});
const selectedButton = document.querySelector('.option-button.selected');
if (selectedButton) {
selectedButton.click();
}
}
const sizeMessages = parseProductDescription();
setupSizeButtons(sizeMessages);
}
document.addEventListener('salla.product.options.loaded', function() {
setTimeout(initSizeMessageFeature, 1000);
});
document.addEventListener('salla.product.options.updated', function() {
setTimeout(initSizeMessageFeature, 1000);
});