MediaWiki:Common.js

From the Combine OverWiki, the original Half-Life and Portal wiki
(Redirected from Template:Information\n)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
window.overwikiCommon = {};

/*
 * Collapsible navigation boxes
 */

overwikiCommon.navtemp = {};

overwikiCommon.navtemp.toggle = function ( button ) {
  $( button ).closest( '.navtemp' ).toggleClass( 'navtempcoll' );
};

overwikiCommon.navtemp.createToggles = function ( $content ) {
  $content.find( '.navtemp' ).not( '[data-navtemp-ready]' ).each( function () {
    var $table = $( this );
    var $header = $table.find( 'tr' ).first().children( 'th' ).first();
    if ( !$header.length ) {
      return;
    }
    $header.prepend(
      '<span class="navtemptoggle">' +
        '<span class="navtempshow" role="button" tabindex="0">[show]</span>' +
        '<span class="navtemphide" role="button" tabindex="0">[hide]</span>' +
      '</span>'
    );
    $table.addClass( 'navtempcoll' ).attr( 'data-navtemp-ready', '1' );
  } );
};

$( document ).on( 'click keydown', '.navtempshow, .navtemphide', function ( e ) {
  if ( e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ' ) {
    return;
  }
  e.preventDefault();
  overwikiCommon.navtemp.toggle( this );
} );

mw.hook( 'wikipage.content' ).add( overwikiCommon.navtemp.createToggles );

/*
 * Proper positioning of the license box when uploading.
 */

overwikiCommon.upload = {};

overwikiCommon.upload.updateLicense = function () {
  var description = document.getElementById( 'wpUploadDescription' );
  var license = document.getElementById( 'wpLicense' );
  if ( description && license ) {
    description.value = description.value.replace( /\|licensing=.*/m, '|licensing=' + ( license.value ? '{{' + license.value + '}}' : '' ) );
  }
};

overwikiCommon.upload.setupLicensing = function () {
  var description = document.getElementById( 'wpUploadDescription' );
  var license = document.getElementById( 'wpLicense' );
  if ( !license || !description || !/\|licensing=/.test( description.value ) ) {
    return;
  }
  license.removeAttribute( 'name' );
  license.addEventListener( 'change', overwikiCommon.upload.updateLicense );
};

if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' && !/[?&]wpForReUpload=1/.test( location.search ) ) {
  $( overwikiCommon.upload.setupLicensing );
}