1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
| <!DOCTYPE HTML >
<html lang="fr">
<head>
<!--meta charset="utf-8"-->
<title>patrick WYSIWYG html </title>
<meta http-equiv="X-UA-Compatible" content="IE=10">
<style> html {
width: 100%;
height: 100%;
}
body {
display: flex;
flex-direction: column;
box-sizing: border-box;
width: 100%;
height: 100%;
border: 1px solid black;
margin: 0;
padding: 0;
overflow: hidden;
}
#cadre_cmd {
padding: 3px;
background: linear-gradient(to right, rgba(247, 150, 50, 1) 0%, rgba(217, 237, 242, 1) 40%, rgba(150, 180, 250, 1) 100%);
border: 1px solid yellow;
min-height: 40px;
}
#divrouge {
position: relative;
flex: 1 0 auto;
font-size: 0;
border: 1px solid red;
}
#editeur {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: auto;
font-size: 18px;
border: 1px solid green;
word-break: break-all;
}
.fondbouton {
display: block;
background-color: #F2F2F2;
width: 25px;
height: 25px;
margin-left: 5px;
margin-top: 3px;
border: 1px solid black;
float: left;
border-radius: 7px;
overflow: hidden;
}
.bouton {
width: 104%;
height: 102%;
margin-left: 2px;
}
.fondbouton:hover {
border: 1px solid red;
}
#palette {
background-color: gray;
font-size=1px;
display: inline-block;
box-sizing: border-box;
position: absolute;
width: 225px;
min-height:160px;
top: 40px;
left: 5px;
padding:5px;
border: 1px solid black;
border-radius:10px;
}
.Bcolor {
flex: 1 1 auto;
box-sizing: border-box;
font_size: 0px;
fload: left;
width: 18px;
height: 18px;
margin-top: 1px;
margin-left: 3px;
border: 1px solid white;
}
#fname {
position: absolute;
top: 30px;
left: 120px;
}
#fsize {
position: absolute;
top: 30px;
left: 145px;
width: 80px;
}
@media print {
#cadre_cmd {
visibility: hidden;
height: 0px
}
#editeur {
top: 0px;
border: 0px;
}
body {
border: 0px;
}
#divrouge {
border: 0px;
}
}
p {
margin: 0;
}
</style>
<script type="text/javascript">
var editeur;
var panne;
var palet;
var modepal;
var listefsize;
var listefont;
var choixfichier;
var Bbold = ["execCom", "bold", "false", "null", "bold", 113, "Texte en gras"];
var Bitalic = ["execCom", "italic", "false", "null", "italic", "114", "Mettre le texte de la selection en italic"];
var Bunderline = ["execCom", "underline", "false", "null", "underline", "115", "Souligner le texte"];
var BfontName = ["listeF", "fontName", "null", "null", "fontName", "1063", "Afficher la liste des font name"];
var BfontSize = ["listeFZ", "fontSize", "null", "null", "fontSize", "1061", "Afficher la liste des font size"];
var BforeColor = ["affichepalette", "foreColor", "null", "null", "foreColor", "1858", "Afficher la palette des font color"];
var BbackColor = ["affichepalette", "backColor", "null", "null", "backColor", "1031", "Texte avec le Fond en couleur"];
var Bindent = ["execCom", "indent", "false", "null", "indent", "3161", "indenter le texte"];
var Boutdent = ["execCom", "outdent", "false", "null", "outdent", "3162", "outdenter le texte"];
var Bsubscript = ["execCom", "subscript", "false", "null", "subscript", "333", "Mettre en souexposant le texte sélectionné"];
var Bsuperscript = ["execCom", "superscript", "false", "null", "superscript", "333", "Mettre le texte sélectionné en exposant"];
var Bcopy = ["execCom", "copy", "false", "null", "copy", "19", "Copier la selection "];
var Bcut = ["execCom", "cut", "false", "null", "cut", "21", "Couper la selection"];
var Bpaste = ["execCom", "paste", "false", "true", "paste", "22", "coller"];
var BcreateLink = ["execCom", "createLink", "false", "null", "createLink", "1015", "Mettre un lien sur la selection"];
var Bunlink = ["execCom", "unlink", "false", "null", "unlink", "1576", "Suprimer le lien "];
var BinsertHorizontalRule = ["execCom", "insertHorizontalRule", "true", "null", "insertHorizontalRule", "33", "Tirer un trait"];
var BinsertOrderedList = ["execCom", "insertOrderedList", "false", "null", "insertOrderedList", "439", "insérer ou transformer la selection en liste ordonnée"];
var BinsertUnorderedList = ["execCom", "insertUnorderedList", "false", "null", "insertUnorderedList", "439", "insérer ou transformer la selection en liste non ordonnée"];
var BjustifyCenter = ["execCom", "justifyCenter", "false", "null", "justifyCenter", "122", "Centrer le texte"];
var BjustifyLeft = ["execCom", "justifyLeft", "false", "null", "justifyLeft", "120", "Aligner le texte a gauche "];
var BjustifyRight = ["execCom", "justifyRight", "false", "null", "justifyRight", "121", "Aligner le texte a droite"];
var Bredo = ["execCom", "redo", "false", "null", "redo", "333", "refaire"];
var removeFormat = ["execCom", "removeFormat", "false", "null", "removeFormat", "108", "suprimer le formatage du texte"];
var BstrikeThrough = ["execCom", "strikeThrough", "false", "null", "strikeThrough", "333", "Barrer le texte sélectionné"];
var Bundo = ["execCom", "undo", "false", "null", "undo", "333", "Annuler la dernier operation"];
var Binsertimg = ["insertimage", "insertimage", "null", "null","insertimage", "682", "inserer une image "];
var Bhtml = ["afficherhtml", "afficherhtml", "null", "null", "afficherhtml", "1922", "Afficher le code HTML"];
var Bouvrir = ["bycommandvba", "ouvrirfichier", "null", "null", "Ouvrir", "23", "Ouvrir un fichier"];
var Bimprimer = ["execCom", "print", "false", "null", "print", "4", "Imprimer le document"];
var Benregistrer = ["bycommandvba", "enregistrer", "null", "null", "Enregistrer", "3", "enregistrer le document"];
var Bnouveau = ["nouveau", "nouveau", "null", "null", "nouveau", "2520", "Nouveau document"];
var Blayer = ["inserdiv", "ajouterdiv", "null", "null", "ajouterdiv", "178", "Ajouter un div"];
var Bapercu = ["apercu", "apercu", "null", "null", "apercu", "109", "Apercu dans une page unique"];
var Btest = ["btest", "btest", "null", "null", "btest", "544", "bouton de test"];
var coul = ["FFFFFF", "FFCCCC", "FFCC99", "FFFF99", "FFFFCC", "99FF99", "99FFFF", "CCFFFF", "CCCCFF", "FFCCFF", "CCCCCC", "FF6666", "FF9966", "FFFF66", "FFFF33", "66FF99", "33FFFF", "66FFFF", "9999FF", "FF99FF", "C0C0C0", "FF0000", "FF9900", "FFCC66", "FFFF00", "33FF33", "66CCCC", "33CCFF", "6666CC", "CC66CC", "999999", "CC0000", "FF6600", "FFCC33", "FFCC00", "33CC00", "00CCCC", "3366FF", "6633FF", "CC33CC", "666666", "990000", "CC6600", "CC9933", "999900", "009900", "339999", "3333FF", "6600CC", "993399", "333333", "660000", "993300", "996633", "666600", "006600", "336666", "000099", "333399", "663366", "000000", "330000", "663300", "663333", "333300", "003300", "003333", "000066", "330099", "330033"];
var fn =["F-name", "arial", "calibri", "algerian", "arialblack", "aharoni", "baskerville", "comic sans ms", "forte", "georgia", "script"];
///////////////////////////////////////////////////fonction execComand//////////////////////////////////////////
function execCom(fonct, argmt1, argmt2) {
//alert(fonct +":" + argmt1 +":" + argmt2);
if (argmt1 === "undefined") {
argmt1 = false;
}
if (argmt2 === "undefined") {
argmt2 = null;
}
document.execCommand(fonct, argmt1, argmt2);
if(palet!=null){palet.style.visibility="hidden";}
}
/////////////////////////////////////////////////////////////// CREATION DE LA PLATFORME (LES DIVS)////////////////////////////
function createplateform() {
var div1 = document.createElement("DIV");
var div2 = document.createElement("DIV");
var div3 = document.createElement("DIV");
div1.id = "cadre_cmd";
div2.id = "divrouge";
div3.id = "editeur";
div3.setAttribute("contenteditable", "true");
div3.innerHTML = "<p></p>";
div2.appendChild(div3);
document.body.appendChild(div1);
document.body.appendChild(div2);
editeur = div3 //on les a dispo dans tout le javascript par leur nom ils ont été déclarés en haut de script
panne = div1 //on les a dispo dans tout le javascript par leur nom ils ont été déclarés en haut de script
editeur.addEventListener('mouseover', function() {
if (palet != null) {palet.style.visibility = "hidden";};
});
var inputt = document.createElement("INPUT");
inputt.type = "file";
inputt.style.height="0px";
choixfichier = inputt;
document.body.appendChild(inputt);
// ******************************************************************* creation des list font
var listfn = document.createElement("SELECT");
listfn.id = "fname";
listfn.size = fn.length;
listfn.style.visibility = "hidden";
for (var f = 0; f < fn.length; f++) {
var opt = document.createElement("OPTION");
opt.value = fn[f];
opt.innerHTML = fn[f];
listfn.appendChild(opt);
}
document.body.appendChild(listfn);
listefont = listfn;
listfn.setAttribute("onmouseout", "this.style.visibility = 'hidden'")
listfn.setAttribute("onchange", "execCom('fontName','false', this.value)");
// addeventlistener ne fonctionne pas avec les balises select dans le support OCX Webbrowser de "vba Excel" je ne sais encore pas pourquoi
//listfn.addEventListener('change', function(event){
//execCom('fontName','false', event.target.value);},false);
// ************************************************************************************************
// ************************************************************* creation de la liste des font size
var listfz = document.createElement("SELECT");
listfz.id = "fsize";
listfz.size = 7;
listfz.style.visibility = "hidden";
for (var s = 0; s < 8; s++) {
var opt = document.createElement("OPTION");
opt.value = s;
opt.innerHTML = s;
listfz.appendChild(opt);
}
document.body.appendChild(listfz);
listefsize = listfz;
listfz.setAttribute("onmouseout", "this.style.visibility = 'hidden'")
listfz.setAttribute("onchange", "execCom('fontSize','false', this.value)");
// addeventlistener ne fonctionne pas avec les balises select dans le support OCX Webbrowser de "vba Excel" je ne sais encore pas pourquoi
//listfn.addEventListener('change', function(event){
//execCom('fontName','false', event.target.value);},false);
// ***************************************************************************************************
//****************************************CREATION DE LA PALETTE COULEUR***************************************
createpalette();
} //fin de fonction createplateform
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////CREATION DES BOUTONS///////////////////////////////////////////////
function createbouton(boutons) {
console.log(boutons.length);
for (var b = 0; b < boutons.length; b++) {
var arr = boutons[b];
console.log(arr.length);
var fondbout = document.createElement("DIV");
fondbout.className = "fondbouton";
var argument0 = boutons[b][4];
var bout = document.createElement("img");
bout.id = "BT_" + boutons[b][4];
bout.className = "bouton";
bout.setAttribute("fonction", boutons[b][0]);
bout.setAttribute("argumt1", boutons[b][1]);
bout.setAttribute("argumt2", boutons[b][2]);
bout.setAttribute("argumt3", boutons[b][3]);
bout.setAttribute("src", "imageBouton\\" + boutons[b][4] + ".png");
bout.setAttribute("title", boutons[b][6]);
//});
//console.log("BT_"+boutons[b][4] + " fonction : " + boutons[b][0] + "::" + boutons[b][1] + "::" + boutons[b][2] + "::" + boutons[b][3])
fondbout.appendChild(bout)
panne.appendChild(fondbout);
if (boutons[b][0] === "execCom") {
// IMPORTANT !!!!!je suis obligé de faire comme ca sinon le addEventListener ne memorise pas les items du tableau boutons[b][1,2,3]
bout.setAttribute("onclick", "execCom('" +boutons[b][1]+ "'" + ",'" +boutons[b][2] + "','" + boutons[b][3] +"')");
}
if (boutons[b][1] === "afficherhtml") {
bout.addEventListener("click", function() {afficherhtml();});
}
if (boutons[b][1] === "foreColor") {
//bout.setAttribute("onclick", "modepal='foreColor';palet.style.visibility='visible';palet.left=this.offsetLeft +'px';");
bout.addEventListener('click', function(event) {
event.preventDefault();modepal='foreColor';
palet.style.visibility='visible';
palet.style.left=this.offsetLeft +'px';
});
bout.addEventListener('contextmenu', function(event) {event.preventDefault();execCom("foreColor","false","null");}, true);
}
if (boutons[b][1] === "backColor") {
bout.addEventListener("click", function() {
modepal="backColor";
palet.style.visibility="visible";
palet.style.left=this.offsetLeft+'px';
});
bout.addEventListener('contextmenu', function(event) {event.preventDefault();execCom("backColor","false","null");}, true);
}
if (boutons[b][1] === "fontName") {
bout.addEventListener("click", function() {
listefont.style.visibility="visible";listefont.style.left=this.offsetLeft+"px";
});
}
if (boutons[b][1] === "fontSize") {
bout.addEventListener("click", function() {
listefsize.style.visibility="visible";listefsize.style.left=this.offsetLeft+"px";
});
}
if (boutons[b][1] === "nouveau") {
bout.addEventListener("click", function() {
editeur.innerHTML="";
});
}
if (boutons[b][1] === "insertimage") {
bout.addEventListener("click", function() {
insertimg2("insertimage","null","null");
});
}
}///fin du for
} //fin de fonction createbouton
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////CREATION DE LA PALETTE COULEUR//////////////////////////////////////////////
function createpalette() {
var pal = document.createElement("DIV");
pal.id = "palette";
pal.style.visibility="hidden";
document.body.appendChild(pal);
palet = pal;
for (var c = 0; c < coul.length; c++) {
var btc = document.createElement("BUTTON");
btc.className = "Bcolor";
btc.style.backgroundColor = "#" + coul[c];
btc.id = "btc_" + coul[c];
palet.appendChild(btc);
btc.addEventListener("click", function() {
execCom(modepal, "false", "#" + this.id.substring(4));
});
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function afficherhtml() {
var ed = document.getElementById("editeur");
if (ed.contentEditable === "true") {
ed.className = "noedit";
ed.contentEditable = "false";
ed.innerText = ed.innerHTML;
} else {
ed.className = "edit";
ed.contentEditable = "true";
ed.innerHTML = ed.innerText;
}
}
function insertimg2(argmt,b,url){
if (url==="undefined"){url=null;;b=null;}
// il est important de determiner la selection (meme vide) sinon l'insertion se fait sur tout le document et remplace tout
var selection = window.getSelection().getRangeAt(0);
selection.collapse(true);//au cas ou la selection contient du texte on met le start et end a zero avec collapse pour ne pas remplacer le texte
window.getSelection().addRange(selection);
//l'avantage de execCommand c'est qu'il ouvre sa propre petite fenetre avec un bouton "parcourir"
//possibilité de regler dans cette fenetre l'alignement et le hspaces le src a l'url du fichier local tel quel
document.execCommand("insertimage",b,url);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
</script>
</head>
<body>
<script>
createplateform();
boutons=[Btest,Bbold,Bitalic,Bunderline,BstrikeThrough,BfontName,BfontSize,BforeColor,BbackColor,BjustifyLeft,BjustifyCenter,BjustifyRight,Bindent,Boutdent,BinsertOrderedList,BinsertUnorderedList,Bsubscript,Bsuperscript ,removeFormat,BinsertHorizontalRule,BcreateLink,Bunlink,Binsertimg,Blayer,Bundo,Bredo,Bcut,Bcopy,Bpaste,Bhtml,Bapercu,Bimprimer,Bnouveau,Bouvrir,Benregistrer ]
createbouton(boutons);
</script>
</body>
</html> |
Partager