MediaWiki:Skin/KamelionaryEdit.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
(was hab ich denn bitte da gemacht …)
K (mormo -> net)
 
(3 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 16: Zeile 16:
 
{
 
{
 
jQuery.ajax( {
 
jQuery.ajax( {
    url: "http://kamelopedia.mormo.org/index.php",
+
    url: "http://kamelopedia.net/index.php",
 
    data: "title=Vorlage:Kamelionary/preload&action=raw",
 
    data: "title=Vorlage:Kamelionary/preload&action=raw",
 
    dataType: "text",
 
    dataType: "text",
Zeile 36: Zeile 36:
 
};
 
};
  
 +
String.prototype.strip = function () {
 +
    return this.replace(/^\s*/,"").replace(/\s*$/,"");
 +
};
  
 
function allKamelionaryParams(withcomments)
 
function allKamelionaryParams(withcomments)
Zeile 64: Zeile 67:
 
   
 
   
 
// get supported params
 
// get supported params
var getPreloadText = new Ajax.Request
+
jQuery.ajax( {
(
+
        url: "http://kamelopedia.net/index.php",
    "http://kamelopedia.mormo.org/index.php",
+
data: "title=Vorlage:Kamelionary/preload&action=raw",
    {
+
        dataType: "text",
        method:"get",
+
success: function (txt)  
parameters: "title=Vorlage:Kamelionary/preload&action=raw",
 
onSuccess: function (trans)  
 
 
{
 
{
    var suppText = trans.responseText.replace(/<[\/]?pre>/g, "");
+
    var suppText = txt.replace(/<[\/]?pre>/g, "");
 
    var suppTemplate = suppText.match(findTemplate);
 
    var suppTemplate = suppText.match(findTemplate);
 
             var suppParams = suppTemplate[0].split("\n|");
 
             var suppParams = suppTemplate[0].split("\n|");

Aktuelle Version vom 2. Januar 2014, 12:03 Uhr

addOnloadHook( function () {
    if( ! document.getElementById("wpTextbox1") )
        return;
    if( document.getElementById("wpTextbox1").value == "" &&
        (typeof(disableKamelionaryPreload) == "undefined" || !disableKamelionaryPreload) )
            insertPreload();
    var kd2 = document.getElementById("kat_div_2");
    var html = "<b>Kamelionary-Tools:</b>";
    html += '<div>Alle Parameter anzeigen:</div>';
    html += '<div class="pseudolink" onclick="allKamelionaryParams(false)">ohne Kommentar</div>';
    html += '<div class="pseudolink" onclick="allKamelionaryParams(true)">mit Kommentar</div>';
    kd2.innerHTML += html;
} );

function insertPreload()
	{
	jQuery.ajax( {
	    url: "http://kamelopedia.net/index.php",
	    data: "title=Vorlage:Kamelionary/preload&action=raw",
	    dataType: "text",
	    success: function (txt) 
		{
		  var x = txt.split("<pre>");
		  if (x[1]){
		    var y = x[1].replace(/\s*/,"").split("</pre>");
		    document.getElementById("wpTextbox1").value = y[0];
		  }else{
		    alert("<pre> im Preload nicht gefunden. Bitte laut um Hilfe rufen!");
		  }
		}
	} );
	};

String.prototype.removeHTMLComments = function () {
    return this.replace(/<!--.*?-->/,'');
};

String.prototype.strip = function () {
    return this.replace(/^\s*/,"").replace(/\s*$/,"");
};

function allKamelionaryParams(withcomments)
{
 
if ( ! confirm("Achtung, experimentelle Funktion!\n\nDiese Javascript-funktion fügt fehlende Parameter für die Kamelionary-Vorlage ins Textfeld ein. Dabei können aber z.B. falsch geschriebene Parameter versehentlich gelöscht werden.\nBitte überprüfe das Ergebnis mit dem Button 'Änderungen zeigen'!\n\nWeitermachen?") )
    return;
 
var findTemplate = /\{\{Kamelionary(\s|\n)*\|[^}]*?\}\}/;
 
// used parameters
var usedParams = {};
 
// get used params
var template = document.getElementById("wpTextbox1").value.match(findTemplate);
var params = template[0].slice(0,template[0].length-2).split("\n|");
 
for (var i=1; i < params.length; i++)
{
    // split doesn't work here
    var eqpos = pos = params[i].search("=");
    if (eqpos == -1)
        continue;
    var arr = [params[i].slice(0,eqpos), params[i].slice(eqpos+1)];

    usedParams[arr[0].removeHTMLComments().strip()] = arr[1].replace(/(^[ \t]+|[\s\n]+$)/g,"");
}
 
// get supported params
jQuery.ajax( {
        url: "http://kamelopedia.net/index.php",
	data: "title=Vorlage:Kamelionary/preload&action=raw",
        dataType: "text",
	success: function (txt) 
	{
	    var suppText = txt.replace(/<[\/]?pre>/g, "");
	    var suppTemplate = suppText.match(findTemplate);
            var suppParams = suppTemplate[0].split("\n|");
            var resulttext = "{{Kamelionary";
            for (var i=1; i < suppParams.length; i++)
            {
                var arr = suppParams[i].split("=");
                if (arr.length < 2)
                    continue;
                var p = arr[0].removeHTMLComments().strip();
                if ( withcomments )
                    pn = arr[0];
                else
                    pn = arr[0].removeHTMLComments();
                resulttext += "\n|" + pn + "= ";
                if (usedParams[p] != null)
                    resulttext += usedParams[p];
            }
            resulttext += "\n}}"
            var tb = document.getElementById("wpTextbox1");
            tb.value = tb.value.replace(findTemplate,resulttext);

            //show the ok in the textbox
            tb.style.backgroundColor = "#ddffcc";
            setTimeout(function () { tb.style.backgroundColor = "white"; }, 1000);
	}
    }
);
}