mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdb66d3f16 | ||
|
|
e0f82241d0 | ||
|
|
4d4c25c505 | ||
|
|
5ef3f1a817 | ||
|
|
3382ea3d14 | ||
|
|
0fcf8c9460 | ||
|
|
e1d571b3f3 | ||
|
|
43beb07bac | ||
|
|
9086f3ed64 | ||
|
|
750cf124d7 | ||
|
|
d25dcac817 | ||
|
|
f7e2f58c96 | ||
|
|
2d5b2df811 | ||
|
|
0c3bce265f | ||
|
|
3c0dfe5a38 | ||
|
|
f960b0d20a | ||
|
|
b6e6b80ab0 | ||
|
|
a55c9ac513 | ||
|
|
39e622456c | ||
|
|
f8c322f163 | ||
|
|
f42b57067d | ||
|
|
4065080a17 | ||
|
|
5ab50475e0 | ||
|
|
e1394b3b8c | ||
|
|
f59d4e6b4d | ||
|
|
9ddff7e591 |
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.6.0",
|
||||
"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);
|
||||
|
||||
962
dist/clipboard.js
vendored
962
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.6.0",
|
||||
summary: "Modern copy to clipboard. No Flash. Just 3kb.",
|
||||
version: "2.0.2",
|
||||
git: "https://github.com/zenorocha/clipboard.js"
|
||||
});
|
||||
|
||||
|
||||
43
package.json
43
package.json
@@ -1,48 +1,51 @@
|
||||
{
|
||||
"name": "clipboard",
|
||||
"version": "1.6.0",
|
||||
"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",
|
||||
"cut"
|
||||
],
|
||||
"dependencies": {
|
||||
"good-listener": "^1.2.0",
|
||||
"good-listener": "^1.2.2",
|
||||
"select": "^1.1.2",
|
||||
"tiny-emitter": "^1.0.0"
|
||||
"tiny-emitter": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.5.1",
|
||||
"babel-core": "^6.5.2",
|
||||
"babel-plugin-transform-es2015-modules-umd": "^6.5.0",
|
||||
"babel-preset-es2015": "^6.5.0",
|
||||
"babelify": "^7.2.0",
|
||||
"bannerify": "Vekat/bannerify#feature-option",
|
||||
"browserify": "^13.0.0",
|
||||
"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",
|
||||
"install": "^0.8.1",
|
||||
"cross-env": "^3.1.4",
|
||||
"karma": "^1.3.0",
|
||||
"karma-browserify": "^5.0.1",
|
||||
"karma-chai": "^0.1.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",
|
||||
"uglify-js": "^2.4.24",
|
||||
"watchify": "^3.4.0"
|
||||
"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"
|
||||
]
|
||||
}
|
||||
|
||||
42
readme.md
42
readme.md
@@ -21,13 +21,7 @@ You can get it on npm.
|
||||
npm install clipboard --save
|
||||
```
|
||||
|
||||
Or bower, too.
|
||||
|
||||
```
|
||||
bower install clipboard --save
|
||||
```
|
||||
|
||||
If you're not into package management, just [download a ZIP](https://github.com/zenorocha/clipboard.js/archive/master.zip) file.
|
||||
Or if you're not into package management, just [download a ZIP](https://github.com/zenorocha/clipboard.js/archive/master.zip) file.
|
||||
|
||||
## Setup
|
||||
|
||||
@@ -40,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.
|
||||
@@ -109,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);
|
||||
@@ -125,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
|
||||
|
||||
@@ -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,17 +144,25 @@ 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');
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
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 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();
|
||||
```
|
||||
|
||||
@@ -168,7 +176,13 @@ 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
|
||||
|
||||
A browser extension that adds a "copy to clipboard" button to every code block on *GitHub, MDN, Gist, StackOverflow, StackExchange, npm, and even Medium.*
|
||||
|
||||
Install for [Chrome](https://chrome.google.com/webstore/detail/codecopy/fkbfebkcoelajmhanocgppanfoojcdmg) and [Firefox](https://addons.mozilla.org/en-US/firefox/addon/codecopy/).
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -18,11 +18,12 @@ class ClipboardAction {
|
||||
* @param {Object} options
|
||||
*/
|
||||
resolveOptions(options = {}) {
|
||||
this.action = options.action;
|
||||
this.emitter = options.emitter;
|
||||
this.target = options.target;
|
||||
this.text = options.text;
|
||||
this.trigger = options.trigger;
|
||||
this.action = options.action;
|
||||
this.container = options.container;
|
||||
this.emitter = options.emitter;
|
||||
this.target = options.target;
|
||||
this.text = options.text;
|
||||
this.trigger = options.trigger;
|
||||
|
||||
this.selectedText = '';
|
||||
}
|
||||
@@ -50,7 +51,7 @@ class ClipboardAction {
|
||||
this.removeFake();
|
||||
|
||||
this.fakeHandlerCallback = () => this.removeFake();
|
||||
this.fakeHandler = document.body.addEventListener('click', this.fakeHandlerCallback) || true;
|
||||
this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
|
||||
|
||||
this.fakeElem = document.createElement('textarea');
|
||||
// Prevent zooming on iOS
|
||||
@@ -64,12 +65,12 @@ class ClipboardAction {
|
||||
this.fakeElem.style[ isRTL ? 'right' : 'left' ] = '-9999px';
|
||||
// Move element to the same position vertically
|
||||
let yPosition = window.pageYOffset || document.documentElement.scrollTop;
|
||||
this.fakeElem.style.top = yPosition + 'px';
|
||||
this.fakeElem.style.top = `${yPosition}px`;
|
||||
|
||||
this.fakeElem.setAttribute('readonly', '');
|
||||
this.fakeElem.value = this.text;
|
||||
|
||||
document.body.appendChild(this.fakeElem);
|
||||
this.container.appendChild(this.fakeElem);
|
||||
|
||||
this.selectedText = select(this.fakeElem);
|
||||
this.copyText();
|
||||
@@ -81,13 +82,13 @@ class ClipboardAction {
|
||||
*/
|
||||
removeFake() {
|
||||
if (this.fakeHandler) {
|
||||
document.body.removeEventListener('click', this.fakeHandlerCallback);
|
||||
this.container.removeEventListener('click', this.fakeHandlerCallback);
|
||||
this.fakeHandler = null;
|
||||
this.fakeHandlerCallback = null;
|
||||
}
|
||||
|
||||
if (this.fakeElem) {
|
||||
document.body.removeChild(this.fakeElem);
|
||||
this.container.removeChild(this.fakeElem);
|
||||
this.fakeElem = null;
|
||||
}
|
||||
}
|
||||
@@ -130,11 +131,11 @@ class ClipboardAction {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes current selection and focus from `target` element.
|
||||
* Moves focus away from `target` and back to the trigger, removes current selection.
|
||||
*/
|
||||
clearSelection() {
|
||||
if (this.target) {
|
||||
this.target.blur();
|
||||
if (this.trigger) {
|
||||
this.trigger.focus();
|
||||
}
|
||||
|
||||
window.getSelection().removeAllRanges();
|
||||
|
||||
@@ -24,9 +24,10 @@ class Clipboard extends Emitter {
|
||||
* @param {Object} options
|
||||
*/
|
||||
resolveOptions(options = {}) {
|
||||
this.action = (typeof options.action === 'function') ? options.action : this.defaultAction;
|
||||
this.target = (typeof options.target === 'function') ? options.target : this.defaultTarget;
|
||||
this.text = (typeof options.text === 'function') ? options.text : this.defaultText;
|
||||
this.action = (typeof options.action === 'function') ? options.action : this.defaultAction;
|
||||
this.target = (typeof options.target === 'function') ? options.target : this.defaultTarget;
|
||||
this.text = (typeof options.text === 'function') ? options.text : this.defaultText;
|
||||
this.container = (typeof options.container === 'object') ? options.container : document.body;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,11 +50,12 @@ class Clipboard extends Emitter {
|
||||
}
|
||||
|
||||
this.clipboardAction = new ClipboardAction({
|
||||
action : this.action(trigger),
|
||||
target : this.target(trigger),
|
||||
text : this.text(trigger),
|
||||
trigger : trigger,
|
||||
emitter : this
|
||||
action : this.action(trigger),
|
||||
target : this.target(trigger),
|
||||
text : this.text(trigger),
|
||||
container : this.container,
|
||||
trigger : trigger,
|
||||
emitter : this
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,12 @@ describe('ClipboardAction', () => {
|
||||
it('should set base properties', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'foo'
|
||||
});
|
||||
|
||||
assert.property(clip, 'action');
|
||||
assert.property(clip, 'container');
|
||||
assert.property(clip, 'emitter');
|
||||
assert.property(clip, 'target');
|
||||
assert.property(clip, 'text');
|
||||
@@ -41,6 +43,7 @@ describe('ClipboardAction', () => {
|
||||
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'foo'
|
||||
});
|
||||
|
||||
@@ -82,6 +85,7 @@ describe('ClipboardAction', () => {
|
||||
it('should create a fake element and select its value', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah'
|
||||
});
|
||||
|
||||
@@ -93,6 +97,7 @@ describe('ClipboardAction', () => {
|
||||
it('should remove a temporary fake element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah'
|
||||
});
|
||||
|
||||
@@ -106,6 +111,7 @@ describe('ClipboardAction', () => {
|
||||
it('should select text from editable element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
|
||||
@@ -115,6 +121,7 @@ describe('ClipboardAction', () => {
|
||||
it('should select text from non-editable element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#paragraph')
|
||||
});
|
||||
|
||||
@@ -141,7 +148,7 @@ describe('ClipboardAction', () => {
|
||||
});
|
||||
|
||||
let clip = new ClipboardAction({
|
||||
emitter: emitter,
|
||||
emitter,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
});
|
||||
@@ -156,7 +163,7 @@ describe('ClipboardAction', () => {
|
||||
});
|
||||
|
||||
let clip = new ClipboardAction({
|
||||
emitter: emitter,
|
||||
emitter,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
});
|
||||
@@ -166,6 +173,7 @@ describe('ClipboardAction', () => {
|
||||
it('should fire a success event with certain properties', done => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
|
||||
@@ -184,6 +192,7 @@ describe('ClipboardAction', () => {
|
||||
it('should fire a error event with certain properties', done => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
|
||||
@@ -203,6 +212,7 @@ describe('ClipboardAction', () => {
|
||||
it('should remove focus from target and text selection', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
target: document.querySelector('#input')
|
||||
});
|
||||
|
||||
@@ -220,6 +230,7 @@ describe('ClipboardAction', () => {
|
||||
it('should destroy an existing fake element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah'
|
||||
});
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('Clipboard', () => {
|
||||
|
||||
describe('#resolveOptions', () => {
|
||||
before(() => {
|
||||
global.fn = function() {};
|
||||
global.fn = () => {};
|
||||
});
|
||||
|
||||
it('should set action as a function', () => {
|
||||
@@ -52,6 +52,20 @@ describe('Clipboard', () => {
|
||||
|
||||
assert.equal(global.fn, clipboard.text);
|
||||
});
|
||||
|
||||
it('should set container as an object', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
container: document.body
|
||||
});
|
||||
|
||||
assert.equal(document.body, clipboard.container);
|
||||
});
|
||||
|
||||
it('should set container as body by default', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
assert.equal(document.body, clipboard.container);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#listenClick', () => {
|
||||
@@ -79,8 +93,8 @@ describe('Clipboard', () => {
|
||||
|
||||
it('should throw an exception when target is invalid', done => {
|
||||
try {
|
||||
var clipboard = new Clipboard('.btn', {
|
||||
target: function() {
|
||||
const clipboard = new Clipboard('.btn', {
|
||||
target() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
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