mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Fix Event API. Update demos. Update tests (#793)
This commit is contained in:
parent
9698b1176a
commit
7d675f5fc1
@ -20,11 +20,15 @@
|
|||||||
var clipboard = new ClipboardJS(btn);
|
var clipboard = new ClipboardJS(btn);
|
||||||
|
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('error', function (e) {
|
clipboard.on('error', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -20,11 +20,15 @@
|
|||||||
var clipboard = new ClipboardJS(btns);
|
var clipboard = new ClipboardJS(btns);
|
||||||
|
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('error', function (e) {
|
clipboard.on('error', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -19,11 +19,15 @@
|
|||||||
var clipboard = new ClipboardJS('.btn');
|
var clipboard = new ClipboardJS('.btn');
|
||||||
|
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('error', function (e) {
|
clipboard.on('error', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -22,11 +22,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('error', function (e) {
|
clipboard.on('error', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -21,11 +21,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('error', function (e) {
|
clipboard.on('error', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -24,11 +24,15 @@
|
|||||||
var clipboard = new ClipboardJS('.btn');
|
var clipboard = new ClipboardJS('.btn');
|
||||||
|
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('error', function (e) {
|
clipboard.on('error', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -24,7 +24,9 @@
|
|||||||
var clipboard = new ClipboardJS('.btn');
|
var clipboard = new ClipboardJS('.btn');
|
||||||
|
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('error', function (e) {
|
clipboard.on('error', function (e) {
|
||||||
|
@ -24,11 +24,15 @@
|
|||||||
var clipboard = new ClipboardJS('.btn');
|
var clipboard = new ClipboardJS('.btn');
|
||||||
|
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
|
|
||||||
clipboard.on('error', function (e) {
|
clipboard.on('error', function (e) {
|
||||||
console.log(e);
|
console.info('Action:', e.action);
|
||||||
|
console.info('Text:', e.text);
|
||||||
|
console.info('Trigger:', e.trigger);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
11
dist/clipboard.js
vendored
11
dist/clipboard.js
vendored
@ -287,16 +287,17 @@ var Clipboard = /*#__PURE__*/function (_Emitter) {
|
|||||||
key: "onClick",
|
key: "onClick",
|
||||||
value: function onClick(e) {
|
value: function onClick(e) {
|
||||||
var trigger = e.delegateTarget || e.currentTarget;
|
var trigger = e.delegateTarget || e.currentTarget;
|
||||||
var selectedText = actions_default({
|
var action = this.action(trigger) || 'copy';
|
||||||
action: this.action(trigger),
|
var text = actions_default({
|
||||||
|
action: action,
|
||||||
container: this.container,
|
container: this.container,
|
||||||
target: this.target(trigger),
|
target: this.target(trigger),
|
||||||
text: this.text(trigger)
|
text: this.text(trigger)
|
||||||
}); // Fires an event based on the copy operation result.
|
}); // Fires an event based on the copy operation result.
|
||||||
|
|
||||||
this.emit(selectedText ? 'success' : 'error', {
|
this.emit(text ? 'success' : 'error', {
|
||||||
action: this.action,
|
action: action,
|
||||||
text: selectedText,
|
text: text,
|
||||||
trigger: trigger,
|
trigger: trigger,
|
||||||
clearSelection: function clearSelection() {
|
clearSelection: function clearSelection() {
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
|
2
dist/clipboard.min.js
vendored
2
dist/clipboard.min.js
vendored
File diff suppressed because one or more lines are too long
@ -69,17 +69,18 @@ class Clipboard extends Emitter {
|
|||||||
*/
|
*/
|
||||||
onClick(e) {
|
onClick(e) {
|
||||||
const trigger = e.delegateTarget || e.currentTarget;
|
const trigger = e.delegateTarget || e.currentTarget;
|
||||||
const selectedText = ClipboardActionDefault({
|
const action = this.action(trigger) || 'copy';
|
||||||
action: this.action(trigger),
|
const text = ClipboardActionDefault({
|
||||||
|
action,
|
||||||
container: this.container,
|
container: this.container,
|
||||||
target: this.target(trigger),
|
target: this.target(trigger),
|
||||||
text: this.text(trigger),
|
text: this.text(trigger),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fires an event based on the copy operation result.
|
// Fires an event based on the copy operation result.
|
||||||
this.emit(selectedText ? 'success' : 'error', {
|
this.emit(text ? 'success' : 'error', {
|
||||||
action: this.action,
|
action,
|
||||||
text: selectedText,
|
text,
|
||||||
trigger,
|
trigger,
|
||||||
clearSelection() {
|
clearSelection() {
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
|
@ -158,6 +158,7 @@ describe('Clipboard', () => {
|
|||||||
|
|
||||||
clipboard.on('success', (e) => {
|
clipboard.on('success', (e) => {
|
||||||
assert.property(e, 'action');
|
assert.property(e, 'action');
|
||||||
|
assert.equal(e.action, 'copy');
|
||||||
assert.property(e, 'text');
|
assert.property(e, 'text');
|
||||||
assert.property(e, 'trigger');
|
assert.property(e, 'trigger');
|
||||||
assert.property(e, 'clearSelection');
|
assert.property(e, 'clearSelection');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user