/* California Scrubs — navigation, color previews and size help */ (function(){ "use strict"; function route(p){ return location.hostname.indexOf('salla.sa') > -1 && location.pathname.indexOf('/sfot') === 0 ? '/sfot' + p : p; } function home(){ return document.querySelector('.ca-home'); } function menu(){ var target = document.querySelector( '.mobile-menu .main-menu, nav.mobile-menu ul, #mobile-menu .main-menu' ); if (!target || target.querySelector('.ca-native-menu')) return; var n = document.createElement('nav'); n.className = 'ca-native-menu'; n.setAttribute('aria-label', 'أقسام المتجر'); n.innerHTML = '' + 'سكرابالموديلان ←' + '' + '' + 'لاب كوتتسوق الآن ←' + '' + '' + 'وارمرتسوق الآن ←' + '' + '' + 'التطريز المخصصاطلب الآن ←' + '' + '' + '' + ''; target.appendChild(n); } function init(){ menu(); document.querySelectorAll('a[href*="wa.me/508516668"]').forEach(function(a){ a.href = a.href.replace( 'wa.me/508516668', 'wa.me/966508516668' ); }); var root = home(); if (root && !root.dataset.caReady){ root.dataset.caReady = '1'; root.querySelectorAll('a[href^="/"]').forEach(function(a){ a.setAttribute('href', route(a.getAttribute('href'))); }); document.body.classList.toggle( 'ca-only-scrubs', location.hash === '#ca-scrub-models' ); } } init(); var queued = false; new MutationObserver(function(){ if (queued) return; queued = true; requestAnimationFrame(function(){ queued = false; init(); }); }).observe(document.documentElement, { childList: true, subtree: true }); document.addEventListener('DOMContentLoaded', init, {once: true}); window.addEventListener('hashchange', function(){ document.body.classList.toggle( 'ca-only-scrubs', location.hash === '#ca-scrub-models' ); }); })(); /* California Scrubs — Style category pages: show every product assigned to each category. */ (function(){ 'use strict'; var stylePages = { '60392763': { title: 'سكراب طبي — ستايل 1' }, '295608529': { title: 'سكراب طبي — ستايل 2' }, '1007910163': { title: 'لابكوت طبي — ستايل 1' }, '1647730194': { title: 'لابكوت طبي — ستايل 2' } }; var busy = false; function applyStylePage(){ if (busy) return; var hit = location.pathname.split('/').filter(Boolean).pop(); var cat = hit && hit.charAt(0) === 'c' ? hit.slice(1) : ''; var config = stylePages[cat]; if (!config) return; busy = true; try { document.documentElement.classList.add('ca-style-category'); document.documentElement.dataset.caStyle = cat; var title = document.querySelector('main h1'); if (title && title.textContent.trim() !== config.title){ title.textContent = config.title; } var crumb = document.querySelector('main nav li:last-child'); if (crumb && crumb.textContent.trim() !== config.title){ crumb.textContent = config.title; } [].slice.call( document.querySelectorAll( 'main salla-products-list custom-salla-product-card[hidden]' ) ).forEach(function(card){ card.hidden = false; }); var oldPlaceholder = document.querySelector('.ca-style-placeholder'); if (oldPlaceholder){ oldPlaceholder.remove(); } } finally { busy = false; } } applyStylePage(); document.addEventListener( 'DOMContentLoaded', applyStylePage, {once: true} ); new MutationObserver(function(){ requestAnimationFrame(applyStylePage); }).observe(document.documentElement, { childList: true, subtree: true }); })(); /* California Scrubs — interactive homepage colour preview */ (function(){ "use strict"; var colors = { "الرمادي": { src: "https://cdn.files.salla.network/products/278511394/a48922fe-bd05-4828-a428-88959042710c-original.webp", alt: "سكراب ستايل 2 باللون الرمادي" }, "السماوي الفاتح": { src: "https://cdn.files.salla.network/products/278511394/369ce2c0-06cf-4548-9b93-798aae9f7ad0-original.webp", alt: "سكراب ستايل 2 باللون السماوي الفاتح" }, "الأزرق الملكي": { src: "https://cdn.files.salla.network/products/278511394/8bb1fd57-b8c9-4e41-8821-411ef5fada8b-original.webp", alt: "سكراب موديل 2 باللون الأزرق الملكي" }, "ستيل بلو": { src: "https://cdn.files.salla.network/products/278511394/4b4772f5-352a-4021-8af0-173928ee09fb-original.webp", alt: "سكراب ستايل 2 باللون ستيل بلو" }, "الكحلي": { src: "https://cdn.files.salla.network/products/278511394/ca9e56d7-abda-4b08-b7ef-4336744120c1-original.webp", alt: "سكراب ستايل 2 باللون الكحلي" } }; Object.keys(colors).forEach(function(k){ var p = new Image(); p.src = colors[k].src; }); function setup(){ var title = document.getElementById("ca-color-title"); var section = title && title.closest("section"); if (!section) return; var image = section.querySelector("img"); if (!image) return; var controls = section.querySelectorAll( "button,[role=button],input[type=radio],input[type=checkbox]" ); controls.forEach(function(control){ var name = ( control.getAttribute("aria-label") || control.textContent || "" ).trim(); if (!colors[name] || control.dataset.caColorReady) return; control.dataset.caColorReady = "1"; function choose(){ var item = colors[name]; image.src = item.src; image.removeAttribute("srcset"); image.setAttribute("data-src", item.src); image.alt = item.alt; controls.forEach(function(c){ c.classList.remove("is-active"); if (c.matches("button,[role=button]")){ c.setAttribute("aria-pressed", "false"); } }); control.classList.add("is-active"); if (control.matches("button,[role=button]")){ control.setAttribute("aria-pressed", "true"); } var leaves = section.querySelectorAll( "span,strong,b,small,p" ); for (var i = 0; i < leaves.length; i++){ if ( (leaves[i].textContent || "").trim() in colors && !leaves[i].querySelector("*") ){ leaves[i].textContent = name; break; } } } control.addEventListener("click", choose); control.addEventListener("change", choose); }); } setup(); document.addEventListener( "DOMContentLoaded", setup, {once: true} ); new MutationObserver(function(){ requestAnimationFrame(setup); }).observe(document.documentElement, { childList: true, subtree: true }); })(); /* California Scrubs — unified accordion navigation */ (function(){ 'use strict'; function route(p){ return location.hostname.indexOf('salla.sa') > -1 && location.pathname.indexOf('/sfot') === 0 ? '/sfot' + p : p; } function build(menu){ if (!menu || menu.dataset.caAccordionReady) return; menu.dataset.caAccordionReady = '1'; menu.innerHTML = '
' + '
' + '' + '' + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '
' + '' + 'التطريز المخصص' + 'اطلب الآن عبر واتساب' + '' + '
' + 'جاكيتقريبًا' + '
' + '
' + 'زي كلية التقنيةقريبًا' + '
' + '
' + 'زي الهلال الأحمرقريبًا' + '
' + '
'; menu.querySelectorAll('.ca-acc-trigger').forEach(function(trigger){ trigger.addEventListener('click', function(){ var item = trigger.closest('.ca-acc-item'); var open = item.classList.contains('is-open'); menu.querySelectorAll('.ca-acc-item.is-open').forEach(function(other){ if (other !== item){ other.classList.remove('is-open'); other .querySelector('.ca-acc-trigger') .setAttribute('aria-expanded', 'false'); } }); item.classList.toggle('is-open', !open); trigger.setAttribute('aria-expanded', String(!open)); }); }); } function init(){ document.querySelectorAll('.ca-native-menu').forEach(build); } init(); document.addEventListener( 'DOMContentLoaded', init, {once: true} ); new MutationObserver(function(){ requestAnimationFrame(init); }).observe(document.documentElement, { childList: true, subtree: true }); })(); /* California — keep the header cart counter in sync with the real cart page */ (function(){ 'use strict'; var marker = 'ca-cart-empty'; function setEmptyState(isEmpty){ document.documentElement.classList.toggle(marker, isEmpty); document.querySelectorAll('.s-cart-summary-count').forEach(function(count){ if (isEmpty){ count.textContent = '0'; count.setAttribute('aria-hidden', 'true'); } else { count.removeAttribute('aria-hidden'); } }); } function syncCartCounter(){ var link = document.querySelector('a.s-cart-summary-wrapper[href*="/cart"]'); var url = link ? link.href : '/cart'; fetch(url, {credentials:'same-origin', cache:'no-store'}) .then(function(response){ return response.ok ? response.text() : ''; }) .then(function(html){ if (!html) return; var doc = new DOMParser().parseFromString(html, 'text/html'); var text = (doc.body && doc.body.textContent) || ''; setEmptyState(text.indexOf('سلتك فارغة') !== -1); }) .catch(function(){}); } function initCartSync(){ syncCartCounter(); window.setTimeout(syncCartCounter, 1200); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initCartSync, {once:true}); } else { initCartSync(); } window.addEventListener('pageshow', syncCartCounter); document.addEventListener('click', function(event){ if (event.target.closest('salla-add-product-button, [aria-label="Add to cart button"], .s-add-product-button')) { window.setTimeout(syncCartCounter, 1400); } }); })(); /* California Scrubs — accurate homepage FAQ copy */ (function(){ 'use strict'; var queued = false; function replaceExact(oldText, newText){ document.querySelectorAll('.s-block--faq [data-selia], .s-block--faq p, .s-block--faq h2').forEach(function(el){ if ((el.textContent || '').trim() === oldText){ el.textContent = newText; } }); } function polishFaq(){ replaceExact('لديك سؤال؟ اجابته هنا', 'لديك سؤال؟ إجابته هنا'); replaceExact('كل ما تريد معرفته عن الأزياء والموضة', 'إجابات سريعة عن المقاسات والخامات والعناية بالزي الطبي.'); replaceExact('لماذا السكراب الطبي من لدينا هو الأفضل؟', 'لماذا تختار سكراب كاليفورنيا سكربز؟'); replaceExact('ماهي الوان السكرابات الطبيه؟', 'ما ألوان السكرابات الطبية المتوفرة؟'); document.querySelectorAll('.s-block--faq [data-selia="home-faq-answer"]').forEach(function(el){ var text = (el.textContent || '').trim(); if (text.indexOf('في متجر ألوان النسيج') !== -1){ el.textContent = text.replace(/ألوان النسيج/g, 'كاليفورنيا سكربز'); } if (text.indexOf('ألوان السكرابات الطبية تعتبر من العوامل الأساسية') === 0){ el.textContent = 'تختلف الألوان المتاحة حسب الموديل. افتحي صفحة الموديل لمشاهدة الألوان المتوفرة حاليًا، ثم افتحي اللون المطلوب لاختيار المقاس وإتمام الطلب.'; } }); } function schedule(){ if (queued) return; queued = true; requestAnimationFrame(function(){ queued = false; polishFaq(); }); } polishFaq(); document.addEventListener('DOMContentLoaded', polishFaq, {once:true}); new MutationObserver(schedule).observe(document.documentElement,{childList:true,subtree:true}); })();