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

Материал из Ботвапедии
Перейти к: навигация, поиск
 
(не показано 80 промежуточных версий этого же участника)
Строка 1: Строка 1:
 
/* Размещённый здесь JavaScript код будет загружаться всем пользователям при обращении к каждой странице */
 
/* Размещённый здесь JavaScript код будет загружаться всем пользователям при обращении к каждой странице */
 +
 +
 +
window.onload = function() { // после загрузки страницы
 +
 +
var scrollUp = document.getElementById('scrollup'); // найти элемент
 +
 +
 +
scrollUp.onmouseover = function() { // добавить прозрачность
 +
  scrollUp.style.opacity=0.5;
 +
  scrollUp.style.filter  = 'alpha(opacity=50)';
 +
};
 +
 +
scrollUp.onmouseout = function() { //убрать прозрачность
 +
  scrollUp.style.opacity = 0.3;
 +
  scrollUp.style.filter  = 'alpha(opacity=30)';
 +
};
 +
 +
scrollUp.onclick = function() { //обработка клика
 +
  window.scrollTo(0,-100);
 +
};
 +
 +
// show button
 +
 +
window.onscroll = function () { // при скролле показывать и прятать блок
 +
  if ( window.pageYOffset > 300 ) {
 +
  scrollUp.style.display = 'block';
 +
  } else {
 +
  scrollUp.style.display = 'none';
 +
  }
 +
};
 +
};
 +
 +
 +
 
/** Collapsible tables *********************************************************
 
/** Collapsible tables *********************************************************
 
  *
 
  *
Строка 8: Строка 42:
 
   
 
   
 
var autoCollapse = 2;
 
var autoCollapse = 2;
var collapseCaption = 'Закрыть';
+
var collapseCaption = '' // скрыть
var expandCaption = 'Развернуть';
+
var expandCaption = '' // показать
 
   
 
   
 
function collapseTable( tableIndex ) {
 
function collapseTable( tableIndex ) {
Строка 91: Строка 125:
 
   
 
   
 
addOnloadHook( createCollapseButtons );
 
addOnloadHook( createCollapseButtons );
+
 
 
/** Test if an element has a certain class **************************************
 
/** Test if an element has a certain class **************************************
 
  *
 
  *
Строка 104: Строка 138:
 
         };
 
         };
 
})();
 
})();
 +
 +
var site = function() {
 +
this.navLi = $('#nav li').children('ul').hide().end();
 +
this.init();
 +
};
  
  
 
/*удалить*/
 
/*удалить*/
  
//Execution
 
  
if (wgCanonicalNamespace == 'Special'){
+
site.prototype = {
 
+
if (/^(Uplo|Sear|Stat|Spec|Abus|Prefe)/i.test(wgCanonicalSpecialPageName))
+
init : function() {
  importMW(wgCanonicalSpecialPageName)
+
this.setMenu();
 
+
},
}else switch (wgAction){
+
 
+
// Enables the slidedown menu, and adds support for IE6
case 'history': importMW('History'); break
+
 
+
setMenu : function() {
case 'delete': importMW('Deletepage'); break
+
 
+
$.each(this.navLi, function() {
case 'edit': case 'submit': importMW('Editpage') //and continue with the default: view, purge
+
if ( $(this).children('ul')[0] ) {
 
+
$(this)
default:
+
.append('<span />')
 
+
.children('span')
  addOnloadHook(collapsibleDivs)
+
.addClass('hasChildren')
  addOnloadHook(collapsibleTables)
+
}
  importScriptURI(metaBase+'/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400')
+
});
  if (navigator.platform.indexOf('Win') != -1)
+
    importStylesheetURI('http://en.wikipedia.org/w/index.php?title=MediaWiki:Common.css/WinFixes.css&action=raw&ctype=text/css')
+
this.navLi.hover(function() {
 
+
// mouseover
  if (wgNamespaceNumber==0 || wgNamespaceNumber==100){
+
$(this).find('> ul').stop(true, true).slideDown('slow', 'easeOutBounce');
    addOnloadHook(LinkFA)
+
}, function() {
    importMW('Osm')
+
// mouseout
    importMW('Collapserefs')
+
$(this).find('> ul').stop(true, true).hide();
    if (wgArticleId==4401) importMW('Mainpage')
+
});
  }else{
+
    if (wgNamespaceNumber==4){
+
}
      if (/^(Мастер статей|Инкубатор)/.test(wgTitle)) importMW('Incubator')
+
      if (wgTitle=='Скрипты') importMW('Scripts')
 
    }
 
    addOnloadHook(icqIcons)
 
  }
 
 
 
}
 
 
 
 
 
if (wgUserGroups){
 
  for (var i=0; i<wgUserGroups.length; i++) switch (wgUserGroups[i]){
 
    case 'sysop': importMW('Sysop'); break
 
}
 
if (wgNamespaceNumber==2 && wgTitle.indexOf(wgUserName)==0 && wgArticleId==0 && /\/skin\.(js|css)$/.test(wgTitle))
 
  window.location.href = window.location.href.replace(/skin\.(css|js)$/, skin+'.$1')
 
 
}
 
}
  
  
// ВП:СО, кроме статей  В Контакте, Одноклассники и Facebook
 
