Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Gadget-quickLinkCardClick.js: Difference between revisions

MediaWiki interface page
mNo edit summary
No edit summary
Line 1: Line 1:
// quickLinkCardClick.js
(function () {
(function () {
if(mw.config.get('wgIsMainPage') !== true) return;
  if (mw.config.get('wgIsMainPage') !== true) return;
  // Wait until the DOM is fully loaded
 
   document.addEventListener('DOMContentLoaded', function () {
   mw.hook('wikipage.content').add(function (content) {
     document.querySelectorAll('.vh-quick-link-card').forEach(card => {
     const cards = content.querySelectorAll('.vh-quick-link-card');
    cards.forEach(card => {
       const link = card.querySelector('a');
       const link = card.querySelector('a');
       if (!link) return;
       if (!link) return;


       card.addEventListener('click', function (e) {
       card.addEventListener('click', function (e) {
         // Avoid double-activating if user clicks directly on the <a>
         if (e.target.closest('a')) return;
        if (
          e.target.tagName.toLowerCase() === 'a' ||
          e.target.closest('a')
        ) return;
 
         window.location.href = link.href;
         window.location.href = link.href;
       });
       });


      // Accessibility: allow Enter/Space key activation
       card.setAttribute('role', 'link');
       card.setAttribute('role', 'link');
       card.setAttribute('tabindex', '0');
       card.setAttribute('tabindex', '0');

Revision as of 04:38, 23 July 2025

(function () {
  if (mw.config.get('wgIsMainPage') !== true) return;

  mw.hook('wikipage.content').add(function (content) {
    const cards = content.querySelectorAll('.vh-quick-link-card');
    cards.forEach(card => {
      const link = card.querySelector('a');
      if (!link) return;

      card.addEventListener('click', function (e) {
        if (e.target.closest('a')) return;
        window.location.href = link.href;
      });

      card.setAttribute('role', 'link');
      card.setAttribute('tabindex', '0');

      card.addEventListener('keydown', function (e) {
        if (e.key === 'Enter' || e.key === ' ') {
          e.preventDefault();
          window.location.href = link.href;
        }
      });
    });
  });
})();