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 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)
  	    dest = getInterwikiDest(currentInterwikiLink);
		currentInterwikiLink.innerHTML += text;
	}
}

/* add interwiki destination to sorted array interwikiLinksSorted */
function addInterwikiDest(interwikiLink) {
	dest = getInterwikiDest(interwikiLink);
	if (!(dest in interwikiLinksSorted)) {
		interwikiLinksSorted[dest] = [interwikiLink];
	} else {
		interwikiLinksSorted[dest].push(interwikiLink);
	}
}

/* get all interwikilinks and sort them into array interwikiLinksSorted */
function sortAllInterwikiLinks() {
	interwikiLinks = getAllInterwikiLinks();
	for (var i = 0; i < interwikiLinks.length; i++) {
		interwikiLink = interwikiLinks[i];
		addInterwikiDest(interwikiLink);
	}
}

sortAllInterwikiLinks();

/* 
1) Get all interwikilinks. 
2) Sort them by destinations. 
3) Make ajax call for every destination defined by templates in interwikiSuffixTemplates.
Ajax success function appends return value to all interwikilinks found in first step. */
function appendInterwikiLinks() { 
  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
	});
  }
}

appendInterwikiLinks();

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