MediaWiki:Common.js: Difference between revisions

Dude of Wealth and Taste (talk | contribs)
No edit summary
Dude of Wealth and Taste (talk | contribs)
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. */
// === Create Page Button (sitewide) ===
// === Universal "Create Page" Button for WikiOasis ===
// Adds a "Create page" button for easy new page creation
( function () {
( function () {
  // Only run when the page is fully loaded
   $(function () {
   $(function () {
     // If you also want it to show for anonymous users, remove the next line
     // Remove this line if you want guests to see it too:
     if ( mw.user.isAnon() ) return;
     if ( mw.user.isAnon() ) return;


     // Function to open the edit page for a new title
     // Function to open the edit page
     function createPage(title) {
     function createPage(title) {
       if (!title) return;
       if (!title) return;
       title = title.trim().replace(/\s+/g, ' ');
       title = title.trim().replace(/\s+/g, ' ');
       var url = mw.config.get('wgScript') + '?title=' + encodeURIComponent(title) + '&action=edit';
       var url = mw.util.getUrl(title, { action: 'edit' });
       window.location.href = url;
       window.location.href = url;
     }
     }


     // Create the button element
     // Create the button
     var $btn = $('<a>')
     var $btn = $('<a>')
       .attr('id', 'create-new-page-button')
       .attr('id', 'create-new-page-button')
Line 28: Line 26:
         'border-radius': '4px',
         'border-radius': '4px',
         'text-decoration':'none',
         'text-decoration':'none',
         'font-weight':'600'
         'font-weight':'600',
        'cursor': 'pointer'
       })
       })
       .click(function (e) {
       .click(function (e) {
Line 36: Line 35:
       });
       });


     // Try to add to the top-right user toolbar
     // Try different common locations for modern Vector / Oasis skins
     var $personal = $('#p-personal ul');
    var added = false;
     if ($personal.length) {
 
       $personal.append($('<li>').append($btn));
    // 1. New Vector user menu area
     } else {
     if ($('.vector-user-menu, .vector-menu-content-list, .vector-menu-content').length) {
      // Fallback: add to the left sidebar navigation
      $('.vector-user-menu .vector-menu-content-list, .vector-menu-content').first().append($('<li>').append($btn));
      added = true;
    }
 
    // 2. Classic personal toolbar
     if (!added && $('#p-personal ul').length) {
       $('#p-personal ul').append($('<li>').append($btn));
      added = true;
     }
 
    // 3. Sidebar navigation
    if (!added && $('#p-navigation .body ul').length) {
       $('#p-navigation .body ul').append($('<li>').append($btn));
       $('#p-navigation .body ul').append($('<li>').append($btn));
      added = true;
    }
    // 4. Absolute fallback – inject near the top of the page
    if (!added) {
      $('#mw-content-text').prepend($('<div style="margin-bottom:1em;">').append($btn));
     }
     }
   });
   });
}() );
}() );