MediaWiki:Common.js: Difference between revisions

From QME Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
// Google Analytics 4 tracking via MediaWiki:Common.js
// Google Analytics 4 tracking via MediaWiki:Common.js
(function() {
(function () {
   var gaScript = document.createElement('script');
   var gaScript = document.createElement('script');
   gaScript.async = true;
   gaScript.async = true;
Line 7: Line 7:


   window.dataLayer = window.dataLayer || [];
   window.dataLayer = window.dataLayer || [];
   function gtag(){ dataLayer.push(arguments); }
   function gtag() { dataLayer.push(arguments); }
   window.gtag = gtag;
   window.gtag = gtag;


Line 22: Line 22:
   });
   });


   // Disable clicking on image links for anonymous users
  const userGroups = mw.config.get('wgUserGroups') || [];
   if (mw.config.get('wgUserGroups').includes('anon')) {
  // console.log('User groups:', userGroups); // Uncomment for debugging
     // Event delegation: handle current and future links
 
     document.body.addEventListener('click', function(event) {
   // Disable image interaction for anonymous users
   if (userGroups.includes('*')) {
     // Disable clicking on image links
     document.body.addEventListener('click', function (event) {
       const anchor = event.target.closest('a');
       const anchor = event.target.closest('a');
       if (!anchor) return;
       if (!anchor) return;
Line 31: Line 34:
       if (anchor.querySelector('img')) {
       if (anchor.querySelector('img')) {
         event.preventDefault();
         event.preventDefault();
        event.stopPropagation();
         anchor.style.cursor = 'default';
         anchor.style.cursor = 'default';
       }
       }
     });
     });


     // Attempt to disable MediaViewer for anonymous users
     // Properly disable MediaViewer for anonymous users
     mw.loader.using('mediawiki.mediaViewer', function() {
     mw.config.set('wgMediaViewerOnClick', false);
      if (window.MediaViewer) {
        MediaViewer.disabled = true;
      }
    });
   }
   }
});
});

Latest revision as of 16:49, 7 August 2025

// Google Analytics 4 tracking via MediaWiki:Common.js
(function () {
  var gaScript = document.createElement('script');
  gaScript.async = true;
  gaScript.src = 'https://www.googletagmanager.com/gtag/js?id=G-01G5LMDW7X';
  document.head.appendChild(gaScript);

  window.dataLayer = window.dataLayer || [];
  function gtag() { dataLayer.push(arguments); }
  window.gtag = gtag;

  gtag('js', new Date());
  gtag('config', 'G-01G5LMDW7X');
})();

document.addEventListener("DOMContentLoaded", function () {
  // Disable right-click on all images
  document.addEventListener("contextmenu", function (event) {
    if (event.target.tagName === "IMG") {
      event.preventDefault();
    }
  });

  const userGroups = mw.config.get('wgUserGroups') || [];
  // console.log('User groups:', userGroups); // Uncomment for debugging

  // Disable image interaction for anonymous users
  if (userGroups.includes('*')) {
    // Disable clicking on image links
    document.body.addEventListener('click', function (event) {
      const anchor = event.target.closest('a');
      if (!anchor) return;

      if (anchor.querySelector('img')) {
        event.preventDefault();
        event.stopPropagation();
        anchor.style.cursor = 'default';
      }
    });

    // Properly disable MediaViewer for anonymous users
    mw.config.set('wgMediaViewerOnClick', false);
  }
});
By using this site, you agree to the Terms of Use. © 1996–2025 The Quincy Examiner / MTB. All rights reserved.