MediaWiki:Common.js: Dallime mes rishikimesh
Content deleted Content added
No edit summary |
Hoo man (diskuto | kontribute) v Fixed some minor flaws, should work exactly as it did before |
||
Rreshti 580: | Rreshti 580: | ||
// Crudely widen the sitenotice message to 100% page width and hide the dismiss link. |
// Crudely widen the sitenotice message to 100% page width and hide the dismiss link. |
||
// NB: This one is better left commented out when not specifically needed. |
// NB: This one is better left commented out when not specifically needed. |
||
/* |
|||
addOnloadHook(function(){ |
addOnloadHook(function(){ |
||
try { |
|||
⚫ | |||
var siteNoticeText = document.getElementById('mw-dismissable-notice').childNodes[0].childNodes[0].childNodes[0]; |
|||
⚫ | |||
⚫ | |||
}catch(e){ |
|||
⚫ | |||
return false; |
|||
} |
|||
⚫ | |||
⚫ | |||
}); |
}); |
||
*/ |
|||
/** Interwiki links to featured articles *************************************** |
/** Interwiki links to featured articles *************************************** |
||
* |
* |
Versioni i datës 2 maj 2012 23:23
/** Main Page layout fixes *********************************************************
*
* Description: Adds an additional link to the complete list of languages available.
* Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
*/
function mainPageAppendCompleteListLink() {
addPortletLink('p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
'Lista komplete', 'interwiki-completelist', 'Complete list of Wikipedias');
}
if ( wgTitle == wgMainPageTitle ) {
jQuery(document).ready( mainPageAppendCompleteListLink );
}
/** "Technical restrictions" title fix *****************************************
*
* Description: For pages that have something like Template:Lowercase, replace
* the title, but only if it is cut-and-pasteable as a valid
* wikilink. For instance, iPod's title is updated, but [[C#]]
* is not an equivalent wikilink, so [[C Sharp]] doesn't have its
* main title changed. Likewise, for users who have selected the
* UK date format ("1 March"), the titles of day-of-the-year
* articles will appear in that style. Users with any other date
* setting are not affected.
*
* 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: [[User:Interiot]], [[User:Mets501]], [[User:Freakofnurture]]
*/
var disableRealTitle = 0; // users can set disableRealTitle = 1 locally to disable.
if (wgIsArticle) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
addOnloadHook(function() {
try {
var realTitleBanner = document.getElementById("RealTitleBanner");
if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle ) {
var realTitle = document.getElementById("RealTitle");
if (realTitle) {
var realTitleHTML = realTitle.innerHTML;
if (realTitle.textContent) { //everyone but IE
realTitleText = realTitle.textContent;
} else { //IE
realTitleText = realTitle.innerText;
}
var isPasteable = 0;
var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
// calculate whether the title is pasteable
var verifyTitle = realTitleText.replace(/^ +/, ""); // trim left spaces
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
// if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
if (wgNamespaceNumber != 0) {
if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
} else {
realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
}
}
// verify whether wgTitle matches
verifyTitle = verifyTitle.replace(/[\s_]+/g, " "); // underscores and multiple spaces to single spaces
verifyTitle = verifyTitle.replace(/^\s+/, "").replace(/\s+$/, ""); // trim left and right spaces
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
if ( (verifyTitle == wgTitle) || (verifyTitle == wgTitle.replace(/^(.+)?(January|February|March|April|May|June|July|August|September|October|November|December)\s+([12]?[0-9]|3[0123])([^\d].*)?$/g, "$1$3 $2$4") )) isPasteable = 1;
var h1 = document.getElementsByTagName("h1")[0];
if (h1 && isPasteable) {
h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
if (!containsTooMuchHTML)
realTitleBanner.style.display = "none";
}
document.title = realTitleText + " - Uikipedia, enciklopedia e lirë";
}
}
} catch (e) {
/* Something went wrong. */
}
});
}
// similar to innerHTML, but only returns the text portions of the insides, excludes HTML
function pickUpText(aParentElement) {
var str = "";
function pickUpTextInternal(aElement) {
var child = aElement.firstChild;
while (child) {
if (child.nodeType == 1) // ELEMENT_NODE
pickUpTextInternal(child);
else if (child.nodeType == 3) // TEXT_NODE
str += child.nodeValue;
child = child.nextSibling;
}
}
pickUpTextInternal(aParentElement);
return str;
}
/* 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);
};
})();
/** Collapsible tables *********************************************************
*
* Shpikësi(t): [[User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = "fsheh";
var expandCaption = "shfaq";
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 Common.css
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "#" );
addHandler( ButtonLink, "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") );
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;
}
}
}
}
}
$( createCollapseButtons );
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
// set up the words in your language
var NavigationBarHide = '▲ fsheh';
var NavigationBarShow = '▼ shfaq';
// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
var NavigationBarShowDefault = 0;
// 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 ( hasClass( NavChild, 'NavPic' ) ) {
NavChild.style.display = 'none';
}
if ( hasClass( NavChild, '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 (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
if (hasClass(NavChild, '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 (hasClass(NavFrame, "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 ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, '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 (hasClass(NavFrame.childNodes[j], "NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
}
addOnloadHook( createNavigationBarToggleButton );
//EXPERIMENTAL
/**
* WikiMiniAtlas is a popup click and drag world map.
* See [[meta:WikiMiniAtlas]] for more information.
* Maintainers: [[w:User:Dschwen]]
*/
var metaBase = 'http://meta.wikimedia.org';
if ( mw.config.get( 'wgServer' ) == 'https://secure.wikimedia.org' ) {
var metaBase = 'https://secure.wikimedia.org/wikipedia/meta';
}
mw.loader.load(metaBase + '/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400');
/*
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
Adapted for Wikipedia by Remember_the_dot
http://homepage.ntlworld.com/bobosola/pnginfo.htm states "This page contains more information for the curious or those who wish to amend the script for special needs", which I take as permission to modify or adapt this script freely. I release my changes into the public domain.
*/
function PngFix(){
if (document.body.filters)
{
var documentImages = document.images;
for (var i = 0; i < documentImages.length;)
{
var img = documentImages[i];
var imgSrc = img.src;
if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png" && !img.useMap && !img.onclick)
{
var imgID = (img.id) ? "id=\"" + img.id + "\" " : "";
var imgClass = (img.className) ? "class=\"" + img.className + "\" " : "";
var imgTitle = (img.title) ? "title=\"" + img.title + "\" " : "";
var imgStyle = "display:inline-block; font-size:0; vertical-align:middle;" + img.style.cssText;
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
img.outerHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + imgStyle + "\"><span style=\"width:" + img.width + "px; height:" + img.height + "px; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "');\"></span></span>";
}
else
{
i++;
}
}
}
}
if (navigator.appName == "Microsoft Internet Explorer")
{
var version = navigator.appVersion.substr(22, 3);
if (version == "6.0" || version == "5.5")
{
window.attachEvent("onload", PngFix);
}
}
/** Interwiki links to featured articles ***************************************
*
* Description: Highlights interwiki links to featured articles (or
* equivalents) by changing the bullet before the interwiki link
* into a star.
* Maintainers: [[User:R. Koot]]
*/
function LinkFA() {
if ( document.getElementById( "p-lang" ) ) {
var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {
InterwikiLinks[i].className += " FA";
InterwikiLinks[i].title = "Ky artikull ka arritur një kualitet të lartë në këtë gjuhë.";
}
}
}
}
addOnloadHook( LinkFA );
// Import Onlyifuploading-functions from [[MediaWiki:Onlyifuploading.js]]
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) == 'Upload' ) {
importScript("MediaWiki:Onlyifuploading.js");
importScript("MediaWiki:Onlyifediting.js");
}
// Import Onlyifediting-functions from [[MediaWiki:Onlyifediting.js]]
if ( wgAction == 'edit' || wgAction == 'submit' ) {
importScript("MediaWiki:Onlyifediting.js");
}
/* OPEN STREET MAP SCRIPT */
/**
* Move the coordinates which are at the top of the page
* From fr:mediawiki:common.js
*/
function moveCoord() {
var h1 = document.getElementById('firstHeading');
if(!h1) h1 = document.getElementsByTagName('h1')[0]; // Nostalgia, Standard
var coord = document.getElementById('coordinates');
if ( !coord || !h1 ) return;
coord.id = "coordinates-title";
h1.parentNode.insertBefore(coord, h1); /* déplacement de l'élément */
}
addOnloadHook(moveCoord);
// Verwendung von OpenStreetMap in Wikipedia.
// (c) 2008 by Magnus Manske
// Released under GPL
// Modified version in order to makes it work with moveCoord() above
// From fr:mediawiki:common.js
// modified to makes it work for IT : Otourly
if(typeof(MoveResizeAbsolute_AddMoveArea)!="function") importScriptURI('//sq.wikipedia.org/w/index.php?title=MediaWiki:Gadget-MoveResizeAbsolute.js&action=raw&ctype=text/javascript');
function openStreetMap_Init () {
var c = document.getElementById ( 'coordinates-title' ) ;
if ( !c ) return ;
var a = c.getElementsByTagName ( 'a' ) ;
var geohack = false;
for ( var i = 0 ; i < a.length ; i++ ) {
var h = a[i].href ;
if ( !h.match(/geohack/) ) continue ;
geohack = true ;
break ;
}
if ( !geohack ) return ;
var na = document.createElement ( 'a' ) ;
na.href = 'javascript:openStreetMap_Toggle();' ;
na.title = 'Shfaq / fshih hartën' ;
na.appendChild ( document.createTextNode ( 'Harta' ) ) ;
c.appendChild ( document.createTextNode ( ' (' ) ) ;
c.appendChild ( na ) ;
c.appendChild ( document.createTextNode ( ') ' ) ) ;
}
function openStreetMap_Toggle () {
var c = document.getElementById ( 'coordinates-title' ) ;
if ( !c) return ;
var osm = document.getElementById ( 'OpenStreetMap' ) ;
if (osm) {
if ( osm.style.display == 'none' ) {
osm.style.display = 'block' ;
} else {
osm.style.display = 'none' ;
}
return;
}
var found_link = false ;
var a = c.getElementsByTagName ( 'a' ) ;
var h;
for ( var i = 0 ; i < a.length ; i++ ) {
h = a[i].href ;
if ( !h.match(/geohack/) ) continue ;
found_link = true ;
break ;
}
if ( !found_link ) return ; // No geohack link found
h = h.split('params=')[1] ;
var LarghezzaSchermo = MoveResizeAbsolute_GetScreenWidth();
var AlterigiaSchermo = MoveResizeAbsolute_GetScreenHeight();
var OSMDiv = document.createElement('div');
OSMDiv.id = 'OpenStreetMap' ;
OSMDiv.style.position = "absolute";
OSMDiv.style.zIndex = 5000;
OSMDiv.style.top = (AlterigiaSchermo*10/100) + "px";
OSMDiv.style.left = (LarghezzaSchermo*15/100) + "px";
OSMDiv.style.width = "74%";
OSMDiv.style.height = (AlterigiaSchermo*80/100) + "px";
OSMDiv.style.border = "3px solid grey";
OSMDiv.style.backgroundColor = "white";
OSMDiv.style.overflow = "hidden";
var MoveArea = document.createElement('div');
MoveArea.style.position = "relative";
MoveArea.style.top = "0";
MoveArea.style.width = "100%";
MoveArea.style.height = "50px";
MoveArea.title = "Kliko dhe tërhiqe për të ndryshuar madhësinë e dritares";
var CloseLink = document.createElement('a');
CloseLink.setAttribute("style", "float:right;margin:10px;");
CloseLink.innerHTML = "Fshih";
CloseLink.title = "Kliko për të mbyllur hartën";
CloseLink.href = "javascript:openStreetMap_Toggle();";
MoveArea.appendChild(CloseLink);
var iFrame = document.createElement ( 'iframe' ) ;
var url = 'http://toolserver.org/~kolossos/openlayers/kml-on-ol.php?lang=' + mw.config.get('wgUserLanguage') + '¶ms=' + h ;
iFrame.style.width = '100%' ;
iFrame.style.height = ((AlterigiaSchermo*80/100)-100) + 'px' ;
iFrame.style.clear = 'both' ;
iFrame.src = url ;
var ResizeArea = document.createElement('div');
ResizeArea.style.position = "relative";
ResizeArea.style.top = "0";
ResizeArea.style.width = "100%";
ResizeArea.style.height = "50px";
ResizeArea.title = "Kliko dhe tërhiqe për të ndryshuar madhësinë e dritares";
OSMDiv.appendChild(MoveArea);
OSMDiv.appendChild(iFrame);
OSMDiv.appendChild(ResizeArea);
document.body.appendChild ( OSMDiv ) ;
var ElementsToMove = new Array(OSMDiv);
var ElementsToResize = new Array(OSMDiv, iFrame);
var ElementsMinWidth = new Array(150, 150);
var ElementsMinHeights = new Array(200, 100);
MoveResizeAbsolute_AddMoveArea(MoveArea, ElementsToMove);
MoveResizeAbsolute_AddResizeArea(ResizeArea, ElementsToResize, ElementsMinWidth, ElementsMinHeights);
}
addOnloadHook(openStreetMap_Init);
/**
* Kështu mund të shtohen Kategoritë të fshehura shpejt
*/
function hiddencat(){
if(document.URL.indexOf("printable=yes")!=-1) return;
var cl = document.getElementById('catlinks'); if(!cl) return;
if( !(hc = document.getElementById('mw-hidden-catlinks')) ) return;
if( hasClass(hc, 'mw-hidden-cats-user-shown') ) return;
if( hasClass(hc, 'mw-hidden-cats-ns-shown') ) addClass(hc, 'mw-hidden-cats-hidden');
var nc = document.getElementById('mw-normal-catlinks');
if( !nc ) {
var catline = document.createElement('div');
catline.id = 'mw-normal-catlinks';
var a = document.createElement('a');
a.href = '/wiki/Kategori:Accueil';
a.title = 'Kategoria:Accueil';
a.appendChild(document.createTextNode('Kategoritë'));
catline.appendChild(a);
catline.appendChild(document.createTextNode(' : '));
nc = cl.insertBefore(catline, cl.firstChild);
}
else nc.appendChild(document.createTextNode(' | '));
var lnk = document.createElement('a');
lnk.id = 'mw-hidden-cats-link';
lnk.title = 'Ky artikull ka kategori të fshehura';
lnk.style.cursor = 'pointer';
lnk.style.color = 'black';
lnk.onclick = toggleHiddenCats;
lnk.appendChild(document.createTextNode('[+]'));
hclink = nc.appendChild(lnk);
}
function toggleHiddenCats(){
if( hasClass(hc, 'mw-hidden-cats-hidden') ) {
removeClass(hc, 'mw-hidden-cats-hidden');
addClass(hc, 'mw-hidden-cat-user-shown');
changeText(hclink, '[–]');
} else {
removeClass(hc, 'mw-hidden-cat-user-shown');
addClass(hc, 'mw-hidden-cats-hidden');
changeText(hclink, '[+]');
}
}
addOnloadHook(hiddencat);
// Crudely widen the sitenotice message to 100% page width and hide the dismiss link.
// NB: This one is better left commented out when not specifically needed.
/*
addOnloadHook(function(){
try {
var siteNoticeText = document.getElementById('mw-dismissable-notice').childNodes[0].childNodes[0].childNodes[0];
var siteNoticeDismiss = document.getElementById('mw-dismissable-notice').childNodes[0].childNodes[0].childNodes[2];
}catch(e){
return false;
}
siteNoticeDismiss.setAttribute('style', 'display:none;');
siteNoticeText.setAttribute('width', '100%');
});
*/
/** Interwiki links to featured articles ***************************************
*
* Description: Highlights interwiki links to featured articles (or
* equivalents) by changing the bullet before the interwiki link
* into a star.
*/
function LinkFA() {
if ( document.getElementById( "p-lang" ) ) {
var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {
InterwikiLinks[i].className += " FA";
InterwikiLinks[i].title = "This is a featured article in another language.";
} else if ( document.getElementById( InterwikiLinks[i].className + "-ga" ) ) {
InterwikiLinks[i].className += " GA";
InterwikiLinks[i].title = "This is a good article in another language.";
}
}
}
}
$( LinkFA );