mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4ab305297 | ||
|
|
294e9fcb5d | ||
|
|
79c3361ca4 | ||
|
|
c3fefc1fc0 | ||
|
|
42bd266f0b | ||
|
|
53a733fcb5 | ||
|
|
7a5a910bcd | ||
|
|
0163f7cb72 | ||
|
|
941bdbb16e | ||
|
|
00d5cc4e96 | ||
|
|
07a1f8456b |
12
.github/issue_template.md
vendored
12
.github/issue_template.md
vendored
@@ -1,3 +1,7 @@
|
|||||||
|
### Minimal example
|
||||||
|
|
||||||
|
> Fork this [JSFiddle](https://jsfiddle.net/zenorocha/5kk0eysw/) and reproduce your issue.
|
||||||
|
|
||||||
### Expected behaviour
|
### Expected behaviour
|
||||||
|
|
||||||
I thought that by going to the page '...' and pressing the button '...' then '...' would happen.
|
I thought that by going to the page '...' and pressing the button '...' then '...' would happen.
|
||||||
@@ -6,14 +10,6 @@ I thought that by going to the page '...' and pressing the button '...' then '..
|
|||||||
|
|
||||||
Instead of '...', what I saw was that '...' happened instead.
|
Instead of '...', what I saw was that '...' happened instead.
|
||||||
|
|
||||||
### Steps to reproduce
|
|
||||||
|
|
||||||
1. Go this JSFiddle, JSBin, CodePen, etc
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. Refresh the page and wait 5 secs
|
|
||||||
5. Finally the error will magically happen (if it is raining)
|
|
||||||
|
|
||||||
### Browsers affected
|
### Browsers affected
|
||||||
|
|
||||||
I tested on all major browsers and only IE 11 does not work.
|
I tested on all major browsers and only IE 11 does not work.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "clipboard",
|
"name": "clipboard",
|
||||||
"version": "1.5.9",
|
"version": "1.5.11",
|
||||||
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/clipboard.js",
|
"main": "dist/clipboard.js",
|
||||||
|
|||||||
20
dist/clipboard.js
vendored
20
dist/clipboard.js
vendored
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* clipboard.js v1.5.9
|
* clipboard.js v1.5.10
|
||||||
* https://zenorocha.github.io/clipboard.js
|
* https://zenorocha.github.io/clipboard.js
|
||||||
*
|
*
|
||||||
* Licensed MIT © Zeno Rocha
|
* Licensed MIT © Zeno Rocha
|
||||||
@@ -434,14 +434,10 @@ module.exports = E;
|
|||||||
};
|
};
|
||||||
|
|
||||||
ClipboardAction.prototype.initSelection = function initSelection() {
|
ClipboardAction.prototype.initSelection = function initSelection() {
|
||||||
if (this.text && this.target) {
|
if (this.text) {
|
||||||
throw new Error('Multiple attributes declared, use either "target" or "text"');
|
|
||||||
} else if (this.text) {
|
|
||||||
this.selectFake();
|
this.selectFake();
|
||||||
} else if (this.target) {
|
} else if (this.target) {
|
||||||
this.selectTarget();
|
this.selectTarget();
|
||||||
} else {
|
|
||||||
throw new Error('Missing required attributes, use either "target" or "text"');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -454,7 +450,7 @@ module.exports = E;
|
|||||||
|
|
||||||
this.fakeHandler = document.body.addEventListener('click', function () {
|
this.fakeHandler = document.body.addEventListener('click', function () {
|
||||||
return _this.removeFake();
|
return _this.removeFake();
|
||||||
});
|
}) || true;
|
||||||
|
|
||||||
this.fakeElem = document.createElement('textarea');
|
this.fakeElem = document.createElement('textarea');
|
||||||
// Prevent zooming on iOS
|
// Prevent zooming on iOS
|
||||||
@@ -464,7 +460,7 @@ module.exports = E;
|
|||||||
this.fakeElem.style.padding = '0';
|
this.fakeElem.style.padding = '0';
|
||||||
this.fakeElem.style.margin = '0';
|
this.fakeElem.style.margin = '0';
|
||||||
// Move element out of screen horizontally
|
// Move element out of screen horizontally
|
||||||
this.fakeElem.style.position = 'fixed';
|
this.fakeElem.style.position = 'absolute';
|
||||||
this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
|
this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
|
||||||
// Move element to the same position vertically
|
// Move element to the same position vertically
|
||||||
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
|
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
|
||||||
@@ -554,6 +550,14 @@ module.exports = E;
|
|||||||
set: function set(target) {
|
set: function set(target) {
|
||||||
if (target !== undefined) {
|
if (target !== undefined) {
|
||||||
if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
|
if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
|
||||||
|
if (this.action === 'copy' && target.hasAttribute('disabled')) {
|
||||||
|
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
|
||||||
|
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
|
||||||
|
}
|
||||||
|
|
||||||
this._target = target;
|
this._target = target;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid "target" value, use a valid Element');
|
throw new Error('Invalid "target" value, use a valid Element');
|
||||||
|
|||||||
4
dist/clipboard.min.js
vendored
4
dist/clipboard.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@
|
|||||||
Package.describe({
|
Package.describe({
|
||||||
name: "zenorocha:clipboard",
|
name: "zenorocha:clipboard",
|
||||||
summary: "Modern copy to clipboard. No Flash. Just 2kb.",
|
summary: "Modern copy to clipboard. No Flash. Just 2kb.",
|
||||||
version: "1.5.9",
|
version: "1.5.11",
|
||||||
git: "https://github.com/zenorocha/clipboard.js"
|
git: "https://github.com/zenorocha/clipboard.js"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "clipboard",
|
"name": "clipboard",
|
||||||
"version": "1.5.9",
|
"version": "1.5.11",
|
||||||
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
||||||
"repository": "zenorocha/clipboard.js",
|
"repository": "zenorocha/clipboard.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
[](https://travis-ci.org/zenorocha/clipboard.js)
|
[](https://travis-ci.org/zenorocha/clipboard.js)
|
||||||

|

|
||||||
|
|
||||||
> Modern copy to clipboard. No Flash. Just 2kb
|
> Modern copy to clipboard. No Flash. Just 3kb gzipped.
|
||||||
|
|
||||||
<a href="http://clipboardjs.com/"><img width="728" src="https://cloud.githubusercontent.com/assets/398893/9983535/5ab0a950-5fb4-11e5-9602-e73c0b661883.jpg" alt="Demo"></a>
|
<a href="http://clipboardjs.com/"><img width="728" src="https://cloud.githubusercontent.com/assets/398893/9983535/5ab0a950-5fb4-11e5-9602-e73c0b661883.jpg" alt="Demo"></a>
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ This library relies on both [Selection](https://developer.mozilla.org/en-US/docs
|
|||||||
|
|
||||||
Although copy/cut operations with [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) aren't supported on Safari yet (including mobile), it gracefully degrades because [Selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection) is supported.
|
Although copy/cut operations with [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) aren't supported on Safari yet (including mobile), it gracefully degrades because [Selection](https://developer.mozilla.org/en-US/docs/Web/API/Selection) is supported.
|
||||||
|
|
||||||
That means you can 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.
|
That means you can show a tooltip saying `Copied!` when `success` event is called and `Press Command+C to copy` when `error` event is called because the text is already selected.
|
||||||
|
|
||||||
For a live demonstration, open this [site](http://clipboardjs.com) on Safari.
|
For a live demonstration, open this [site](http://clipboardjs.com) on Safari.
|
||||||
|
|
||||||
|
|||||||
@@ -32,18 +32,12 @@ class ClipboardAction {
|
|||||||
* on the existence of `text` and `target` properties.
|
* on the existence of `text` and `target` properties.
|
||||||
*/
|
*/
|
||||||
initSelection() {
|
initSelection() {
|
||||||
if (this.text && this.target) {
|
if (this.text) {
|
||||||
throw new Error('Multiple attributes declared, use either "target" or "text"');
|
|
||||||
}
|
|
||||||
else if (this.text) {
|
|
||||||
this.selectFake();
|
this.selectFake();
|
||||||
}
|
}
|
||||||
else if (this.target) {
|
else if (this.target) {
|
||||||
this.selectTarget();
|
this.selectTarget();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
throw new Error('Missing required attributes, use either "target" or "text"');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,11 +45,11 @@ class ClipboardAction {
|
|||||||
* and makes a selection on it.
|
* and makes a selection on it.
|
||||||
*/
|
*/
|
||||||
selectFake() {
|
selectFake() {
|
||||||
let isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
const isRTL = document.documentElement.getAttribute('dir') == 'rtl';
|
||||||
|
|
||||||
this.removeFake();
|
this.removeFake();
|
||||||
|
|
||||||
this.fakeHandler = document.body.addEventListener('click', () => this.removeFake());
|
this.fakeHandler = document.body.addEventListener('click', () => this.removeFake()) || true;
|
||||||
|
|
||||||
this.fakeElem = document.createElement('textarea');
|
this.fakeElem = document.createElement('textarea');
|
||||||
// Prevent zooming on iOS
|
// Prevent zooming on iOS
|
||||||
@@ -65,7 +59,7 @@ class ClipboardAction {
|
|||||||
this.fakeElem.style.padding = '0';
|
this.fakeElem.style.padding = '0';
|
||||||
this.fakeElem.style.margin = '0';
|
this.fakeElem.style.margin = '0';
|
||||||
// Move element out of screen horizontally
|
// Move element out of screen horizontally
|
||||||
this.fakeElem.style.position = 'fixed';
|
this.fakeElem.style.position = 'absolute';
|
||||||
this.fakeElem.style[ isRTL ? 'right' : 'left' ] = '-9999px';
|
this.fakeElem.style[ isRTL ? 'right' : 'left' ] = '-9999px';
|
||||||
// Move element to the same position vertically
|
// Move element to the same position vertically
|
||||||
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
|
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
|
||||||
@@ -179,6 +173,14 @@ class ClipboardAction {
|
|||||||
set target(target) {
|
set target(target) {
|
||||||
if (target !== undefined) {
|
if (target !== undefined) {
|
||||||
if (target && typeof target === 'object' && target.nodeType === 1) {
|
if (target && typeof target === 'object' && target.nodeType === 1) {
|
||||||
|
if (this.action === 'copy' && target.hasAttribute('disabled')) {
|
||||||
|
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
|
||||||
|
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
|
||||||
|
}
|
||||||
|
|
||||||
this._target = target;
|
this._target = target;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class Clipboard extends Emitter {
|
|||||||
* @param {Event} e
|
* @param {Event} e
|
||||||
*/
|
*/
|
||||||
onClick(e) {
|
onClick(e) {
|
||||||
let trigger = e.delegateTarget || e.currentTarget;
|
const trigger = e.delegateTarget || e.currentTarget;
|
||||||
|
|
||||||
if (this.clipboardAction) {
|
if (this.clipboardAction) {
|
||||||
this.clipboardAction = null;
|
this.clipboardAction = null;
|
||||||
@@ -70,7 +70,7 @@ class Clipboard extends Emitter {
|
|||||||
* @param {Element} trigger
|
* @param {Element} trigger
|
||||||
*/
|
*/
|
||||||
defaultTarget(trigger) {
|
defaultTarget(trigger) {
|
||||||
let selector = getAttributeValue('target', trigger);
|
const selector = getAttributeValue('target', trigger);
|
||||||
|
|
||||||
if (selector) {
|
if (selector) {
|
||||||
return document.querySelector(selector);
|
return document.querySelector(selector);
|
||||||
@@ -105,7 +105,7 @@ class Clipboard extends Emitter {
|
|||||||
* @param {Element} element
|
* @param {Element} element
|
||||||
*/
|
*/
|
||||||
function getAttributeValue(suffix, element) {
|
function getAttributeValue(suffix, element) {
|
||||||
let attribute = `data-clipboard-${suffix}`;
|
const attribute = `data-clipboard-${suffix}`;
|
||||||
|
|
||||||
if (!element.hasAttribute(attribute)) {
|
if (!element.hasAttribute(attribute)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -35,29 +35,6 @@ describe('ClipboardAction', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#initSelection', () => {
|
describe('#initSelection', () => {
|
||||||
it('should throw an error since both "text" and "target" were passed', done => {
|
|
||||||
try {
|
|
||||||
new ClipboardAction({
|
|
||||||
text: 'foo',
|
|
||||||
target: document.querySelector('#input')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
assert.equal(e.message, 'Multiple attributes declared, use either "target" or "text"');
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error since neither "text" nor "target" were passed', done => {
|
|
||||||
try {
|
|
||||||
new ClipboardAction();
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
assert.equal(e.message, 'Missing required attributes, use either "target" or "text"');
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set the position right style property', done => {
|
it('should set the position right style property', done => {
|
||||||
// Set document direction
|
// Set document direction
|
||||||
document.documentElement.setAttribute('dir', 'rtl');
|
document.documentElement.setAttribute('dir', 'rtl');
|
||||||
|
|||||||
Reference in New Issue
Block a user