1 directories, 5 files

dangs_demo

Home / testing / dangs_demo
/**
 * Dang's Automotive & Marine - Tab Navigation & Interactions
 */

document.addEventListener('DOMContentLoaded', () => {
  // Update footer year dynamically
  const yearEl = document.getElementById('year');
  if (yearEl) {
    yearEl.textContent = new Date().getFullYear();
  }

  // Set up tab buttons
  const tabBtns = document.querySelectorAll('.tab-btn');
  tabBtns.forEach(btn => {
    btn.addEventListener('click', () => {
      const targetTab = btn.getAttribute('data-tab');
      switchTab(targetTab);
    });
  });

  // Handle URL hash routing (e.g. #contact or #home)
  const hash = window.location.hash.replace('#', '').toLowerCase();
  if (hash === 'contact' || hash === 'home') {
    switchTab(hash);
  }

  // Listen for hash changes in browser
  window.addEventListener('hashchange', () => {
    const newHash = window.location.hash.replace('#', '').toLowerCase();
    if (newHash === 'contact' || newHash === 'home') {
      switchTab(newHash, false);
    }
  });
});

/**
 * Switches the active tab view
 * @param {string} tabName - 'home' or 'contact'
 * @param {boolean} updateHash - whether to update window hash
 */
function switchTab(tabName, updateHash = true) {
  // Update tab buttons
  const tabBtns = document.querySelectorAll('.tab-btn');
  tabBtns.forEach(btn => {
    const isTarget = btn.getAttribute('data-tab') === tabName;
    btn.classList.toggle('active', isTarget);
    btn.setAttribute('aria-selected', isTarget ? 'true' : 'false');
  });

  // Update tab panels
  const homePanel = document.getElementById('home-panel');
  const contactPanel = document.getElementById('contact-panel');

  if (tabName === 'contact') {
    if (homePanel) homePanel.classList.remove('active');
    if (contactPanel) contactPanel.classList.add('active');
  } else {
    if (contactPanel) contactPanel.classList.remove('active');
    if (homePanel) homePanel.classList.add('active');
  }

  if (updateHash) {
    window.location.hash = tabName;
  }
}

/**
 * Switch between background texture modes:
 * - 'split': Semi-diagonal split (Diamond Plate top-left, Boat Deck bottom-right)
 * - 'diamond': Diamond Plate only
 * - 'deck': Boat Deck only
 * @param {string} mode
 */
function setBackground(mode) {
  const bgEl = document.getElementById('site-bg');
  const btnSplit = document.getElementById('bg-btn-split');
  const btnDiamond = document.getElementById('bg-btn-diamond');
  const btnDeck = document.getElementById('bg-btn-deck');

  if (!bgEl) return;

  const buttons = [btnSplit, btnDiamond, btnDeck];
  buttons.forEach(b => { if (b) b.classList.remove('active'); });

  if (mode === 'diamond') {
    bgEl.style.backgroundImage = "url('gfx/diamond_plate.jpg')";
    if (btnDiamond) btnDiamond.classList.add('active');
  } else if (mode === 'deck') {
    bgEl.style.backgroundImage = "url('gfx/boat_deck_yacht.jpg')";
    if (btnDeck) btnDeck.classList.add('active');
  } else {
    bgEl.style.backgroundImage = "url('gfx/split_background.jpg')";
    if (btnSplit) btnSplit.classList.add('active');
  }
}

/**
 * Switch between the new high-resolution image and the original mockup crop
 * @param {string} mode - 'hi-res' or 'mockup'
 */
function setImage(mode) {
  const img = document.getElementById('featured-img');
  const btnHiRes = document.getElementById('btn-hi-res');
  const btnMockup = document.getElementById('btn-mockup');

  if (!img) return;

  if (mode === 'mockup') {
    img.src = 'gfx/original_photo_crop.jpg';
    if (btnHiRes) btnHiRes.classList.remove('active');
    if (btnMockup) btnMockup.classList.add('active');
  } else {
    img.src = 'gfx/truck_boat.jpg';
    if (btnMockup) btnMockup.classList.remove('active');
    if (btnHiRes) btnHiRes.classList.add('active');
  }
}
🌐
script.js ×
Type: Web, text/plain
3.65 Kilobytes
Last Modified 2026-11-01 20:10:26
⬇ Download File