Jump to content

Help changing this little script


liam1412

Recommended Posts

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>

 

 

This script basically wraps BBCODE tags around highligted text.

 

The I use my BBCODE php function to parse the text

 

At the moment I use this for links

 

so

 

(url)http://www.phpfreaks.com(/url) but with sq brackets but bbcode on here is parsing it

 

becomes

 

CLick Here

 

How would I ammend this script so that the text that is displayed is the actual URL itself. For info this is my parser code.

 

function BBCODE($bbcode) 
{ 
//the bbcode tags.. 
$bbc_a=array(
"[strike]",
"[/strike]",
"[b]",
"[/b]",
"[u]",
"[/u]",
"[big]",
"[/big]",
"[huge]",
"[/huge]",
"[e_mail]",
"[/e_mail]",
"[url=http://",
"]",
"[/url]",
"[url=http://",
"]",
"[/url]",
"::smile::",
"::mad::",
"::sad::",
"::",
"::smirk::",
"::wink::",
"::surprised::",
"::thinking::",
"::tongue::",
"::cool::",
"[img]http://",
"[/img]",
"[img]http://",
"[/img]",
"[quote]",
"[/quote]",
"[quote]",
"[/quote]",
); 

//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; 
}

[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.