Compare commits

..

9 Commits

Author SHA1 Message Date
Zeno Rocha
f59d4e6b4d Release v1.6.1 2017-02-28 09:58:40 -08:00
Zeno Rocha
9ddff7e591 Prevents Node env from throwing an error 2017-02-28 09:57:36 -08:00
Zeno Rocha
a00f1fe327 Release v1.6.0 2017-02-08 00:02:14 -08:00
Zeno Rocha
38ae5b34f3 Adds documentation about #355 2017-02-07 23:59:27 -08:00
Zeno Rocha
41b7234d50 Prevents keyboard from opening on iOS when using "data-clipboard-target" 2017-02-07 23:41:46 -08:00
Zeno Rocha
3696739e5e Prevents scroll jump on iOS when using "data-clipboard-text"
Thanks to @geraldarthur at #369
2017-02-07 23:37:43 -08:00
Itai Steinherz
63d1b0f014 Add isSupported method #355 2017-02-07 23:36:29 -08:00
Zeno Rocha
402c9ee17b Release v1.5.16 2016-12-12 11:54:35 -02:00
Zeno Rocha
0538f6e212 Ensures that event delegation works with multiple documents (a page with iframes) 2016-12-12 11:53:41 -02:00
9 changed files with 65 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "clipboard", "name": "clipboard",
"version": "1.5.15", "version": "1.6.1",
"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",

35
dist/clipboard.js vendored
View File

@@ -1,14 +1,16 @@
/*! /*!
* clipboard.js v1.5.15 * clipboard.js v1.6.1
* https://zenorocha.github.io/clipboard.js * https://zenorocha.github.io/clipboard.js
* *
* Licensed MIT © Zeno Rocha * Licensed MIT © Zeno Rocha
*/ */
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var DOCUMENT_NODE_TYPE = 9;
/** /**
* A polyfill for Element.matches() * A polyfill for Element.matches()
*/ */
if (Element && !Element.prototype.matches) { if (typeof Element !== 'undefined' && !Element.prototype.matches) {
var proto = Element.prototype; var proto = Element.prototype;
proto.matches = proto.matchesSelector || proto.matches = proto.matchesSelector ||
@@ -26,7 +28,7 @@ if (Element && !Element.prototype.matches) {
* @return {Function} * @return {Function}
*/ */
function closest (element, selector) { function closest (element, selector) {
while (element && element !== document) { while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
if (element.matches(selector)) return element; if (element.matches(selector)) return element;
element = element.parentNode; element = element.parentNode;
} }
@@ -238,9 +240,19 @@ function select(element) {
selectedText = element.value; selectedText = element.value;
} }
else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
element.focus(); var isReadOnly = element.hasAttribute('readonly');
if (!isReadOnly) {
element.setAttribute('readonly', '');
}
element.select();
element.setSelectionRange(0, element.value.length); element.setSelectionRange(0, element.value.length);
if (!isReadOnly) {
element.removeAttribute('readonly');
}
selectedText = element.value; selectedText = element.value;
} }
else { else {
@@ -450,7 +462,6 @@ module.exports = E;
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
var yPosition = window.pageYOffset || document.documentElement.scrollTop; var yPosition = window.pageYOffset || document.documentElement.scrollTop;
this.fakeElem.addEventListener('focus', window.scrollTo(0, yPosition));
this.fakeElem.style.top = yPosition + 'px'; this.fakeElem.style.top = yPosition + 'px';
this.fakeElem.setAttribute('readonly', ''); this.fakeElem.setAttribute('readonly', '');
@@ -726,6 +737,20 @@ module.exports = E;
this.clipboardAction = null; this.clipboardAction = null;
} }
} }
}], [{
key: 'isSupported',
value: function isSupported() {
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
var actions = typeof action === 'string' ? [action] : action;
var support = !!document.queryCommandSupported;
actions.forEach(function (action) {
support = support && !!document.queryCommandSupported(action);
});
return support;
}
}]); }]);
return Clipboard; return Clipboard;

File diff suppressed because one or more lines are too long

View File

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

View File

@@ -1,6 +1,6 @@
{ {
"name": "clipboard", "name": "clipboard",
"version": "1.5.15", "version": "1.6.1",
"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",
@@ -12,7 +12,7 @@
], ],
"dependencies": { "dependencies": {
"good-listener": "^1.2.0", "good-listener": "^1.2.0",
"select": "^1.0.6", "select": "^1.1.2",
"tiny-emitter": "^1.0.0" "tiny-emitter": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -168,6 +168,8 @@ 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. 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.
## License ## License
[MIT License](http://zenorocha.mit-license.org/) © Zeno Rocha [MIT License](http://zenorocha.mit-license.org/) © Zeno Rocha

View File

@@ -64,7 +64,6 @@ class ClipboardAction {
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
let yPosition = window.pageYOffset || document.documentElement.scrollTop; let yPosition = window.pageYOffset || document.documentElement.scrollTop;
this.fakeElem.addEventListener('focus', window.scrollTo(0, yPosition));
this.fakeElem.style.top = yPosition + 'px'; this.fakeElem.style.top = yPosition + 'px';
this.fakeElem.setAttribute('readonly', ''); this.fakeElem.setAttribute('readonly', '');

View File

@@ -77,6 +77,22 @@ class Clipboard extends Emitter {
} }
} }
/**
* Returns the support of the given action, or all actions if no action is
* given.
* @param {String} [action]
*/
static isSupported(action = ['copy', 'cut']) {
const actions = (typeof action === 'string') ? [action] : action;
let support = !!document.queryCommandSupported;
actions.forEach((action) => {
support = support && !!document.queryCommandSupported(action);
});
return support;
}
/** /**
* Default `text` lookup function. * Default `text` lookup function.
* @param {Element} trigger * @param {Element} trigger

View File

@@ -94,6 +94,17 @@ describe('Clipboard', () => {
}); });
}); });
describe('#static isSupported', () => {
it('should return the support of the given action', () => {
assert.equal(Clipboard.isSupported('copy'), false);
assert.equal(Clipboard.isSupported('cut'), false);
});
it('should return the support of the cut and copy actions', () => {
assert.equal(Clipboard.isSupported(), false);
});
});
describe('#destroy', () => { describe('#destroy', () => {
it('should destroy an existing instance of ClipboardAction', () => { it('should destroy an existing instance of ClipboardAction', () => {
let clipboard = new Clipboard('.btn'); let clipboard = new Clipboard('.btn');