MediaWiki:Common.js — различия между версиями

Материал из Guild Wars 2 wiki
Перейти к: навигация, поиск
(новая версия autoConvertUTC)
 
(не показано 17 промежуточных версий 2 участников)
Строка 1: Строка 1:
 
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
 
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
  
/** additional scripts **/
+
// Scripts to use when viewing articles
if (wgIsArticle || window.location.href.indexOf('action=submit') > -1 || wgNamespaceNumber == -1) {
+
if (mw.config.get('wgIsArticle') || window.location.href.indexOf('action=submit') > -1 || mw.config.get('wgNamespaceNumber') == -1) {
  importScript('MediaWiki:CollapsibleTables.js');
+
    mw.loader.load( '/index.php?title=MediaWiki:TPprices.js&action=raw&ctype=text/javascript' );
  importScript('MediaWiki:TPprices.js');
+
    mw.loader.load( '/index.php?title=MediaWiki:GameLinks.js&action=raw&ctype=text/javascript' );
  importScript('MediaWiki:GameLinks.js');
+
    mw.loader.load( '/index.php?title=MediaWiki:CurrentTime.js&action=raw&ctype=text/javascript' );
  importScript('MediaWiki:BloodTest.js');
+
    mw.loader.load( '/index.php?title=MediaWiki:Winter.js&action=raw&ctype=text/javascript' );
  $(function() {
+
    mw.loader.load( '/index.php?title=MediaWiki:Halloween.js&action=raw&ctype=text/javascript' );
 +
    mw.loader.load( '/index.php?title=MediaWiki:GameModeVersion.js&action=raw&ctype=text/javascript' );
 +
    mw.loader.load( '/index.php?title=MediaWiki:BloodTest.js&action=raw&ctype=text/javascript' );
 +
 
 +
    // Article namespace
 +
    if (mw.config.get('wgNamespaceNumber') === 0 ) {
 +
        gameUpdateIcons();
 +
    }
 +
 
 +
    // Only if the page contains collapsible tables
 +
    if ( $('.collapsible, .expandable').length > 0 ) {
 +
        mw.loader.load( '/index.php?title=MediaWiki:CollapsibleTables.js&action=raw&ctype=text/javascript' );
 +
    }
 +
 
 
     autoConvertUTC();
 
     autoConvertUTC();
  });
+
    semanticGalleryCleanup();
 
}
 
}
  
/*
+
/**
  * autoConvertUTC (see [[Template:UTC time]])
+
  * Convert UTC time to local time. (see [[Template:UTC time]])
 
  */
 
  */
 
function autoConvertUTC () {
 
function autoConvertUTC () {
  function pad (s) {  return (s < 10 ? '0' : '') + s; }
+
    function pad (s) {  return (s < 10 ? '0' : '') + s; }
  var days = ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'];
+
    var days = ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'];
  $('.utc-auto-convert').each(function(i,v){
+
    $('.utc-auto-convert').each(function(i,v){
 
+
        // Get UTC time using MediaWiki {{#time: U}} epoch format
    // Get UTC time using MediaWiki {{#time: U}} epoch format
+
        var utcseconds = v.getAttribute('data-time');
    var utcseconds = v.getAttribute('data-time');
+
        if (utcseconds == 'error') {
    if (utcseconds == 'error') {
+
            return;
      return;
+
        }
    }
+
        var d = new Date(0);
    var d = new Date(0);
+
        d.setUTCSeconds(utcseconds);
    d.setUTCSeconds(utcseconds);
+
        var offset = (-1 * d.getTimezoneOffset() / 60);
    var offset = (-1 * d.getTimezoneOffset() / 60);
+
        var offsetstring = '';
    var offsetstring = '';
+
        if (offset > 0) { offsetstring = '+' + offset; }
    if (offset > 0) { offsetstring = '+' + offset; }
+
        if (offset < 0) { offsetstring = offset; }
    if (offset < 0) { offsetstring = offset;       }
+
       
 
+
        // Default to showing the time only
    // Default to showing the time only
+
        var datestring = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ' UTC' + offsetstring;
    var datestring = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ' UTC' + offsetstring;
+
        var titlestring = pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ' UTC';
    var titlestring = pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ' UTC';
+
       
   
+
        // But check for different formatting in case there is a day of the week given inside the span
    // But check for different formatting in case there is a day of the week given inside the span
+
        if (!v.textContent.match(/^\d/)) {
    if (!v.textContent.match(/^\d/)) {
+
            datestring  = days[d.getDay()] + ' ' + datestring;
      datestring  = days[d.getDay()] + ' ' + datestring;
+
            titlestring = days[d.getUTCDay()] + ' ' + titlestring;
      titlestring = days[d.getUTCDay()] + ' ' + titlestring;
+
        }
    }
+
       
 
+
        // Show result
    // Show result
+
        $(v).html('<span style="cursor:help; border-bottom:1px dotted silver;" title="'+titlestring+'">'+datestring+'</span>');
    $(v).html('<span style="cursor:help; border-bottom:1px dotted silver;" title="'+titlestring+'">'+datestring+'</span>');
+
    });
  });
 
 
}
 
}
  
 
/**
 
/**
 
  * Helper script for .hlist class in Common.css
 
  * Helper script for .hlist class in Common.css
  * Add pseudo-selector class to last-child list items in IE8
+
  *   add pseudo-selector class to last-child list items in IE8
  * @source mediawiki.org/wiki/Snippets/Horizontal_lists
+
  *   @source mediawiki.org/wiki/Snippets/Horizontal_lists
  * @revision 6 (2014-08-23)
+
  *   @revision 6 (2014-08-23)
  * @author mediawiki.org/wiki/User:Edokter
+
  *   @author mediawiki.org/wiki/User:Edokter
 
  */
 
  */
