forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: nickfzx on December 21, 2006, 11:25:16 am

Title: bbcode in comments buttons
Post by: nickfzx on December 21, 2006, 11:25:16 am
I worked out the other day that I can put bbcode into comments (links and the like)

It would be great if there were some easy shortcut buttons like there are in this simple machines forum to make inserting bbcode really easy.

Does this already exhist...how hard would it be to make?
Title: Re: bbcode in comments buttons
Post by: Nibbler on December 21, 2006, 01:10:44 pm
Not too hard, the javascript used for smf can be adapted for use inside Coppermine.
Title: Re: bbcode in comments buttons
Post by: nickfzx on December 21, 2006, 07:07:11 pm
cool, ill look into that and post my results here if I figure it out.

Cheers
Nick
Title: Re: bbcode in comments buttons
Post by: nickfzx on December 21, 2006, 10:57:27 pm
ok so ive figured this out

seems to work fine except does not give easybb options when editing a comment (because it tries to put it in the post form not the edit form so I just left the option out)

to see it in action you will have to goto my site and open an account as guests can't comment.

this is how to do it.

Open your template.html file and stick this javascript in the header:
Code: [Select]
<script type="text/javascript">
function insert_text(open, close){
msgfield = (document.all) ? document.all.msg_body : document.forms['post']['msg_body'];
// IE support
if (document.selection && document.selection.createRange)
{
msgfield.focus();
sel = document.selection.createRange();
sel.text = open + sel.text + close;
msgfield.focus();
}

// Moz support
else if (msgfield.selectionStart || msgfield.selectionStart == '0')
{
var startPos = msgfield.selectionStart;
var endPos = msgfield.selectionEnd;

msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
msgfield.focus();
}

// Fallback support for other browsers
else
{
msgfield.value += open + close;
msgfield.focus();
}

return;
}</script>

Then open themes.inc.php and search for <!-- END input_box_smilies --> (must have smilies enabled otherwise use the without smilies input box)

add this code just before that:

Code: [Select]
<div style="padding-top: 4px">
<input type="button" value=" B " name="B" onclick="insert_text('[b]','[/b]')" />
<input type="button" value=" I " name="I" onclick="insert_text('[i]','[/i]')" />
<input type="button" value="http://" name="Url" onclick="insert_text('[url]','[/url]')" />
<input type="button" value="Img" name="Img" onclick="insert_text('[img]','[/img]')" />
</div>

Hope this is clear enough...give me a shout if you need help with this.

Cheers

Nick
Title: Re: bbcode in comments buttons
Post by: Joachim Müller on December 22, 2006, 07:11:53 am
You mustn't edit include/themes.inc.php, under no circumstances. You're suppossed to edit themes/yourtheme/theme.php instead.
Title: Re: bbcode in comments buttons
Post by: nickfzx on December 22, 2006, 07:15:24 am
oh sorry I diddn't know this :-X...but I see the logic there...things could get messy if everyone was editing the include files.

anyone using little mod do what gaugau says and stick the code in theme.php.