if (wgArticleId!=639373 && wgArticleId!=932117 && wgArticleId!=1297302 && wgArticleId!=25133866)
 
importMW('Wikibugs')
 
 
 
// 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}')
+
new site();
  
function addWikifButton() {
+
function DropDown(el) {
        var toolbar = document.getElementById('toolbar')
+
    this.dd = el;
        if (!toolbar) return
+
    this.initEvents();
        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) {
+
DropDown.prototype = {
document.write('<script type="text/javascript" src="http://ru.wikipedia.org/w/index.php?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript"><\/script>')
+
    initEvents : function() {
        addOnloadHook(addWikifButton)
+
        var obj = this;
}
+
 
+
         obj.dd.on('click', function(event){
////////////////////////////////////////////////////////////////
+
            $(this).toggleClass('active');
// =-=-=- HELPER FUNCTIONS -=-=-=-
+
            event.stopPropagation();
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>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* ================================================================
 
This copyright notice must be kept untouched in the stylesheet at
 
all times.
 
 
The original version of this script and the associated (x)html
 
is available at http://www.stunicholls.com/menu/pro_drop_1.html
 
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
 
This script and the associated (x)html may be modified in any
 
way to fit your requirements.
 
=================================================================== */
 
stuHover = function() {
 
var cssRule;
 
var newSelector;
 
for (var i = 0; i < document.styleSheets.length; i++)
 
for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
 
{
 
cssRule = document.styleSheets[i].rules[x];
 
if (cssRule.selectorText.indexOf("LI:hover") != -1)
 
{
 
newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
 
document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
 
}
 
}
 
var getElm = document.getElementById("nav").getElementsByTagName("LI");
 
for (var i=0; i<getElm.length; i++) {
 
getElm[i].onmouseover=function() {
 
this.className+=" iehover";
 
}
 
getElm[i].onmouseout=function() {
 
this.className=this.className.replace(new RegExp(" iehover\\b"), "");
 
}
 
}
 
 
}
 
}
if (window.attachEvent) window.attachEvent("onload", stuHover);
 

Текущая версия на 20:49, 4 ноября 2016

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


window.onload = function() { // после загрузки страницы

 var scrollUp = document.getElementById('scrollup'); // найти элемент


 scrollUp.onmouseover = function() { // добавить прозрачность
  scrollUp.style.opacity=0.5;
  scrollUp.style.filter  = 'alpha(opacity=50)';
 };

 scrollUp.onmouseout = function() { //убрать прозрачность
  scrollUp.style.opacity = 0.3;
  scrollUp.style.filter  = 'alpha(opacity=30)';
 };

 scrollUp.onclick = function() { //обработка клика
  window.scrollTo(0,-100);
 };

// show button

 window.onscroll = function () { // при скролле показывать и прятать блок
  if ( window.pageYOffset > 300 ) {
   scrollUp.style.display = 'block';
  } else {
   scrollUp.style.display = 'none';
  }
 };
};



/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *                         http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
 *  Maintainers: [[en:User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = '▼' // скрыть
var expandCaption = '►' // показать
 
function collapseTable( tableIndex ) {
        var Button = document.getElementById( 'collapseButton' + tableIndex );
        var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
        if ( !Table || !Button ) {
                return false;
        }
 
        var Rows = Table.rows;
 
        if ( Button.firstChild.data == collapseCaption ) {
                for ( var i = 1; i < Rows.length; i++ ) {
                        Rows[i].style.display = 'none';
                }
                Button.firstChild.data = expandCaption;
        } else {
                for ( var i = 1; i < Rows.length; i++ ) {
                        Rows[i].style.display = Rows[0].style.display;
                }
                Button.firstChild.data = collapseCaption;
        }
}
 
function createCollapseButtons() {
        var tableIndex = 0;
        var NavigationBoxes = new Object();
        var Tables = document.getElementsByTagName( 'table' );
 
        for ( var i = 0; i < Tables.length; i++ ) {
                if ( hasClass( Tables[i], 'collapsible' ) ) {
 
                        /* only add button and increment count if there is a header row to work with */
                        var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
                        if ( !HeaderRow ) {
                                continue;
                        }
                        var Header = HeaderRow.getElementsByTagName( 'th' )[0];
                        if ( !Header ) {
                                continue;
                        }
 
                        NavigationBoxes[tableIndex] = Tables[i];
                        Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
 
                        var Button = document.createElement( 'span' );
                        var ButtonLink = document.createElement( 'a' );
                        var ButtonText = document.createTextNode( collapseCaption );
 
                        Button.className = 'collapseButton'; // Styles are declared in [[MediaWiki:Common.css]]
 
                        ButtonLink.style.color = Header.style.color;
                        ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
                        ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
                        ButtonLink.appendChild( ButtonText );
 
                        Button.appendChild( document.createTextNode( '[' ) );
                        Button.appendChild( ButtonLink );
                        Button.appendChild( document.createTextNode( ']' ) );
 
                        Header.insertBefore( Button, Header.childNodes[0] );
                        tableIndex++;
                }
        }
 
        for ( var i = 0;  i < tableIndex; i++ ) {
                if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
                        collapseTable( i );
                } else if ( hasClass( NavigationBoxes[i], 'innercollapse' ) ) {
                        var element = NavigationBoxes[i];
                        while ( element = element.parentNode ) {
                                if ( hasClass( element, 'outercollapse' ) ) {
                                        collapseTable( i );
                                        break;
                                }
                        }
                }
        }
}
 
addOnloadHook( createCollapseButtons );

/** Test if an element has a certain class **************************************
 *
 * Description: Uses regular expressions and caching for better performance.
 * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 */
 
var hasClass = ( function() {
        var reCache = {};
        return function( element, className ) {
                return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
        };
})();

var site = function() {
	this.navLi = $('#nav li').children('ul').hide().end();
	this.init();
};


/*удалить*/


site.prototype = {
 	
 	init : function() {
 		this.setMenu();
 	},
 	
 	// Enables the slidedown menu, and adds support for IE6
 	
 	setMenu : function() {
 	
 	$.each(this.navLi, function() {
 		if ( $(this).children('ul')[0] ) {
 			$(this)
 				.append('<span />')
 				.children('span')
 					.addClass('hasChildren')
 		}
 	});
 	
 		this.navLi.hover(function() {
 			// mouseover
			$(this).find('> ul').stop(true, true).slideDown('slow', 'easeOutBounce');
 		}, function() {
 			// mouseout
 			$(this).find('> ul').stop(true, true).hide(); 		
		});
 		
 	}
 
}



new site();

function DropDown(el) {
    this.dd = el;
    this.initEvents();
}
DropDown.prototype = {
    initEvents : function() {
        var obj = this;
 
        obj.dd.on('click', function(event){
            $(this).toggleClass('active');
            event.stopPropagation();
        });
    }
}