Nicht angemeldeter Benutzer - Bearbeiten von Seiten ist nur als angemeldeter Benutzer möglich.

MediaWiki:Common.js

Aus imedwiki
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Speichern den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Gehe zu Menü → Einstellungen (Opera → Einstellungen auf dem Mac) und dann auf Datenschutz & Sicherheit → Browserdaten löschen → Gespeicherte Bilder und Dateien.
/* Das folgende JavaScript wird für alle Benutzer geladen. */

/* ein <div id="log"></div> auf der Seite einfügen, auf der ein Skript debugt werden soll */
if($("#log")){$("#log").append("<p>Javascript begin</p>")}

/** Helper functions for maps checkbox selector */
/* Steuerung von Maps über Checkboxen */

/* return filename from url - omit path and all that comes before */
function getFilenameFromUrl(urlString) {
	url = new URL(urlString);
	filename = url.pathname.split('/').pop();
	return filename;
}

/* compare url to filename, used to check in checkbox for maps */ 
function compareImgUrl(url, name) {
	nameEscaped = name.replace(/ /g,"_");
	filename = decodeURIComponent(getFilenameFromUrl(url));
	return filename == nameEscaped;
}

/* get all map markers that match provided name of image */
function getAllMarkersBySrcName(name) {
	markers = $(".leaflet-marker-icon");
	returnArray = [];
	for (var i = 0; i < markers.length; i++) {
	    marker = markers[i];
		if (marker.src && compareImgUrl(marker.src, name)) returnArray.push(marker);
	}
	return returnArray;
}

/* enable or disable markers depending on checkbox value */
function checkboxOnChange() {
	fileName = this.value;
	checkedState = this.checked;
	markers = getAllMarkersBySrcName(fileName);
	for (var i = 0; i < markers.length; i++) {
	    marker = markers[i];
		if (checkedState) $(marker).removeClass("nodisplay"); else $(marker).addClass("nodisplay");
	}
}

function checkboxPropagate(checkbox) {
	fileName = checkbox.value;
	checkedState = checkbox.checked;
	markers = getAllMarkersBySrcName(fileName);
	for (var i = 0; i < markers.length; i++) {
	    marker = markers[i];
		if (checkedState) $(marker).removeClass("nodisplay"); else $(marker).addClass("nodisplay");
	}
}

function checkboxesAllPropagate() {
	checkboxes = $('#checkbox input');
    for (var i = 0; i < checkboxes.length; i++) {
    	checkbox = checkboxes[i];
    	checkboxPropagate(checkbox);
    }
}

$('#checkbox input').attr('change', undefined).change(checkboxOnChange);
$("#map_leaflet_1").on('click', function() { checkboxesAllPropagate(); /* console.log("click"); */ });
$("#map_leaflet_1").on('wheel', function() { checkboxesAllPropagate(); /* console.log("wheel"); */ });
/* $("#map_leaflet_1").on('transitionstart', function() { checkboxesAllPropagate(); console.log("transitionstart");}); */
$("#map_leaflet_1").on('transitionrun', function() { checkboxesAllPropagate(); /* console.log("transitionrun"); */ });
/* $("#map_leaflet_1").on('transitionend', function() { checkboxesAllPropagate(); console.log("transitionend")}); */

$(document).on("ready", function(e){
/* this structure is assumed (as provided by Vorlage:AufKarteZeigen):
<span class=".Kartenlink"><a href="URL#divId">LINKTEXT</a><span class="coords"><span class="coordvalues">lat,long</span></span></span>
The map has to be enclosed by a div with id divId. It works as link target on page and to identify the map.
*/

if($("#log")){$("#log").append("<p>append links</p>")}

$(".Kartenlink a").on('click', function() {
	divId = $(this).attr("href").split('#').pop(); 
	if($("#log")){$("#log").append("<p>"+divId+"</p>")}
	for (var i = 0; i < mapsLeafletList.length; i++) {
      if ($(mapsLeafletList[i][0]).parents("#"+divId).length) {
      	coords = $(this).parent().find("span.coordvalues").html();
      	var latLng=L.latLng(coords.split(","));
      	mapsLeafletList[i].map.flyTo(latLng, 16);
      }
    } 
});
});

/* dealing with interwikilinks */

var interwikiSuffixes = Array();
const interwikiSuffixTemplates = {"wikipedia":"{{Vorlage:InterwikilinkWikipedia}}", "wikipedia-de":"{{Vorlage:InterwikilinkWikipedia}}"};
var interwikiLinksSorted = {};

/* this function returns all interwikilinks 
return jQuery results */
function getAllInterwikiLinks() {
	interwikilinks = $("#content a.extiw");
	return interwikilinks;
}

