MediaWiki:Common.js: Difference between revisions

From NARA
Jump to navigation Jump to search
No edit summary
Tag: Manual revert
No edit summary
Line 9: Line 9:
     }
     }
   }  
   }  
}
// Force links to open in new tab in embed mode
if (document.body.classList.contains('vc-embed-mode')) {
  document.addEventListener('DOMContentLoaded', function () {
    const links = document.querySelectorAll('a[href]');
   
    links.forEach(link => {
      const href = link.getAttribute('href');
      // Skip anchors and empty links
      if (!href || href.startsWith('#')) return;
      // Make all links open in new tab
      link.setAttribute('target', '_blank');
      link.setAttribute('rel', 'noopener noreferrer');
    });
  });
}
}

Revision as of 16:38, 28 February 2026

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

// Remove whitespace tags using JS. The CSS-based approach seems to work fine on Chromium-based browsers, but not very well on Firefox.
window.onload = function() {
  var paras = document.querySelectorAll('.mw-parser-output p');
  for (var i = 0; i < paras.length; i++) {
    if (paras[i].childNodes[0].nodeName === 'BR') {
      paras[i].remove();
    }
  } 
}

// Force links to open in new tab in embed mode
if (document.body.classList.contains('vc-embed-mode')) {
  document.addEventListener('DOMContentLoaded', function () {
    const links = document.querySelectorAll('a[href]');
    
    links.forEach(link => {
      const href = link.getAttribute('href');

      // Skip anchors and empty links
      if (!href || href.startsWith('#')) return;

      // Make all links open in new tab
      link.setAttribute('target', '_blank');
      link.setAttribute('rel', 'noopener noreferrer');
    });
  });
}