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

Материал из Wiki Grepolis RU
Перейти к навигации
Нет описания правки
Нет описания правки
Строка 1: Строка 1:
// *****************************************************
// * Experimental javascript countdown timer (Splarka) *
// * Version 0.0.3                                    *
// *****************************************************
//
// Usage example:
//  <span class="countdown" style="display:none;">
//  Only <span class="countdowndate">January 01 2007 00:00:00 PST</span> until New years.
//  </span>
//  <span class="nocountdown">Javascript disabled.</span>
function updatetimer(i) {
  var now = new Date();
  var then = timers[i].eventdate;
  var diff = count=Math.floor((then.getTime()-now.getTime())/1000);
  // catch bad date strings
  if(isNaN(diff)) {
    timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **' ;
    return;
  }
  // determine plus/minus
  if(diff<0) {
    diff = -diff;
    var tpm = '';''
  } else {
    var tpm = '';''
  }
  // Calculate the diff - Modified by Eladkse
  if ((diff%60) == 1) {
    left = (diff%60) + ' секунды';
  } else {
    left = (diff%60) + ' секунда';
  }
    diff=Math.floor(diff/60);
  if(diff > 0) {
    if ((diff%60) == 1) {
      left = (diff%60) + ' минута, и ' + left;
    } else {
      left = (diff%60) + ' минут, и ' + left;
    }
  }
    diff=Math.floor(diff/60);
  if(diff > 0) {
    if ((diff%24) == 1) {
      left = (diff%24) + ' час, ' + left;
    } else {
      left = (diff%24) + ' часов, ' + left;
    }
  }
    diff=Math.floor(diff/24);
  if(diff > 0) {
    if (diff == 1) {
      left = diff + ' день, ' + left;
    } else {
      left = diff + ' дней, ' + left;
    }
  }
  timers[i].firstChild.nodeValue = tpm + left;
  // a setInterval() is more efficient, but calling setTimeout()
  // makes errors break the script rather than infinitely recurse
  timeouts[i] = setTimeout('updatetimer(' + i + ')',1000);
}
function checktimers() {
  //hide 'nocountdown' and show 'countdown'
  var nocountdowns = getElementsByClassName(document, 'span', 'nocountdown');
  for(var i in nocountdowns) nocountdowns[i].style.display = 'none'
  var countdowns = getElementsByClassName(document, 'span', 'countdown');
  for(var i in countdowns) countdowns[i].style.display = 'inline'
  //set up global objects timers and timeouts.
  timers = getElementsByClassName(document, 'span', 'countdowndate');  //global
  timeouts = new Array(); // generic holder for the timeouts, global
  if(timers.length == 0) return;
  for(var i in timers) {
    timers[i].eventdate = new Date(timers[i].firstChild.nodeValue);
    updatetimer(i);  //start it up
  }
}
addOnloadHook(checktimers);
// **************************************************
//  - end -  Experimental javascript countdown timer
// **************************************************
if(wgAction == 'view' || wgAction == 'submit') {
if(wgAction == 'view' || wgAction == 'submit') {
   importScript('MediaWiki:Collapsebuttons.js');
   importScript('MediaWiki:Collapsebuttons.js');

Версия от 15:22, 23 сентября 2014

if(wgAction == 'view' || wgAction == 'submit') {
  importScript('MediaWiki:Collapsebuttons.js');
}
if(wgAction == 'edit' || wgAction == 'submit') {
  importScript('MediaWiki:Editpage.js');
}

importScript_ = importScript
importScript = function (page, proj){
 if (!proj) importScript_(page)
 else {
   if (proj.indexOf('.')==-1) proj += '.wikipedia.org'
   importScriptURI('http://'+proj+'/w/index.php?action=raw&ctype=text/javascript&title='+encodeURIComponent(page.replace(/ /g,'_')))
 }
}
importMW = function (name) { importScript('MediaWiki:'+name+'.js') }

function LinkFA(){
 var pLang = document.getElementById('p-lang')
 if (!pLang) return
 var list = {
 'fa':'Эта статья является избранной',
 'fl':'Этот список или портал является избранным',
 'ga':'Эта статья является хорошей'}
 var iw = pLang.getElementsByTagName('li')
 for (var i=0; i<iw.length; i++)
   for (var s in list)
     if (document.getElementById(iw[i].className+'-'+s)){
       iw[i].className += ' ' + s.toUpperCase()
       iw[i].title = list[s] + ' в другом языковом разделе'
     }
}


// iwiki sorting
 if (!wgUserName
     || (wgUserName
         && (((typeof wgLangPrefs == 'undefined') ? false : true)
             || ((typeof wgAddLangHints == 'undefined') ? false : wgAddLangHints)
             || ((typeof wgUseUserLanguage == 'undefined') ? false : wgUseUserLanguage))))
     importMW('Interwiki-links');

var withJS = document.URL.match(/[&?]withjs=((mediawiki:)?([^&#]+))/i)
if (withJS) importScript_('MediaWiki:'+withJS[3])

if (!window.wgUserName) appendCSS('#mw-fr-revisiontag {display:none}')

function addWikifButton() {
        var toolbar = document.getElementById('toolbar')
        if (!toolbar) return
        var i = document.createElement('img')
        i.src = 'http://upload.wikimedia.org/wikisource/ru/d/d1/Button-wikifikator.png'
        i.alt = i.title = 'викификатор'
        i.onclick = Wikify
        i.style.cursor = 'pointer'
        toolbar.appendChild(i)
}
if (document.URL.indexOf('action=edit') > 0 || document.URL.indexOf('action=submit') > 0) {
document.write('<script type="text/javascript" src="http://ru.wikipedia.org/w/index.php?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript"><\/script>')
        addOnloadHook(addWikifButton)
}

////////////////////////////////////////////////////////////////
// =-=-=- HELPER FUNCTIONS -=-=-=-
function addlilink(tabs, url, name, id, title, key){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    if(id)
    {
        if(key && title)
        {
            ta[id] = [key, title];
        }
        else if(key)
        {
            ta[id] = [key, ''];
        }
        else if(title)
        {
            ta[id] = ['', title];
        }
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}

function addToolboxLink(url, name, id, title){
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    addlilink(tb, url, name, id, title);
}

function addTab(url, name, id, title, key) {
    return addPortletLink('p-cactions', url, name, id, title, key);
}

function addLink(where, url, name, id, title, key, after){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
    if(after) {
	tabs.insertBefore(li,document.getElementById(after));
    } else {
	tabs.appendChild(li);
    }
    if(id) {
	if(key && title) { ta[id] = [key, title]; }
	else if(key) { ta[id] = [key, '']; }
	else if(title) { ta[id] = ['', title];} 
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
}

function addlimenu(tabs, name, id)
{
    var na = document.createElement('a');
    na.href = '#';
    var mn = document.createElement('ul');
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.className = 'tabmenu';
    li.appendChild(na);
    li.appendChild(mn);
    tabs.appendChild(li);
    return li;
}

function addnavbox_link(URL,Name,ID)
{
var portlet = document.getElementById('p-navigation');
var links = portlet.getElementsByTagName('ul')[0];
links.innerHTML += '<li id="' + ID + '"><a href="' + URL + '">' + Name + '</a></li>';
}
document.write("<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js' type='text/javascript'></script>");

document.write("<script src='/index.php?title=Global.js&action=raw&smaxage=0&ctype=text/javascript' type='text/javascript'></script>");

var Engine = (function(){
    return {
        init: function(){
            console.log('hello world');
        }
    }
})();

//Попытка реализовать гибкую навигацию
$(function() {
   $('.jnav').each(function(i,e) {
      $(this).data('i', i+1).click(function() {
         var $this = $(this),
             $jnavb = $('#jnavb-' + $this.data('i'));
         if( $this.hasClass('jnav-inactive') ) {
            $('.jnav-active').removeClass('jnav-active').addClass('jnav-inactive');
            $('.jnavb').slideUp(250);
            $this.removeClass('jnav-inactive').addClass('jnav-active');
            $jnavb.slideDown(300);
         } else {
            $this.removeClass('jnav-active').addClass('jnav-inactive');
            $jnavb.slideUp(300);
         }
         return false;
      });
   });
 
   if($('.jnavpm').width() > 0)
   {
      $('.jnavpm').each(function(i,e) {
         $(this).data('i', i+1).click(function() {
            var $this = $(this), $jnavb = $('#jnavb-' + $this.data('i'));
            if( $this.hasClass('jnavpm-inactive') ) {
               $('.jnavpm-active').removeClass('jnavpm-active').addClass('jnavpm-inactive');
               $('.jnavb').slideUp(250);
               $this.removeClass('jnavpm-inactive').addClass('jnavpm-active');
               $jnavb.slideDown(300);
            } else {
               $this.removeClass('jnavpm-active').addClass('jnavpm-inactive');
               $jnavb.slideUp(300);
            }
            return false;
         });
      });
   }   
});