BB Code Button Function in the Post.template.php file.

Started by blsilks, December 21, 2004, 08:43:50 AM

Previous topic - Next topic

blsilks

First off I installed the Custom BB Code mod which works great so now I can create my own BB code.

I made a BB code call bgred:

bgred <table width="100%" border=0 bordercolor=000000 cellspacing=0><tr><td bgcolor="#B22222"><font color="white">$1</font></td></tr></table>


Basically what this code does is make a table, a table row and then table column and make the entire background red.

I have made a drop down menu in the Post.template.php file that allows me to apply the bb code with ease and it works properly

echo ' <select onchange="surroundText(\'[\'+this.options[this.selectedIndex].value+\']\', \'[/\'+this.options[this.selectedIndex].value+\']\', document.', $context['post_form'], '.', $context['post_box_name'], '); this.selectedIndex = 0;" style="margin-bottom: 1ex;">
<option value="" selected="selected">', Severity, '</option>
<option value="bgred">', Critical, '</option>
</select>';



however I would like to make it so that this button automatically applies its bb code to the entire message in one click instead of me having to highlight the entire message manually and then click the button.  Anyboyd have any idea how I would make this work?

[Unknown]

#1
First, I'd personally use this for the custom bbc:

bgred <div style="background-color: #b22222; color: white;">$1</div>

Anyhow... you'd want some code like:
echo '
<select onchange="document.', $context['post_form'], '.', $context['post_box_name'], '.value = \'[\' + this.options[this.selectedIndex].value+\']\' + document.', $context['post_form'], '.', $context['post_box_name'], '.value + \'[/\' + this.options[this.selectedIndex].value + \']\'; this.selectedIndex = 0;" style="margin-bottom: 1ex;">
<option value="" selected="selected">Severity</option>
<option value="bgred">Critical</option>
</select>';



Does that work?

-[Unknown]

blsilks

Well I enter in your code and then I go into post and type in "bla bla bla" and then select severity.  Instead of surounding bla bla bla with [bgred] and [/bgred] (Example:  [bgred]bla bla bla[/bgred]), it wipes out bla bla bla and replaces it with "[bgred][object][/bgred]"

blsilks

A button that just selects all Text might even be nice.  I found lots of scripts on how to do that however I wasn't sure how to integrate that script into this form.

blsilks

Well I was able to create a "Select All" button by using the code:
echo ' <input type=button value="Highlight All" onClick="javascript:this.form.message.focus();this.form.message.select();">';
and I still have the drop down menu to tag everything with the [bgred] tag
echo ' <select onchange="surroundText(\'[\'+this.options[this.selectedIndex].value+\']\', \'[/\'+this.options[this.selectedIndex].value+\']\', document.', $context['post_form'], '.', $context['post_box_name'], '); this.selectedIndex = 0;" style="margin-bottom: 1ex;">
<option value="" selected="selected">', Severity, '</option>
<option value="bgred">', Critical, '</option>
</select>';


I just need to find a way to combine these buttons and have the first fuction of the button be Highlight All and the second function tag the highlighted text.

blsilks

Ok, I got it working.  I used the Code:

echo ' <select onchange="javascript:this.form.message.focus();this.form.message.select();surroundText(\'[\'+this.options[this.selectedIndex].value+\']\', \'[/\'+this.options[this.selectedIndex].value+\']\', document.', $context['post_form'], '.', $context['post_box_name'], '); this.selectedIndex = 0;" style="margin-bottom: 1ex;">
<option value="" selected="selected">', Severity, '</option>
<option value="bgred">', Critical, '</option>
</select>';

[Unknown]

Sorry, I made a typo.  I've edited my post above to a working alternative.

-[Unknown]

Advertisement: