ClipLab
A Simple JavaScript Library to copy text to clipboard.
Install / Use
/learn @MoralistFestus/ClipLabREADME
CLIPLAB LIBRARY - JavaScript
<img src="https://raw.githubusercontent.com/MoralistFestus/ClipLab/master/20200924_225649.png" alt="ClipLab">ClipLab is a Simple but Effective Copy to Clipboard 📋 Library ♎. This simple library allows copying text to clipboard with a single JavaScript function.
How to Use
✔ Download or Clone this Library <br>
✔ Link it in your html file using <script src="cliplab.js"></script> or use the minified version.
CDN
https://cdn.jsdelivr.net/gh/MoralistFestus/ClipLab/src/cliplab.js
Or minifed version
https://cdn.jsdelivr.net/gh/MoralistFestus/ClipLab/src/cliplab.min.js
By tagged version
https://cdn.jsdelivr.net/gh/MoralistFestus/ClipLab@1.0.0/src/cliplab.js
https://cdn.jsdelivr.net/gh/MoralistFestus/ClipLab@1.0.0/src/cliplab.min.js
Example Code
new ClipLab()
This simple function triggers the copy to clipboard 📋 action.
ClipLab Attribute 📋
The ClipLab Js library has two data attributes:
- data-copy-text
- data-attr-selector
The two data attributes in cliplab are used for specifying clipboard value (text to be copied to clipboard).
- The
data-copy-textholds the text value to be copied to clipboard, while - The
data-attr-selectorpoints to the class or id value of an input field to be copied.
data-copy-text example
<button id="btn" data-copy-text="This text will be copied">Copy</button>
The <b>data-copy-text</b> attribute holds the text that will be copied to clipboard. To further copy the text to clipboard. let's call the ClipLab function and pass the id="btn" attribute into the function.
Sample code
<button id="btn" data-copy-text="This text will be copied">Copy text</button>
<script>
new ClipLab("#btn"); // btn attribute
</script>
Once the copy text button is clicked, the text is copied.
You can let the user aware that the text is successfully copied to clipboard.
<button id="btn" data-copy-text="The text will be copied">Copy text</button>
<script type="text/javascript">
var copyText = new ClipLab("#btn");
var copyText = new ClipLab("#btn");
// true
copyText.onCopied = function(copied) {
alert("Copied: " + copied);
};
// false
copyText.notCopied = function(copied) {
window.prompt("Ctrl+C: ", copied);
};
</script>
Texts from input or textarea fields can be copied with use of ClipLab library.
<input class="input" value="Press Copy to copy this text"></input>
<button id="btn" data-attr-selector=".input">Copy</button>
<script type="text/javascript">
var copyText = new ClipLab("#btn");
copyText.onCopied = function(copy) {
alert("Copied: " + copy)
this.unselect();
};
copyText.notCopied = function(copy) {
window.prompt("Ctrl+C: ", copy);
};
</script>
Browser Support
ClipLab works with the latest version of JavaScript on Chrome, Firefox, Opera Mini and other browsers but as not being tested with IE (Internet Explorer).
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
