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

Материал из Guild Wars 2 wiki
Перейти к: навигация, поиск
 
(новая версия autoConvertUTC)
Строка 12: Строка 12:
 
}
 
}
  
/**** autoConvertUTC (see [[Template:UTC time]])
+
/*
* by Patrick Westerhoff [poke]
+
* autoConvertUTC (see [[Template:UTC time]])
 
  */
 
  */
 
function autoConvertUTC () {
 
function autoConvertUTC () {
   function pad (s) {
+
   function pad (s) { return (s < 10 ? '0' : '') + s; }
    return (s < 10 ? '0' : '') + s;
+
   var days = ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'];
  }
+
  $('.utc-auto-convert').each(function(i,v){
   [].forEach.call(document.querySelectorAll('.utc-auto-convert'), function(v, i) {
+
 
     var time = v.innerHTML.match(/(\d?\d):(\d\d) UTC/);
+
    // Get UTC time using MediaWiki {{#time: U}} epoch format
     if (!time) {
+
     var utcseconds = v.getAttribute('data-time');
 +
     if (utcseconds == 'error') {
 
       return;
 
       return;
 
     }
 
     }
 
+
     var d = new Date(0);
     var date = new Date();
+
     d.setUTCSeconds(utcseconds);
     date.setUTCHours(time[1], time[2], 0, 0);
+
     var offset = (-1 * d.getTimezoneOffset() / 60);
 
+
    var offsetstring = '';
     if (date.getTimezoneOffset() == 0) {
+
    if (offset > 0) { offsetstring = '+' + offset; }
      v.title = 'Это ваш часовой пояс';
+
     if (offset < 0) { offsetstring = offset;      }
     }
+
 
     else {
+
     // Default to showing the time only
      var offset = (-1 * date.getTimezoneOffset() / 60);
+
    var datestring = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ' UTC' + offsetstring;
      var local = pad(date.getHours()) + ':' + pad(date.getMinutes()) + ' UTC' + (offset < 0 ? offset : '+' + offset);
+
    var titlestring = pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ' UTC';
       v.innerHTML += ' (<span style="cursor: help; border-bottom: 1px dotted silver;" title="Это ваш часовой пояс">' + local + '</span>)';
+
   
 +
    // 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>');
 
   });
 
   });
 
}
 
}

Версия 19:41, 29 сентября 2016

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

/** additional scripts **/
if (wgIsArticle || window.location.href.indexOf('action=submit') > -1 || wgNamespaceNumber == -1) {
  importScript('MediaWiki:CollapsibleTables.js');
  importScript('MediaWiki:TPprices.js');
  importScript('MediaWiki:GameLinks.js');
  importScript('MediaWiki:BloodTest.js');
  $(function() {
    autoConvertUTC();
  });
}

/*
 * autoConvertUTC (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 ) );