User:SVG/vector.js

var drag_move=0; var drag_resize=1;

var drag_type;

var drag_esx; var drag_esy;

var drag_msx; var drag_msy;

var frame_zi = 5;

var mousePosX = 50; var mousePosY = 50;

function onload { //var frame = new Frame("fooo :)", 80, 80, 300, 300);	//var frame = new Frame("fooo :)", 10, 10, 300, 300); //	frame.hide; // document.getElementById("p-logo").style.display="none"; // readContent("/w/api.php?action=parse&page=Wikipedia:Hauptseite&format=json", new JSONReader(frame)); //var frame = new Frame("fooo :)", 80, 80, 300, 300);	//readContent("/w/api.php?action=parse&page=Test&format=json", new JSONReader(frame));	//openFrame("Test");	//openWikiPage("ajax");	var a = document.createElement("input");	a.type="button";	a.value="frame";	//a.appendChild(document.createTextNode('Frame')); 	a.onclick=function(ev) {		openWikiPage(document.getElementById("searchInput").value);	}	document.getElementById("searchform").appendChild(a);	//document.getElementById("column-one").style.display="none"	document.body.style.backgroundAttachment="fixed"; }

function openWikiPage(art) { //alert(mousePosX + ", " + mousePosY); var frame = new Frame(wiki_dec(art), mousePosX, mousePosY, 500, 500); readContent("/w/api.php?action=parse&page="+art+"&format=json", new JSONContentReader(frame)); readContent("/w/api.php?action=query&titles="+art+"&redirects&format=json&prop=info|langlinks", new JSONTitleReader(frame.titlediv)); } function JSONTitleReader(target) { var target=target; this.contentloaded = function(text) { //alert(text); var jsonobj = eval('('+text+')'); for(page in jsonobj.query.pages) target.contentloaded(jsonobj['query']['pages'][page].title); //			alert(jsonobj['query']['pages'][page].title); //.pages.673270);		//var newcontent = content.replace(/href=\"\/wiki\/(\S*)\"/g, 'onclick="openWikiPage(\'$1\');"'); //		target.contentloaded(newcontent);	} }

function JSONContentReader(target) { var target=target; this.contentloaded = function(text) { var jsonobj = eval('('+text+')'); var content = jsonobj.parse.text.*; var newcontent = content.replace(/href=\"\/wiki\/(\S*)\"/g, 'onclick="openWikiPage(\'$1\');"'); target.contentloaded(newcontent); } }

function wiki_dec(utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0;

while ( i < utftext.length ) {

c = utftext.charCodeAt(i);

if (c < 128) { string += String.fromCharCode(c); i++; }           else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; }           else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; }

}

return string.replace(/_/g, ' ');

}

function onmousemove(ev) { mousePosX = ev.pageX; mousePosY = ev.pageY; if(document.getElementById("drag")!=null) { if(drag_type==drag_move) { document.getElementById("drag").style.left = (drag_esx + (ev.clientX-drag_msx))+"px"; document.getElementById("drag").style.top = (drag_esy + (ev.clientY-drag_msy))+"px"; }

if(drag_type==drag_resize) { //			alert(document.getElementById("drag").offsetWidth); document.getElementById("drag").style.width = (drag_esx + (ev.clientX-drag_msx))+"px"; document.getElementById("drag").style.height = (drag_esy + (ev.clientY-drag_msy))+"px";

}	} }

function onmouseup(ev) { if(document.getElementById("drag")) { document.getElementById("drag").id=""; } }

function Frame(title, x, y, width, height) { /*var contentdiv; var framediv; var titlediv;*/ this.framediv = document.createElement("div"); this.framediv.setAttribute("class", "window"); this.framediv.style.top = y + "px"; this.framediv.style.left = x + "px"; this.framediv.style.width = width + "px"; this.framediv.style.height = height + "px";

this.titlediv = document.createElement("div"); this.titleh = document.createElement("h2"); this.titleh.innerHTML=title; this.titlediv.appendChild(this.titleh); this.titlediv.setAttribute("class", "title");

this.closebtn = document.createElement("div"); this.closebtn.setAttribute("class", "closebtn"); this.titlediv.appendChild(this.closebtn);

this.scrollerdiv = document.createElement("div"); this.scrollerdiv.setAttribute("class", "scroller"); this.contentdiv = document.createElement("div"); this.contentdiv.setAttribute("class", "content");

this.resizediv = document.createElement("div"); this.resizediv.setAttribute("class", "resize");

this.framediv.appendChild(this.titlediv); this.framediv.appendChild(this.scrollerdiv); this.scrollerdiv.appendChild(this.contentdiv);

this.framediv.appendChild(this.resizediv); document.body.appendChild(this.framediv); this.scrollerdiv.style.top = this.titlediv.offsetHeight+"px"; var th=this; this.titlediv.contentloaded = function(t) { th.titleh.innerHTML=t; }

this.closebtn.onclick = function(evc) { th.hide; }	this.hide = function { this.framediv.style.display="none"; }	this.contentdiv.setAttribute("id", "load"); this.contentloaded = function(text) { this.contentdiv.setAttribute("id", ""); this.contentdiv.innerHTML = text; }

var framediv = this.framediv; this.framediv.style.zIndex = frame_zi; this.framediv.onmousedown = function(evc) { framediv.style.zIndex = frame_zi++; } /* * mouselistener im framediv */

this.titlediv.onmousedown = function(evc) { framediv.setAttribute("id", "drag") drag_esx = framediv.offsetLeft; drag_esy = framediv.offsetTop; drag_msx = evc.clientX; drag_msy = evc.clientY; drag_type = drag_move; }

/* * mouselistener im resizediv */	this.resizediv.onmousedown = function(evc) { framediv.setAttribute("id", "drag") drag_esx = framediv.offsetWidth; drag_esy = framediv.offsetHeight; drag_msx = evc.clientX; drag_msy = evc.clientY; drag_type = drag_resize; } }

function readContent(url, target) { var req = null; try { req = new XMLHttpRequest; } catch (ms) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (nonms) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { req = null; }		}	}	req.open("GET", url, true); req.onreadystatechange = function { switch(req.readyState) { case 4: if(req.status!=200) { target.contentloaded("Fehler:"+req.status); } else { backvar = req.responseText; target.contentloaded(backvar); }				break; default: return; break; }

};

req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send(null); }