/*
 Theme Name:   Woodmart Child
 Description:  Woodmart Child Theme
 Author:       XTemos
 Author URI:   http://xtemos.com
 Template:     woodmart
 Version:      1.0.0
 Text Domain:  woodmart
*/

<script>
(function(){
  // Sadece bu sayfada çalışsın:
  if (!location.pathname.includes("/cnc-digerleri/")) return;

  function getSectionTitle(el){
    // Tıklanan itemdan yukarı doğru en yakın başlığı ara
    const scope = el.closest("section, .elementor-section, .wpb_wrapper, .container, .content-area, .site-content") || document;
    const h4 = scope.querySelector(".woodmart-title-container, .title, h2, h3, h4");
    return h4 ? h4.textContent.trim() : document.title.trim();
  }

  function applyTitles(){
    const links = document.querySelectorAll(".wd-images-gallery .wd-gallery-item > a");
    links.forEach(a => {
      const title = getSectionTitle(a);
      // Elementor lightbox caption/title alanı
      a.setAttribute("data-elementor-lightbox-title", title);

      // Eğer görsel alt'ı varsa, description gibi de basabiliriz:
      const img = a.querySelector("img");
      const alt = img && img.getAttribute("alt") ? img.getAttribute("alt").trim() : "";
      if (alt) a.setAttribute("data-elementor-lightbox-description", alt);
    });
  }

  document.addEventListener("DOMContentLoaded", applyTitles);

  // Elementor bazen sonradan DOM basıyor; garanti olsun:
  setTimeout(applyTitles, 800);
})();
</script>

