MediaWiki:Common.js: Difference between revisions

m
Test
m (Undo revision 57799 by Abhidevananda (talk))
m (Test)
Line 12: Line 12:
  */
  */


/* global mw, $, importStylesheet, importScript */
/* global mw, $ */
/* jshint strict:false, browser:true */
/* jshint strict:false, browser:true */


mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'] ).done( function () {
mw.loader.using( ['mediawiki.user', 'mediawiki.util', 'mediawiki.notify'] ).done( function () {
/* Begin of mw.loader.using callback */
/* Begin of mw.loader.using callback */


Line 23: Line 23:
  * Description: Adds an additional link to the complete list of languages available.
  * Description: Adds an additional link to the complete list of languages available.
  * Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
  * Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
  *
  */
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
if ( mw.config.get( 'wgPageName' ) === 'Main_Page' || mw.config.get( 'wgPageName' ) === 'Talk:Main_Page' ) {
     $( function () {
     $( function () {
Line 30: Line 30:
     } );
     } );
}
}
*/


/**
/**
Line 81: Line 80:
if ( extraCSS ) {
if ( extraCSS ) {
     if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
     if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
         importStylesheet( extraCSS );
         mw.loader.load( '/w/index.php?title=' + extraCSS + '&action=raw&ctype=text/css', 'text/css' );
     } else {
     } else {
         mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
         mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
Line 89: Line 88:
if ( extraJS ) {
if ( extraJS ) {
     if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
     if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
         importScript( extraJS );
         mw.loader.load( '/w/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
     } else {
     } else {
         mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
         mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
     }
     }
}
/**
* Import more specific scripts if necessary
*/
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
    /* scripts specific to editing pages */
    importScript( 'MediaWiki:Common.js/edit.js' );
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
    /* watchlist scripts */
    importScript( 'MediaWiki:Common.js/watchlist.js' );
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
    /* file description page scripts */
    importScript( 'MediaWiki:Common.js/file.js' );
}
/**
* Helper script for .hlist class in Common.css
* Add pseudo-selector class to last-child list items in IE8
* @source mediawiki.org/wiki/Snippets/Horizontal_lists
* @revision 6 (2014-08-23)
* @author [[User:Edokter]]
*/
( function ( mw, $ ) {
    var profile = $.client.profile();
    if ( profile.name === 'msie' && profile.versionNumber === 8 ) {
        mw.hook( 'wikipage.content' ).add( function ( $content ) {
            $content.find( '.hlist' ).find( 'dd:last-child, dt:last-child, li:last-child' )
                .addClass( 'hlist-last-child' );
        } );
    }
}( mediaWiki, jQuery ) );
/**
* Fix for Windows XP Unicode font rendering
*/
if ( navigator.appVersion.search(/windows nt 5/i) !== -1 ) {
    mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' +
                '.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' );
}
}


Line 167: Line 126:
  * Collapsible tables
  * Collapsible tables
  *
  *
  * Allows tables to be collapsed, showing only the header. See [[Wikipedia:NavFrame]].
  * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
  *
  *
  * @version 2.0.3 (2014-03-14)
  * @version 2.0.3 (2014-03-14)
Line 192: Line 151:
     var Rows = Table.rows;
     var Rows = Table.rows;
     var i;
     var i;
    var $row0 = $(Rows[0]);


     if ( Button.firstChild.data === collapseCaption ) {
     if ( Button.firstChild.data === collapseCaption ) {
Line 200: Line 160:
     } else {
     } else {
         for ( i = 1; i < Rows.length; i++ ) {
         for ( i = 1; i < Rows.length; i++ ) {
             Rows[i].style.display = Rows[0].style.display;
             Rows[i].style.display = $row0.css( 'display' );
         }
         }
         Button.firstChild.data = collapseCaption;
         Button.firstChild.data = collapseCaption;
Line 274: Line 234:


mw.hook( 'wikipage.content' ).add( createCollapseButtons );
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
/**
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
*
* Maintainers: TheDJ
*/
function mwCollapsibleSetup( $collapsibleContent ) {
var $element,
    $toggle,
autoCollapseThreshold = 2;
$.each( $collapsibleContent, function (index, element) {
$element = $( element );
if ( $collapsibleContent.length > autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
$element.data( 'mw-collapsible' ).collapse();
} else if ( $element.hasClass( 'innercollapse' ) ) {
if ( $element.parents( '.outercollapse' ).length > 0 ) {
$element.data( 'mw-collapsible' ).collapse();
}
}
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $toggle.length ) {
// Make the toggle inherit text color
if( $toggle.parent()[0].style.color ) {
$toggle.find( 'a' ).css( 'color', 'inherit' );
}
}
} );
}
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );


/**
/**
Line 438: Line 428:
}
}


/* Actions specific to the edit page */
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) {
/**
* Fix edit summary prompt for undo
*
*  Fixes the fact that the undo function combined with the "no edit summary prompter"
*  complains about missing editsummary, if leaving the edit summary unchanged.
*  Added by [[User:Deskana]], code by [[User:Tra]].
*  See also [[phab:T10912]].
*/
$(function () {
    if (document.location.search.indexOf('undo=') !== -1 && document.getElementsByName('wpAutoSummary')[0]) {
        document.getElementsByName('wpAutoSummary')[0].value = '1';
    }
});
}


//Global Show/Hide
//Global Show/Hide