MediaWiki:Skin/Kamelopedia:Zeitreisemaschine.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
J* (Diskussion | Beiträge) |
J* (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
+ | /* | ||
+ | * Zeitwähler-Code | ||
+ | */ | ||
+ | function getTotalOffset( element, offsetType, sum ) | ||
+ | { | ||
+ | if ( element.offsetParent != null ) | ||
+ | sum += getTotalOffset( element.offsetParent, offsetType, sum ); | ||
+ | return sum + element[offsetType]; | ||
+ | } | ||
+ | |||
+ | Node.prototype.getTotalOffsetTop = function () { return getTotalOffset( this, "offsetTop", 0 ); }; | ||
+ | Node.prototype.getTotalOffsetLeft = function () { return getTotalOffset( this, "offsetLeft", 0 ); }; | ||
+ | var s = { | ||
+ | init: function () { | ||
+ | s.info = $("sliderinfo"); | ||
+ | s.info2 = $("sliderinfo2"); | ||
+ | s.case = $("slidercase"); | ||
+ | s.back = $("sliderback"); | ||
+ | s.slider = $("slider"); | ||
+ | s.slider2 = $("slider2"); | ||
+ | s.top = s.case.getTotalOffsetTop(); | ||
+ | s.left = s.case.getTotalOffsetLeft(); | ||
+ | }, | ||
+ | move: function (e) { | ||
+ | var x = document.all ? window.event.clientX : e.pageX; | ||
+ | var y = document.all ? window.event.clientY : e.pageY; | ||
+ | if ( x > s.left && x < s.left + s.case.offsetWidth && | ||
+ | y > s.top && y < s.top + s.case.offsetHeight ) | ||
+ | { | ||
+ | s.dx = x - s.left - 1 ; | ||
+ | s.px = s.dx / ( s.case.offsetWidth - 2 ); | ||
+ | s.date = s.calcTime(s.px); | ||
+ | s.dateInfo = ""; | ||
+ | s.dateInfo += s.date.getDate() + ". "; | ||
+ | s.dateInfo += ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"][s.date.getMonth()] + " "; | ||
+ | s.dateInfo += s.date.getFullYear(); | ||
+ | s.info.innerHTML = s.dateInfo; | ||
+ | s.slider.style.left = (s.dx - 1 ) + "px"; | ||
+ | s.slider.style.display = "block"; | ||
+ | |||
+ | } | ||
+ | else | ||
+ | { | ||
+ | s.info.innerHTML = "Kein Datum ausgewählt."; | ||
+ | s.slider.style.display = "none"; | ||
+ | } | ||
+ | }, | ||
+ | calcTime: function (p) { | ||
+ | return new Date( ( (s.today - s.birth) * p + s.birth ) * 1000 ); | ||
+ | }, | ||
+ | click: function (e) { | ||
+ | s.move(e); | ||
+ | s.info2.innerHTML = s.dateInfo; | ||
+ | s.slider2.style.left = (s.dx - 2 ) + "px"; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function initSlider() | ||
+ | { | ||
+ | s.init(); | ||
+ | window.onmousemove = s.move; | ||
+ | s.case.onclick = s.click; | ||
+ | s.birth = parseInt( $("t_birth").innerHTML ); | ||
+ | s.today = parseInt( $("t_today").innerHTML ); | ||
+ | var b = new Date ( s.birth * 1000 ); | ||
+ | var t = new Date ( s.today * 1000 ); | ||
+ | s.back.innerHTML=""; | ||
+ | for (var x=b.getFullYear(); x<t.getFullYear(); x++) | ||
+ | { | ||
+ | var e = document.createElement("DIV"); | ||
+ | e.style.position = "absolute"; | ||
+ | e.style.height = "100%"; | ||
+ | e.style.width = "100%"; | ||
+ | e.innerHTML = x+1; | ||
+ | e.style.margin = "0px"; | ||
+ | e.style.padding = "0px"; | ||
+ | e.style.borderLeft = "1px darkblue solid"; | ||
+ | e.style.color = "darkblue"; | ||
+ | e.style.top = "0px"; | ||
+ | e.style.width = "5em"; | ||
+ | e.style.left = ( (new Date(x+1,0,1) - b) / ( t - b ) * (s.case.offsetWidth - 2) ) + "px"; | ||
+ | s.back.appendChild(e); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | * Zeitmaschinen-Code | ||
+ | */ | ||
ready = function ( a ) { alert(a.wiki.HTML ) }; | ready = function ( a ) { alert(a.wiki.HTML ) }; | ||
Zeile 9: | Zeile 99: | ||
{ | { | ||
document.getElementById("zr_content").innerHTML = a.wiki.HTML; | document.getElementById("zr_content").innerHTML = a.wiki.HTML; | ||
+ | document.getElementsByTagName("H1")[0].innerHTML = page; | ||
dbg = wiki.transport; | dbg = wiki.transport; | ||
var links = document.getElementsByTagName("A"); | var links = document.getElementsByTagName("A"); | ||
Zeile 21: | Zeile 112: | ||
nextlink = function () | nextlink = function () | ||
{ | { | ||
− | page = | + | page = this.title; |
alert(page); | alert(page); | ||
getRevision.start(); | getRevision.start(); | ||
Zeile 32: | Zeile 123: | ||
getRevision = new Async( [ | getRevision = new Async( [ | ||
− | function () { | + | function () { a = { wiki: { source: "{{#dpl: namespace = | lastrevisionbefore = "+parseInt(time)+" | format=,%REVISION%, | skipthispage = no | count = 1 | titlematch = "+page+" | count = 1}}", title: "Hauptseite" } }; alert(a.wiki.source); return a; }, |
wiki.parse, | wiki.parse, | ||
− | function (a) { a.wiki.args = "oldid="+parseInt(a.wiki.HTML); a.wiki.title = page; return a; }, | + | function (a) { alert(a.wiki.HTML); a.wiki.args = "oldid="+parseInt(a.wiki.HTML); a.wiki.title = page; return a; }, |
wiki.getHTML, | wiki.getHTML, | ||
− | parseRevision, | + | parseRevision |
− | function (a) { return { wiki: { source: " | + | ], function () {} ); |
+ | |||
+ | getRescue = new Async( [ | ||
+ | function (a) { page="Zufällige Artikelvorschläge"; return { wiki: { source: "Probier doch mal: {{#dpl: namespace = | lastrevisionbefore = "+parseInt(time)+" | format = ,\\n*[[%PAGE%]], | randomcount = 6 }}", title: "Hauptseite" } } }, | ||
wiki.parse, | wiki.parse, | ||
− | + | parseRevision | |
− | ], function () {} | + | ], function () {} ); |
− | |||
− | |||
// später mit onloadHook() | // später mit onloadHook() | ||
Zeile 51: | Zeile 143: | ||
for(var i=0; i<links.length; i++) | for(var i=0; i<links.length; i++) | ||
links[i].keepToday = true; | links[i].keepToday = true; | ||
+ | |||
+ | $("zr_info").onclick = function () { getRescue.start(); }; | ||
+ | initSlider() | ||
} | } | ||
− | initTM | + | addOnloadHook(initTM); |
Version vom 5. April 2009, 20:15 Uhr
/*
* Zeitwähler-Code
*/
function getTotalOffset( element, offsetType, sum )
{
if ( element.offsetParent != null )
sum += getTotalOffset( element.offsetParent, offsetType, sum );
return sum + element[offsetType];
}
Node.prototype.getTotalOffsetTop = function () { return getTotalOffset( this, "offsetTop", 0 ); };
Node.prototype.getTotalOffsetLeft = function () { return getTotalOffset( this, "offsetLeft", 0 ); };
var s = {
init: function () {
s.info = $("sliderinfo");
s.info2 = $("sliderinfo2");
s.case = $("slidercase");
s.back = $("sliderback");
s.slider = $("slider");
s.slider2 = $("slider2");
s.top = s.case.getTotalOffsetTop();
s.left = s.case.getTotalOffsetLeft();
},
move: function (e) {
var x = document.all ? window.event.clientX : e.pageX;
var y = document.all ? window.event.clientY : e.pageY;
if ( x > s.left && x < s.left + s.case.offsetWidth &&
y > s.top && y < s.top + s.case.offsetHeight )
{
s.dx = x - s.left - 1 ;
s.px = s.dx / ( s.case.offsetWidth - 2 );
s.date = s.calcTime(s.px);
s.dateInfo = "";
s.dateInfo += s.date.getDate() + ". ";
s.dateInfo += ["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"][s.date.getMonth()] + " ";
s.dateInfo += s.date.getFullYear();
s.info.innerHTML = s.dateInfo;
s.slider.style.left = (s.dx - 1 ) + "px";
s.slider.style.display = "block";
}
else
{
s.info.innerHTML = "Kein Datum ausgewählt.";
s.slider.style.display = "none";
}
},
calcTime: function (p) {
return new Date( ( (s.today - s.birth) * p + s.birth ) * 1000 );
},
click: function (e) {
s.move(e);
s.info2.innerHTML = s.dateInfo;
s.slider2.style.left = (s.dx - 2 ) + "px";
}
}
function initSlider()
{
s.init();
window.onmousemove = s.move;
s.case.onclick = s.click;
s.birth = parseInt( $("t_birth").innerHTML );
s.today = parseInt( $("t_today").innerHTML );
var b = new Date ( s.birth * 1000 );
var t = new Date ( s.today * 1000 );
s.back.innerHTML="";
for (var x=b.getFullYear(); x<t.getFullYear(); x++)
{
var e = document.createElement("DIV");
e.style.position = "absolute";
e.style.height = "100%";
e.style.width = "100%";
e.innerHTML = x+1;
e.style.margin = "0px";
e.style.padding = "0px";
e.style.borderLeft = "1px darkblue solid";
e.style.color = "darkblue";
e.style.top = "0px";
e.style.width = "5em";
e.style.left = ( (new Date(x+1,0,1) - b) / ( t - b ) * (s.case.offsetWidth - 2) ) + "px";
s.back.appendChild(e);
}
}
/*
* Zeitmaschinen-Code
*/
ready = function ( a ) { alert(a.wiki.HTML ) };
var ret;
function parseRevision( a )
{
document.getElementById("zr_content").innerHTML = a.wiki.HTML;
document.getElementsByTagName("H1")[0].innerHTML = page;
dbg = wiki.transport;
var links = document.getElementsByTagName("A");
for(var i=0; i<links.length; i++)
if (links[i].keepToday != true)
links[i].onclick = nextlink;
return a;
}
nextlink = function ()
{
page = this.title;
alert(page);
getRevision.start();
return false;
}
var time="20050101";
var page="Hauptseite";
var dbg;
getRevision = new Async( [
function () { a = { wiki: { source: "{{#dpl: namespace = | lastrevisionbefore = "+parseInt(time)+" | format=,%REVISION%, | skipthispage = no | count = 1 | titlematch = "+page+" | count = 1}}", title: "Hauptseite" } }; alert(a.wiki.source); return a; },
wiki.parse,
function (a) { alert(a.wiki.HTML); a.wiki.args = "oldid="+parseInt(a.wiki.HTML); a.wiki.title = page; return a; },
wiki.getHTML,
parseRevision
], function () {} );
getRescue = new Async( [
function (a) { page="Zufällige Artikelvorschläge"; return { wiki: { source: "Probier doch mal: {{#dpl: namespace = | lastrevisionbefore = "+parseInt(time)+" | format = ,\\n*[[%PAGE%]], | randomcount = 6 }}", title: "Hauptseite" } } },
wiki.parse,
parseRevision
], function () {} );
// später mit onloadHook()
function initTM()
{
var links = document.getElementsByTagName("A");
for(var i=0; i<links.length; i++)
links[i].keepToday = true;
$("zr_info").onclick = function () { getRescue.start(); };
initSlider()
}
addOnloadHook(initTM);