Compare commits

...

19 Commits
2.0 ... v2.0.3

Author SHA1 Message Date
Zeno Rocha
5be63e28dd 2.0.3 2018-11-11 18:56:51 -08:00
Rouven Weßling
adc669df06 Always run webpack in production mode. (#595)
Otherwise horribly inefficent code that evals(!) strings of code is generated.
2018-11-11 18:53:43 -08:00
Rouven Weßling
b57e6d019f Don't claim to support ESM 2018-11-11 18:51:00 -08:00
Rouven Weßling
3d005b547e Maintain banner in minified file 2018-11-11 18:49:23 -08:00
Zeno Rocha
cf9e8fd7ce Updates devDependencies 2018-11-11 09:58:44 -08:00
Zeno Rocha
f1d99de5d3 Removes .npmignore file 2018-11-11 09:48:15 -08:00
Zeno Rocha
fdb66d3f16 2.0.2 2018-11-11 09:14:19 -08:00
Zeno Rocha
e0f82241d0 Removes bundle analyzer 2018-11-11 09:10:37 -08:00
Zeno Rocha
4d4c25c505 Updates Webpack CLI 2018-11-11 08:20:47 -08:00
Samuel Oloruntoba
5ef3f1a817 Migrates to Webpack 4 2018-11-11 08:17:25 -08:00
Zeno Rocha
3382ea3d14 2.0.1 2018-04-29 16:41:13 -07:00
Paweł Lesiecki
0fcf8c9460 Update package.json (#532)
Correct module path
2018-04-29 16:14:20 -07:00
Zeno Rocha
e1d571b3f3 Updates docs to use ClipboardJS 2.0 2018-03-01 09:07:10 -08:00
Zeno Rocha
43beb07bac Release v2.0.0 2018-02-28 21:56:32 -08:00
Zeno Rocha
9086f3ed64 Updates demos to use new constructor 2018-02-28 21:46:48 -08:00
Zeno Rocha
750cf124d7 Changes global variable from "Clipboard" to "ClipboardJS"
This was introduced in order to prevent a name conflict with the new `window.Clipboard` native function

For more info check:
* https://w3c.github.io/clipboard-apis/
* ac319a7ed3
2018-02-28 21:45:59 -08:00
Zeno Rocha
d25dcac817 Migrates banner from Browserify to Webpack #372 2018-02-28 20:32:25 -08:00
Fernando Herrero
f7e2f58c96 Create composer.json for instalation with composer (#467)
* Create composer.json for instalation with composer

The installation is much simpler with Composer and https://github.com/RobLoach/component-installer

After merged you can test it:
```
composer config repositories.zenorocha-clipboardjs vcs "https://github.com/zenorocha/clipboard.js/"
composer require zenorocha-clipboardjs:dev-master
```
Before merged you can test using my git fork.

Composer creates a "components" folder that contains the "clipboardjs" whith all files spec in "files" of composer.json.
You can then register the "package" at https://packagist.org In this way the installation would be simpler:
`composer require zenorocha-clipboardjs:dev-master`

* Remove icon
2018-02-28 17:05:21 -08:00
Guillaume Vincent
2d5b2df811 Migrate from Browserify to Webpack (#372)
* Migrate from Browserify to Webpack

close https://github.com/zenorocha/clipboard.js/issues/371

 Author:    Guillaume Vincent <guillaume@oslab.fr>

* remove browserify and associated modules and update tests
2018-02-28 17:03:39 -08:00
22 changed files with 9607 additions and 711 deletions

View File

@@ -1,4 +1,3 @@
{
"presets": ["es2015"],
"plugins": ["transform-es2015-modules-umd"]
"presets": ["env"]
}

View File

@@ -1,6 +0,0 @@
/*!
* clipboard.js v<%= pkg.version %>
* https://zenorocha.github.io/clipboard.js
*
* Licensed MIT © Zeno Rocha
*/

2
.gitignore vendored
View File

@@ -2,3 +2,5 @@ lib
npm-debug.log
bower_components
node_modules
yarn-error.log
yarn.lock

View File

@@ -1,7 +0,0 @@
/.*/
/demo/
/test/
/.*
/bower.json
/karma.conf.js
/src

View File

@@ -1,7 +1,7 @@
{
"name": "clipboard",
"version": "1.7.1",
"description": "Modern copy to clipboard. No Flash. Just 2kb",
"version": "2.0.3",
"description": "Modern copy to clipboard. No Flash. Just 3kb",
"license": "MIT",
"main": "dist/clipboard.js",
"ignore": [

25
composer.json Normal file
View 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"
]
}
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -15,7 +15,7 @@
<!-- 3. Instantiate clipboard -->
<script>
var clipboard = new Clipboard('.btn', {
var clipboard = new ClipboardJS('.btn', {
target: function() {
return document.querySelector('div');
}

View File

@@ -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';
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

1460
dist/clipboard.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -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']
});
}
};

8645
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -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.3",
git: "https://github.com/zenorocha/clipboard.js"
});

View File

@@ -1,10 +1,10 @@
{
"name": "clipboard",
"version": "1.7.1",
"version": "2.0.3",
"description": "Modern copy to clipboard. No Flash. Just 2kb",
"repository": "zenorocha/clipboard.js",
"license": "MIT",
"main": "lib/clipboard.js",
"main": "dist/clipboard.js",
"keywords": [
"clipboard",
"copy",
@@ -16,33 +16,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": "^4.2.0",
"cross-env": "^5.2.0",
"karma": "^3.1.1",
"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": "^3.0.5",
"mocha": "^5.2.0",
"phantomjs-prebuilt": "^2.1.4",
"sinon": "^7.1.1",
"uglifyjs-webpack-plugin": "^2.0.1",
"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",
"build-min": "cross-env NODE_ENV=production webpack",
"build-watch": "webpack --watch",
"test": "karma start --single-run",
"prepublish": "babel src --out-dir lib"
}
"prepublish": "npm run build"
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}

View File

@@ -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);
@@ -134,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;
}
@@ -144,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');
}
@@ -154,7 +154,7 @@ 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', {
new ClipboardJS('.btn', {
container: document.getElementById('modal')
});
```
@@ -162,7 +162,7 @@ new Clipboard('.btn', {
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();
```
@@ -176,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

44
webpack.config.js Normal file
View File

@@ -0,0 +1,44 @@
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',
mode: 'production',
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: {
minimize: production,
minimizer: [
new UglifyJSPlugin({
parallel: require('os').cpus().length,
uglifyOptions: {
ie8: false,
keep_fnames: false,
output: {
beautify: false,
comments: (node, {value, type}) => type == 'comment2' && value.startsWith('!')
}
}
})
]
},
plugins: [new webpack.BannerPlugin({ banner })]
};