( function ( mw, $ ) {
+
(function ( mw, $ ) {
 
     var profile = $.client.profile();
 
     var profile = $.client.profile();
 
     if ( profile.name === 'msie' && profile.versionNumber === 8 ) {
 
     if ( profile.name === 'msie' && profile.versionNumber === 8 ) {
Строка 62: Строка 74:
 
         } );
 
         } );
 
     }
 
     }
} ( mediaWiki, jQuery ) );
+
}) (mediaWiki, jQuery);
 +
 
 +
/**
 +
* Remove image dimension text from Semantic galleries created with {{#ask: ... | format = gallery }}
 +
*/
 +
function semanticGalleryCleanup () {
 +
    var captions = $('.srf-gallery .gallerytext p');
 +
    if (captions.length > 0) {
 +
        $.each(captions, function(i,v){
 +
          var p = this.innerHTML.replace(/(\d+|\d+,\d+) × (\d+|\d+,\d+)\<br\>\n/,"<br>\n")
 +
          $(this).html(p);
 +
        });
 +
    }
 +
}
 +
 
 +
/**
 +
* Increased line spacing for skill and trait icons on the Game update page and subpages
 +
*/
 +
function gameUpdateIcons () {
 +
    if (~mw.config.get('wgPageName').indexOf('Обновления_игры')) {
 +
        $('li .skillicon, li .effecticon, li .traiticon').each(function(){
 +
            $(this).parent('li').addClass('patchnote');
 +
        });
 +
    }
 +
}

Текущая версия на 23:29, 1 декабря 2018

/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */

// Scripts to use when viewing articles
if (mw.config.get('wgIsArticle') || window.location.href.indexOf('action=submit') > -1 || mw.config.get('wgNamespaceNumber') == -1) {
    mw.loader.load( '/index.php?title=MediaWiki:TPprices.js&action=raw&ctype=text/javascript' );
    mw.loader.load( '/index.php?title=MediaWiki:GameLinks.js&action=raw&ctype=text/javascript' );
    mw.loader.load( '/index.php?title=MediaWiki:CurrentTime.js&action=raw&ctype=text/javascript' );
    mw.loader.load( '/index.php?title=MediaWiki:Winter.js&action=raw&ctype=text/javascript' );
    mw.loader.load( '/index.php?title=MediaWiki:Halloween.js&action=raw&ctype=text/javascript' );
    mw.loader.load( '/index.php?title=MediaWiki:GameModeVersion.js&action=raw&ctype=text/javascript' );
    mw.loader.load( '/index.php?title=MediaWiki:BloodTest.js&action=raw&ctype=text/javascript' );

    // Article namespace
    if (mw.config.get('wgNamespaceNumber') === 0 ) {
        gameUpdateIcons();
    }

    // Only if the page contains collapsible tables
    if ( $('.collapsible, .expandable').length > 0 ) {
        mw.loader.load( '/index.php?title=MediaWiki:CollapsibleTables.js&action=raw&ctype=text/javascript' );
    }

    autoConvertUTC();
    semanticGalleryCleanup();
}

/**
 * Convert UTC time to local time. (see [[Template:UTC time]])
 */
function autoConvertUTC () {
    function pad (s) {  return (s < 10 ? '0' : '') + s; }
    var days = ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'];
    $('.utc-auto-convert').each(function(i,v){
        // Get UTC time using MediaWiki {{#time: U}} epoch format
        var utcseconds = v.getAttribute('data-time');
        if (utcseconds == 'error') {
            return;
        }
        var d = new Date(0);
        d.setUTCSeconds(utcseconds);
        var offset = (-1 * d.getTimezoneOffset() / 60);
        var offsetstring = '';
        if (offset > 0) { offsetstring = '+' + offset; }
        if (offset < 0) { offsetstring = offset; }
        
        // Default to showing the time only
        var datestring = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ' UTC' + offsetstring;
        var titlestring = pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ' UTC';
        
        // But check for different formatting in case there is a day of the week given inside the span
        if (!v.textContent.match(/^\d/)) {
            datestring  = days[d.getDay()] + ' ' + datestring;
            titlestring = days[d.getUTCDay()] + ' ' + titlestring;
        }
        
        // Show result
        $(v).html('<span style="cursor:help; border-bottom:1px dotted silver;" title="'+titlestring+'">'+datestring+'</span>');
    });
}

/**
 * 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 mediawiki.org/wiki/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);

/**
 * Remove image dimension text from Semantic galleries created with {{#ask: ... | format = gallery }}
 */
function semanticGalleryCleanup () {
    var captions = $('.srf-gallery .gallerytext p');
    if (captions.length > 0) {
        $.each(captions, function(i,v){
          var p = this.innerHTML.replace(/(\d+|\d+,\d+) × (\d+|\d+,\d+)\<br\>\n/,"<br>\n")
          $(this).html(p);
        });
    }
}

/**
 * Increased line spacing for skill and trait icons on the Game update page and subpages
 */
function gameUpdateIcons () {
    if (~mw.config.get('wgPageName').indexOf('Обновления_игры')) {
        $('li .skillicon, li .effecticon, li .traiticon').each(function(){
            $(this).parent('li').addClass('patchnote');
        });
    }
}