[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 var phpmvRowsArray = new Array(); 2 function getHTTPObject(elt,url,typeResponse,loadingRow) { 3 var xmlhttp = false; 4 /* Compilation conditionnelle d'IE */ 5 /*@cc_on 6 @if (@_jscript_version >= 5) 7 try { 8 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 9 } 10 catch (e) { 11 try { 12 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 13 } 14 catch (E) { 15 xmlhttp = false; 16 } 17 } 18 @else 19 xmlhttp = false; 20 @end @*/ 21 /* on essaie de créer l'objet si ce n'est pas déjà fait */ 22 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { 23 try { 24 xmlhttp = new XMLHttpRequest(); 25 } 26 catch (e) { 27 xmlhttp = false; 28 } 29 } 30 if (xmlhttp) { 31 /* on définit ce qui doit se passer quand la page répondra */ 32 xmlhttp.onreadystatechange=function() { 33 if (xmlhttp.readyState == 4) { 34 if (xmlhttp.status == 200 || xmlhttp.status == 304 ) { 35 switch ( typeResponse ) { 36 case 'xml': 37 if (window.ActiveXObject){ 38 vXMLDoc = new ActiveXObject("Microsoft.XMLDOM"); 39 vXMLDoc.async = false; 40 vXMLDoc.loadXML(xmlhttp.responseText); 41 } else { 42 var vParser = new DOMParser(); 43 vXMLDoc = vParser.parseFromString(xmlhttp.responseText, "text/xml"); 44 } 45 traitementDOM(elt,vXMLDoc,url,loadingRow); 46 //var parentElt = elt.parentNode; 47 //if(parentElt) parentElt.removeChild(loadingRow); 48 break; 49 case 'html': 50 phpmvRowsArray[url] = xmlhttp.responseText; 51 elt.innerHTML = xmlhttp.responseText; 52 break; 53 } 54 } 55 } 56 } 57 } 58 return xmlhttp; 59 } 60 61 function createLoadingRow (elt) { 62 var myDocument = elt.ownerDocument; 63 var loadingRow = myDocument.createElement('tr'); 64 var loadingCell = myDocument.createElement('td'); 65 setAttributeDom(loadingCell,'colspan', elt.getElementsByTagName("td").length); 66 var txtNode = myDocument.createTextNode('Loading...'); 67 loadingCell.appendChild(txtNode); 68 loadingRow.appendChild(loadingCell); 69 insertAfterRow(elt,loadingRow); 70 71 return loadingRow; 72 } 73 74 function viewRowsDetails(elt,url,p_changeImage) { 75 // add or remove sub-row details 76 var myDocument = elt.ownerDocument; 77 var exp; 78 // Change expand / collapse image 79 if ((typeof(p_changeImage) == "undefined") || (p_changeImage)) { 80 var myImgExpandCollapse = elt.getElementsByTagName("td")[0].getElementsByTagName("img"); 81 if (myImgExpandCollapse.length > 0) { 82 exp = new RegExp(/(.*)(switch[a-b])(\..*)/); 83 var tabElt = exp.exec(myImgExpandCollapse[0].getAttribute('src')); 84 if (tabElt != null) { 85 switchStr = (tabElt[2]=='switcha') ? 'switchb':'switcha'; 86 setAttributeDom(myImgExpandCollapse[0],'src',tabElt[1]+switchStr+tabElt[3]); 87 } 88 } 89 } 90 exp = new RegExp(/(.*)\sselectedRow/); 91 // unselected all rows 92 var allRows = myDocument.getElementsByTagName("tr"); 93 for (var i=0;i<allRows.length;i++) { 94 tabClass = exp.exec(allRows[i].className); 95 if (tabClass != null) { 96 allRows[i].className = tabClass[1]; 97 } 98 } 99 // Verify if next row is detail 100 if ((elt.nextSibling != null) // IE 101 && (typeof(elt.nextSibling) != "undefined") 102 && (elt.nextSibling.nodeName == 'TR') 103 && (elt.nextSibling.firstChild.firstChild.nodeName == 'TABLE')) { 104 // Remove detail 105 var v_parent = elt.parentNode; 106 var v_toDelete = elt.nextSibling; 107 v_parent.removeChild (v_toDelete); 108 } 109 else { 110 if (phpmvRowsArray[url] == undefined) { // load detail from http 111 // when row is selected for expand details 112 if(elt.className != 'details') elt.className = elt.className + ' selectedRow'; 113 if (elt.getElementsByTagName("td")[0].getElementsByTagName("a").length == 0) { 114 // add loading's row for information 115 var loadingRow = createLoadingRow (elt); 116 // ********************************* 117 } else { 118 var loadingRow = elt.cloneNode(true) 119 loadingRow.getElementsByTagName("td")[0].innerHTML = 'Loading...'; 120 insertAfterRow(elt,loadingRow); 121 elt.parentNode.removeChild(elt); 122 elt = loadingRow; 123 } 124 var xmlhttp = getHTTPObject(elt,url,'xml',loadingRow); 125 xmlhttp.open("GET",url,true); 126 xmlhttp.send( null ); 127 } else { // load detail from cache 128 var loadingRow = createLoadingRow (elt); 129 traitementDOM(elt,phpmvRowsArray[url],url,loadingRow); 130 } 131 } 132 } 133 134 function searchTagInParent (p_elt, p_tag) { 135 var v_tmpElt = p_elt.parentNode; 136 while ((v_tmpElt != null) && (v_tmpElt.nodeName != p_tag)) { 137 v_tmpElt = v_tmpElt.parentNode; 138 } 139 return v_tmpElt; 140 } 141 142 function viewNextPreviousRowsDetailsXX(elt,url) { 143 // view next rows details, for all table, or sub-rows only 144 var tmpElt = elt; 145 var replaceAll = false; 146 while (tmpElt.tagName != 'TR') { 147 tmpElt = tmpElt.parentNode; 148 } 149 var curTable = tmpElt.parentNode; 150 // Is the link in a cell ? 151 if (tmpElt != null && tmpElt.getElementsByTagName("td")[0].attributes.getNamedItem('class').value.indexOf('subLevel')==-1) replaceAll = true; 152 if (!replaceAll) { // if we haven't row contain link 153 viewRowsDetails(tmpElt,url); 154 } else { 155 alert("changeDetail"); 156 changeDetails(elt,url); 157 } 158 } 159 160 function viewNextPreviousRowsDetails(elt,url) { 161 // Search Detail table 162 var v_tmpTableDetail = searchTagInParent (elt, 'TABLE'); 163 if (v_tmpTableDetail.id != "detail") { 164 changeDetails(elt,url); 165 } 166 else { 167 var v_tmpTD = searchTagInParent (v_tmpTableDetail, 'TD'); 168 if (phpmvRowsArray[url] == undefined) { 169 elt.parentNode.innerHTML = 'Loading...'; 170 var xmlhttp = getHTTPObject(v_tmpTD,url,'html'); 171 xmlhttp.open("GET",url,true); 172 xmlhttp.send( null ); 173 } else { 174 v_tmpTD.innerHTML = phpmvRowsArray[url]; 175 } 176 177 /* 178 // Search TR which contains detail table 179 var v_tmpTRLoading = searchTagInParent (v_tmpTableDetail, 'TR'); 180 // Get parent of TR 181 var v_tmpTRParent = v_tmpTRLoading.parentNode; 182 // Get TR of parent 183 var v_tmpTR = v_tmpTRLoading.previousSibling; 184 // Removing old data 185 v_tmpTRParent.removeChild (v_tmpTRLoading); 186 // Load data 187 viewRowsDetails(v_tmpTR,url, false); 188 */ 189 } 190 } 191 192 function traitementDOM (elt,response,url,loadingRow) { 193 var v_content = ""; 194 var v_doc = loadingRow.ownerDocument; 195 //removeChild 196 var v_TD = loadingRow.firstChild; 197 var v_TxtLoad = loadingRow.firstChild.firstChild; 198 // Set data in cache 199 phpmvRowsArray[url] = response; 200 // Add element 201 traiteHTML (v_doc, loadingRow.firstChild, response.firstChild, false, 0, "12"); 202 // Remove Loading.. text 203 v_TD.removeChild(v_TxtLoad); 204 } 205 206 207 208 function traitementDOMxx (elt,response,url,loadingRow) { 209 // adding new content with DOM gestion 210 var newphpmvRowsArray = new Array(); 211 elt = removeOldRows(elt,url); 212 var level = elt; 213 var eltTD; 214 var attrName; 215 var myDocument = elt.ownerDocument; 216 eltTD = elt.getElementsByTagName("td")[0]; // cell contain link detail 217 if (eltTD.attributes.getNamedItem('class') && eltTD.attributes.getNamedItem('class').value.indexOf('subLevel')!=-1) { // if not first level detail 218 level = eltTD.attributes.getNamedItem('class').value; 219 level = 'subLevel' + (parseInt(level.substr(8))+1); 220 } else { // if first detail detail 221 level = 'subLevel1'; 222 } 223 newphpmvRowsArray[0] = "level" + level; 224 var allRows = response.getElementsByTagName("tr"); 225 for (var i=allRows.length;i>0;i--) { 226 var isInterrest = false; // if the rows details is in table with header 227 if (response.getElementsByTagName("th").length>0) isInterrest = true; // we are in table with header cells 228 var newRow = myDocument.createElement('tr'); 229 if (allRows[i-1].getAttributeNode('onclick')!=null) { // add attributes for the new row 230 setAttributeDom(newRow,'onclick',allRows[i-1].attributes.getNamedItem('onclick').value); 231 setAttributeDom(newRow,'class','expandcollapse'); 232 } else if (isInterrest) { 233 setAttributeDom(newRow,'class','details'); 234 } 235 // add header's details cells 236 var myRow = allRows[i-1].getElementsByTagName("th"); 237 for (var j=0;j<myRow.length;j++) { 238 var newCell = myDocument.createElement('th'); 239 setAttributeDom(newCell,'class','subLevel'); 240 for (var k=0;k<myRow[j].attributes.length;k++) { 241 setAttributeDom(newCell,myRow[j].attributes[k].name,myRow[j].attributes[k].value); 242 } 243 contentNode(newCell,myRow[j]); 244 newRow.appendChild(newCell); 245 } 246 insertAfterRow(elt,newRow); 247 // add rows details 248 var myRow = allRows[i-1].getElementsByTagName("td"); 249 for (var j=0;j<myRow.length;j++) { 250 var newCell = myDocument.createElement('td'); 251 if (j==0) { // add class for the new cell 252 setAttributeDom(newCell,'class',level); 253 } else { 254 setAttributeDom(newCell,'class','subLevel'); 255 } 256 for (var k=0;k<myRow[j].attributes.length;k++) { // add attributes for the new cell 257 attrName = myRow[j].attributes[k].name; 258 if (newCell.attributes.getNamedItem(attrName) != null) { 259 setAttributeDom(newCell,attrName,newCell.attributes.getNamedItem(attrName).value+' '+myRow[j].attributes[k].value); 260 } else { 261 setAttributeDom(newCell,attrName,myRow[j].attributes[k].value); 262 } 263 } 264 contentNode(newCell,myRow[j]); 265 newRow.appendChild(newCell); 266 } 267 insertAfterRow(elt,newRow) 268 newphpmvRowsArray[i] = newRow; 269 } 270 var sum = 0; 271 for (var toto in phpmvRowsArray) sum++; 272 setAttributeDom(elt,'id','rowElt'+sum); 273 phpmvRowsArray[url] = newphpmvRowsArray; 274 } 275 function insertAfterRow(elt,newRow) { 276 // insert row after reference row 277 var currentTable; 278 if (elt.tagName == 'TABLE' || elt.tagName == 'TBODY') { 279 elt.appendChild(newRow); 280 } else { 281 currentTable = elt.parentNode; 282 if(elt.nextSibling) currentTable.insertBefore(newRow, elt.nextSibling); 283 else currentTable.appendChild(newRow); 284 } 285 } 286 function contentNode(newCell,myContent) { 287 // add all child of myContent to the new cell newCell 288 var myDocument = newCell.ownerDocument; 289 for (var i=0;i<myContent.childNodes.length;i++) { 290 if (myContent.childNodes[i].tagName) { 291 var tmpNode = myDocument.createElement(myContent.childNodes[i].tagName); 292 for (var j=0;j<myContent.childNodes[i].attributes.length;j++) { 293 setAttributeDom(tmpNode,myContent.childNodes[i].attributes[j].name,myContent.childNodes[i].attributes[j].value); 294 } 295 contentNode(tmpNode,myContent.childNodes[i]); 296 newCell.appendChild(tmpNode); 297 } else { 298 var tmpNode = myDocument.createTextNode(myContent.childNodes[i].nodeValue); 299 newCell.appendChild(tmpNode); 300 } 301 } 302 } 303 function removeDetails(elt,url) { 304 // remove all details's elt 305 var parentElt = elt.parentNode; 306 for (var i=1;i<phpmvRowsArray[url].length;i++) { 307 if (phpmvRowsArray[url][i].parentNode != null) { 308 //if (phpmvRowsArray[url][i].attributes.getNamedItem('id')) { // with row's datails (visible or hidden) 309 if (phpmvRowsArray[url][i].getAttribute('id') != '' && phpmvRowsArray[url][i].getAttribute('id') != null) { // with row's datails (visible or hidden) 310 // test if img is collapse 311 var myImgExpandCollapse = phpmvRowsArray[url][i].getElementsByTagName("td")[0].getElementsByTagName("img"); 312 if (myImgExpandCollapse.length > 0) { 313 exp = new RegExp(/(.*)(switch[a-b])(\..*)/); 314 var tabElt = exp.exec(myImgExpandCollapse[0].getAttribute('src')); 315 if (tabElt != null) { 316 if (tabElt[2]=='switchb') setAttributeDom(myImgExpandCollapse[0],'src',tabElt[1]+'switcha'+tabElt[3]); 317 } 318 } 319 var exp = /.*(\(this,')(.*)('\)).*/; 320 //var curURL = exp.exec(phpmvRowsArray[url][i].attributes.getNamedItem('onclick').value); 321 var curURL = exp.exec(phpmvRowsArray[url][i].getAttribute('onclick')); 322 if (curURL != null) curURL = curURL[2]; 323 removeDetails(phpmvRowsArray[url][i],curURL); 324 } 325 parentElt.removeChild(phpmvRowsArray[url][i]); 326 } 327 } 328 } 329 function displayInterest( curElt ) { 330 // display complet table for more information 331 exp = new RegExp(/(.*<span>)(.*)(<\/span>.*)/i); 332 var tabElt = exp.exec(curElt.innerHTML); 333 switchStr = (tabElt[2]=='+') ? '-':'+'; 334 curElt.innerHTML = tabElt[1] + switchStr + tabElt[3]; // switch '+' and '-' when expand/collapse 335 var tmpElt = curElt.nextSibling; 336 while (tmpElt.tagName != 'DIV') { 337 tmpElt = tmpElt.nextSibling; 338 } 339 if (tmpElt.style.display == 'block') tmpElt.style.display = 'none'; 340 else tmpElt.style.display = 'block'; 341 } 342 343 function changeDetails(curElt,url) { 344 // load complete content with cache 345 var tmpElt = curElt.parentNode; 346 while (tmpElt.tagName != 'DIV') { 347 tmpElt = tmpElt.parentNode; 348 } 349 if (phpmvRowsArray[url] == undefined) { 350 curElt.parentNode.innerHTML = 'Loading...'; 351 var xmlhttp = getHTTPObject(tmpElt,url,'html'); 352 xmlhttp.open("GET",url,true); 353 xmlhttp.send( null ); 354 } else { 355 tmpElt.innerHTML = phpmvRowsArray[url]; 356 } 357 } 358 359 function removeOldRows(tmpElt,url) { 360 var curTable = tmpElt.parentNode; 361 var myTmpRow; 362 var myTmpElt = tmpElt; 363 while (!attributeExist(myTmpElt,'id') && !attributeExist(myTmpElt,'onclick')) { // search for parent rows wich contain link 364 myTmpRow = myTmpElt; 365 myTmpElt = myTmpElt.previousSibling; 366 curTable.removeChild(myTmpRow); 367 if (myTmpElt == null) { 368 break; 369 } 370 } 371 exp = new RegExp(/(.*')(.*)('.*)/); 372 var tabElt = exp.exec(myTmpElt.getAttribute('onclick')); 373 if (myTmpElt.onclick != null) { 374 //setAttributeDom(tmpElt,'onclick','javascript:alert('+tabElt[1]+url+tabElt[2]+')'); 375 if (url != tabElt[2]) { 376 setAttributeDom(tmpElt,'onclick',tabElt[1]+url+tabElt[3]); 377 } 378 } 379 return myTmpElt; 380 } 381 function setAttributeDom(myElt,attributeName,attributeValue) { 382 var testWithOnlyOneCharacter = 'test'+attributeValue; // indexOf don't work with only 1 character :-( 383 if (attributeName == 'colspan' && testWithOnlyOneCharacter.indexOf(' ') != -1) { 384 attributeValue = attributeValue.substring(attributeValue.lastIndexOf(' '),attributeValue.length); 385 } 386 z = document.createAttribute(attributeName); 387 z.value = attributeValue; 388 //SS 389 myElt.setAttributeNode(z); 390 myElt.setAttribute(attributeName,attributeValue); 391 if (attributeName=='onclick') { 392 myElt.onclick = function() { eval(attributeValue) } 393 } 394 } 395 function attributeExist(myElt,attrName) { 396 // test if an element has the specified attribute, because hasAttribute DOM's function is buggy 397 if (myElt.getAttributeNode(attrName) != null) { 398 if (myElt.getAttributeNode(attrName).value == 'null' || myElt.getAttributeNode(attrName).value == '') { //saloperie d'IE ! 399 return false; 400 } else { 401 return true; 402 } 403 } else { 404 return false; 405 } 406 } 407 // Ajout CMI 408 409 function inverseSpan( cur ) { 410 if(cur.innerHTML == ' - ') 411 cur.innerHTML = ' + '; 412 else 413 cur.innerHTML = ' - '; 414 } 415 function getDisplay( i ) 416 { 417 d = i.style.display; 418 if(d == 'none') return 'none'; 419 else return ''; 420 } 421 function inverseDisplay( i ) 422 { 423 if(getDisplay(i)=='') 424 { 425 newD = 'none'; 426 returned = false; 427 } 428 else 429 { 430 newD = ''; 431 returned = true; 432 } 433 setDisplay(i, newD); 434 return returned; 435 } 436 function setDisplay(i, d) 437 { 438 i.style.display = d; 439 } 440 function findFirstChildWithType( targetNode, type ) 441 { 442 for(var i = 0; i < targetNode.childNodes.length; i++) 443 { 444 var child = targetNode.childNodes[i]; 445 if (child.nodeName == type ) 446 return child; 447 } 448 return false; 449 } 450 function pointer( current ) 451 { 452 current.style.cursor = 'pointer'; 453 } 454 function loadUrl( url ) 455 { 456 window.location = url; 457 } 458 function hideIt(current) 459 { 460 inverseDisplay(current); 461 } 462 function displayVariables( cur ) 463 { 464 hideIt( findFirstChildWithType( cur, 'DIV') ); 465 466 spanToInverse = findFirstChildWithType( cur, 'SPAN'); 467 inverseSpan( spanToInverse ); 468 469 }
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 |
![]() |