MediaWiki:Common.js: Difference between revisions

From Makerpedia

Chetitac (talk | contribs)
No edit summary
Chetitac (talk | contribs)
No edit summary
Line 67: Line 67:


$(document).ready(function () {
$(document).ready(function () {
     let images = $(".slide");
    // Carousel variables
     let $carouselWrapper = $(".carousel-wrapper");
    let $carouselGallery = $(".carousel-gallery");
    let $images = $carouselGallery.find("img");
    let imageWidth = $images.first().outerWidth(true); // Get the width of one image including margins
    let totalImages = $images.length;
     let currentIndex = 0;
     let currentIndex = 0;


     function showImage(index) {
     // Add the "prev" and "next" buttons dynamically to the carousel container
        images.hide();
    let prevButton = $('<button class="prev">Prev</button>');
        images.eq(index).show();
    let nextButton = $('<button class="next">Next</button>');
    }
    $(".carousel-container").append(prevButton).append(nextButton);


     showImage(currentIndex);
     // Style the buttons with jQuery if you want to do it dynamically
    prevButton.css({
        position: 'absolute',
        top: '50%',
        left: '0',
        transform: 'translateY(-50%)',
        backgroundColor: 'rgba(0, 0, 0, 0.5)',
        color: 'white',
        border: 'none',
        padding: '10px',
        cursor: 'pointer',
        zIndex: '10'
    });
 
    nextButton.css({
        position: 'absolute',
        top: '50%',
        right: '0',
        transform: 'translateY(-50%)',
        backgroundColor: 'rgba(0, 0, 0, 0.5)',
        color: 'white',
        border: 'none',
        padding: '10px',
        cursor: 'pointer',
        zIndex: '10'
    });


     $(".left").click(function () {
     // "Prev" button click - move carousel to the left
    prevButton.click(function () {
         if (currentIndex > 0) {
         if (currentIndex > 0) {
             currentIndex--;
             currentIndex--;
             showImage(currentIndex);
             $carouselWrapper.css("transform", "translateX(-" + (imageWidth * currentIndex) + "px)");
         }
         }
     });
     });


     $(".right").click(function () {
     // "Next" button click - move carousel to the right
         if (currentIndex < images.length - 1) {
    nextButton.click(function () {
         if (currentIndex < totalImages - 1) {
             currentIndex++;
             currentIndex++;
             showImage(currentIndex);
             $carouselWrapper.css("transform", "translateX(-" + (imageWidth * currentIndex) + "px)");
         }
         }
     });
     });
    // Show the first image initially
    $carouselWrapper.css("transform", "translateX(0)");
});
});

Revision as of 21:13, 6 February 2025

/* Any JavaScript here will be loaded for all users on every page load. */

if (document) window.µ = function (id, elem) {
  var ret;
  var root = ((elem) ? elem : document);
  switch (id.charAt(0)) {
    case '|':
      ret = root;
      break;
    case '+':
      ret = document.createElement(id.substring(1));
      if (elem) elem.appendChild(ret);
      break;
    case '#':
      ret = root.querySelector(id);
      break;
    default:
      ret = Array.prototype.slice.call(root.querySelectorAll(id));
      break;
  }

  return ret;
};

/* add additional edit button (prioritize 'Edit' over 'Edit Source' when available) -- styled in Medik.css */ 
if(document.getElementById("ca-edit") != null || document.getElementById("ca-ve-edit") != null) {
    let link = document.getElementById("ca-ve-edit") != null ? document.querySelector("#ca-ve-edit a").href : document.querySelector("#ca-edit a").href;
    document.getElementById("content").innerHTML += '<a href='+link+'><button class="big-edit-button"><p>EDIT</p></button></a>';
}

$(document).ready(function () {
    // Add the category filter buttons before the gallery
    $("#tool-gallery").before('<div id="category-filter">' +
        '<button class="filter-btn" data-filter="Tools">Show All</button>' +  
        '<button class="filter-btn" data-filter="Makerspace Tools">Makerspace Tools</button>' +
        '<button class="filter-btn" data-filter="Wood Shop Tools">Wood Shop Tools</button>' +
        '<button class="filter-btn" data-filter="Machine Shop Tools">Machine Shop Tools</button>' +
    '</div>');

    // Initially, show all galleries
    $("#tool-gallery, #makerspace-gallery, #machineshop-gallery, #woodshop-gallery").show();

    // Filter logic when a button is clicked
    $(".filter-btn").click(function () {
        var selectedCategory = $(this).data("filter");

        // Hide all galleries first
        $("#tool-gallery, #makerspace-gallery, #machineshop-gallery, #woodshop-gallery").hide();

        // Show the appropriate gallery based on the selected category
        if (selectedCategory === "Tools") {
            // Show all galleries when "Show All" is clicked
            $("#tool-gallery, #makerspace-gallery, #machineshop-gallery, #woodshop-gallery").show();
        } else if (selectedCategory === "Machine Shop Tools") {
            // Show only Machine Shop Tools gallery
            $("#machineshop-gallery").show();
        } else if (selectedCategory === "Makerspace Tools") {
            // Show only Makerspace Tools gallery
            $("#makerspace-gallery").show();
        } else if (selectedCategory === "Wood Shop Tools") {
            // Show only Wood Shop Tools gallery
            $("#woodshop-gallery").show();
        }
    });
});


$(document).ready(function () {
    // Carousel variables
    let $carouselWrapper = $(".carousel-wrapper");
    let $carouselGallery = $(".carousel-gallery");
    let $images = $carouselGallery.find("img");
    let imageWidth = $images.first().outerWidth(true); // Get the width of one image including margins
    let totalImages = $images.length;
    let currentIndex = 0;

    // Add the "prev" and "next" buttons dynamically to the carousel container
    let prevButton = $('<button class="prev">Prev</button>');
    let nextButton = $('<button class="next">Next</button>');
    $(".carousel-container").append(prevButton).append(nextButton);

    // Style the buttons with jQuery if you want to do it dynamically
    prevButton.css({
        position: 'absolute',
        top: '50%',
        left: '0',
        transform: 'translateY(-50%)',
        backgroundColor: 'rgba(0, 0, 0, 0.5)',
        color: 'white',
        border: 'none',
        padding: '10px',
        cursor: 'pointer',
        zIndex: '10'
    });

    nextButton.css({
        position: 'absolute',
        top: '50%',
        right: '0',
        transform: 'translateY(-50%)',
        backgroundColor: 'rgba(0, 0, 0, 0.5)',
        color: 'white',
        border: 'none',
        padding: '10px',
        cursor: 'pointer',
        zIndex: '10'
    });

    // "Prev" button click - move carousel to the left
    prevButton.click(function () {
        if (currentIndex > 0) {
            currentIndex--;
            $carouselWrapper.css("transform", "translateX(-" + (imageWidth * currentIndex) + "px)");
        }
    });

    // "Next" button click - move carousel to the right
    nextButton.click(function () {
        if (currentIndex < totalImages - 1) {
            currentIndex++;
            $carouselWrapper.css("transform", "translateX(-" + (imageWidth * currentIndex) + "px)");
        }
    });

    // Show the first image initially
    $carouselWrapper.css("transform", "translateX(0)");
});