mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdb66d3f16 | ||
|
|
e0f82241d0 | ||
|
|
4d4c25c505 | ||
|
|
5ef3f1a817 | ||
|
|
3382ea3d14 | ||
|
|
0fcf8c9460 | ||
|
|
e1d571b3f3 | ||
|
|
43beb07bac | ||
|
|
9086f3ed64 | ||
|
|
750cf124d7 | ||
|
|
d25dcac817 | ||
|
|
f7e2f58c96 | ||
|
|
2d5b2df811 | ||
|
|
0c3bce265f | ||
|
|
3c0dfe5a38 | ||
|
|
f960b0d20a |
3
.babelrc
3
.babelrc
@@ -1,4 +1,3 @@
|
||||
{
|
||||
"presets": ["es2015"],
|
||||
"plugins": ["transform-es2015-modules-umd"]
|
||||
"presets": ["env"]
|
||||
}
|
||||
|
||||
6
.banner
6
.banner
@@ -1,6 +0,0 @@
|
||||
/*!
|
||||
* clipboard.js v<%= pkg.version %>
|
||||
* https://zenorocha.github.io/clipboard.js
|
||||
*
|
||||
* Licensed MIT © Zeno Rocha
|
||||
*/
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@ lib
|
||||
npm-debug.log
|
||||
bower_components
|
||||
node_modules
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "clipboard",
|
||||
"version": "1.7.1",
|
||||
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
||||
"version": "2.0.2",
|
||||
"description": "Modern copy to clipboard. No Flash. Just 3kb",
|
||||
"license": "MIT",
|
||||
"main": "dist/clipboard.js",
|
||||
"ignore": [
|
||||
|
||||
25
composer.json
Normal file
25
composer.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "zenorocha/clipboardjs",
|
||||
"description": "Modern copy to clipboard. No Flash. Just 3kb gzipped https://clipboardjs.com",
|
||||
"type": "component",
|
||||
"homepage": "https://clipboardjs.com/",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Zeno Rocha",
|
||||
"url": "http://zenorocha.com/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"robloach/component-installer": "*"
|
||||
},
|
||||
"extra": {
|
||||
"component": {
|
||||
"scripts": [
|
||||
"dist/clipboard.js"
|
||||
],
|
||||
"files": [
|
||||
"dist/clipboard.min.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
<!-- 3. Instantiate clipboard by passing a HTML element -->
|
||||
<script>
|
||||
var btn = document.getElementById('btn');
|
||||
var clipboard = new Clipboard(btn);
|
||||
var clipboard = new ClipboardJS(btn);
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<!-- 3. Instantiate clipboard by passing a list of HTML elements -->
|
||||
<script>
|
||||
var btns = document.querySelectorAll('button');
|
||||
var clipboard = new Clipboard(btns);
|
||||
var clipboard = new ClipboardJS(btns);
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<!-- 3. Instantiate clipboard by passing a string selector -->
|
||||
<script>
|
||||
var clipboard = new Clipboard('.btn');
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new Clipboard('.btn', {
|
||||
var clipboard = new ClipboardJS('.btn', {
|
||||
target: function() {
|
||||
return document.querySelector('div');
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new Clipboard('.btn', {
|
||||
var clipboard = new ClipboardJS('.btn', {
|
||||
text: function() {
|
||||
return 'to be or not to be';
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new Clipboard('.btn');
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new Clipboard('.btn');
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<!-- 3. Instantiate clipboard -->
|
||||
<script>
|
||||
var clipboard = new Clipboard('.btn');
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.log(e);
|
||||
|
||||
974
dist/clipboard.js
vendored
974
dist/clipboard.js
vendored
File diff suppressed because one or more lines are too long
8
dist/clipboard.min.js
vendored
8
dist/clipboard.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,8 +1,10 @@
|
||||
module.exports = function(karma) {
|
||||
karma.set({
|
||||
plugins: ['karma-browserify', 'karma-chai', 'karma-sinon', 'karma-mocha', 'karma-phantomjs-launcher'],
|
||||
var webpackConfig = require('./webpack.config.js');
|
||||
|
||||
frameworks: ['browserify', 'chai', 'sinon', 'mocha'],
|
||||
module.exports = function (karma) {
|
||||
karma.set({
|
||||
plugins: ['karma-webpack', 'karma-chai', 'karma-sinon', 'karma-mocha', 'karma-phantomjs-launcher'],
|
||||
|
||||
frameworks: ['chai', 'sinon', 'mocha'],
|
||||
|
||||
files: [
|
||||
'src/**/*.js',
|
||||
@@ -10,18 +12,20 @@ module.exports = function(karma) {
|
||||
'./node_modules/phantomjs-polyfill/bind-polyfill.js'
|
||||
],
|
||||
|
||||
exclude: ['test/module-systems.js'],
|
||||
|
||||
preprocessors: {
|
||||
'src/**/*.js' : ['browserify'],
|
||||
'test/**/*.js': ['browserify']
|
||||
'src/**/*.js': ['webpack'],
|
||||
'test/**/*.js': ['webpack']
|
||||
},
|
||||
|
||||
browserify: {
|
||||
debug: true,
|
||||
transform: ['babelify']
|
||||
webpack: {
|
||||
module: webpackConfig.module,
|
||||
plugins: webpackConfig.plugins
|
||||
},
|
||||
|
||||
webpackMiddleware: {
|
||||
stats: 'errors-only'
|
||||
},
|
||||
|
||||
browsers: ['PhantomJS']
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
7818
package-lock.json
generated
Normal file
7818
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,8 @@
|
||||
|
||||
Package.describe({
|
||||
name: "zenorocha:clipboard",
|
||||
summary: "Modern copy to clipboard. No Flash. Just 2kb.",
|
||||
version: "1.7.1",
|
||||
summary: "Modern copy to clipboard. No Flash. Just 3kb.",
|
||||
version: "2.0.2",
|
||||
git: "https://github.com/zenorocha/clipboard.js"
|
||||
});
|
||||
|
||||
|
||||
55
package.json
55
package.json
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "clipboard",
|
||||
"version": "1.7.1",
|
||||
"version": "2.0.2",
|
||||
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
||||
"repository": "zenorocha/clipboard.js",
|
||||
"license": "MIT",
|
||||
"main": "lib/clipboard.js",
|
||||
"main": "dist/clipboard.js",
|
||||
"module": "dist/clipboard.js",
|
||||
"keywords": [
|
||||
"clipboard",
|
||||
"copy",
|
||||
@@ -16,33 +17,35 @@
|
||||
"tiny-emitter": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-core": "^6.24.1",
|
||||
"babel-plugin-transform-es2015-modules-umd": "^6.24.1",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"babelify": "^7.3.0",
|
||||
"bannerify": "Vekat/bannerify#feature-option",
|
||||
"browserify": "^14.3.0",
|
||||
"chai": "^3.5.0",
|
||||
"install": "^0.9.6",
|
||||
"karma": "^1.6.0",
|
||||
"karma-browserify": "^5.1.1",
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-loader": "^7.1.4",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"chai": "^3.4.1",
|
||||
"cross-env": "^3.1.4",
|
||||
"karma": "^1.3.0",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-phantomjs-launcher": "^1.0.4",
|
||||
"karma-sinon": "^1.0.5",
|
||||
"mocha": "^3.3.0",
|
||||
"phantomjs-prebuilt": "^2.1.14",
|
||||
"sinon": "^2.2.0",
|
||||
"uglify-js": "^2.8.22",
|
||||
"watchify": "^3.9.0"
|
||||
"karma-mocha": "^1.2.0",
|
||||
"karma-phantomjs-launcher": "^1.0.0",
|
||||
"karma-sinon": "^1.0.4",
|
||||
"karma-webpack": "^2.0.2",
|
||||
"mocha": "^3.1.2",
|
||||
"phantomjs-prebuilt": "^2.1.4",
|
||||
"sinon": "^1.17.2",
|
||||
"uglifyjs-webpack-plugin": "^1.2.4",
|
||||
"webpack": "^4.5.0",
|
||||
"webpack-cli": "^3.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build-debug && npm run build-min",
|
||||
"build-debug": "browserify src/clipboard.js -s Clipboard -t [babelify] -p [bannerify --file .banner ] -o dist/clipboard.js",
|
||||
"build-min": "uglifyjs dist/clipboard.js --comments '/!/' -m screw_ie8=true -c screw_ie8=true,unused=false -o dist/clipboard.min.js",
|
||||
"build-watch": "watchify src/clipboard.js -s Clipboard -t [babelify] -o dist/clipboard.js -v",
|
||||
"build-debug": "webpack --mode=development",
|
||||
"build-min": "cross-env NODE_ENV=production webpack --mode=production",
|
||||
"build-watch": "webpack --watch",
|
||||
"test": "karma start --single-run",
|
||||
"prepublish": "babel src --out-dir lib"
|
||||
}
|
||||
"prepublish": "npm run build"
|
||||
},
|
||||
"browserslist": [
|
||||
"> 1%",
|
||||
"last 2 versions"
|
||||
]
|
||||
}
|
||||
|
||||
24
readme.md
24
readme.md
@@ -34,7 +34,7 @@ First, include the script located on the `dist` folder or load it from [a third-
|
||||
Now, you need to instantiate it by [passing a DOM selector](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-selector.html#L18), [HTML element](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-node.html#L16-L17), or [list of HTML elements](https://github.com/zenorocha/clipboard.js/blob/master/demo/constructor-nodelist.html#L18-L19).
|
||||
|
||||
```js
|
||||
new Clipboard('.btn');
|
||||
new ClipboardJS('.btn');
|
||||
```
|
||||
|
||||
Internally, we need to fetch all elements that matches with your selector and attach event listeners for each one. But guess what? If you have hundreds of matches, this operation can consume a lot of memory.
|
||||
@@ -103,7 +103,7 @@ There are cases where you'd like to show some user feedback or capture what has
|
||||
That's why we fire custom events such as `success` and `error` for you to listen and implement your custom logic.
|
||||
|
||||
```js
|
||||
var clipboard = new Clipboard('.btn');
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
|
||||
clipboard.on('success', function(e) {
|
||||
console.info('Action:', e.action);
|
||||
@@ -119,7 +119,13 @@ clipboard.on('error', function(e) {
|
||||
});
|
||||
```
|
||||
|
||||
For a live demonstration, open this [site](https://clipboardjs.com/) and just your console :)
|
||||
For a live demonstration, go to this [site](https://clipboardjs.com/) and open your console.
|
||||
|
||||
## Tooltips
|
||||
|
||||
Each application has different design needs, that's why clipboard.js does not include any CSS or built-in tooltip solution.
|
||||
|
||||
The tooltips you see on the [demo site](https://clipboardjs.com/) were built using [GitHub's Primer](https://github.com/primer/primer-css/tree/master/modules/primer-tooltips). You may want to check that out if you're looking for a similar look and feel.
|
||||
|
||||
## Advanced Options
|
||||
|
||||
@@ -128,7 +134,7 @@ If you don't want to modify your HTML, there's a pretty handy imperative API for
|
||||
For instance, if you want to dynamically set a `target`, you'll need to return a Node.
|
||||
|
||||
```js
|
||||
new Clipboard('.btn', {
|
||||
new ClipboardJS('.btn', {
|
||||
target: function(trigger) {
|
||||
return trigger.nextElementSibling;
|
||||
}
|
||||
@@ -138,7 +144,7 @@ new Clipboard('.btn', {
|
||||
If you want to dynamically set a `text`, you'll return a String.
|
||||
|
||||
```js
|
||||
new Clipboard('.btn', {
|
||||
new ClipboardJS('.btn', {
|
||||
text: function(trigger) {
|
||||
return trigger.getAttribute('aria-label');
|
||||
}
|
||||
@@ -148,15 +154,15 @@ new Clipboard('.btn', {
|
||||
For use in Bootstrap Modals or with any other library that changes the focus you'll want to set the focused element as the `container` value.
|
||||
|
||||
```js
|
||||
new Clipboard('.btn', {
|
||||
container: document.getElementById('#modal')
|
||||
new ClipboardJS('.btn', {
|
||||
container: document.getElementById('modal')
|
||||
});
|
||||
```
|
||||
|
||||
Also, if you are working with single page apps, you may want to manage the lifecycle of the DOM more precisely. Here's how you clean up the events and objects that we create.
|
||||
|
||||
```js
|
||||
var clipboard = new Clipboard('.btn');
|
||||
var clipboard = new ClipboardJS('.btn');
|
||||
clipboard.destroy();
|
||||
```
|
||||
|
||||
@@ -170,7 +176,7 @@ This library relies on both [Selection](https://developer.mozilla.org/en-US/docs
|
||||
|
||||
The good news is that clipboard.js gracefully degrades if you need to support older browsers. All you have to do is show a tooltip saying `Copied!` when `success` event is called and `Press Ctrl+C to copy` when `error` event is called because the text is already selected.
|
||||
|
||||
You can also check if clipboard.js is supported or not by running `Clipboard.isSupported()`, that way you can hide copy/cut buttons from the UI.
|
||||
You can also check if clipboard.js is supported or not by running `ClipboardJS.isSupported()`, that way you can hide copy/cut buttons from the UI.
|
||||
|
||||
## Bonus
|
||||
|
||||
|
||||
42
webpack.config.js
Normal file
42
webpack.config.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const pkg = require('./package.json');
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
||||
|
||||
const production = process.env.NODE_ENV === 'production' || false;
|
||||
|
||||
const banner = `clipboard.js v${pkg.version}
|
||||
https://zenorocha.github.io/clipboard.js
|
||||
|
||||
Licensed MIT © Zeno Rocha`;
|
||||
|
||||
module.exports = {
|
||||
entry: './src/clipboard.js',
|
||||
output: {
|
||||
filename: production ? 'clipboard.min.js' : 'clipboard.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
library: 'ClipboardJS',
|
||||
libraryTarget: 'umd'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
|
||||
]
|
||||
},
|
||||
optimization: {
|
||||
minimizer: [
|
||||
new UglifyJSPlugin({
|
||||
parallel: require('os').cpus().length,
|
||||
uglifyOptions: {
|
||||
ie8: false,
|
||||
keep_fnames: false,
|
||||
output: {
|
||||
beautify: false,
|
||||
comments: false
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
},
|
||||
plugins: [new webpack.BannerPlugin({ banner })]
|
||||
};
|
||||
Reference in New Issue
Block a user