[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 function myGetHTTPObject(p_tab, p_id, p_url, p_loading, p_typeResponse) { 2 var v_xmlhttp = false; 3 /* Compilation conditionnelle d'IE */ 4 /*@cc_on 5 @if (@_jscript_version >= 5) 6 try { 7 v_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 8 } 9 catch (e) { 10 try { 11 v_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 12 } 13 catch (E) { 14 v_xmlhttp = false; 15 } 16 } 17 @else 18 v_xmlhttp = false; 19 @end @*/ 20 /* on essaie de creer l'objet si ce n'est pas deja fait */ 21 if (!v_xmlhttp && typeof XMLHttpRequest != 'undefined') { 22 try { 23 v_xmlhttp = new XMLHttpRequest(); 24 } 25 catch (e) { 26 v_xmlhttp = false; 27 } 28 } 29 if (v_xmlhttp) { 30 /* on definit ce qui doit se passer quand la page repondra */ 31 v_xmlhttp.open("GET",p_url,true); 32 v_xmlhttp.onreadystatechange=function() { 33 if (v_xmlhttp.readyState == 4) { 34 if (v_xmlhttp.status == 200 || v_xmlhttp.status == 304 ) { 35 var vXMLDoc; 36 if (window.ActiveXObject){ 37 vXMLDoc = new ActiveXObject("Microsoft.XMLDOM"); 38 vXMLDoc.async = false; 39 vXMLDoc.loadXML(v_xmlhttp.responseText); 40 } else { 41 var vParser = new DOMParser(); 42 vXMLDoc = vParser.parseFromString(v_xmlhttp.responseText, "text/xml"); 43 } 44 tabXML[p_url] = vXMLDoc; 45 updatePageList(p_tab, p_id, p_url, p_loading, vXMLDoc); 46 } 47 } 48 } 49 v_xmlhttp.send( null ); 50 } 51 return v_xmlhttp; 52 } 53 54 var tabXML = new Array(); 55 var tabChild = new Array(); 56 var tabNumTR = new Array(); 57 58 function loadDetailXML (p_tab, p_elt, p_url, e) { 59 60 var v_doc = p_elt.ownerDocument; 61 var v_table =p_elt.parentNode; 62 var v_trNext = p_elt.nextSibling; 63 64 // Verify if event is for me (firefox) 65 if (typeof (e) != "undefined") { 66 if (e.target.nodeName == "SPAN") { 67 return; 68 } 69 } 70 // Verify if event is for me (IE) 71 if (typeof (event) != "undefined") { 72 if (event.srcElement.nodeName == "SPAN") { 73 return; 74 } 75 } 76 77 // Change function for close 78 p_elt.onclick = function (e) {closeDetail (p_tab, this, p_url, e); } 79 80 // Change expand / collapse image 81 changeExpandCollapseImage(p_elt); 82 83 //Create loading 84 var loadingRow = v_doc.createElement('tr'); 85 var loadingCell = v_doc.createElement('td'); 86 mySetAttribute(loadingCell,'colspan', p_elt.getElementsByTagName("td").length); 87 var txtNode = v_doc.createTextNode('Loading...'); 88 loadingCell.appendChild (txtNode); 89 loadingRow.appendChild (loadingCell); 90 var v_loading = v_table.insertBefore(loadingRow, v_trNext); 91 92 if (tabXML[p_url]) { 93 // Already loaded 94 updatePageList(p_tab, p_elt.id, p_url, v_loading, tabXML[p_url]); 95 } 96 else { 97 // Not loaded 98 if (typeof(tabChild[p_tab]) == "undefined") { 99 tabChild[p_tab] = new Array(); 100 tabNumTR[p_tab] = 0; 101 } 102 if (p_elt.id) { 103 v_id = p_elt.id; 104 } 105 else { 106 v_id = p_tab+"."+tabNumTR[p_tab]; 107 p_elt.id = v_id; 108 tabNumTR[p_tab] ++; 109 } 110 111 myGetHTTPObject(p_tab, v_id, p_url, v_loading, "rien"); 112 } 113 } 114 115 function changeExpandCollapseImage(p_elt) { 116 // Change expand / collapse image 117 var myImgExpandCollapse = p_elt.getElementsByTagName("td")[0].getElementsByTagName("img"); 118 if (myImgExpandCollapse.length > 0) { 119 var exp = new RegExp(/(.*)(switch[a-b])(\..*)/); 120 var tabElt = exp.exec(myImgExpandCollapse[0].getAttribute('src')); 121 if (tabElt != null) { 122 var switchStr = (tabElt[2]=='switcha') ? 'switchb':'switcha'; 123 setAttributeDom(myImgExpandCollapse[0],'src',tabElt[1]+switchStr+tabElt[3]); 124 } 125 } 126 } 127 128 function closeDetail (p_tab, p_elt, p_url, e) { 129 var i; 130 var v_child; 131 var v_parent = p_elt.parentNode; 132 var v_id = p_elt.id; 133 134 // Verify if event is for me (firefox) 135 if (typeof (e) != "undefined") { 136 if (e.target.nodeName == "SPAN") { 137 return; 138 } 139 } 140 // Verify if event is for me (IE) 141 if (typeof (event) != "undefined") { 142 if (event.srcElement.nodeName == "SPAN") { 143 return; 144 } 145 } 146 147 if (p_url) { 148 p_elt.onclick = function (e) {loadDetailXML (p_tab, this, p_url, e);} 149 // Change expand / collapse image 150 changeExpandCollapseImage(p_elt); 151 } 152 153 // Verify if there is child 154 if (tabChild[p_tab][v_id]) { 155 for (var i=0; i < tabChild[p_tab][v_id].length; i++) { 156 v_child = document.getElementById(tabChild[p_tab][v_id][i]); 157 if (v_child) { 158 if (v_child.id) { 159 closeDetail (p_tab, v_child); 160 } 161 v_parent = v_child.parentNode; 162 if (v_child) { 163 v_parent.removeChild(v_child); 164 } 165 } 166 } 167 } 168 } 169 170 function updatePageList(p_tab, p_id, p_url, p_loading, p_xml) { 171 var i; 172 var v_child; 173 var v_doc = p_loading.ownerDocument; 174 var v_table = p_loading.parentNode; 175 176 // Save xml in cache 177 tabChild[p_tab][p_id] = new Array(); 178 var nbTr = 0; 179 for (i=0; i < p_xml.firstChild.childNodes.length; i++) { 180 v_child = p_xml.firstChild.childNodes[i]; 181 if (v_child.nodeName == "tr") { 182 //alert(p_id+"."+nbTr); 183 tabChild[p_tab][p_id][nbTr] = p_id+"."+nbTr; 184 traiteHTML (v_doc, v_table, v_child, true, p_loading, p_id+"."+nbTr); 185 nbTr ++; 186 } 187 } 188 v_table.removeChild(p_loading); 189 } 190 191 192 function mySetAttribute (p_elt, p_name, p_value) { 193 var v_name = p_name.toLowerCase(); 194 if (v_name=='class') { 195 p_elt.className = p_value; 196 } 197 else if (v_name=='colspan') { 198 p_elt.colSpan = p_value; 199 } 200 else if (v_name=='onclick') { 201 p_elt.onclick = function() { eval(p_value) } 202 } 203 else if (v_name=='onmouseover') { 204 p_elt.onmouseover = function() { eval(p_value) } 205 } 206 else if (v_name=='style') { 207 p_elt.style.cssText = p_value; 208 } 209 else { 210 p_elt.setAttribute(p_name,p_value); 211 } 212 } 213 214 function replaceAllSpace (p_str) { 215 var v_ch = p_str.replace(/ /g,''); 216 v_ch = v_ch.replace(/\t/g,''); 217 v_ch = v_ch.replace(/\n/g,''); 218 return v_ch; 219 } 220 221 function myTrim (p_str) { 222 var v_ch = p_str.replace(/\n/g,' '); 223 v_ch = v_ch.replace(/\t/g,' '); 224 v_ch = v_ch.replace(/ /g,' '); 225 return v_ch; 226 } 227 228 function getIndent (p_nb) { 229 var i; 230 var ch =""; 231 for (i=0; i < p_nb-2; i++) { 232 ch = ch + ' '; 233 } 234 return ch; 235 } 236 237 function traiteHTML (p_doc, p_parent, p_node, p_first, p_trNext, p_id) { 238 var i; 239 var ch = ""; 240 var v_cur; 241 if (p_node.nodeType != 3) { 242 // Create node 243 v_cur = p_doc.createElement (p_node.nodeName); 244 if (p_first) { 245 v_cur.id = p_id; 246 } 247 // Attribut of node 248 var v_attr; 249 if (p_node.attributes) { 250 for (i=0; i < p_node.attributes.length; i++) { 251 v_attr = p_node.attributes[i]; 252 mySetAttribute(v_cur, v_attr.name, v_attr.value); 253 } 254 } 255 if ((p_node.nodeName == "td") && (! p_first) && (p_trNext > 0)) { 256 mySetAttribute(v_cur, "style", "padding-left:"+((p_trNext-1)*15)+"px;"); 257 } 258 259 var v_curForChild = v_cur; 260 if (p_node.nodeName == 'table') { // For IE create tbody 261 v_curForChild = p_doc.createElement ("tbody"); 262 v_cur.appendChild(v_curForChild); 263 } 264 265 // Process childs 266 var v_child; 267 var v_firstTD = true; 268 var v_firstText = true; 269 if (p_node.childNodes) { 270 for (i=0; i < p_node.childNodes.length; i++) { 271 v_child = p_node.childNodes[i]; 272 if (((v_child.nodeType == 3) || (v_child.nodeName == 'img')) && (p_node.nodeName == "td") && (v_firstText)) { 273 v_firstText = false; 274 ch += traiteHTML (p_doc, v_curForChild, v_child, false, p_trNext, p_id); 275 } 276 else if ((p_first) && (v_firstTD) && (v_child.nodeName == 'td')) { 277 v_firstTD = false; 278 ch += traiteHTML (p_doc, v_curForChild, v_child, false, p_id.split(".").length, p_id); 279 } 280 else { 281 ch += traiteHTML (p_doc, v_curForChild, v_child, false, 0, p_id); 282 } 283 } 284 } 285 } 286 else { 287 if (replaceAllSpace (p_node.nodeValue) != "") { 288 v_cur = p_doc.createTextNode (myTrim(p_node.nodeValue)); 289 } 290 else { 291 v_cur = p_doc.createTextNode (" "); 292 } 293 } 294 if (p_first) { 295 p_parent.insertBefore(v_cur, p_trNext); 296 } 297 else { 298 p_parent.appendChild(v_cur); 299 } 300 } 301
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |