Header Ads Widget

Responsive Advertisement
Loading Recent Posts...

sfhbs

 <!-- Outer Structural Wrapper for Page Margins and Spacing -->

<div class="custom-slider-layout-wrapper">


  <!-- Slider Styles -->

  <style>

    :root {

      --primary-color: #ff5722;

      --text-dark: #333333;

    }

    

    .custom-slider-layout-wrapper {

      max-width: 1200px;

      width: 100%;

      margin: 25px auto 0 auto;

      padding: 0 15px;

      box-sizing: border-box;

    }


    .custom-slider-container {

      position: relative;

      width: 100%;

      height: 420px;

      background: #ffffff;

      overflow: hidden;

      border-radius: 4px;

      box-shadow: 0 2px 8px rgba(0,0,0,0.12);

    }

    .custom-slider-wrapper {

      display: flex;

      width: 500%;

      height: 100%;

      transition: transform 0.5s ease-in-out;

    }

    .custom-slide {

      width: 20%;

      height: 100%;

      position: relative;

    }

    .custom-slide img {

      width: 100%;

      height: 100%;

      object-fit: cover;

    }

    .custom-slide-content {

      position: absolute;

      bottom: 0;

      left: 0;

      right: 0;

      background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));

      color: #ffffff;

      padding: 35px 25px;

    }

    .custom-slide-content a {

      color: #ffffff;

      text-decoration: none;

    }

    .custom-slide-content a:hover {

      text-decoration: underline;

    }

    .custom-tag {

      display: inline-block;

      background-color: var(--primary-color);

      color: #ffffff;

      padding: 4px 10px;

      font-size: 11px;

      font-weight: bold;

      text-transform: uppercase;

      border-radius: 3px;

      margin-bottom: 10px;

      letter-spacing: 1px;

    }

    .custom-slide-title {

      font-size: 24px;

      margin-bottom: 8px;

      font-weight: 600;

    }

    .custom-slide-desc {

      font-size: 14px;

      color: #e0e0e0;

      line-height: 1.4;

    }

    .custom-nav-btn {

      position: absolute;

      top: 50%;

      transform: translateY(-50%);

      background-color: rgba(255, 255, 255, 0.85);

      border: none;

      width: 45px;

      height: 45px;

      border-radius: 50%;

      cursor: pointer;

      font-size: 20px;

      color: var(--text-dark);

      display: flex;

      align-items: center;

      justify-content: center;

      box-shadow: 0 2px 8px rgba(0,0,0,0.2);

      transition: background 0.3s, color 0.3s;

      z-index: 10;

    }

    .custom-nav-btn:hover {

      background-color: var(--primary-color);

      color: #ffffff;

    }

    .custom-prev { left: 20px; }

    .custom-next { right: 20px; }

    .custom-dots-container {

      position: absolute;

      bottom: 20px;

      right: 25px;

      display: flex;

      gap: 8px;

      z-index: 10;

    }

    .custom-dot {

      width: 10px;

      height: 10px;

      background-color: rgba(255, 255, 255, 0.4);

      border-radius: 50%;

      cursor: pointer;

      transition: background-color 0.3s, transform 0.3s;

    }

    .custom-dot.active {

      background-color: var(--primary-color);

      transform: scale(1.2);

    }

    

    .slider-loading {

      display: flex;

      justify-content: center;

      align-items: center;

      height: 100%;

      font-size: 16px;

      color: #666;

    }

  </style>


  <div class="custom-slider-container" id="sliderMainContainer">

    <div class="slider-loading">Loading Recent Posts...</div>

  </div>


</div>


<!-- Automated Feeds Logic -->

