// (gH) -_- testdom.js ; TimeStamp (unix) : 16 Juin 2009 vers 14:44
// ###############################################################
function reset_infos() {
// ###############################################################
document.getElementById("infos").value = ""
return(false)
} // fin de fonction reset_infos
// ###############################################################
function ecrit_infos(mesTxt) {
// ###############################################################
document.getElementById("infos").value += mesTxt + "\n" ;
return(false)
} // fin de fonction ecrit_infos
// ###############################################################
function ecrit_infos_sansrc(mesTxt) {
// ###############################################################
document.getElementById("infos").value += mesTxt ;
return(false)
} // fin de fonction ecrit_infos_sansrc
// ###############################################################
function analyse_cellule() {
// ###############################################################
tv = document.getElementById("ventes") // tableau des ventes
msg = "-- Analyse d'une cellule\n"
ecrit_infos(msg) ;
// ---------------------------------------------------------
lig = document.getElementById("ligne").value ;
tdl = typeof(lig)
if (tdl=="undefined") {
msg = "Il n'y a rien dans le champ correspondant au numéro de ligne "
ecrit_infos(msg)
return(false)
} //
msg = "Numéro de ligne transmis : \""+lig+"\" typé en "+tdl
ecrit_infos(msg)
ilig = parseInt(lig,10)
tdi = typeof(ilig)
if (isNaN(ilig)) {
msg = "Cette valeur ne correspond pas à un nombre entier"
ecrit_infos(msg)
return(false)
} ; // fin de si
msg = "après conversion en entier, ce numéro vaut : "+ilig+" typé en "+tdi
ecrit_infos(msg)
idlig = ilig - 1
msg = "indice de ligne interne : "+idlig
ecrit_infos(msg)
// on teste s'il déborde
leslignes = tv.getElementsByTagName("tr")
nblig = leslignes.length
if (idlig>nblig-1) {
msg = "Il n'y a que "+nblig+" ligne(s). L'indice "+idlig+" est donc incorrect."
ecrit_infos(msg)
return(false)
} ; // fin de si
if (idlig<0) {
msg = "Le premier indice possible en interne est 0. L'indice "+idlig+" est donc incorrect."
ecrit_infos(msg)
return(false)
} ; // fin de si
ecrit_infos("")
// ---------------------------------------------------------
col = document.getElementById("colonne").value ;
tdc = typeof(col)
if (tdc=="undefined") {
msg = "Il n'y a rien dans le champ correspondant au numéro de colonne "
ecrit_infos(msg)
return(false)
} //
msg = "Numéro de colonne transmis : \""+col+"\" typé en "+tdc
ecrit_infos(msg)
jcol = parseInt(col,10)
tdj = typeof(jcol)
if (isNaN(jcol)) {
msg = "Cette valeur ne correspond pas à un nombre entier"
ecrit_infos(msg)
return(false)
} ; // fin de si
msg = "après conversion en entier, ce numéro vaut : "+jcol+" typé en "+tdj
ecrit_infos(msg)
jdcol = jcol - 1
msg = "indice de colonne interne : "+jdcol
ecrit_infos(msg)
// on teste s'il déborde
if (jdcol<0) {
msg = "Le premier indice possible en interne est 0. L'indice "+jdcol+" est donc incorrect."
ecrit_infos(msg)
return(false)
} ; // fin de si
maligne = leslignes[idlig]
mescolonnes = maligne.getElementsByTagName("td")
nbcol = mescolonnes.length
// c'est peut-etre du th
if (nbcol==0) {
mescolonnes = maligne.getElementsByTagName("th")
if (mescolonnes) { nbcol = mescolonnes.length }
} ; // fin de si
if (jdcol>nbcol-1) {
msg = "Pour cette ligne, il n'y a que "+nbcol+" colonnne(s). L'indice "+jdcol+" est donc incorrect."
ecrit_infos(msg)
return(false)
} ; // fin de si
// ---------------------------------------------------------
maCase = maligne.cells[jdcol]
msg = "La cellule est, en interne "+maCase // HTMLTableCellElement
ecrit_infos(msg)
// pas de nodeValue
// msg = "En tant que noeud, elle vaut "+maCase.nodeValue
// ecrit_infos(msg)
modet = document.getElementById("modet")
// modet est object HTMLInputElement]
if (modet.checked) {
msg = "\nAffichage en mode texte\n"
ecrit_infos(msg)
msg = sousArbreDom(maCase)
ecrit_infos(msg)
msg = "\n -- fin d'affichage en mode texte"
} // fin si mode texte
modea = document.getElementById("modea")
if (modea.checked) {
msg = "\nAffichage en mode arbre\n"
ecrit_infos(msg)
sousArbreDomGraphique(maCase,1,1)
msg = "\n -- fin d'affichage en mode arbre"
} // fin si mode texte
// ---------------------------------------------------------
msg = "\nFin de l'analyse de la cellule"
ecrit_infos(msg) ;
} // fin de fonction analyse_cellule
// ###############################################################
function modifie(nature) {
// ###############################################################
/* récupération des valeurs */
ilig = document.getElementById("ligne").value ;
jcol = document.getElementById("colonne").value ;
msg = "Tentative de modification de la case " ;
msg += "en ligne "+ilig+" colonne "+jcol ;
msg += " en mode "+nature+"\n"
ecrit_infos(msg) ;
/* recherche dans le tableau */
nomTableau = "ventes"
leTableau = document.getElementById(nomTableau)
lesLignes = leTableau.getElementsByTagName("tr")
// oui mais les indices commencent à 0
ilig_1 = ilig-1
jcol_1 = jcol-1
maLigne = lesLignes[ilig_1]
mesColonnes = maLigne.getElementsByTagName("td")
maCase = mesColonnes[jcol_1]
msg = "son contenu en TD était *"
msg += sousArbreDom(maCase)
msg += "*"
ecrit_infos(msg) ;
maCase = maLigne.cells[jcol_1]
msg = "sa nature était *"
msg += maCase
msg += "*"
ecrit_infos(msg) ;
msg = "son nombre d'enfants "
nbe = maCase.childNodes.length
msg += nbe
ecrit_infos(msg) ;
msg = "le type de son premier enfant est "
tdpe = maCase.childNodes[0].nodeType
msg += tdpe
ecrit_infos(msg) ;
msg = "description de son parent (balise <td>) :"
atd = maCase.attributes
for (ida=0;ida<atd.length;ida++) {
msg += " Attribut "+(1+ida)+" : "
msg += atd[ida].name + " ==> "
msg += atd[ida].value
// maCase.removeAttribute(atd[ida].name)
} // fin pour
ecrit_infos(msg) ;
if (nature=="txt") {
nouveauTexte = document.getElementById("nvt").value
msg = "\non remplace le contenu par : \""+nouveauTexte+"\""
ecrit_infos(msg) ;
if ((tdpe==3) && (nbe==1)) { // remplacement simple d'un noeud texte
// ok pour document.getElementById(nomTableau).getElementsByTagName("tr")[ilig_1].
// getElementsByTagName("td")[jcol_1].childNodes[0].nodeValue = nouveauTexte
maCase.childNodes[0].nodeValue = nouveauTexte
} else {
while (maCase.firstChild) {
maCase.removeChild(maCase.firstChild)
} // fin de tant que
nouvelElement = document.createTextNode(nouveauTexte)
maCase.appendChild(nouvelElement)
} // fin de si
/* remarque : le texte suivant marche tout aussi bien :
maCase.innerHTML = nouveauTexte
*/
} // fin de si
ecrit_infos("et voilà !") ;
if (nature=="html") {
nouveauHtml = document.getElementById("nvh").value
msg = "\non remplace le contenu par : \""+nouveauHtml+"\""
ecrit_infos(msg) ;
maCase.innerHTML = nouveauHtml
} // fin de si
ecrit_infos("et voilà !") ;
return( false )
} // fin de fonction modifie
// ###############################################################
function clones() {
// ###############################################################
// on clone le tableau original
cloneV = document.getElementById("ventes").cloneNode(true)
} // fin de fonction clones
// ###############################################################
function taborg() {
// ###############################################################
attri = 0
finMsg = " (sans attributs)"
if (document.getElementById("retr_tn").checked) { attri = 0 }
if (document.getElementById("retr_to").checked) { attri = 1 }
if (attri==1) { finMsg = " (avec attributs)" }
msg = "Retour au tableau original "+finMsg+" sans recharger la page.\n"
ecrit_infos(msg) ;
lesTr = document.getElementById("ventes").getElementsByTagName("tr")
ancTr = cloneV.getElementsByTagName("tr")
msg = "Il y a "+lesTr.length+" lignes à remettre."
ecrit_infos(msg) ;
idl = 0 ;
while (idl<lesTr.length) {
msg = " restauration de la ligne "+idl
// ecrit_infos(msg) ;
laLig = lesTr[idl]
vxLig = ancTr[idl]
nbCol = laLig.cells.length
// on fait l'impasse sur les attributs de <tr> ?
jdc = 0
while (jdc<nbCol) {
if (attri==0) { // sans attribut de cellule
aval = laLig.cells[jdc].innerHTML
nval = sousArbreDom(vxLig.cells[jdc],1,0)
// il faut enlver td ou th
nval = nval.replace(/<td>/,"")
nval = nval.replace(/<\/td>/,"")
nval = nval.replace(/<th>/,"")
nval = nval.replace(/<\/th>/,"")
msg = " en colonne "+jdc+" à la place de "+aval+" on met "+nval
// if (jdc<=1) { ecrit_infos(msg) ; }
laLig.cells[jdc].innerHTML = nval
} else { // avec attributs
aval = laLig.cells[jdc].innerHTML
nval = vxLig.cells[jdc].innerHTML
msg = " en colonne "+jdc+" à la place de "+aval+" on met "+nval
// ecrit_infos(msg) ;
laLig.cells[jdc].innerHTML = vxLig.cells[jdc].innerHTML
// passons aux attributs du parent (<td>)
leTd = laLig.cells[jdc]
vxTd = vxLig.cells[jdc]
vtd = vxTd.attributes
nba = vtd.length
if (nba>0) {
msg = " "+nba+" anciens attributs "
// ecrit_infos(msg) ;
for (ida=0;ida<vtd.length;ida++) {
msg = " ancien attribut numéro "+ida+" nom = "+vtd[ida].name+" valeur = "+vtd[ida].value
// ecrit_infos(msg) ;
leTd.setAttribute(vtd[ida].name,vtd[ida].value)
} // fin pour ida
} // fin si
} // fin de si
jdc++
} // fin de tant que
idl++
} // fin de tant que
msg = "Et voilà."
ecrit_infos(msg) ;
return( false )
} // fin de fonction taborg
// ###############################################################
function nocolor4tds() {
// ###############################################################
lesTr = document.getElementById("ventes").getElementsByTagName("tr")
msg = "Suppression des couleurs de case..."
ecrit_infos(msg) ;
idl = 0 ;
pom = document.getElementById("pomme") ;
//pom.setAttribute(class,"vide") ;
//pom.setAttribute(className,"vide") ;
pom.className = "vide" ; // pour IE
// pour chaque ligne ("<tr>") du tableau
while (idl<lesTr.length) {
// suppression des attributs pour la cellule
laLig = lesTr[idl]
nbCol = laLig.cells.length
jdc = 0
while (jdc<nbCol) {
maCase = laLig.cells[jdc]
atd = maCase.attributes
for (ida=0;ida<atd.length;ida++) {
maCase.className = "vide"
maCase.removeAttribute(atd[ida].name)
} // fin pour
jdc++
} // fin de tant que
// suppression des attributs pour l'élément
lesTd = laLig.getElementsByTagName("td")
nbTd = lesTd.length
jdc = 0
while (jdc<nbTd) {
leTd = lesTd[jdc]
// leTd.setAttribute(class,"vide")
// leTd.setAttribute(className,"vide")
atd = leTd.attributes
for (ida=0;ida<atd.length;ida++) {
leTd.className = "vide" // pour IE
leTd.removeAttribute(atd[ida].name)
} // fin pour
jdc++
} // fin de tant que
// on passe à la ligne suivante
idl++
} // fin de tant que
msg = "Terminée (remarque : on n'a pas supprimé les couleurs \"internes\")."
ecrit_infos(msg) ;
return( false )
} // fin de fonction nocolor4tds
// ###############################################################
function description_l2() {
// ###############################################################
attri = 0
finMsg = " (sans attributs)"
if (document.getElementById("attr_tn").checked) { attri = 0 }
if (document.getElementById("attr_to").checked) { attri = 1 }
if (attri==1) { finMsg = " (avec attributs)" }
numligsel = document.getElementById("numligsel")
numlig = numligsel.selectedIndex
msg = "Description du tableau ventes, ligne "+(1+numlig)+finMsg+"\n"
ecrit_infos(msg) ;
ecrit_infos(sousArbreDom(document.getElementById("ventes").getElementsByTagName("tr")[numlig],1,attri))
ecrit_infos("") ;
// ###############################################################
} // fin de fonction description_l2
// ###############################################################
function arbre_l2() {
// ###############################################################
attri = 0
finMsg = " (sans attributs)"
if (document.getElementById("attr_tn").checked) { attri = 0 }
if (document.getElementById("attr_to").checked) { attri = 1 }
if (attri==1) { finMsg = " (avec attributs)" }
numligsel = document.getElementById("numligsel")
numlig = numligsel.selectedIndex
msg = "Arbre du tableau ventes, ligne "+(1+numlig)+finMsg+"\n"
ecrit_infos(msg) ;
depart = document.getElementById("ventes").getElementsByTagName("tr")[numlig]
sousArbreDomGraphique(depart,1,attri)
ecrit_infos("") ;
} // fin de fonction arbre_l2
// ###############################################################
function ajouteBoutonsDeTri(sens) { // sens ="ligne" ou "colonne"
// ###############################################################
tvn = document.getElementById("ventes").className
msg = "la classe du tableau ventes était " + tvn + " sens demandé : " + sens
ecrit_infos(msg) ;
// on ajoute la classe qu'il faut si elle n'était pas déjà présente
if (sens=="ligne") {
if (tvn.indexOf("triLig") == -1) { tvn += " triLig" }
// if (tvn.indexOf("triCol") != -1) { tvn = tvn.replace(" triCol","") }
} else {
if (tvn.indexOf("triCol") == -1) { tvn += " triCol" }
// if (tvn.indexOf("triLig") != -1) { tvn = tvn.replace(" triLig","") }
} // fin de si
msg = "elle devient " + tvn
ecrit_infos(msg) ;
document.getElementById("ventes").className =tvn
initialisationDesTableaux()
} // fin de fonction ajouteBoutonsDeTri
// ###############################################################
function suppressionDesBoutonsDeTri() {
// ###############################################################
txt = "th><span onclick='tri_lig(this, 0);return false;' class='sortheader'>"
txt += "<span senstri='d' class='triLig'><input type='button' value='d' class='vert_clair'></input></span>"
txt += "<span class='gbleuf'>Mois</span>Bien joué !</span></th>"
msg = "\nAU DEPART, ON A : "+txt
ecrit_infos(msg) ;
tabTxt = txt.split(/</)
debTxt = ""
finTxt = ""
lonTab = tabTxt.length
for (ide=0;ide<lonTab;ide++) {
ok = 1
nelt = "<" + tabTxt[ide]
msg = " indice "+ide+" elt = " + nelt
ecrit_infos(msg) ;
} // fin pour ide
msg = ""
ecrit_infos(msg) ;
for (ide=0;ide<(lonTab/2)+1;ide++) {
ok = 1
nelt = "<" + tabTxt[ide]
msg = " indice "+ide+" elt = " + nelt
ecrit_infos(msg) ;
deb = nelt
fin = "<"+tabTxt[lonTab-ide-1]
trans = 0
if (nelt.indexOf("<span onclick='tri_")>-1) { trans = 1 }
if (nelt.indexOf("<span senstri")>-1) { trans = 1 }
if (trans==1) {
// on doit virre la balise d'ouverture et la partie </span> correspondante
// dans la balise de fermeture
deb = ""
fin = fin.replace(/<\/span>/,"")
} // fin si
debTxt = debTxt + deb
finTxt = fin + finTxt
msg = " ICI deb = "+deb+" et fin = "+fin + "\n"
ecrit_infos(msg) ;
} // fin pour ide
newtxt = debTxt + finTxt
msg = "\nAU FINAL, ON A : "+newTxt
ecrit_infos(msg) ;
return(false)
// ----------------------------------------------
tvn = document.getElementById("ventes").className
msg = "la classe du tableau ventes était " + tvn
ecrit_infos(msg) ;
tvn = tvn.replace(" triCol","")
tvn = tvn.replace(" triLig","")
tvn = tvn.replace(" triTab","")
msg = "elle devient " + tvn
ecrit_infos(msg) ;
document.getElementById("ventes").className =tvn
// cela ne suffit pas car
// initialisationDesTableaux()
// ajoute les flèches, mais ne les retire pas
// on passe en revue : toute la ligne numéro 1 (indice 0)
// et toutes les colonnes numéro 1 (indice 0) des autres lignes
lesTh = document.getElementById("ventes").getElementsByTagName("th")
nbTh = lesTh.length
idTh = 0
while (idTh<nbTh) {
elt = lesTh[idTh]
msg = "- pour le th d'indice "+idTh
ecrit_infos(msg) ;
cnt = sousArbreDom(elt,1,1)
msg = "il y a : "+cnt
ecrit_infos(msg) ;
msg = " si on enlève les span de tri, il reste : "
ecrit_infos(msg) ;
newCnt = "?"
msg = newCnt
elt.innerHTML = newCnt
idTh++
} // fin tant que
lesTr = document.getElementById("ventes").getElementsByTagName("tr")
} // fin de fonction suppressionDesBoutonsDeTri
// ###############################################################
|