Code Box Copy

What is this?

Code Box Copy is a lightweight, flexible syntax highlighter jQuery plugin, that provides easy to use, simple method to copy any text to the clipboard with a single click.

Usage

Sources

Put the following lines below to the head section. Do not forget to use the copy function :)

<!-- Cod Box Copy begin -->
<link href="prism/prism.min.css" rel="stylesheet">
<link href="code-box-copy/css/code-box-copy.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
<script src="prism/prism.min.js"></script>
<script src="clipboard/clipboard.min.js"></script>
<script src="code-box-copy/js/code-box-copy.js"></script>
<!-- Cod Box Copy end -->

Content you want to copy

Test it with a simple HTML code like below:

<div class="code-box-copy">
    <button class="code-box-copy__btn" data-clipboard-target="#example-html" title="Copy"></button>
    <pre><code class="language-html" id="example-html">&lt;div class=&quot;example&quot;&gt;
        Lorem ipsum
    &lt;/div&gt;</code></pre>
</div>

Plugin initialization

Put in the head section the plugin initialization's code or in the end of the body section:

<script>
$(document).ready(function () {
    $('.code-box-copy').codeBoxCopy();
});
</script>

Plugin initialization with parameters:

<script>
$(document).ready(function () {
    $('.code-box-copy').codeBoxCopy({
        tooltipText: 'Copied',
        tooltipShowTime: 1000,
        tooltipFadeInTime: 300,
        tooltipFadeOutTime: 300
    });
});
</script>

Parameters

Third-party libraries (MIT Licence)

HTML Example

<div class="my-class">
    <span>Lorem ipsum</span>
</div>

CSS Example

.my-class {
    display: flex;
    align-items: center;
    background-color: #c5c5c5;
    font-size: 1.2em;
    line-height: 1.5;
    font-weight: normal;
}

JavaScript Example

window.addEventListener('resize', function () {
    console.log('Lorem ipsum');    
});

Full Example

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Code Box Copy – Full Example</title>
        <!-- Cod Box Copy begin -->
        <link href="prism/prism.min.css" rel="stylesheet">
        <link href="code-box-copy/css/code-box-copy.css" rel="stylesheet">
        <script src="js/jquery.min.js"></script>
        <script src="prism/prism.min.js"></script>
        <script src="clipboard/clipboard.min.js"></script>
        <script src="code-box-copy/js/code-box-copy.js"></script>
        <!-- Cod Box Copy end -->
    </head>
    <body>
        <div class="code-box-copy">
            <button class="code-box-copy__btn" data-clipboard-target="#example-full" title="Copy"></button>
            <pre><code class="language-html" id="example-full">&lt;div class=&quot;my-class&quot;&gt;
    &lt;span&gt;Lorem ipsum&lt;/span&gt;
&lt;/div&gt;</code></pre>
        </div>
                        
       <script>
            $('.code-box-copy').codeBoxCopy({
                tooltipText: 'Copied',
                tooltipShowTime: 1000,
                tooltipFadeInTime: 300,
                tooltipFadeOutTime: 300
            });
        </script>
    </body>
</html>

Licence

The MIT Licence

Copyright 2017 © jablonczay.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Other projects