<script>

  (function() {

    fetch('/feeds/posts/default?alt=json&max-results=5')

      .then(response => response.json())

      .then(data => {

        const entries = data.feed.entry || [];

        if (entries.length === 0) {

          document.getElementById('sliderMainContainer').innerHTML = '<div class="slider-loading">No posts found.</div>';

          return;

        }


        let slidesHtml = '<div class="custom-slider-wrapper" id="customSliderWrapper">';

        let dotsHtml = '<div class="custom-dots-container" id="customDotsContainer">';


        entries.forEach((entry, idx) => {

          const title = entry.title.$t;

          

          let postUrl = '';

          for (let i = 0; i < entry.link.length; i++) {

            if (entry.link[i].rel === 'alternate') {

              postUrl = entry.link[i].href;

              break;

            }

          }


          // Parse categories/labels dynamically

          let categoryTag = '';

          if (entry.category && entry.category.length > 0) {

            categoryTag = `<span class="custom-tag">${entry.category[0].term}</span>`;

          }


          // Image resolution fallback handler fixed

          let imgSrc = 'https://unsplash.com';

          if (entry.media$thumbnail) {

            imgSrc = entry.media$thumbnail.url.replace('/s72-c/', '/s1600/');

            imgSrc = imgSrc.replace('-c/', '/');

          } else if (entry.content && entry.content.$t) {

            const imgMatch = entry.content.$t.match(/<img[^>]+src="([^">]+)"/);

            if (imgMatch && imgMatch[1]) imgSrc = imgMatch[1];

          }


          let summary = '';

          if (entry.summary && entry.summary.$t) {

            summary = entry.summary.$t.substring(0, 140) + '...';

          } else if (entry.content && entry.content.$t) {

            summary = entry.content.$t.replace(/<[^>]*>/g, '').substring(0, 140) + '...';

          }


          slidesHtml += `

            <div class="custom-slide">

              <img src="${imgSrc}" alt="${title}">

              <div class="custom-slide-content">

                ${categoryTag}

                <h2 class="custom-slide-title"><a href="${postUrl}">${title}</a></h2>

                <p class="custom-slide-desc">${summary}</p>

              </div>

            </div>`;


          dotsHtml += `<div class="custom-dot ${idx === 0 ? 'active' : ''}" data-idx="${idx}"></div>`;

        });


        slidesHtml += '</div>';

        dotsHtml += '</div>';


        const mainContainer = document.getElementById('sliderMainContainer');

        mainContainer.innerHTML = `

          ${slidesHtml}

          <button class="custom-nav-btn custom-prev" id="customPrevBtn">&#10094;</button>

          <button class="custom-nav-btn custom-next" id="customNextBtn">&#10095;</button>

          ${dotsHtml}

        `;


        initializeSliderEngine(entries.length);

      })

      .catch(err => {

        console.error("Error loading Blogger feed scripts: ", err);

        document.getElementById('sliderMainContainer').innerHTML = '<div class="slider-loading">Error loading posts slider layout elements.</div>';

      });


    function initializeSliderEngine(totalSlides) {

      const wrapper = document.getElementById('customSliderWrapper');

      const prevBtn = document.getElementById('customPrevBtn');

      const nextBtn = document.getElementById('customNextBtn');

      const dots = document.querySelectorAll('.custom-dot');


      let currentIndex = 0;

      let autoSlideInterval;


      function updateSliderPosition() {

        wrapper.style.transform = `translateX(-${currentIndex * (100 / totalSlides)}%)`;

        dots.forEach((dot, idx) => {

          dot.classList.toggle('active', idx === currentIndex);

        });

      }


      function goToSlide(index) {

        currentIndex = index;

        updateSliderPosition();

        resetAutoSlide();

      }


      function nextSlide() {

        currentIndex = (currentIndex + 1) % totalSlides;

        updateSliderPosition();

      }


      function prevSlide() {

        currentIndex = (currentIndex - 1 + totalSlides) % totalSlides;

        updateSliderPosition();

      }


      nextBtn.addEventListener('click', () => { nextSlide(); resetAutoSlide(); });

      prevBtn.addEventListener('click', () => { prevSlide(); resetAutoSlide(); });

      

      dots.forEach(dot => {

        dot.addEventListener('click', (e) => {

          const idx = parseInt(e.target.getAttribute('data-idx'));

          goToSlide(idx);

        });

      });


      function startAutoSlide() { autoSlideInterval = setInterval(nextSlide, 5000); }

      function resetAutoSlide() { clearInterval(autoSlideInterval); startAutoSlide(); }


      startAutoSlide();

    }

  })();

</script>


Post a Comment

0 Comments