Listing du fichier exemple2.js
00001// (gH) -_- testdom.js ; TimeStamp (unix) : 16 Juin 2009 vers 14:44
00002
00003 // ###############################################################
00004
00005 function reset_infos() {
00006
00007 // ###############################################################
00008
00009 document.getElementById("infos").value = ""
00010
00011 return(false)
00012
00013 } // fin de fonction reset_infos
00014
00015 // ###############################################################
00016
00017 function ecrit_infos(mesTxt) {
00018
00019 // ###############################################################
00020
00021 document.getElementById("infos").value += mesTxt + "\n" ;
00022
00023 return(false)
00024
00025 } // fin de fonction ecrit_infos
00026
00027 // ###############################################################
00028
00029 function ecrit_infos_sansrc(mesTxt) {
00030
00031 // ###############################################################
00032
00033 document.getElementById("infos").value += mesTxt ;
00034
00035 return(false)
00036
00037 } // fin de fonction ecrit_infos_sansrc
00038
00039 // ###############################################################
00040
00041 function analyse_cellule() {
00042
00043 // ###############################################################
00044
00045 tv = document.getElementById("ventes") // tableau des ventes
00046 msg = "-- Analyse d'une cellule\n"
00047 ecrit_infos(msg) ;
00048
00049 // ---------------------------------------------------------
00050
00051 lig = document.getElementById("ligne").value ;
00052
00053 tdl = typeof(lig)
00054 if (tdl=="undefined") {
00055 msg = "Il n'y a rien dans le champ correspondant au numéro de ligne "
00056 ecrit_infos(msg)
00057 return(false)
00058 } //
00059
00060 msg = "Numéro de ligne transmis : \""+lig+"\" typé en "+tdl
00061 ecrit_infos(msg)
00062
00063 ilig = parseInt(lig,10)
00064 tdi = typeof(ilig)
00065
00066 if (isNaN(ilig)) {
00067 msg = "Cette valeur ne correspond pas à un nombre entier"
00068 ecrit_infos(msg)
00069 return(false)
00070 } ; // fin de si
00071
00072 msg = "après conversion en entier, ce numéro vaut : "+ilig+" typé en "+tdi
00073 ecrit_infos(msg)
00074
00075 idlig = ilig - 1
00076
00077 msg = "indice de ligne interne : "+idlig
00078 ecrit_infos(msg)
00079
00080 // on teste s'il déborde
00081
00082 leslignes = tv.getElementsByTagName("tr")
00083 nblig = leslignes.length
00084
00085 if (idlig>nblig-1) {
00086 msg = "Il n'y a que "+nblig+" ligne(s). L'indice "+idlig+" est donc incorrect."
00087 ecrit_infos(msg)
00088 return(false)
00089 } ; // fin de si
00090
00091 if (idlig<0) {
00092 msg = "Le premier indice possible en interne est 0. L'indice "+idlig+" est donc incorrect."
00093 ecrit_infos(msg)
00094 return(false)
00095 } ; // fin de si
00096
00097 ecrit_infos("")
00098
00099 // ---------------------------------------------------------
00100
00101 col = document.getElementById("colonne").value ;
00102 tdc = typeof(col)
00103 if (tdc=="undefined") {
00104 msg = "Il n'y a rien dans le champ correspondant au numéro de colonne "
00105 ecrit_infos(msg)
00106 return(false)
00107 } //
00108
00109 msg = "Numéro de colonne transmis : \""+col+"\" typé en "+tdc
00110 ecrit_infos(msg)
00111
00112 jcol = parseInt(col,10)
00113 tdj = typeof(jcol)
00114
00115 if (isNaN(jcol)) {
00116 msg = "Cette valeur ne correspond pas à un nombre entier"
00117 ecrit_infos(msg)
00118 return(false)
00119 } ; // fin de si
00120
00121 msg = "après conversion en entier, ce numéro vaut : "+jcol+" typé en "+tdj
00122 ecrit_infos(msg)
00123
00124 jdcol = jcol - 1
00125
00126 msg = "indice de colonne interne : "+jdcol
00127 ecrit_infos(msg)
00128
00129 // on teste s'il déborde
00130
00131 if (jdcol<0) {
00132 msg = "Le premier indice possible en interne est 0. L'indice "+jdcol+" est donc incorrect."
00133 ecrit_infos(msg)
00134 return(false)
00135 } ; // fin de si
00136
00137 maligne = leslignes[idlig]
00138 mescolonnes = maligne.getElementsByTagName("td")
00139
00140 nbcol = mescolonnes.length
00141
00142 // c'est peut-etre du th
00143
00144 if (nbcol==0) {
00145 mescolonnes = maligne.getElementsByTagName("th")
00146 if (mescolonnes) { nbcol = mescolonnes.length }
00147 } ; // fin de si
00148
00149
00150 if (jdcol>nbcol-1) {
00151 msg = "Pour cette ligne, il n'y a que "+nbcol+" colonnne(s). L'indice "+jdcol+" est donc incorrect."
00152 ecrit_infos(msg)
00153 return(false)
00154 } ; // fin de si
00155
00156 // ---------------------------------------------------------
00157
00158 maCase = maligne.cells[jdcol]
00159 msg = "La cellule est, en interne "+maCase // HTMLTableCellElement
00160 ecrit_infos(msg)
00161
00162 // pas de nodeValue
00163 // msg = "En tant que noeud, elle vaut "+maCase.nodeValue
00164 // ecrit_infos(msg)
00165
00166 modet = document.getElementById("modet")
00167 // modet est object HTMLInputElement]
00168
00169 if (modet.checked) {
00170 msg = "\nAffichage en mode texte\n"
00171 ecrit_infos(msg)
00172 msg = sousArbreDom(maCase)
00173 ecrit_infos(msg)
00174 msg = "\n -- fin d'affichage en mode texte"
00175 } // fin si mode texte
00176
00177 modea = document.getElementById("modea")
00178
00179 if (modea.checked) {
00180 msg = "\nAffichage en mode arbre\n"
00181 ecrit_infos(msg)
00182 sousArbreDomGraphique(maCase,1,1)
00183 msg = "\n -- fin d'affichage en mode arbre"
00184 } // fin si mode texte
00185
00186 // ---------------------------------------------------------
00187
00188 msg = "\nFin de l'analyse de la cellule"
00189 ecrit_infos(msg) ;
00190
00191 } // fin de fonction analyse_cellule
00192
00193 // ###############################################################
00194
00195 function modifie(nature) {
00196
00197 // ###############################################################
00198
00199 /* récupération des valeurs */
00200
00201 ilig = document.getElementById("ligne").value ;
00202 jcol = document.getElementById("colonne").value ;
00203
00204 msg = "Tentative de modification de la case " ;
00205 msg += "en ligne "+ilig+" colonne "+jcol ;
00206 msg += " en mode "+nature+"\n"
00207 ecrit_infos(msg) ;
00208
00209 /* recherche dans le tableau */
00210
00211 nomTableau = "ventes"
00212 leTableau = document.getElementById(nomTableau)
00213 lesLignes = leTableau.getElementsByTagName("tr")
00214 // oui mais les indices commencent à 0
00215 ilig_1 = ilig-1
00216 jcol_1 = jcol-1
00217 maLigne = lesLignes[ilig_1]
00218 mesColonnes = maLigne.getElementsByTagName("td")
00219 maCase = mesColonnes[jcol_1]
00220
00221 msg = "son contenu en TD était *"
00222 msg += sousArbreDom(maCase)
00223 msg += "*"
00224 ecrit_infos(msg) ;
00225
00226 maCase = maLigne.cells[jcol_1]
00227 msg = "sa nature était *"
00228 msg += maCase
00229 msg += "*"
00230 ecrit_infos(msg) ;
00231
00232
00233 msg = "son nombre d'enfants "
00234 nbe = maCase.childNodes.length
00235 msg += nbe
00236 ecrit_infos(msg) ;
00237
00238 msg = "le type de son premier enfant est "
00239 tdpe = maCase.childNodes[0].nodeType
00240 msg += tdpe
00241 ecrit_infos(msg) ;
00242
00243 msg = "description de son parent (balise <td>) :"
00244 atd = maCase.attributes
00245 for (ida=0;ida<atd.length;ida++) {
00246 msg += " Attribut "+(1+ida)+" : "
00247 msg += atd[ida].name + " ==> "
00248 msg += atd[ida].value
00249 // maCase.removeAttribute(atd[ida].name)
00250 } // fin pour
00251 ecrit_infos(msg) ;
00252
00253
00254 if (nature=="txt") {
00255
00256 nouveauTexte = document.getElementById("nvt").value
00257 msg = "\non remplace le contenu par : \""+nouveauTexte+"\""
00258 ecrit_infos(msg) ;
00259
00260 if ((tdpe==3) && (nbe==1)) { // remplacement simple d'un noeud texte
00261 // ok pour document.getElementById(nomTableau).getElementsByTagName("tr")[ilig_1].
00262 // getElementsByTagName("td")[jcol_1].childNodes[0].nodeValue = nouveauTexte
00263 maCase.childNodes[0].nodeValue = nouveauTexte
00264 } else {
00265 while (maCase.firstChild) {
00266 maCase.removeChild(maCase.firstChild)
00267 } // fin de tant que
00268 nouvelElement = document.createTextNode(nouveauTexte)
00269 maCase.appendChild(nouvelElement)
00270 } // fin de si
00271
00272 /* remarque : le texte suivant marche tout aussi bien :
00273
00274 maCase.innerHTML = nouveauTexte
00275
00276 */
00277
00278 } // fin de si
00279
00280 ecrit_infos("et voilà !") ;
00281
00282 if (nature=="html") {
00283 nouveauHtml = document.getElementById("nvh").value
00284 msg = "\non remplace le contenu par : \""+nouveauHtml+"\""
00285 ecrit_infos(msg) ;
00286
00287 maCase.innerHTML = nouveauHtml
00288 } // fin de si
00289 ecrit_infos("et voilà !") ;
00290
00291 return( false )
00292
00293 } // fin de fonction modifie
00294
00295 // ###############################################################
00296
00297 function clones() {
00298
00299 // ###############################################################
00300
00301 // on clone le tableau original
00302
00303 cloneV = document.getElementById("ventes").cloneNode(true)
00304
00305 } // fin de fonction clones
00306
00307 // ###############################################################
00308
00309 function taborg() {
00310
00311 // ###############################################################
00312
00313 attri = 0
00314 finMsg = " (sans attributs)"
00315 if (document.getElementById("retr_tn").checked) { attri = 0 }
00316 if (document.getElementById("retr_to").checked) { attri = 1 }
00317 if (attri==1) { finMsg = " (avec attributs)" }
00318
00319 msg = "Retour au tableau original "+finMsg+" sans recharger la page.\n"
00320 ecrit_infos(msg) ;
00321
00322 lesTr = document.getElementById("ventes").getElementsByTagName("tr")
00323 ancTr = cloneV.getElementsByTagName("tr")
00324 msg = "Il y a "+lesTr.length+" lignes à remettre."
00325 ecrit_infos(msg) ;
00326 idl = 0 ;
00327 while (idl<lesTr.length) {
00328 msg = " restauration de la ligne "+idl
00329 // ecrit_infos(msg) ;
00330 laLig = lesTr[idl]
00331 vxLig = ancTr[idl]
00332 nbCol = laLig.cells.length
00333 // on fait l'impasse sur les attributs de <tr> ?
00334 jdc = 0
00335 while (jdc<nbCol) {
00336 if (attri==0) { // sans attribut de cellule
00337 aval = laLig.cells[jdc].innerHTML
00338 nval = sousArbreDom(vxLig.cells[jdc],1,0)
00339 // il faut enlver td ou th
00340 nval = nval.replace(/<td>/,"")
00341 nval = nval.replace(/<\/td>/,"")
00342 nval = nval.replace(/<th>/,"")
00343 nval = nval.replace(/<\/th>/,"")
00344 msg = " en colonne "+jdc+" à la place de "+aval+" on met "+nval
00345 // if (jdc<=1) { ecrit_infos(msg) ; }
00346 laLig.cells[jdc].innerHTML = nval
00347 } else { // avec attributs
00348 aval = laLig.cells[jdc].innerHTML
00349 nval = vxLig.cells[jdc].innerHTML
00350 msg = " en colonne "+jdc+" à la place de "+aval+" on met "+nval
00351 // ecrit_infos(msg) ;
00352 laLig.cells[jdc].innerHTML = vxLig.cells[jdc].innerHTML
00353 // passons aux attributs du parent (<td>)
00354 leTd = laLig.cells[jdc]
00355 vxTd = vxLig.cells[jdc]
00356 vtd = vxTd.attributes
00357 nba = vtd.length
00358 if (nba>0) {
00359 msg = " "+nba+" anciens attributs "
00360 // ecrit_infos(msg) ;
00361 for (ida=0;ida<vtd.length;ida++) {
00362 msg = " ancien attribut numéro "+ida+" nom = "+vtd[ida].name+" valeur = "+vtd[ida].value
00363 // ecrit_infos(msg) ;
00364 leTd.setAttribute(vtd[ida].name,vtd[ida].value)
00365 } // fin pour ida
00366 } // fin si
00367 } // fin de si
00368 jdc++
00369 } // fin de tant que
00370
00371 idl++
00372 } // fin de tant que
00373 msg = "Et voilà."
00374 ecrit_infos(msg) ;
00375
00376 return( false )
00377
00378 } // fin de fonction taborg
00379
00380 // ###############################################################
00381
00382 function nocolor4tds() {
00383
00384 // ###############################################################
00385
00386 lesTr = document.getElementById("ventes").getElementsByTagName("tr")
00387 msg = "Suppression des couleurs de case..."
00388 ecrit_infos(msg) ;
00389 idl = 0 ;
00390
00391 pom = document.getElementById("pomme") ;
00392 //pom.setAttribute(class,"vide") ;
00393 //pom.setAttribute(className,"vide") ;
00394 pom.className = "vide" ; // pour IE
00395
00396 // pour chaque ligne ("<tr>") du tableau
00397
00398 while (idl<lesTr.length) {
00399
00400 // suppression des attributs pour la cellule
00401
00402 laLig = lesTr[idl]
00403 nbCol = laLig.cells.length
00404 jdc = 0
00405 while (jdc<nbCol) {
00406 maCase = laLig.cells[jdc]
00407 atd = maCase.attributes
00408 for (ida=0;ida<atd.length;ida++) {
00409 maCase.className = "vide"
00410 maCase.removeAttribute(atd[ida].name)
00411 } // fin pour
00412 jdc++
00413 } // fin de tant que
00414
00415 // suppression des attributs pour l'élément
00416
00417 lesTd = laLig.getElementsByTagName("td")
00418 nbTd = lesTd.length
00419 jdc = 0
00420 while (jdc<nbTd) {
00421 leTd = lesTd[jdc]
00422 // leTd.setAttribute(class,"vide")
00423 // leTd.setAttribute(className,"vide")
00424 atd = leTd.attributes
00425 for (ida=0;ida<atd.length;ida++) {
00426 leTd.className = "vide" // pour IE
00427 leTd.removeAttribute(atd[ida].name)
00428 } // fin pour
00429 jdc++
00430 } // fin de tant que
00431
00432 // on passe à la ligne suivante
00433 idl++
00434 } // fin de tant que
00435 msg = "Terminée (remarque : on n'a pas supprimé les couleurs \"internes\")."
00436 ecrit_infos(msg) ;
00437
00438 return( false )
00439
00440 } // fin de fonction nocolor4tds
00441
00442 // ###############################################################
00443
00444 function description_l2() {
00445
00446 // ###############################################################
00447
00448 attri = 0
00449 finMsg = " (sans attributs)"
00450 if (document.getElementById("attr_tn").checked) { attri = 0 }
00451 if (document.getElementById("attr_to").checked) { attri = 1 }
00452 if (attri==1) { finMsg = " (avec attributs)" }
00453
00454 numligsel = document.getElementById("numligsel")
00455 numlig = numligsel.selectedIndex
00456
00457 msg = "Description du tableau ventes, ligne "+(1+numlig)+finMsg+"\n"
00458 ecrit_infos(msg) ;
00459 ecrit_infos(sousArbreDom(document.getElementById("ventes").getElementsByTagName("tr")[numlig],1,attri))
00460 ecrit_infos("") ;
00461
00462
00463 // ###############################################################
00464
00465 } // fin de fonction description_l2
00466
00467 // ###############################################################
00468
00469 function arbre_l2() {
00470
00471 // ###############################################################
00472
00473 attri = 0
00474 finMsg = " (sans attributs)"
00475 if (document.getElementById("attr_tn").checked) { attri = 0 }
00476 if (document.getElementById("attr_to").checked) { attri = 1 }
00477 if (attri==1) { finMsg = " (avec attributs)" }
00478
00479 numligsel = document.getElementById("numligsel")
00480 numlig = numligsel.selectedIndex
00481
00482 msg = "Arbre du tableau ventes, ligne "+(1+numlig)+finMsg+"\n"
00483 ecrit_infos(msg) ;
00484 depart = document.getElementById("ventes").getElementsByTagName("tr")[numlig]
00485 sousArbreDomGraphique(depart,1,attri)
00486 ecrit_infos("") ;
00487
00488 } // fin de fonction arbre_l2
00489
00490 // ###############################################################
00491
00492 function ajouteBoutonsDeTri(sens) { // sens ="ligne" ou "colonne"
00493
00494 // ###############################################################
00495
00496 tvn = document.getElementById("ventes").className
00497
00498 msg = "la classe du tableau ventes était " + tvn + " sens demandé : " + sens
00499 ecrit_infos(msg) ;
00500
00501 // on ajoute la classe qu'il faut si elle n'était pas déjà présente
00502
00503 if (sens=="ligne") {
00504 if (tvn.indexOf("triLig") == -1) { tvn += " triLig" }
00505 // if (tvn.indexOf("triCol") != -1) { tvn = tvn.replace(" triCol","") }
00506 } else {
00507 if (tvn.indexOf("triCol") == -1) { tvn += " triCol" }
00508 // if (tvn.indexOf("triLig") != -1) { tvn = tvn.replace(" triLig","") }
00509 } // fin de si
00510
00511 msg = "elle devient " + tvn
00512 ecrit_infos(msg) ;
00513
00514 document.getElementById("ventes").className =tvn
00515
00516 initialisationDesTableaux()
00517
00518 } // fin de fonction ajouteBoutonsDeTri
00519
00520 // ###############################################################
00521
00522 function suppressionDesBoutonsDeTri() {
00523
00524 // ###############################################################
00525
00526 txt = "th><span onclick='tri_lig(this, 0);return false;' class='sortheader'>"
00527 txt += "<span senstri='d' class='triLig'><input type='button' value='d' class='vert_clair'></input></span>"
00528 txt += "<span class='gbleuf'>Mois</span>Bien joué !</span></th>"
00529 msg = "\nAU DEPART, ON A : "+txt
00530 ecrit_infos(msg) ;
00531 tabTxt = txt.split(/</)
00532 debTxt = ""
00533 finTxt = ""
00534 lonTab = tabTxt.length
00535
00536 for (ide=0;ide<lonTab;ide++) {
00537 ok = 1
00538 nelt = "<" + tabTxt[ide]
00539 msg = " indice "+ide+" elt = " + nelt
00540 ecrit_infos(msg) ;
00541 } // fin pour ide
00542 msg = ""
00543 ecrit_infos(msg) ;
00544
00545 for (ide=0;ide<(lonTab/2)+1;ide++) {
00546 ok = 1
00547 nelt = "<" + tabTxt[ide]
00548 msg = " indice "+ide+" elt = " + nelt
00549 ecrit_infos(msg) ;
00550 deb = nelt
00551 fin = "<"+tabTxt[lonTab-ide-1]
00552 trans = 0
00553 if (nelt.indexOf("<span onclick='tri_")>-1) { trans = 1 }
00554 if (nelt.indexOf("<span senstri")>-1) { trans = 1 }
00555 if (trans==1) {
00556 // on doit virre la balise d'ouverture et la partie </span> correspondante
00557 // dans la balise de fermeture
00558 deb = ""
00559 fin = fin.replace(/<\/span>/,"")
00560 } // fin si
00561 debTxt = debTxt + deb
00562 finTxt = fin + finTxt
00563 msg = " ICI deb = "+deb+" et fin = "+fin + "\n"
00564 ecrit_infos(msg) ;
00565 } // fin pour ide
00566 newtxt = debTxt + finTxt
00567
00568 msg = "\nAU FINAL, ON A : "+newTxt
00569 ecrit_infos(msg) ;
00570 return(false)
00571
00572 // ----------------------------------------------
00573
00574 tvn = document.getElementById("ventes").className
00575
00576 msg = "la classe du tableau ventes était " + tvn
00577 ecrit_infos(msg) ;
00578
00579 tvn = tvn.replace(" triCol","")
00580 tvn = tvn.replace(" triLig","")
00581 tvn = tvn.replace(" triTab","")
00582
00583 msg = "elle devient " + tvn
00584 ecrit_infos(msg) ;
00585
00586 document.getElementById("ventes").className =tvn
00587
00588 // cela ne suffit pas car
00589 // initialisationDesTableaux()
00590 // ajoute les flèches, mais ne les retire pas
00591
00592 // on passe en revue : toute la ligne numéro 1 (indice 0)
00593 // et toutes les colonnes numéro 1 (indice 0) des autres lignes
00594
00595 lesTh = document.getElementById("ventes").getElementsByTagName("th")
00596 nbTh = lesTh.length
00597 idTh = 0
00598 while (idTh<nbTh) {
00599 elt = lesTh[idTh]
00600 msg = "- pour le th d'indice "+idTh
00601 ecrit_infos(msg) ;
00602 cnt = sousArbreDom(elt,1,1)
00603 msg = "il y a : "+cnt
00604 ecrit_infos(msg) ;
00605 msg = " si on enlève les span de tri, il reste : "
00606 ecrit_infos(msg) ;
00607 newCnt = "?"
00608 msg = newCnt
00609 elt.innerHTML = newCnt
00610 idTh++
00611 } // fin tant que
00612
00613
00614 lesTr = document.getElementById("ventes").getElementsByTagName("tr")
00615
00616
00617 } // fin de fonction suppressionDesBoutonsDeTri
00618
00619 // ###############################################################
Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.
Retour à la page principale de (gH)