MediaWiki:Common.js: Difference between revisions

From Makerpedia

Chetitac (talk | contribs)
No edit summary
Tag: Reverted
Chetitac (talk | contribs)
No edit summary
Tag: Reverted
Line 64: Line 64:
     });
     });
});
});


$(document).ready(function () {
$(document).ready(function () {
     let $wrapper = $(".wrapper");
     let $wrapper = $(".wrapper");
     let animationSpeed = 30; // Adjust for desired speed
     let step = 200; // Distance moved per click
     let wrapperWidth = $wrapper.width();
     let wrapperWidth = $wrapper.width();
     let step = 200; // Distance moved per click
      
    let isAnimating = true;
 
    // Function to start automatic scrolling
    function startScrolling() {
        isAnimating = true;
        $wrapper.css("animation", `${animationSpeed}s credits linear infinite`);
    }
 
    // Function to stop automatic scrolling
    function stopScrolling() {
        isAnimating = false;
        $wrapper.css("animation", "none");
    }
 
     // Left arrow click (move right)
     // Left arrow click (move right)
     $("#leftArrow").click(function () {
     $("#leftArrow").click(function () {
        stopScrolling();
         let currentMargin = parseInt($wrapper.css("margin-left")) || 0;
         let currentMargin = parseInt($wrapper.css("margin-left")) || 0;
         if (currentMargin < 0) {
         if (currentMargin < 0) {
Line 95: Line 82:
     // Right arrow click (move left)
     // Right arrow click (move left)
     $("#rightArrow").click(function () {
     $("#rightArrow").click(function () {
        stopScrolling();
         let currentMargin = parseInt($wrapper.css("margin-left")) || 0;
         let currentMargin = parseInt($wrapper.css("margin-left")) || 0;
         if (Math.abs(currentMargin) < wrapperWidth - $(".gallery").width()) {
         if (Math.abs(currentMargin) < wrapperWidth - $(".gallery").width()) {
Line 101: Line 87:
         }
         }
     });
     });
    // Restart scrolling when user stops interacting
    $("#leftArrow, #rightArrow").on("mouseleave", function () {
        if (!isAnimating) {
            setTimeout(startScrolling, 5000); // Restart after 5 sec
        }
    });
    startScrolling(); // Start animation initially
});
});

Revision as of 02:54, 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 () {
    let $wrapper = $(".wrapper");
    let step = 200; // Distance moved per click
    let wrapperWidth = $wrapper.width();
    
    // Left arrow click (move right)
    $("#leftArrow").click(function () {
        let currentMargin = parseInt($wrapper.css("margin-left")) || 0;
        if (currentMargin < 0) {
            $wrapper.css("margin-left", currentMargin + step + "px");
        }
    });

    // Right arrow click (move left)
    $("#rightArrow").click(function () {
        let currentMargin = parseInt($wrapper.css("margin-left")) || 0;
        if (Math.abs(currentMargin) < wrapperWidth - $(".gallery").width()) {
            $wrapper.css("margin-left", currentMargin - step + "px");
        }
    });
});