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