Skip to content

Commit dccc87c

Browse files
authored
Merge pull request #2 from masgalih320/core
core to master: new update for 1.1.8
2 parents dca12ae + 3052a1d commit dccc87c

File tree

4 files changed

+372
-14
lines changed

4 files changed

+372
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
package-lock.json

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Galih Sukristyan Saputra
4+
5+
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:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
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.

README.md

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,141 @@
1-
# kopasin-js
2-
kopasin-js is a simple, lightweight, and customizable JavaScript library for adding copy-paste interactivity to your projects
1+
# KopasinJS
2+
3+
**kopasin-js** is a lightweight and customizable JavaScript library designed to add copy-paste functionality to your web projects. With `kopasin-js`, you can effortlessly enable users to copy and paste text with minimal setup and maximum flexibility. This library use 0% of JQuery.
4+
5+
![License](https://img.shields.io/npm/l/kopasin-js)
6+
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/masgalih320/kopasin-js/total)
7+
![npm bundle size](https://img.shields.io/bundlephobia/min/kopasin-js)
8+
![GitHub commit activity](https://img.shields.io/github/commit-activity/w/masgalih320/kopasin-js)
9+
10+
## Features
11+
12+
- **Simple Setup:** Easy to integrate with just a few lines of code.
13+
- **Customizable:** Tailor the library to fit your specific needs.
14+
- **Lightweight:** Minimal impact on your project's performance.
15+
- **Cross-Browser Support:** Works seamlessly across modern web browsers.
16+
17+
## Visits
18+
19+
- [Demo Site](https://kopasin-js.galih.me)
20+
- [Portfolio](https://galih.me)
21+
- [Galih Blogs](https://masgalih.net)
22+
23+
## Installation
24+
25+
To get started with `kopasin-js`, you can either include it via CDN or install it via npm.
26+
27+
### Using CDN
28+
29+
Add the following script to your HTML:
30+
31+
```html
32+
# USING CDN
33+
<script src="https://cdn.jsdelivr.net/npm/kopasin-js@latest/dist/kopasin-js.global.js"></script>
34+
# OR
35+
<script src="https://unpkg.com/kopasin-js@1.1.7/dist/kopasin-js.global.js"></script>
36+
37+
# USING DOWNLOADED FILES
38+
<script src="dist/kopasin-js.global.js"></script>
39+
```
40+
41+
## With Import
42+
43+
Install via NPM
44+
45+
```bash
46+
npm i kopasin-js
47+
```
48+
49+
And then import the library
50+
51+
```js
52+
import KopasinJS from "kopasin-js"
53+
```
54+
55+
## Example Usage
56+
57+
### Copying Text from an Input
58+
59+
To copy a value from input element, we need to create 2 element, which is the `<input />` element and `<button></button>` element
60+
61+
```html
62+
<input type="text" id="copy-this" value="Copy Me" readonly>
63+
<button type="button" id="copy-button">Copy</button>
64+
```
65+
66+
After that, load KopasinJS like this
67+
68+
```js
69+
new Kopasin({
70+
copy: {
71+
on: 'click',
72+
trigger: document.getElementById('copy-button'),
73+
source: document.getElementById('copy-this'),
74+
success: function () {
75+
console.log('Copied!')
76+
},
77+
error: function () {
78+
console.log('Failed to copy')
79+
}
80+
},
81+
});
82+
```
83+
84+
The `success` and `error` callback is optional, but you can use the `success` callback for improving the user experience with interactivity after copying is successful.
85+
86+
### Copying Text from an Element
87+
88+
To copy a value from an element (example: `<div>`), we also need to create 2 element, which is the `<div></div>` element and `<button></button>` element.
89+
90+
```html
91+
<div id="copy-this">Copy Me</div> <!-- You can also use another element like <p>, <span> and anything -->
92+
<button type="button" id="copy-button">Copy</button>
93+
```
94+
95+
For the javascript code is still same.
96+
97+
```js
98+
new Kopasin({
99+
copy: {
100+
on: 'click',
101+
trigger: document.getElementById('copy-button'),
102+
source: document.getElementById('copy-this'),
103+
success: function () {
104+
console.log('Copied!')
105+
},
106+
error: function () {
107+
console.log('Failed to copy')
108+
}
109+
},
110+
});
111+
```
112+
113+
## Options for `copy`
114+
115+
| Key | Type | Description | Required | Default Value |
116+
|---------|-------------|------------------------------------------------------------------------------------------------------------------------|----------|---------------|
117+
| on | String | The event that will be used to trigger the element in the `trigger` option, must be valid event for `addEventListener` | yes | click |
118+
| trigger | HTMLElement | This element will be used to trigger the copy process | yes | |
119+
| source | HTMLElement | Element that you want to copy the value/text from | yes | |
120+
| success | Function | Function that will fired after copying is done | no | () => {} |
121+
| error | Function | Function that will fired after copying is failed | no | () => {} |
122+
123+
## Options for `paste`
124+
125+
| Key | Type | Description | Required | Default Value |
126+
|---------|---------------------------------|------------------------------------------------------------------------------------------------------------------------|----------|---------------|
127+
| on | String | The event that will be used to trigger the element in the `trigger` option, must be valid event for `addEventListener` | yes | click |
128+
| trigger | HTMLElement | This element will be used to trigger the pasting process | yes | |
129+
| target | HTMLInputElement \| HTMLElement | Target element that the value/text will replaced with a value from your clipboard | yes | |
130+
| success | Function | Function that will fired after pasting is done | no | () => {} |
131+
| error | Function | This function will fired if pasting are failed | no | () => {} |
132+
133+
## Donate
134+
135+
If you have used this library and it's useful for you, please consider to donate:
136+
137+
[Saweria](https://saweria.co/sukristyan)
138+
139+
## License
140+
141+
The KopasinJS is open-sourced software licensed under the [MIT license](/LICENSE.md).

0 commit comments

Comments
 (0)