mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Add isSupported method #355
This commit is contained in:
parent
402c9ee17b
commit
63d1b0f014
14
dist/clipboard.js
vendored
14
dist/clipboard.js
vendored
@ -728,6 +728,20 @@ module.exports = E;
|
||||
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;
|
||||
|
2
dist/clipboard.min.js
vendored
2
dist/clipboard.min.js
vendored
File diff suppressed because one or more lines are too long
@ -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.
|
||||
* @param {Element} trigger
|
||||
|
@ -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', () => {
|
||||
it('should destroy an existing instance of ClipboardAction', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
Loading…
Reference in New Issue
Block a user