O altrimenti qui c'è l'editor più piccolo del mondo :-)
Scherzo ovviamente... ma è piuttosto completo in proporzione alla semplicità. Mi spiace, ma le immagini della barra degli strumenti, che devi posizionare all'interno della cartella «images», te le devi cercare da solo: non posso allegare files zip!! Il codice può essere ulteriormente ottimizzato... Non ricordo neppure dove l'ho trovato. Non mi è mai servito cmq... adoro tinyMCE!
codice:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="it" />
<title>Area editabile in formato html</title>
<script type="text/javascript">
var oEditDoc, bHtmlMode = false;
function initDoc() {
oEditDoc = document.getElementById("editFrame").contentDocument;
oEditDoc.open();
oEditDoc.write("<html><body></body></html>");
oEditDoc.close();
oEditDoc.designMode = "on";
document.getElementById("switchMode").checked = false;
}
function docFocus() { document.getElementById("editFrame").contentWindow.focus() }
function formatDoc(cmd,opt) { if (validateMode()) { oEditDoc.execCommand(cmd, false, opt); docFocus(); } }
function validateMode() {
if (!bHtmlMode) { return(true); } else { alert("Deselezionare \"Visualizza HTML\" per utilizzare le barre degli strumenti"); docFocus(); return(false); }
}
function setDocMode(newMode) {
var sTxtContent;
bHtmlMode = newMode;
oEditBody = oEditDoc.body;
if (bHtmlMode) {
sTxtContent = document.createTextNode(oEditBody.innerHTML);
oEditBody.innerHTML = "";
oEditBody.appendChild(sTxtContent);
} else {
if (document.all) {
sTxtContent = oEditBody.innerText;
oEditBody.innerHTML = sTxtContent;
} else {
sTxtContent = document.createRange();
sTxtContent.selectNodeContents(oEditBody);
oEditBody.innerHTML = sTxtContent.toString();
}
}
docFocus();
}
</script>
<style type="text/css">
.intLink {
cursor: pointer;
}
#paragrBar select {
font-size:10px;
}
#editFrame {
width: 540px;
height: 200px;
}
</style>
</head>
<body onload="initDoc();">
<div><form name="composeForm" onsubmit="this.myDocument.value=oEditDoc.body.innerHTML;">
<input type="hidden" name="myDocument">
<div id="paragrBar">
<select id="ParagraphStyle" onchange="formatDoc('formatBlock',this[this.selectedIndex].value);this.selectedIndex=0">
<option selected>- formattazione -</option>
<option value="<h1>">Titolo 1 <h1></option>
<option value="<h2>">Titolo 2 <h2></option>
<option value="<h3>">Titolo 3 <h3></option>
<option value="<h4>">Titolo 4 <h4></option>
<option value="<h5>">Titolo 5 <h5></option>
<option value="<h6>">Sottotitolo <h6></option>
<option value="<p>">Paragrafo <p></option>
<option value="<pre>">Formattato <pre></option>
</select>
<select id="FontName" onchange="formatDoc('fontName',this[this.selectedIndex].value);this.selectedIndex=0">
<option class="heading" selected>- carattere -</option>
<option value="Arial">Arial</option>
<option value="Arial Black">Arial Black</option>
<option value="Arial Narrow">Arial Narrow</option>
<option value="Comic Sans MS">Comic Sans MS</option>
<option value="Courier New">Courier New</option>
<option value="System">System</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Verdana">Verdana</option>
<option value="Wingdings">Wingdings</option>
</select>
<select id="FontSize" onchange="formatDoc('fontSize',this[this.selectedIndex].value);this.selectedIndex=0">
<option class="heading" selected>- dimensione -</option>
<option value="1">Molto piccolo</option>
<option value="2">Ridotto</option>
<option value="3">Normale</option>
<option value="4">Medio-grande</option>
<option value="5">Grande</option>
<option value="6">Molto grande</option>
<option value="7">Massimo</option>
</select>
<select id="FontColor" onchange="formatDoc('foreColor',this[this.selectedIndex].value);this.selectedIndex=0">
<option class="heading" selected>- sTxtContent -</option>
<option value="red">rosso</option>
<option value="blue">blu</option>
<option value="green">verde</option>
<option value="black">nero</option>
</select>
<select id="FontBackColor" onchange="formatDoc('backcolor',this[this.selectedIndex].value);this.selectedIndex=0">
<option class="heading" selected>- sfondo -</option>
<option value="red">rosso</option>
<option value="blue">blu</option>
<option value="green">verde</option>
<option value="black">nero</option>
<option value="yellow">giallo</option>
<option value="white">bianco</option>
</select>
</div>
<div>
<input class="intLink" title="Salva" type="image" src="images/save.gif" border="0" />
[img]images/print.png[/img]
[img]images/clean.gif[/img]
[img]images/undo.gif[/img]
[img]images/redo.gif[/img]
[img]images/unformat.png[/img]
[img]images/bold.gif[/img]
[img]images/italic.gif[/img]
[img]images/under.gif[/img]
[img]images/aleft.gif[/img]
[img]images/center.gif[/img]
[img]images/aright.gif[/img]
[img]images/nlist.gif[/img]
[img]images/blist.gif[/img]
[img]images/quote.gif[/img]
[img]images/ileft.gif[/img]
[img]images/iright.gif[/img]
[img]images/link.gif[/img]
[img]images/cut.gif[/img]
[img]images/copy.gif[/img]
[img]images/paste.gif[/img]
</div>
<iframe id="editFrame"></iframe>
<div id="EditMode">
<input type="checkbox" name="switchMode" id="switchMode" onclick="setDocMode(switchMode.checked)" />
<label for="switchMode">Visualizza HTML</label> |
<input type="button" onclick="formatDoc('removeFormat')" value="Rimuovi Formattazione Carattere" />
</div>
</div></form>
</body>
</html>