ciao ng
sto usando una classe php per il bb code di andr3a..
il js per inserire i vari codici BB all'interno della text area è questo qui sotto.
questo funziona con una textarea che ha id="InternalTextarea" se io ne avessi + di una come dovrei modificare il cod js?
il bottone ho questo cod
codice:
<input id="B" class="Button" type="button" value="[B]" onClick="BBcode.add('B');" onMouseOver="this.style.background='#D7D7D7'; this.style.color='#565656';" onMouseOut="this.style.background='#EFEFEF' ; this.style.color='#787878';" />
grazie
codice:
<script type=\"text/javascript\">
var BBcode = function() {
var used = Array();
function add(str) {
var codeLighterTextarea_add = '';
var to_span = 'novalue';
if(!document.getElementById('InternalTextarea')) {
alert('You need a TEXTAREA with id=\"InternalTextarea\" to use these buttons!');
}
if(document.getElementById('TextareaSpanChecker')!=null) {
to_span = document.getElementById('TextareaSpanChecker').innerHTML;
to_span = parseInt(to_span);
}
if(document.getElementById( str).value == '['+str+']') {
codeLighterTextarea_add = '['+str+']';
document.getElementById(str).value = '[/'+str+']';
this.total.push('[/'+str+']');
if(to_span!='novalue') {
document.getElementById('TextareaSpanChecker').innerHTML = (to_span+1);
}
}
else {
for(var a=(this.total.length-1); a>=0; a--) {
codeLighterTextarea_add += this.total[a];
var my_str = this.total[a].substr(2, (this.total[a].length-3));
document.getElementById(my_str).value = '['+my_str+']';
if(to_span!='novalue') {
to_span--;
}
if(my_str==str) {
break;
}
}
if(this.total.length==0) {
codeLighterTextarea_add += '[/'+str+']';
document.getElementById(str).value = '['+str+']';
if(to_span!='novalue') {
to_span--;
}
}
this.total = Array();
if(to_span!='novalue') {
document.getElementById('TextareaSpanChecker').innerHTML = to_span;
}
}
document.getElementById('InternalTextarea').value += codeLighterTextarea_add;
document.getElementById('InternalTextarea').focus();
return true;
}
function maxChars() {
if(this.counter!=false) {
var check_len = document.getElementById('InternalTextarea').value.length;
var rest_len = 0;
if ( check_len >= this.counter ) {
document.getElementById('InternalTextarea').value = document.getElementById('InternalTextarea').value.substring(0, this.counter);
}
else {
rest_len = this.counter - check_len;
}
document.getElementById('TextareaSpanCounter').innerHTML = rest_len;
}
else {
document.getElementById('TextareaSpanCounter').innerHTML = document.getElementById('InternalTextarea').value.length;
}
}
function closeTags(ar) {
var to_span = 'novalue';
for(var a=(ar.length-1); a>=0; a--) {
document.getElementById('InternalTextarea').value += ar[a];
var my_str = ar[a].substr(2, (ar[a].length-3));
document.getElementById(my_str).value = '['+my_str+']';
}
this.total = Array();
if(document.getElementById('TextareaSpanChecker')!=null) {
to_span = document.getElementById('TextareaSpanChecker').innerHTML;
to_span = parseInt(to_span);
}
if(to_span!='novalue') {
document.getElementById('TextareaSpanChecker').innerHTML = '0';
}
document.getElementById('InternalTextarea').focus();
}
this.total = used;
this.add = add;
this.close = closeTags;
this.counter = false;
}
var BBcode = new BBcode();
</script>