1 // Ajax Javascript support functions, based on moacdropdown
2 // $Id: ajax.js 6521 2009-02-20 16:20:24Z vargenau $
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 var body = document.getElementById(this.id+'-body');
17 var newbody = this.hXMLHttp.responseXML;
18 if (newbody != null) {
19 // msie: newbody = document, newbody.firstChild.nodeName = xml
20 if (newbody.firstChild && newbody.firstChild.nodeName == 'xml')
21 newbody = newbody.firstChild.nextSibling.nextSibling;
22 // gecko + chrome: skip firstChild = DOCTYPE html
23 if (newbody.firstChild && newbody.firstChild.nodeName == 'html')
24 newbody = newbody.childNodes[1];
25 if (newbody == null) {
26 alert("showHideDone "+this.id+"\nno xml children from "+this.hXMLHttp.responseText);
28 var hContainer = CreateHtmlFromXml(newbody);
29 hContainer.className = 'wikitext';
30 body.appendChild( hContainer );
31 body.style.display = 'block';
33 alert("showHideDone "+this.id+"\nerror no xml from "+this.hXMLHttp.responseText);
37 img.src = stylepath + 'images/folderArrowOpen.png';
41 showHide.prototype.init = function (id) {
43 this.hXMLHttp = XmlHttp.create()
45 this.hXMLHttp.onreadystatechange = function() { hAC.onXmlHttpLoad() }
50 function CreateHtmlFromXml (xml) {
52 return document.createElement('xml');
54 var xmltype = xml.nodeName;
56 if (xmltype == '#text') {
57 html = document.createTextNode( xml.nodeValue );
58 html.nodeValue = xml.nodeValue;
59 if (xml.attributes && (xml.attributes != null))
60 for (var i=0; i < xml.attributes.length; i++) {
61 html.setAttribute( xml.attributes[i].name, xml.attributes[i].value );
64 html = document.createElement( xmltype );
66 html.nodeValue = xml.nodeValue;
67 if (xml.attributes && (xml.attributes != null))
68 for (var i=0; i < xml.attributes.length; i++) {
69 html.setAttribute( xml.attributes[i].name, xml.attributes[i].value );
71 if (xml.hasChildNodes())
72 for (var i=0; i < xml.childNodes.length; i++) {
73 html.appendChild( CreateHtmlFromXml(xml.childNodes[i]) );
79 // if body is empty, load page in background into id+"-body" and show/hide id
80 function showHideAsync(uri, id) {
81 var body = document.getElementById(id+'-body');
83 alert("Error: id="+id+'-body'+" missing.");
86 if (body.hasChildNodes()) {
87 //alert("showHideAsync "+uri+" "+id+"\nalready loaded");
91 //alert("showHideAsync "+uri+" "+id+"\nloading...");
92 var img = document.getElementById(id+'-img');
94 img.src = stylepath + 'images/folderArrowLoading.gif';
95 cShowHide = new showHide(id)
96 cShowHide.hXMLHttp.open( 'GET', uri, true )
97 cShowHide.hXMLHttp.send( null )
101 function showHideDone(id) {
102 // insert tree into id-body
103 var body = document.getElementById(id+'-body');
104 body.parentNode.replaceChild(cShowHide.hXMLHttp.responseText, body);
105 alert("showHideDone "+id+"\ngot "+cShowHide.hXMLHttp.responseText);
109 // hide after 0.4 secs
110 function showHideDelayed(id) {
111 window.setTimeout("doshowHide("+id+")",400);
114 function doshowHide(id) {
115 document.getElementById(id).style.display = "none";
116 var highlight = document.getElementById("LSHighlight");
118 highlight.removeAttribute("id");