Jump to content

MediaWiki:Common.js: Difference between revisions

From Machine Knitting Wiki
Created page with "Any JavaScript here will be loaded for all users on every page load.: // Ensure the DOM is ready and jQuery is available $( function () { // Define the HTML for your ad slot. // This will render the AdManager slot defined in MediaWiki:AdManager-top // The <ad slot="top" /> is a parser function processed by MediaWiki on the server, // but since we're injecting via JS, we're essentially telling the browser // to render whatever HTML is stored in..."
 
No edit summary
Line 2: Line 2:




// Ensure the DOM is ready and jQuery is available
// All ads setup
$( function () {
$( function () {
    $('head').append('<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8332774039939178"
    crossorigin="anonymous"></script>');
     // Define the HTML for your ad slot.
     // Define the HTML for your ad slot.
     // This will render the AdManager slot defined in MediaWiki:AdManager-top
     // This will render the AdManager slot defined in MediaWiki:AdManager-top

Revision as of 18:36, 4 July 2025

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


// All ads setup
$( function () {
    $('head').append('<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8332774039939178"
     crossorigin="anonymous"></script>');

    // Define the HTML for your ad slot.
    // This will render the AdManager slot defined in MediaWiki:AdManager-top
    // The <ad slot="top" /> is a parser function processed by MediaWiki on the server,
    // but since we're injecting via JS, we're essentially telling the browser
    // to render whatever HTML is stored in MediaWiki:AdManager-top.
    // So, make sure MediaWiki:AdManager-top contains the *actual* ad code (HTML/JS).
    var adHtml = '<div class="my-ad-container" style="margin: 10px auto; text-align: center;">' +
                 '<ad slot="top" />' + // This will be processed by MediaWiki's parser
                 '</div>';

    // Find the main content area and prepend the ad HTML
    // The ID for the main content area is typically 'bodyContent' in Vector 2022
    var bodyContent = $( '#bodyContent' );
    if ( bodyContent.length ) {
        bodyContent.prepend( adHtml );
    }

    // You can add other slots similarly:
    var bottomAdHtml = '<div class="my-ad-container" style="margin-top: 20px; text-align: center;"><ad slot="bottom" /></div>';
    if ( bodyContent.length ) {
        bodyContent.append( bottomAdHtml );
    }
} );