mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Changes target to support selector instead of id
This commit is contained in:
parent
1ce64f39a2
commit
beab7bc087
@ -157,13 +157,13 @@ class ClipboardAction {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `target` property using the ID of an element
|
||||
* Sets the `target` property using the selector of an element
|
||||
* that will be have its content copied.
|
||||
* @param {String} target
|
||||
*/
|
||||
set target(target) {
|
||||
if (target) {
|
||||
this._target = document.getElementById(target);
|
||||
this._target = document.querySelector(target);
|
||||
|
||||
if (!this._target) {
|
||||
throw new Error('Invalid "data-clipboard-target" selector, use a value that matches an ID');
|
||||
|
@ -24,7 +24,7 @@ describe('ClipboardAction', () => {
|
||||
try {
|
||||
new ClipboardAction({
|
||||
text: 'foo',
|
||||
target: 'input'
|
||||
target: '#input'
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
@ -65,7 +65,7 @@ describe('ClipboardAction', () => {
|
||||
it('should throw an error since "data-clipboard-target" do not match any element', done => {
|
||||
try {
|
||||
new ClipboardAction({
|
||||
target: 'foo'
|
||||
target: '#foo'
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
@ -103,7 +103,7 @@ describe('ClipboardAction', () => {
|
||||
it('should select text from editable element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
target: 'input'
|
||||
target: '#input'
|
||||
});
|
||||
|
||||
assert.equal(clip.selectedText, clip.target.value);
|
||||
@ -112,7 +112,7 @@ describe('ClipboardAction', () => {
|
||||
it('should select text from non-editable element', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
target: 'paragraph'
|
||||
target: '#paragraph'
|
||||
});
|
||||
|
||||
assert.equal(clip.selectedText, clip.target.textContent);
|
||||
@ -139,7 +139,7 @@ describe('ClipboardAction', () => {
|
||||
|
||||
let clip = new ClipboardAction({
|
||||
emitter: emitter,
|
||||
target: 'input'
|
||||
target: '#input'
|
||||
});
|
||||
});
|
||||
|
||||
@ -154,7 +154,7 @@ describe('ClipboardAction', () => {
|
||||
|
||||
let clip = new ClipboardAction({
|
||||
emitter: emitter,
|
||||
target: 'input'
|
||||
target: '#input'
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -163,7 +163,7 @@ describe('ClipboardAction', () => {
|
||||
it('should fire a success event with certain properties', done => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
target: 'input'
|
||||
target: '#input'
|
||||
});
|
||||
|
||||
clip.emitter.on('success', (e) => {
|
||||
@ -181,7 +181,7 @@ describe('ClipboardAction', () => {
|
||||
it('should fire a error event with certain properties', done => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
target: 'input'
|
||||
target: '#input'
|
||||
});
|
||||
|
||||
clip.emitter.on('error', (e) => {
|
||||
@ -200,7 +200,7 @@ describe('ClipboardAction', () => {
|
||||
it('should remove focus from target and text selection', () => {
|
||||
let clip = new ClipboardAction({
|
||||
emitter: new Emitter(),
|
||||
target: 'input'
|
||||
target: '#input'
|
||||
});
|
||||
|
||||
clip.clearSelection();
|
||||
|
Loading…
Reference in New Issue
Block a user