Zeile 108: |
Zeile 108: |
| function getInterwikiDest(link) { | | function getInterwikiDest(link) { |
| return link.title.split(":")[0]; | | 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) { | | function mySuccess (data, textStatus, jqXHR) { |
− | console.log("data", data, "textStatus", textStatus, "jqXHR", jqXHR, "this", this); | + | // console.log("data", data, "textStatus", textStatus, "jqXHR", jqXHR, "this", this); |
| interwikiLinkDest = this.interwikiLinkDest; | | interwikiLinkDest = this.interwikiLinkDest; |
| text = $(data.parse.text["*"]).find("p").html(); | | text = $(data.parse.text["*"]).find("p").html(); |
− | console.log("text:", text); | + | // console.log("text:", text); |
| | | |
| currentInterwikiLinks = interwikiLinksSorted[interwikiLinkDest]; | | currentInterwikiLinks = interwikiLinksSorted[interwikiLinkDest]; |
| for (var i = 0; i < currentInterwikiLinks.length; i++) { | | for (var i = 0; i < currentInterwikiLinks.length; i++) { |
| currentInterwikiLink = currentInterwikiLinks[i]; | | currentInterwikiLink = currentInterwikiLinks[i]; |
− | console.log("add suffix", currentInterwikiLink) | + | // console.log("add suffix", currentInterwikiLink) |
− | appendInterwikiLinkSuffix(currentInterwikiLink);
| + | dest = getInterwikiDest(currentInterwikiLink); |
| + | currentInterwikiLink.innerHTML += text; |
| } | | } |
| } | | } |
| | | |
| + | /* add interwiki destination to sorted array interwikiLinksSorted */ |
| function addInterwikiDest(interwikiLink) { | | function addInterwikiDest(interwikiLink) { |
| dest = getInterwikiDest(interwikiLink); | | dest = getInterwikiDest(interwikiLink); |
Zeile 173: |
Zeile 135: |
| } | | } |
| | | |
| + | /* get all interwikilinks and sort them into array interwikiLinksSorted */ |
| function sortAllInterwikiLinks() { | | function sortAllInterwikiLinks() { |
| interwikiLinks = getAllInterwikiLinks(); | | interwikiLinks = getAllInterwikiLinks(); |
Zeile 181: |
Zeile 144: |
| } | | } |
| | | |
− | // allInterwikiLinksAppendSuffix();
| |
| sortAllInterwikiLinks(); | | 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() { | | function appendInterwikiLinks() { |
− | console.log("init appendI");
| |
| interwikiLinkDests = Object.keys(interwikiLinksSorted); | | interwikiLinkDests = Object.keys(interwikiLinksSorted); |
| for (var i = 0; i < interwikiLinkDests.length; i++) { | | for (var i = 0; i < interwikiLinkDests.length; i++) { |
| interwikiLinkDest = interwikiLinkDests[i]; | | interwikiLinkDest = interwikiLinkDests[i]; |
− | console.log("fetch", interwikiLinkDest) | + | // console.log("fetch", interwikiLinkDest) |
| $.ajax({ | | $.ajax({ |
| interwikiLinkDest: interwikiLinkDest, | | interwikiLinkDest: interwikiLinkDest, |
Zeile 199: |
Zeile 164: |
| }); | | }); |
| } | | } |
− |
| |
− | console.log("end appendI");
| |
| } | | } |
| | | |
| appendInterwikiLinks(); | | appendInterwikiLinks(); |
| | | |
| + | /* Fehlerlog */ |
| if($("#log")){$("#log").append("<p>Javascript end</p>")} | | if($("#log")){$("#log").append("<p>Javascript end</p>")} |