codice:
// BBCode JS
// Copyright 2003-2005 PaoDJ
function bb_code(what,campo){
if(what=="bold"){
if(!bbcode_sel("","",campo)){
dat=prompt('Inserisci il testo in grassetto:',"");
if((dat!=null)&&(dat!="")){ bbcode_ins(""+dat+"",campo); }
}
}
if(what=="italic"){
if(!bbcode_sel("","",campo)){
dat=prompt('Inserisci il testo in corsivo:',"");
if((dat!=null)&&(dat!="")){ bbcode_ins(""+dat+"",campo); }
}
}
if(what=="testo_nero"){
if(!bbcode_sel("[testo nero]","[/testo]",campo)){
dat=prompt('Inserisci il testo in nero:',"");
if((dat!=null)&&(dat!="")){ bbcode_ins("[testo nero]"+dat+"[/testo]",campo); }
}
}
if(what=="testo_rosso"){
if(!bbcode_sel("[testo rosso]","[/testo]",campo)){
dat=prompt('Inserisci il testo in rosso:',"");
if((dat!=null)&&(dat!="")){ bbcode_ins("[testo rosso]"+dat+"[/testo]",campo); }
}
}
if(what=="testo_tipico"){
if(!bbcode_sel("[testo tipico]","[/testo]",campo)){
dat=prompt('Inserisci il testo:',"");
if((dat!=null)&&(dat!="")){ bbcode_ins("[testo tipico]"+dat+"[/testo]",campo); }
}
}
if(what=="img"){
dat=prompt('Inserisci l\'url dell\'immagine:',"");
if((dat!=null)&&(dat!="")){ bbcode_ins("[img src="+dat+"]",campo); }
}
if(what=="link"){
dat=prompt('Inserisci l\'url del collegamento:',"http://");
if((dat!=null)&&(dat!="http://")&&(dat!="")){
dat2=prompt('Inserisci il testo del collegamento (Lasciare vuoto per visualizzare l\'URL):',"");
if((dat!=null)&&(dat!="")){
bbcode_ins("[a href="+dat+"]"+dat+"[/a]",campo);
}else{
bbcode_ins("[a href="+dat+"]"+dat2+"[/a]",campo);
}
}
}
if(what=="mail"){
dat=prompt('Inserisci l\'indirizzo email:',"");
if((dat!=null)&&(dat!="")){
dat2=prompt('Inserisci il testo del collegamento (Lasciare vuoto per visualizzare l\'indirizzo email):',"");
if((dat!=null)&&(dat!="")){
bbcode_ins("[mail to="+dat+"]"+dat+"[/mail]",campo);
}else{
bbcode_ins("[mail to="+dat+"]"+dat2+"[/mail]",campo);
}
}
}
}
function bbcode_sel(bbcode_before,bbcode_after,bbcode_field){
bbcode_field=getobj(bbcode_field);
if(document.selection){
bbcode_field.focus();
sel=document.selection.createRange();
if(sel.text!=''){
startPos=bbcode_field.value.indexOf(sel.text);
endPos=bbcode_field.value.indexOf(sel.text)+sel.text.length;
bbcode_field.value=bbcode_field.value.substring(0,startPos)+bbcode_before+bbcode_field.value.substring(startPos,endPos)+bbcode_after+bbcode_field.value.substring(endPos,bbcode_field.value.length);
return true;
}else{
return false;
}
}else if(bbcode_field.selectionStart!=bbcode_field.selectionEnd){
startPos=bbcode_field.selectionStart;
endPos=bbcode_field.selectionEnd;
bbcode_field.value=bbcode_field.value.substring(0,startPos)+bbcode_before+bbcode_field.value.substring(startPos,endPos)+bbcode_after+bbcode_field.value.substring(endPos,bbcode_field.value.length);
return true;
}else{
return false;
}
}
function bbcode_ins(bbcode_code,bbcode_field) {
bbcode_field=getobj(bbcode_field);
if(document.selection){
bbcode_field.focus();
sel=document.selection.createRange();
sel.text=bbcode_code;
}else if(bbcode_field.selectionStart||bbcode_field.selectionStart=='0'){
startPos=bbcode_field.selectionStart;
endPos=bbcode_field.selectionEnd;
bbcode_field.value=bbcode_field.value.substring(0,startPos)+bbcode_code+bbcode_field.value.substring(endPos,bbcode_field.value.length);
}else{
bbcode_field.value+=bbcode_code;
}
}
Questo non è il bbcode ufficiale, ho creato i tag per le mie necessità...