1 // Ajax Javascript support functions, based on moacdropdown XmlHttp
2 // Written from scratch by Reini Urban
5 function showHide( id ) {
9 showHide.prototype.onXmlHttpLoad = function( ) {
10 if( this.hXMLHttp.readyState == 4 ) {
11 var hError = this.hXMLHttp.parseError;
12 var img = document.getElementById(this.id+'-img');
13 if( hError && hError.errorCode != 0 ) {
14 alert( hError.reason );
16 // insert external, same-domain XML tree into id-body as HTML
17 // we get this from any page&format=xml
18 var body = document.getElementById(this.id+'-body');
19 var newbody = this.hXMLHttp.responseXML;
20 if (newbody != null) {
21 // DOM quirks with text/xml and DOCTYPE xhtml
22 // msie: newbody = document, newbody.firstChild.nodeName = xml
23 if (newbody.firstChild && newbody.firstChild.nodeName == 'xml')
24 newbody = newbody.firstChild.nextSibling.nextSibling;
25 // gecko + chrome no xml: skip only firstChild = DOCTYPE html
26 if (newbody.firstChild && newbody.firstChild.nodeName == 'html')
27 newbody = newbody.childNodes[1];
28 if (newbody == null) {
29 alert("showHideDone "+this.id+"\nno xml children from "+this.hXMLHttp.responseText);
31 // We cannot just insert the responseXML into the DOM.
32 // well gecko can, but the others not.
33 // So convert the XML tree it on the fly into HTML nodes.
34 // I never saw this before. I needed that, so I think I
35 // invented that sort of rich mashup.
36 var hContainer = CreateHtmlFromXml(newbody);
37 hContainer.className = 'wikitext';
38 body.appendChild( hContainer );
39 body.style.display = 'block';
41 alert("showHideDone "+this.id+"\nerror no xml from "+this.hXMLHttp.responseText);
45 if (!folderArrowPath) folderArrowPath = stylepath + 'images/';
46 img.src = folderArrowPath + '/folderArrowOpen.png';
51 showHide.prototype.init = function (id) {
53 this.hXMLHttp = XmlHttp.create()
55 this.hXMLHttp.onreadystatechange = function() { hAC.onXmlHttpLoad() }
60 /* recursive xml => html converter.
61 This might need a attribute type checker in a bad world.
62 e.g. disable all on* events */
63 function CreateHtmlFromXml (xml) {
65 return document.createElement('xml');
67 var xmltype = xml.nodeName;
69 if (xmltype == '#text') {
70 html = document.createTextNode( xml.nodeValue );
71 html.nodeValue = xml.nodeValue;
72 if (xml.attributes && (xml.attributes != null))
73 for (var i=0; i < xml.attributes.length; i++) {
74 html.setAttribute( xml.attributes[i].name, xml.attributes[i].value );
77 html = document.createElement( xmltype );
79 html.nodeValue = xml.nodeValue;
80 if (xml.attributes && (xml.attributes != null))
81 for (var i=0; i < xml.attributes.length; i++) {
82 html.setAttribute( xml.attributes[i].name, xml.attributes[i].value );
84 if (xml.hasChildNodes())
85 for (var i=0; i < xml.childNodes.length; i++) {
86 html.appendChild( CreateHtmlFromXml(xml.childNodes[i]) );
92 // if body is empty, load page in background into id+"-body" and show/hide id
93 function showHideAsync(uri, id) {
94 var body = document.getElementById(id+'-body');
96 alert("Error: id="+id+'-body'+" missing.");
99 if (body.hasChildNodes()) {
100 //alert("showHideAsync "+uri+" "+id+"\nalready loaded");
104 if (!folderArrowPath) folderArrowPath = stylepath + 'images/';
105 //alert("showHideAsync "+uri+" "+id+"\nloading...");
106 var img = document.getElementById(id+'-img');
108 img.src = folderArrowPath + '/folderArrowLoading.gif';
109 cShowHide = new showHide(id)
110 cShowHide.hXMLHttp.open( 'GET', uri, true )
111 cShowHide.hXMLHttp.send( null )
115 function showHideDone(id) {
116 // insert tree into id-body
117 var body = document.getElementById(id+'-body');
118 body.parentNode.replaceChild(cShowHide.hXMLHttp.responseText, body);
119 alert("showHideDone "+id+"\ngot "+cShowHide.hXMLHttp.responseText);
123 // hide after 0.4 secs
124 function showHideDelayed(id) {
125 window.setTimeout("doshowHide("+id+")",400);
128 function doshowHide(id) {
129 document.getElementById(id).style.display = "none";
130 var highlight = document.getElementById("LSHighlight");
132 highlight.removeAttribute("id");