Back to vBulletin 5.x Template Modifications

Copy Code to Clipboard for CODE/HTML/PHP BBCode
Mod Version: 1.00, by TheDigitalCouch

vB Version: 5.5.5 Rating: (0 vote - 0 average) Installs: 1
Released: 21 Jul 2022 Last Update: Never Downloads: 0
Not Supported Template Edits  

vBulletin 4 Creator:
vBulletin 4 Mod Link: https://vbulletin.org/forum/showthre...ight=copy+code
Javascript Fix:

Working with vB 5.6.9

About:

This modification adds a "Copy Code" box that will select all of the code within the box, as well as automatically copy to clipboard.

The vB4 mod did not automatically copy the code, which I've fixed in this version.

Installation

Copy and paste the following javascript code at the bottom of your head_include template:
AdminCP -> Styles -> Style Manager -> Edit Templates -> head_include
Code:
<script type="text/javascript">
    function selectAll(a)
    {
        var e  = a.parentNode.parentNode.getElementsByTagName('code')[0];
        if  (window.getSelection)
        {
            var s = window.getSelection();
                var r = document.createRange();
                r.selectNodeContents(e);
                s.removeAllRanges();
                s.addRange(r);
		document.execCommand('copy')
        }
        else if (document.getSelection)
        {
            var s = document.getSelection();
            var r = document.createRange();
            r.selectNodeContents(e);
            s.removeAllRanges();
            s.addRange(r);
        }
        else if  (document.selection)
        {
            var r = document.body.createTextRange();
            r.moveToElementText(e);
            r.select();
        }
    }
</script>
Save.

For CODE BBCode:

Navigate to AdminCP -> Styles -> Style Manager -> Edit Templates -> bbcode_code

Find:
Code:
{vb:rawphrase code}:
Replace with:
Code:
{vb:rawphrase code}:&nbsp;<input type="button" value="{vb:rawphrase select_code}" onclick="selectAll(this); return false;">
Find:
Code:
{vb:raw code}
Replace with:
Code:
<code>{vb:raw code}</code>
Save.

For HTML BBCode:

Navigate to AdminCP -> Styles -> Style Manager -> Edit Templates -> bbcode_html

Find:
Code:
{vb:rawphrase html_code}:
Replace with:
Code:
{vb:rawphrase html_code}:&nbsp;<input type="button" value="{vb:rawphrase select_code}" onclick="selectAll(this); return false;">
Find:
Code:
{vb:raw code}
Replace with:
Code:
<code>{vb:raw code}</code>
Save.

For PHP BBCode:

Navigate to AdminCP -> Styles -> Style Manager -> Edit Templates -> bbcode_php

Find:
Code:
{vb:rawphrase php_code}:
Replace with:
Code:
{vb:rawphrase php_code}:&nbsp;<input type="button" value="{vb:rawphrase select_code}" onclick="selectAll(this); return false;">
Find:
Code:
{vb:raw code}
Replace with:
Code:
<code>{vb:raw code}</code>
Save.

Then add the following to your css_additional.css:
Code:
.bbcode_container .bbcode_description {
    background: #777;
    font-weight: 8;
    padding: 5px;
}
.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button {
    font-size: 10px;
    font-weight: 7;
    float: right;
    margin-right: 5px;
}
Save.

You may need to make some adjustments.
Enjoy!

Download

No files for download.

Screenshots

Click image for larger version
Name:	Screenshot 2022-07-20 203653.jpg
Views:	52
Size:	30.0 KB
ID:	159071  

Similar Mods

After posting automatically copy to clipboard vBulletin 3.0 Full Releases
[tweak] Copy Post URL to clipboard vBulletin 2.x Template Modifications

vblts.ru supports vBulletin®, 2022-2024