diff --git a/assets/main.js b/assets/main.js index f212073..368eca1 100644 --- a/assets/main.js +++ b/assets/main.js @@ -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; } }); diff --git a/dist/clipboard.min.js b/dist/clipboard.min.js index 156a7eb..dcb5ae8 100644 --- a/dist/clipboard.min.js +++ b/dist/clipboard.min.js @@ -1 +1 @@ -!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g