Benutzer:J*/vector.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) |
J* (Diskussion | Beiträge) |
||
Zeile 57: | Zeile 57: | ||
/* Zeug für die Buschtrommel */ | /* Zeug für die Buschtrommel */ | ||
− | function | + | function serialize (obj) |
{ | { | ||
− | + | switch (typeof obj) | |
{ | { | ||
− | var | + | case "string": |
+ | return "s"+escape(obj) | ||
+ | break; | ||
+ | case "number": | ||
+ | return "n"+escape(String(obj)); | ||
+ | break; | ||
+ | case "object": | ||
+ | var arr = []; | ||
+ | for (var k in obj) | ||
+ | { | ||
+ | arr.push(serialize(k) + "=" + serialize(obj[k])) | ||
+ | } | ||
+ | if (obj instanceof Array) | ||
+ | return "a"+escape(arr.join("&")); | ||
+ | else | ||
+ | return "o"+escape(arr.join("&")); | ||
− | + | default: | |
− | + | throw "Cannot serialize " + (typeof obj) + " type." | |
− | + | } | |
− | + | } | |
− | |||
− | |||
− | |||
− | + | function deserialize (str) | |
+ | { | ||
+ | var type = str[0] | ||
+ | var data = str.substr(1) | ||
− | + | switch(type) | |
− | + | { | |
− | + | case "s": //string | |
− | + | return unescape(data); | |
− | + | break; | |
− | + | case "n": //number | |
− | + | if (data == "Infinity") | |
− | + | return Infinity | |
− | + | else if (data == "-Infinity") | |
− | + | return -Infinity | |
− | + | else | |
− | + | return parseInt(unescape(data)); | |
− | + | break; | |
− | + | case "a": // Array | |
− | + | case "o": //Object | |
− | |||
− | return | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | var ret = {}; | ||
+ | if (type == "a") | ||
+ | ret = []; | ||
+ | |||
+ | var pairs = unescape(data).split("&") | ||
+ | for (var i=0; i<pairs.length; i++) | ||
+ | { | ||
+ | var kv = pairs[i].split("=") | ||
+ | ret[deserialize(kv[0])] = deserialize(kv[1]); | ||
+ | } | ||
+ | return ret; | ||
+ | break; | ||
+ | |||
+ | default: | ||
+ | throw "Cannot deserialize " + type + " type." | ||
} | } | ||
− | |||
− | |||
} | } |
Version vom 10. Dezember 2010, 17:32 Uhr
/* für's Bürokratenspiel */
function bksp ()
{
if (wgPageName.indexOf("Projekt:Bürokratenspiel") != -1 )
{
var t = wgTitle.split("/");
var e = (wgAction = "edit") ? "$ " : "";
document.title = t[t.length-1];
}
}
addOnloadHook(bksp);
/* Zusammenfassungs-Warnung */
addOnloadHook( function () {
jQuery("#wpSummary, #wpTextbox1").bind("keypress", function() {
jQuery("#wpSummary").css("background-color","#ffffff");
try {
clearInterval(summaryWarnInterval);
summaryWarnInterval = null;
}
catch (e) {}
summaryWarnState = -1;
});
jQuery("#editform").bind("submit", function (e) {
if ( e.originalEvent.explicitOriginalTarget != jQuery("#wpSave")[0] )
return true;
if (! jQuery("#wpSummary").val().replace(/^\s+/,"").replace(/\s+$/,"").replace(/\/\*.*?\*\//,"") && summaryWarnState == -1)
{
jQuery("#wpSummary").focus();
summaryWarnInterval = window.setInterval(summaryWarn,70);
return false;
}
return true;
});
});
summaryWarnState = -1;
summaryWarnInterval = null;
function summaryWarn()
{
summaryWarnState ++;
if (summaryWarnState % 2 == 0)
jQuery("#wpSummary").css("background-color","#ffff99");
else
jQuery("#wpSummary").css("background-color","#ffffff");
if (summaryWarnState > 11)
clearInterval(summaryWarnInterval);
}
/* Zeug für die Buschtrommel */
function serialize (obj)
{
switch (typeof obj)
{
case "string":
return "s"+escape(obj)
break;
case "number":
return "n"+escape(String(obj));
break;
case "object":
var arr = [];
for (var k in obj)
{
arr.push(serialize(k) + "=" + serialize(obj[k]))
}
if (obj instanceof Array)
return "a"+escape(arr.join("&"));
else
return "o"+escape(arr.join("&"));
default:
throw "Cannot serialize " + (typeof obj) + " type."
}
}
function deserialize (str)
{
var type = str[0]
var data = str.substr(1)
switch(type)
{
case "s": //string
return unescape(data);
break;
case "n": //number
if (data == "Infinity")
return Infinity
else if (data == "-Infinity")
return -Infinity
else
return parseInt(unescape(data));
break;
case "a": // Array
case "o": //Object
var ret = {};
if (type == "a")
ret = [];
var pairs = unescape(data).split("&")
for (var i=0; i<pairs.length; i++)
{
var kv = pairs[i].split("=")
ret[deserialize(kv[0])] = deserialize(kv[1]);
}
return ret;
break;
default:
throw "Cannot deserialize " + type + " type."
}
}