Ragazzi,
Sto creando un form con più textarea ed una serie di bottoni cliccando sui quali si può personalizzare il testo con: Grassetto, Corsivi ecc .....
Il problema nasce dal tag 9 in quanto:
per quel che concerne il tag 9 vorrei che fosse concesso all'utente la possibilità del doppio inserimento
codice:
LINK (normale) quindi
LINK + DESC qunidi [/url]"wwww.miosito.com"]desc[/url]
e poi nei tag successiv dal 10 in poi no so come manipolare il codice per fare in modo che vengano inseriti.
codice:
<SCRIPT LANGUAGE="JavaScript">
<!--
var FormNumber = 1;
var LastFocus = "";
var LastDirection = 1;
var InsertionCounter = 0;
var MaxInsertionCounter = 0;
var InsertionHistory = new Array();
var FocusHistory = new Array();
var InitialState = new Array();
function Undo() {
if ( LastFocus != "" ) {
if ( LastDirection == 1 ) SavePreviousTextInput();
LastDirection = -1;
if ( InsertionCounter > 0 ) {
InsertionCounter = InsertionCounter - 2;
document.forms[FormNumber].elements[FocusHistory[InsertionCounter]].value = InsertionHistory[InsertionCounter];
}
}
}
function Redo() {
LastDirection = 1;
if ( InsertionCounter < MaxInsertionCounter ) {
InsertionCounter = InsertionCounter + 2;
document.forms[FormNumber].elements[FocusHistory[InsertionCounter-1]].value = InsertionHistory[InsertionCounter-1];
}
}
function SavePreviousTextInput() {
lastSavedFocusIndex = -1;
for ( I = 0; I < InsertionCounter; I++ ) {
if ( FocusHistory[I] == LastFocus ) lastSavedFocusIndex = I;
}
if ( lastSavedFocusIndex == -1 ) {
previousState = InitialState[LastFocus];
} else {
previousState = InsertionHistory[lastSavedFocusIndex];
}
if ( previousState != document.forms[FormNumber].elements[LastFocus].value ) {
InsertionHistory[InsertionCounter] = previousState;
FocusHistory[InsertionCounter] = LastFocus;
InsertionCounter = InsertionCounter + 1;
InsertionHistory[InsertionCounter] = document.forms[FormNumber].elements[LastFocus].value;
FocusHistory[InsertionCounter] = LastFocus;
InsertionCounter = InsertionCounter + 1;
MaxInsertionCounter = InsertionCounter;
}
}
function GetLastEntry(ObjectName) {
if ( !InitialState[ObjectName] ) {
// this field has never been focused before, save initial state
InitialState[ObjectName] = document.forms[FormNumber].elements[ObjectName].value;
}
if ( LastFocus != "" ) SavePreviousTextInput();
LastFocus = ObjectName;
}
function InsertHtml(TagNum) {
var HtmTag1 = "";
var HtmTag2 = "";
if ( LastFocus != "" ) {
SavePreviousTextInput();
switch ( TagNum ) {
case "1" :
HtmTag1 = "";
HtmTag2 = "";
break;
case "2" :
HtmTag1 = "";
HtmTag2 = "";
break;
case "3" :
HtmTag1 = "
";
HtmTag2 = "</p>";
break;
case "4" :
HtmTag1 = "<ul>\n[*]";
HtmTag2 = "\n[/list]";
break;
case "5" :
HtmTag1 = "
";
HtmTag2 = "";
break;
case "6" :
HtmTag1 = "<centerpar>";
HtmTag2 = "</centerpar>";
break;
case "7" :
HtmTag1 = "<justifiedpar>";
HtmTag2 = "</justifiedpar>";
break;
case "8" :
HtmTag1 = "<rightpar>";
HtmTag2 = "</rightpar>";
break;
case "9" :
HtmTag1 = "<wwwlink>";
HtmTag2 = "</wwwlink>";
break;
case "10" :
HtmTag1 = "<mailto>";
HtmTag2 = "</mailto>";
break;
case "11" :
HtmTag1 ="<font="+document.bottoni.fontselect.options[document.bottoni.fontselect.selectedIndex].value+">";
HtmTag2 = "</font>";
break;
default :
HtmTag = "";
}
LastDirection = 1;
InsertionHistory[InsertionCounter] = document.forms[FormNumber].elements[LastFocus].value;
FocusHistory[InsertionCounter] = LastFocus;
InsertionCounter = InsertionCounter + 1;
if ( document.selection && document.selection.createRange ) {
range = document.selection.createRange();
if ( range.text != "" ) {
if ( TagNum < 9 ) {
if ( TagNum == 4 ) {
SelText = range.text;
var Ergebnis = SelText.match(/\n/);
if ( Ergebnis != null ) {
var NewSelText = SelText.replace(/\n/g,"\n[*]");
HtmTag1 = "<ul>\n[*]";
HtmTag2 = "\n[/list]\n";
SelText = HtmTag1 + NewSelText + HtmTag2;
}
} else {
SelText = HtmTag1 + range.text + HtmTag2;
}
} else {
if (TagNum == 9) {
SelText = HtmTag1 + range.text + HtmTag2 ;
}
}
range.text = SelText;
} else {
if ( TagNum < 9 ) {
document.forms[FormNumber].elements[LastFocus].value = HtmTag1 + document.forms[FormNumber].elements[LastFocus].value + HtmTag2;
} else {
document.forms[FormNumber].elements[LastFocus].value = document.forms[FormNumber].elements[LastFocus].value + HtmTag1 + "http://www.ndtanimtion.com" + HtmTag2 + "<wwwdesc>Descrizione del link</wwwdesc>";
}
}
} else {
if ( TagNum < 9 ) {
document.forms[FormNumber].elements[LastFocus].value = HtmTag1 + document.forms[FormNumber].elements[LastFocus].value + HtmTag2;
} else {
document.forms[FormNumber].elements[LastFocus].value = document.forms[FormNumber].elements[LastFocus].value + HtmTag1 + "http://www.ndtanimtion.com" + HtmTag2 + "<wwwdesc>Descrizione del link</wwwdesc>";
}
}
InsertionHistory[InsertionCounter] = document.forms[FormNumber].elements[LastFocus].value;
FocusHistory[InsertionCounter] = LastFocus;
InsertionCounter = InsertionCounter + 1;
MaxInsertionCounter = InsertionCounter;
}
}
//-->
</SCRIPT>