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

MediaWiki:Mobile.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 JavaScript hier wird für die Benutzer der mobilen Website geladen. */
if($("#log")){$("#log").append("<p>Javascript begin</p>")}

$(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();

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