MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
// All ads setup | // All ads setup | ||
$( function () { | $( function () { | ||
// Define the HTML for your ad slot. | // Define the HTML for your ad slot. | ||
Latest revision as of 17:49, 4 July 2025
/* Any JavaScript here will be loaded for all users on every page load. */
// All ads setup
$( 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 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 );
}
} );