liam1412
13-07-2007, 00:13
More Javascript help
I was given this script buy a guy on another forum but I can't get hold of him now.
Basically it wraps bbcode around highligted text.
It works fine for the bold and font tags.
I also use it for urls
The problem with this is because of how the script is written and my Parser all I can get it to display for the url text is click here
Here is the javascript
[CODE]
Hi
This script was given to me by someone on here for use on my site. I know nothing of JS at all but he offered this for use (but can't remember who it was)
[code]<script type="text/javascript">
function AddEmo(tag)
{
var emo=document.forms["form"].elements["text"];
if (document.selection)
{
emo.focus();
var sel = document.selection.createRange();
sel.text = tag
}
else if (emo.selectionStart || emo.selectionStart == '0')
{
var startPos = emo.selectionStart
var endPos = emo.selectionEnd
emo.value = emo.value.substring(0, startPos)
+ tag
+ emo.value.substring(endPos, emo.value.length)
}
else {
emo.value += tag;
}
}
function AddTag(tag)
{
var txt = '';
if (window.getSelection)
{
txt = window.getSelection();
}
else if (document.getSelection)
{
txt = document.getSelection();
}
else if (document.selection)
{
txt = document.selection.createRange().text;
}
var stri1 = txt
var stri = "["+tag+"]"+stri1+"[/"+tag+"]"
AddEmo(stri);
}
// calling the function
</script>
[/code/]
and here is my parser
function BBCODE($bbcode)
{
//the bbcode tags..
$bbc_a=array(
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"::smile::",
"::mad::",
"::sad::",
"::rolleyes::",
"::smirk::",
"::wink::",
"::surprised::",
"::thinking::",
"::tongue::",
"::cool::",
"",
"",
"",
"",
"",
"",
"",
"",
);
//bbcode gets converted to..
$bbc_b=array(
"<strike>",
"</strike>",
"<b>",
"</b>",
"<u>",
"</u>",
"<font size=4>",
"</font>",
"<font size=8>",
"</font>",
"<a href=\"mailto:",
"\">Click Here</a>",
"<a href=\"",
"\" target=\"blank\">Click Here</a>",
"<a href=\"",
"\" target=\"blank\">Click Here</a>",
"<img src='images/smilies/smile.gif' border='0' />",
"<img src='images/smilies/mad.gif' border='0' />",
"<img src='images/smilies/sad.gif' border='0' />",
"<img src='images/smilies/rolleyes.gif' border='0' />",
"<img src='images/smilies/smirk.gif' border='0' />",
"<img src='images/smilies/wink.gif' border='0' />",
"<img src='images/smilies/surprised.gif' border='0' />",
"<img src='images/smilies/thinking.gif' border='0' />",
"<img src='images/smilies/tongue.gif' border='0' />",
"<img src='images/smilies/cool.gif' border='0' />",
"<img src='",
"' border='2' />",
"<img src='",
"' border='2' />",
"<div class='quote'>Quote:<br />",
"</div>",
"<div class='quote'>Quote:<br />",
"</div>",
);
$bbc_num=count($bbc_a);
$loop=0;
while($loop<$bbc_num)
{
$bbcode=str_replace($bbc_a[$loop], $bbc_b[$loop], $bbcode);
$loop++;
}
return $bbcode;
}
?>
what would I need to do this to either a - display the url itself as the display text.
Thanks as always
I was given this script buy a guy on another forum but I can't get hold of him now.
Basically it wraps bbcode around highligted text.
It works fine for the bold and font tags.
I also use it for urls
The problem with this is because of how the script is written and my Parser all I can get it to display for the url text is click here
Here is the javascript
[CODE]
Hi
This script was given to me by someone on here for use on my site. I know nothing of JS at all but he offered this for use (but can't remember who it was)
[code]<script type="text/javascript">
function AddEmo(tag)
{
var emo=document.forms["form"].elements["text"];
if (document.selection)
{
emo.focus();
var sel = document.selection.createRange();
sel.text = tag
}
else if (emo.selectionStart || emo.selectionStart == '0')
{
var startPos = emo.selectionStart
var endPos = emo.selectionEnd
emo.value = emo.value.substring(0, startPos)
+ tag
+ emo.value.substring(endPos, emo.value.length)
}
else {
emo.value += tag;
}
}
function AddTag(tag)
{
var txt = '';
if (window.getSelection)
{
txt = window.getSelection();
}
else if (document.getSelection)
{
txt = document.getSelection();
}
else if (document.selection)
{
txt = document.selection.createRange().text;
}
var stri1 = txt
var stri = "["+tag+"]"+stri1+"[/"+tag+"]"
AddEmo(stri);
}
// calling the function
</script>
[/code/]
and here is my parser
function BBCODE($bbcode)
{
//the bbcode tags..
$bbc_a=array(
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"::smile::",
"::mad::",
"::sad::",
"::rolleyes::",
"::smirk::",
"::wink::",
"::surprised::",
"::thinking::",
"::tongue::",
"::cool::",
"",
"",
"",
"",
"",
"",
"",
"",
);
//bbcode gets converted to..
$bbc_b=array(
"<strike>",
"</strike>",
"<b>",
"</b>",
"<u>",
"</u>",
"<font size=4>",
"</font>",
"<font size=8>",
"</font>",
"<a href=\"mailto:",
"\">Click Here</a>",
"<a href=\"",
"\" target=\"blank\">Click Here</a>",
"<a href=\"",
"\" target=\"blank\">Click Here</a>",
"<img src='images/smilies/smile.gif' border='0' />",
"<img src='images/smilies/mad.gif' border='0' />",
"<img src='images/smilies/sad.gif' border='0' />",
"<img src='images/smilies/rolleyes.gif' border='0' />",
"<img src='images/smilies/smirk.gif' border='0' />",
"<img src='images/smilies/wink.gif' border='0' />",
"<img src='images/smilies/surprised.gif' border='0' />",
"<img src='images/smilies/thinking.gif' border='0' />",
"<img src='images/smilies/tongue.gif' border='0' />",
"<img src='images/smilies/cool.gif' border='0' />",
"<img src='",
"' border='2' />",
"<img src='",
"' border='2' />",
"<div class='quote'>Quote:<br />",
"</div>",
"<div class='quote'>Quote:<br />",
"</div>",
);
$bbc_num=count($bbc_a);
$loop=0;
while($loop<$bbc_num)
{
$bbcode=str_replace($bbc_a[$loop], $bbc_b[$loop], $bbcode);
$loop++;
}
return $bbcode;
}
?>
what would I need to do this to either a - display the url itself as the display text.
Thanks as always