UBB (IE & FF compatibel)
Auteur: WumTol - 23 juli 2005 - 19:09 - Gekeurd door: Dennis - Hits: 6666 - Aantal punten: 4.50 (6 stemmen)
Heel simpel UBB script.
2 functies, smile(veld, smile) en tag(veld, tag1, tag2).
Je kan tag2 leeglaten als hij hetzelfde moet zijn als tag1 (niet het geval bij url, zie voorbeeld)!
Voorbeelden
Smile:
<img src="smile.gif" OnClick="smile(formulier.testarea, ':)');">
Dikgedruk:
<input type="button" value="B" onClick="tag(formulier.testarea, 'b', '');">
Url:
<input type="button" value="URL" onClick="tag(formulier.testarea, 'url=http://', 'url');">
Code:
Sla op in een js-file, of zet tussen <script> </script>
<!--
function smile(veld, smile)
{
if (document.selection)
{
veld.focus();
var selection = document.selection.createRange();
selection.text = smile;
}
else if (veld.selectionStart || veld.selectionStart == '0')
{
var startPos = veld.selectionStart;
var endPos = veld.selectionEnd;
veld.value = veld.value.substring(0, startPos)
+ smile + veld.value.substring(endPos, veld.value.length);
}
else
{
veld.value += smile;
}
}
function tag(veld, tag1, tag2)
{
if (!tag2)
{
tag2 = tag1;
}
if (document.selection)
{
veld.focus();
var selection = document.selection.createRange();
if(selection.text)
{
selection.text = "["+tag1+"]"+selection.text+"[/"+tag2+"]";
}
else
{
veld.value += "["+tag1+"] [/"+tag2+"]";
}
}
else if (veld.selectionStart || veld.selectionStart == '0')
{
var startPos = veld.selectionStart;
var endPos = veld.selectionEnd;
if (startPos != endPos)
{
veld.value = veld.value.substring(0, startPos)
+ "["+tag1+"]"
+ veld.value.substring(startPos, endPos)
+ "[/"+tag2+"]"
+ veld.value.substring(endPos, veld.value.length);
}
else
{
veld.value = veld.value.substring(0, startPos)
+ "["+tag1+"] [/"+tag2+"]"
+ veld.value.substring(endPos, veld.value.length);
}
}
}
//-->
<!--
function smile( veld, smile)
{
if ( document. selection)
{
veld. focus( ) ;
var selection = document. selection. createRange( ) ;
selection. text = smile;
}
else if ( veld. selectionStart || veld. selectionStart == '0' )
{
var startPos = veld. selectionStart;
var endPos = veld. selectionEnd;
veld. value = veld. value. substring( 0 , startPos)
+ smile + veld. value. substring( endPos, veld. value. length) ;
}
else
{
veld. value += smile;
}
}
function tag( veld, tag1, tag2)
{
if ( ! tag2)
{
tag2 = tag1;
}
if ( document. selection)
{
veld. focus( ) ;
var selection = document. selection. createRange( ) ;
if ( selection. text)
{
selection. text = "[" + tag1+ "]" + selection. text+ "[/" + tag2+ "]" ;
}
else
{
veld. value += "[" + tag1+ "] [/" + tag2+ "]" ;
}
}
else if ( veld. selectionStart || veld. selectionStart == '0' )
{
var startPos = veld. selectionStart;
var endPos = veld. selectionEnd;
if ( startPos != endPos)
{
veld. value = veld. value. substring( 0 , startPos)
+ "[" + tag1+ "]"
+ veld. value. substring( startPos, endPos)
+ "[/" + tag2+ "]"
+ veld. value. substring( endPos, veld. value. length) ;
}
else
{
veld. value = veld. value. substring( 0 , startPos)
+ "[" + tag1+ "] [/" + tag2+ "]"
+ veld. value. substring( endPos, veld. value. length) ;
}
}
}
//-->
Download code (.txt)
Stemmen
Niet ingelogd.