mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Removes tooltip on mouseleave
This commit is contained in:
@@ -6,17 +6,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
for (var i = 0; i < btns.length; i++) {
|
||||
btns[i].addEventListener('success', function(e) {
|
||||
showTooltip(e.currentTarget, 'Copied!');
|
||||
e.detail.clearSelection();
|
||||
|
||||
console.info('Action:', e.detail.action);
|
||||
console.info('Text:', e.detail.text);
|
||||
|
||||
e.detail.clearSelection();
|
||||
showTooltip(e.currentTarget, 'Copied!');
|
||||
});
|
||||
|
||||
btns[i].addEventListener('error', function(e) {
|
||||
showTooltip(e.currentTarget, messageFallback(e.detail.action));
|
||||
});
|
||||
|
||||
btns[i].addEventListener('mouseleave', function(e) {
|
||||
e.currentTarget.setAttribute('class', 'btn');
|
||||
e.currentTarget.removeAttribute('aria-label');
|
||||
});
|
||||
}
|
||||
|
||||
function showTooltip(elem, msg) {
|
||||
@@ -24,27 +29,21 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
elem.setAttribute('aria-label', msg);
|
||||
}
|
||||
|
||||
// Simplistic detection, do not use it in production
|
||||
function messageFallback(action) {
|
||||
var actionKey, actionCommand;
|
||||
var actionMsg = '';
|
||||
var actionKey = (action === 'cut' ? 'X' : 'C');
|
||||
|
||||
if (action === 'copy') {
|
||||
actionKey = 'C';
|
||||
}
|
||||
else {
|
||||
actionKey = 'X';
|
||||
}
|
||||
|
||||
// Simplistic detection, do not use it in production
|
||||
if(/iPhone|iPad/i.test(navigator.userAgent)) {
|
||||
actionCommand = 'No support :(';
|
||||
actionMsg = 'No support :(';
|
||||
}
|
||||
else if (/Mac/i.test(navigator.userAgent)) {
|
||||
actionCommand = 'Press ⌘-' + actionKey + ' to ' + action;
|
||||
actionMsg = 'Press ⌘-' + actionKey + ' to ' + action;
|
||||
}
|
||||
else {
|
||||
actionCommand = 'Press Ctrl-' + actionKey + ' to ' + action;
|
||||
actionMsg = 'Press Ctrl-' + actionKey + ' to ' + action;
|
||||
}
|
||||
|
||||
return actionCommand;
|
||||
return actionMsg;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user