var wysiwygchecklist=new Array(); function getIFrameDocument(aID) { var rv=null; if(document.getElementById(aID) && document.getElementById(aID).contentDocument) { rv=document.getElementById(aID).contentDocument; } else if(document.frames) { rv=document.frames[aID].document; } return rv; } function boutons(textarea,menu,nom,fonction,valeurs,traduction) { var elt = document.createElement("SELECT"); elt.setAttribute("style","font-size:10px; border:1px solid black;margin:-5px 2px 0px 2px;"); var opt = document.createElement("OPTION"); opt.innerHTML=nom; elt.appendChild(opt); for (var tmp in valeurs) { var opt = document.createElement("OPTION"); opt.value=valeurs[tmp]; if(traduction && traduction[tmp]) { opt.innerHTML=traduction[tmp]; } else { opt.innerHTML=valeurs[tmp]; } elt.appendChild(opt); } elt.onchange= function() { modiftext(textarea,fonction,elt.options[this.selectedIndex].value); this.selectedIndex=0; } menu.appendChild(elt); } function applyall() { for (var i in wysiwygchecklist) { apply(wysiwygchecklist[i]); } } function apply(textarea) { doc=getIFrameDocument(textarea.id); textarea.value=doc.body.innerHTML; } function bouton(textarea,menu,nom,fonction,valeur) { var elt = document.createElement("IMG"); elt.alt=nom; elt.src="/images/editor/"+fonction+".gif"; if(fonction=="createlink") { elt.onclick= function() { url=prompt("Entrez l'url"); modiftext(textarea,fonction,url); } } else { elt.onclick= function() { modiftext(textarea,fonction,valeur); } } menu.appendChild(elt); } function wysiwyg(textareaid,submitid) { if(document.getElementById(textareaid)) { // Creation du iframe textarea=document.getElementById(textareaid); aheight=textarea.offsetHeight; awidth=textarea.offsetWidth; //aleft=textarea.offsetLeft; //atop=textarea.offsetTop; aleft=textarea.offsetParent.offsetLeft; atop=textarea.offsetParent.offsetTop; // Efface la textarea mais garde la place conteneur =textarea.parentNode; conteneur.setAttribute("style","display:block;height:"+(aheight+40)+"px; width:30px;"); conteneur.setAttribute("height",(aheight+40)+"px"); textarea.style.display="none"; // Creation de la barre de menu menu = document.createElement("DIV"); if(document.frames) { menu.style.fontsize="30px"; } else { menu.setAttribute('style','text-align:left;border:1px solid black; width:'+awidth+'px; height:20px; background-color:#bbb;padding:0px 5px;'); } conteneur.appendChild(menu); var iframe = document.createElement("iframe"); // Creation des boutons boutons(textarea,menu,"Block","formatblock", Array("h3", "h4", "h5", "p", "blockquote"), Array("Titre 1","Titre 2","Titre 3","Paragraphe","Citation")); bouton(textarea,menu,"B","bold"); bouton(textarea,menu,"I","italic"); bouton(textarea,menu,"S","underline"); boutons(textarea,menu,"Police","fontname",Array("Arial","Verdana","Times New Roman","Courrier","terminal","Sans-serif")); boutons(textarea,menu,"Taille","fontsize",Array("1","2","3","4","5","6","7")); boutons(textarea,menu,"Couleur","forecolor", Array("white","black","red", "blue","purple","yellow"), Array("blanc","noir" ,"rouge","bleu","violet","jaune")); bouton(textarea,menu,"<-","justifyleft"); bouton(textarea,menu,"<->","justifycenter"); bouton(textarea,menu,"->","justifyright"); bouton(textarea,menu,"Liste ordonee","insertorderedlist"); bouton(textarea,menu,"Liste non-ordonee","insertunorderedlist"); bouton(textarea,menu,"Créer un lien","createlink"); // Creation de l'iframe saut= document.createElement("br"); menu.appendChild(saut); iframe.setAttribute("id",textareaid); menu.appendChild(iframe); design=getIFrameDocument(textareaid); iframe=document.getElementById(textareaid); design.designMode="on"; design.open(); content = ""; if(textarea.value != "" && textarea.value!="[object]") { content=textarea.value; var reg=new RegExp("[\r\n]+","g"); content=content.replace(reg,"truc
"); } design.write(""+content+""); design.close(); iframe.setAttribute('style','background-color:white;width:'+awidth+'px;height:'+aheight+'px;border:1px solid black'); design.execCommand("usecss",false,null); apply(textarea); if(submitid && document.getElementById(submitid)) { wysiwygchecklist.push(textarea); document.getElementById(submitid).onclick = function() { applyall(); } } } } function modiftext(textarea,x,y) { design=getIFrameDocument(textarea.id); if(design) { design.execCommand(x,false,y); } }