Jump to content

MediaWiki:Common.js: Difference between revisions

From Shark's Hypothetical Weather
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
$(function() {
$(function() {
     var shortdescText = $('div.shortdescription').text();
     var shortdesc = $('div.shortdescription').text().trim();
     if (shortdescText.length > 0) {
 
         // Remove the existing meta description generated by MediaWiki
     if (shortdesc.length > 0) {
         // SHORTDESC exists: replace the old meta description
         $('meta[name="description"]').remove();
         $('meta[name="description"]').remove();


         // Create a new meta description element
         $('<meta>', {
         var meta = document.createElement('meta');
            name: 'description',
         meta.name = "description";
            content: shortdesc
        meta.content = shortdescText;
         }).appendTo('head');
        document.getElementsByTagName('head')[0].appendChild(meta);
    } else {
        // No SHORTDESC: delete any description tag
         $('meta[name="description"]').remove();
     }
     }
});
});

Revision as of 22:27, 25 April 2025

/* Any JavaScript here will be loaded for all users on every page load. */
$(function() {
    var shortdesc = $('div.shortdescription').text().trim();

    if (shortdesc.length > 0) {
        // SHORTDESC exists: replace the old meta description
        $('meta[name="description"]').remove();

        $('<meta>', {
            name: 'description',
            content: shortdesc
        }).appendTo('head');
    } else {
        // No SHORTDESC: delete any description tag
        $('meta[name="description"]').remove();
    }
});