Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: blsilks on December 21, 2004, 08:43:50 AM

Title: BB Code Button Function in the Post.template.php file.
Post by: blsilks on December 21, 2004, 08:43:50 AM
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?
Title: Re: BB Code Button Function in the Post.template.php file.
Post by: [Unknown] on December 22, 2004, 04:04:32 AM
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]
Title: Re: BB Code Button Function in the Post.template.php file.
Post by: blsilks on December 22, 2004, 09:01:26 AM
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]"
Title: Re: BB Code Button Function in the Post.template.php file.
Post by: blsilks on December 22, 2004, 10:35:32 AM
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.
Title: Re: BB Code Button Function in the Post.template.php file.
Post by: blsilks on December 22, 2004, 12:49:00 PM
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.
Title: Re: BB Code Button Function in the Post.template.php file.
Post by: blsilks on December 22, 2004, 01:20:30 PM
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>';
Title: Re: BB Code Button Function in the Post.template.php file.
Post by: [Unknown] on December 23, 2004, 07:53:42 AM
Sorry, I made a typo.  I've edited my post above to a working alternative.

-[Unknown]