Changes

Jump to navigation Jump to search

MediaWiki:Common.js

737 bytes added, 17:20, 25 July 2008
no edit summary
//<source lang="javascript"> /** Import module ************************************************************* * * Description: Includes a raw wiki page as javascript or CSS, * used for including user made modules. * Maintainers: [[User:AzaToth]] */ importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice function importScript( page ) {
if( importedScripts[page] ) {
return;
scriptElem.setAttribute( 'type' , 'text/javascript' );
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}
function importStylesheet( page ) {
var sheet = '@import "'
+ wgScriptPath
styleElem.appendChild( document.createTextNode( sheet ) );
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}
/* Test if an element has a certain class ***************************************/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/** Internet Explorer bug fix ***************************************************/
if (window.showModalDialog && document.compatMode && document.compatMode == "CSS1Compat") {
var oldWidth;
var docEl = document.documentElement;
document.attachEvent("onreadystatechange", fixIEScroll);
attachEvent("onresize", fixIEScroll);
}
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[Wikipedia:Wikipedia:NavFrame|Wikipedia:NavFrame]].
*/
var autoCollapse = 2; var collapseCaption = "hide"; var expandCaption = "show"; function collapseTable( tableIndex ) {
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
Button.firstChild.data = collapseCaption;
}
} function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = new Object();
}
}
} addOnloadHook( createCollapseButtons );
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[Wikipedia:Wikipedia:NavFrame|Wikipedia:NavFrame]].
*/
// set up the words in your language 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);
NavToggle.firstChild.data = NavigationBarHide;
}
} // adds show/hide-button to navigation bars function createNavigationBarToggleButton() {
var indexNavigationBar = 0;
// iterate over all < div >-elements
}
}
} addOnloadHook( 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 (wgIsArticle) /** /prevents the "Technical restrictionsEditing " title fix ******************************************/prefix from disappearing during preview { // For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink. // // The addOnloadHook(function looks for a banner like this: <nowiki>() // <div id="RealTitleBanner"> <!-- div that gets hidden --> { // <span id var realTitle =document.getElementById("RealTitle">title</span> // </div>) // </nowiki>An element with id=DisableRealTitle disables the function. var disableRealTitle = 0; // users can disable this by making this true from their monobook.js if (wgIsArticlerealTitle) { // don't display the RealTitle when editing, since it is apparently inconsistent normalizes a title or a namespace name (doesn't show when editing sections, doesn't show when but not previewingboth) addOnloadHook //trims leading and trailing underscores and converts (possibly multiple) spaces and underscores to single underscores functionnormalizeTitle(title) { try { var realTitleBanner = document return title.getElementByIdreplace(/^_+/, "RealTitleBanner"); if (realTitleBanner && !document.getElementByIdreplace(/_+$/, "DisableRealTitle") && !disableRealTitle) { var realTitle = document.getElementByIdreplace(/[\s_]+/g, "RealTitle_"); } if (realTitle.textContent) //everyone but IE { var realTitleHTML realTitleText = realTitle.innerHTML;textContent } else //IE { var realTitleText = pickUpText(realTitle);.innerText } var normalizedRealTitle var isPasteable = 0;normalizedPageTitle // var containsHTML indexOfColon = /</realTitleText.testindexOf(realTitleHTML":"); // contains ANY HTML var containsTooMuchHTML normalizedNamespaceName = /</.testnormalizeTitle( realTitleHTMLrealTitleText.replacesubstring(/<\/?(sub|sup|small|big0, indexOfColon)>/gi, "") .toLowerCase(); // contains HTML that will be ignored when cut-n-pasted as a wikilink // calculate whether make namespace prefix lowercase and uppercase the first letter of the title is pasteable var verifyTitle if (indexOfColon == realTitleText-1 || wgCanonicalNamespace.replacetoLowerCase() != normalizedNamespaceName) /^ +/no namespace prefix - either no colon or a nonsensical namespace prefix (for example, "Foo" in "Foo: The Story of My Life"); // trim left spaces verifyTitle { normalizedRealTitle = normalizeTitle(realTitleText) normalizedRealTitle = verifyTitlenormalizedRealTitle.charAt(0).toUpperCase() + verifyTitlenormalizedRealTitle.substring(1, verifyTitle.length); // uppercase first character // if the namespace prefix is there, remove it on our verification copy normalizedPageTitle = wgPageName. If it isn't there, add it to the original realValue copy. if charAt(wgNamespaceNumber != 0) { if (wgCanonicalNamespace == verifyTitle.substrtoUpperCase(0, wgCanonicalNamespace.length)+ wgPageName.replacesubstring(1) } else / /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") using a namespace prefix { verifyTitle var normalizedRealPageTitle = verifyTitlenormalizeTitle(realTitleText.substrsubstring(wgCanonicalNamespace.length indexOfColon + 1);) } else { realTitleText normalizedRealTitle = wgCanonicalNamespace.replacenormalizedNamespaceName if (/_/g, normalizedNamespaceName != " ") + ":" + realTitleText; realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") namespace 0 is a special case where the leading colon should never be shown { normalizedRealTitle + = ":" + realTitleHTML; } } // verify whether wgTitle matches verifyTitle normalizedRealTitle += verifyTitlenormalizedRealPageTitle.replacecharAt(/^ +/, ""0).replacetoUpperCase(/ ) +$/, ""normalizedRealPageTitle.substring(1); // trim left and right spaces verifyTitle normalizedPageTitle = verifyTitlewgPageName.replacesubstring(/_/g0, wgPageName.indexOf(" :"); // underscores to spaces verifyTitle = verifyTitle.charAt(0+ 1).toUpperCasetoLowerCase() + verifyTitlewgPageName.substring(wgPageName.indexOf(":") + 1, verifyTitle.length); // uppercase first character isPasteable = } if (verifyTitle normalizedRealTitle == wgTitlenormalizedPageTitle);//normalized titles match, so we can do full replacement { var h1 = document.getElementsByTagName("h1")[0]; if //remove all child nodes, including text while (h1 && isPasteable.firstChild) { h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML; if removeChild(!containsTooMuchHTMLh1.firstChild) realTitleBanner.style.display = "none"; } } document. //populate with nodes of real title = realTitleText + " - Pensapedia, the Pensacola encyclopedia"; } } } catch while (erealTitle.firstChild) { /* Something went wrong. */the children are moved to a new parent element } { } h1.appendChild(realTitle.firstChild); } // similar to innerHTML, but only returns delete the text portions of real title banner since the insides, excludes HTML function pickUpText(aParentElement) {problem is solved var str realTitleBanner = document.getElementById("RealTitleBanner"; function pickUpTextInternal(aElement) { var child = aElement realTitleBanner.parentNode.firstChild; while removeChild(childrealTitleBanner) { if (child.nodeType == 1) // ELEMENT_NODE } pickUpTextInternal(child); else if (child.nodeType == 3) // TEXT_NODEno matter what, correct the page title str += child document.nodeValue; child title = child.nextSibling;realTitleText + " - Pensapedia, the Pensacola encyclopedia" } } pickUpTextInternal(aParentElement); return str; }
/** Calendar extension ***/ function makeRequest(url) {
var httpRequest;
httpRequest.open("GET", url, true);
httpRequest.send(null);
}
function alertContents(httpRequest) {
if (httpRequest.readyState == 4) {
}
}
//</source>

Navigation menu