/* return destination of interwikilink

extract information from link title (i.e. "wikipedia:Hauptseite"). 
Title gets split by : and the first part is returned */
function getInterwikiDest(link) {
	return link.title.split(":")[0];
}

function getInterwikiLinkSuffix(interwiki) {
	/* cache interwikiSuffixes */
	if (interwiki in interwikiSuffixes) return interwikiSuffixes[interwiki.toLowerCase()];
	
	$suffix = "";
	if (interwikiSuffixTemplates.hasOwnProperty(interwiki.toLowerCase())) {
		textObject = JSON.parse(
    		$.ajax({
        		url: mw.util.wikiScript('api'),
        		data: { action: 'parse', text: interwikiSuffixTemplates[interwiki.toLowerCase()], format: 'json', contentmodel: 'wikitext'},
        		async: false
    		}).responseText
    	);
    	text = textObject.parse.text["*"];
    	$suffix = $(text).find("p").html();
	}
    
    if (!(interwiki in interwikiSuffixes)) interwikiSuffixes[interwiki] = $suffix;
    
    return $suffix;
}

/* append suffix to interwikilink */
function appendInterwikiLinkSuffix(link){
	dest = getInterwikiDest(link);
	interwikiLinkSuffix = getInterwikiLinkSuffix(dest);
	link.innerHTML += interwikiLinkSuffix;
}

/* allInterwikiLinksAppendSuffix 

append link suffix to all interwikilinks on page in content area */
function allInterwikiLinksAppendSuffix() {
	interwikiLinks = getAllInterwikiLinks();
	for (var i = 0; i < interwikiLinks.length; i++) {
		interwikiLink = interwikiLinks[i];
		appendInterwikiLinkSuffix(interwikiLink);
	}
}

function mySuccess (data, textStatus, jqXHR) {
   console.log("data", data, "textStatus", textStatus, "jqXHR", jqXHR, "this", this);
   interwikiLinkDest = this.interwikiLinkDest;
   text = $(data.parse.text["*"]).find("p").html(); 
   console.log("text:", text);
   
   currentInterwikiLinks = interwikiLinksSorted[interwikiLinkDest];
   for (var i = 0; i < currentInterwikiLinks.length; i++) {
  	    currentInterwikiLink = currentInterwikiLinks[i];
  	    console.log("add suffix", currentInterwikiLink)
		appendInterwikiLinkSuffix(currentInterwikiLink);
	}
}

function addInterwikiDest(interwikiLink) {
	dest = getInterwikiDest(interwikiLink);
	if (!(dest in interwikiLinksSorted)) {
		interwikiLinksSorted[dest] = [interwikiLink];
	} else {
		interwikiLinksSorted[dest].push(interwikiLink);
	}
}

function sortAllInterwikiLinks() {
	interwikiLinks = getAllInterwikiLinks();
	for (var i = 0; i < interwikiLinks.length; i++) {
		interwikiLink = interwikiLinks[i];
		addInterwikiDest(interwikiLink);
	}
}

// allInterwikiLinksAppendSuffix();
sortAllInterwikiLinks();


function appendInterwikiLinks() { 
  console.log("init appendI");
  interwikiLinkDests = Object.keys(interwikiLinksSorted);
  for (var i = 0; i < interwikiLinkDests.length; i++) {
  	interwikiLinkDest = interwikiLinkDests[i];
  	console.log("fetch", interwikiLinkDest)
	$.ajax({
		interwikiLinkDest: interwikiLinkDest,
        url: mw.util.wikiScript('api'),
        data: { action: 'parse', text: interwikiSuffixTemplates[interwikiLinkDest], format: 'json', contentmodel: 'wikitext'},
        async: true,
        success: mySuccess
	});
  }
  
  console.log("end appendI");
}

appendInterwikiLinks();

/*
myPromise = new Promise(function(myResolve, myReject) {
  console.log("init promise");
  interwikiLinkDests = Object.keys(interwikiLinksSorted);
  for (var i = 0; i < interwikiLinkDests.length; i++) {
  	interwikiLinkDest = interwikiLinkDests[i];
  	console.log("fetch", interwikiLinkDest)
	$.ajax({
		interwikiLinkDest: interwikiLinkDest,
        url: mw.util.wikiScript('api'),
        data: { action: 'parse', text: interwikiSuffixTemplates[interwikiLinkDest], format: 'json', contentmodel: 'wikitext'},
        async: true,
        success: mySuccess
	});
  }
  
  console.log("end init promise");
});*/

if($("#log")){$("#log").append("<p>Javascript end</p>")}