MediaWiki:Common.js
Poznámka: Aby sa zmeny prejavili, po uložení musíte vymazať vyrovnávaciu pamäť vášho prehliadača.
- Mozilla Firefox / Safari: Držte stlačený Shift a kliknite na Reload alebo stlačte buď Ctrl-F5 alebo Ctrl-R (⌘-R na Mac)
- Google Chrome: Stlačte Ctrl-Shift-R (⌘-Shift-R na Mac)
- Internet Explorer: Držte Ctrl a kliknite na Refresh alebo stlačte Ctrl-F5
- Opera: Stlačte Ctrl-F5.
// import scripts for Interwiki Transclusion from //wikisource.org/wiki/Wikisource:Shared_Scripts
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript');
mw.loader.load('//wikisource.org/w/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript');
/* Import more specific scripts if necessary */
/* ***************************************** */
var load_edittools = true;
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit") //scripts specific to editing pages
{
importScript("MediaWiki:Common.js/edit.js")
// extra drop down menu on editing for adding special characters
importScript( 'MediaWiki:Edittools.js' );
}
/* End of Import */
/* ***************************************** */
/* Scripts specific to Internet Explorer */
if (navigator.appName == "Microsoft Internet Explorer")
{
/**
* Remove need for CSS hacks regarding MSIE and IPA.
*/
if (document.createStyleSheet) {
document.createStyleSheet().addRule('.IPA', 'font-family: "Doulos SIL", "Charis SIL", Gentium, "DejaVu Sans", Code2000, "TITUS Cyberbit Basic", "Arial Unicode MS", "Lucida Sans Unicode", "Chrysanthi Unicode";');
}
}
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
// set up the words in your language
var collapseCaption = "skry";
var expandCaption = "rozbaľ";
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( $(NavChild).hasClass('NavPic' ) ) {
NavChild.style.display = 'none';
}
if ( $(NavChild).hasClass('NavContent') ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ($(NavChild).hasClass('NavPic')) {
NavChild.style.display = 'block';
}
if ($(NavChild).hasClass('NavContent')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// iterate over all < div >-elements
var divs = document.getElementsByTagName("div");
for (var i = 0; NavFrame = divs[i]; i++) {
// if found a navigation bar
if ($(NavFrame).hasClass("NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var NavToggleText = document.createTextNode(NavigationBarHide);
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if ( $(NavChild).hasClass('NavPic' ) || $(NavChild).hasClass('NavContent' ) ) {
if (NavChild.style.display == 'none') {
NavToggleText = document.createTextNode(NavigationBarShow);
break;
}
}
}
NavToggle.appendChild(NavToggleText);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for(var j=0; j < NavFrame.childNodes.length; j++) {
if ($(NavFrame.childNodes[j]).hasClass("NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
}
$(document).ready( createNavigationBarToggleButton );
/** "Technical restrictions" title fix *****************************************
*
* Description: For pages that have something like Template:Wrongtitle, replace
* the title, but only if it is cut-and-pasteable as a valid
* wikilink. For instance, "NZR WB class" can be changed to
* "NZR W<sup>B</sup> class", but [[C#]] is not an equivalent wikilink,
* so [[C Sharp]] doesn't have its main title changed.
*
* The function looks for a banner like this:
* <div id="RealTitleBanner"> ... <span id="RealTitle">title</span> ... </div>
* An element with id=DisableRealTitle disables the function.
* Maintainers: Remember_the_dot
*/
if (mw.config.get('wgIsArticle')) //prevents the "Editing " prefix from disappearing during preview
{
$(document).ready(function()
{
var realTitle = document.getElementById("RealTitle")
if (realTitle)
{
//normalizes a title or a namespace name (but not both)
//trims leading and trailing underscores and converts (possibly multiple) spaces and underscores to single underscores
function normalizeTitle(title)
{
return title.replace(/^_+/, "").replace(/_+$/, "").replace(/[\s_]+/g, "_")
}
if (realTitle.textContent) //everyone but IE
{
var realTitleText = realTitle.textContent
}
else //IE
{
var realTitleText = realTitle.innerText
}
var normalizedRealTitle
var normalizedPageTitle
var indexOfColon = realTitleText.indexOf(":")
var normalizedNamespaceName = normalizeTitle(realTitleText.substring(0, indexOfColon)).toLowerCase()
//make namespace prefix lowercase and uppercase the first letter of the title
if (indexOfColon == -1 || mw.config.get('wgCanonicalNamespace').toLowerCase() != normalizedNamespaceName) //no namespace prefix - either no colon or a nonsensical namespace prefix (for example, "Foo" in "Foo: The Story of My Life")
{
normalizedRealTitle = normalizeTitle(realTitleText)
normalizedRealTitle = normalizedRealTitle.charAt(0).toUpperCase() + normalizedRealTitle.substring(1)
normalizedPageTitle = mw.config.get('wgPageName').charAt(0).toUpperCase() + mw.config.get('wgPageName').substring(1)
}
else //using a namespace prefix
{
var normalizedRealPageTitle = normalizeTitle(realTitleText.substring(indexOfColon + 1))
normalizedRealTitle = normalizedNamespaceName
if (normalizedNamespaceName != "") //namespace 0 is a special case where the leading colon should never be shown
{
normalizedRealTitle += ":"
}
normalizedRealTitle += normalizedRealPageTitle.charAt(0).toUpperCase() + normalizedRealPageTitle.substring(1)
normalizedPageTitle = mw.config.get('wgPageName').substring(0, mw.config.get('wgPageName').indexOf(":") + 1).toLowerCase() + mw.config.get('wgPageName').substring(mw.config.get('wgPageName').indexOf(":") + 1)
}
if (normalizedRealTitle == normalizedPageTitle) //normalized titles match, so we can do full replacement
{
var h1 = document.getElementsByTagName("h1")[0]
//remove all child nodes, including text
while (h1.firstChild)
{
h1.removeChild(h1.firstChild)
}
//populate with nodes of real title
while (realTitle.firstChild) //the children are moved to a new parent element
{
h1.appendChild(realTitle.firstChild)
}
//delete the real title banner since the problem is solved
var realTitleBanner = document.getElementById("RealTitleBanner")
realTitleBanner.parentNode.removeChild(realTitleBanner)
}
//no matter what, correct the page title
document.title = realTitleText + " - Wikipedia, the free encyclopedia"
}
})
}