diff --git a/assets/main.js b/assets/main.js index 9dad26e..f212073 100644 --- a/assets/main.js +++ b/assets/main.js @@ -10,19 +10,12 @@ document.addEventListener('DOMContentLoaded', function() { console.info('Action:', e.detail.action); console.info('Text:', e.detail.text); + + e.detail.clearSelection(); }); btns[i].addEventListener('error', function(e) { - if (e.currentTarget.hasAttribute('data-text')) { - var flash = document.querySelector('.flash'); - flash.textContent = e.detail; - flash.setAttribute('class', 'flash flash-error'); - - e.currentTarget.disabled = true; - } - else { - showTooltip(e.currentTarget, 'Selected!'); - } + showTooltip(e.currentTarget, messageFallback(e.detail.action)); }); } @@ -30,4 +23,28 @@ document.addEventListener('DOMContentLoaded', function() { elem.setAttribute('class', 'btn tooltipped tooltipped-s'); elem.setAttribute('aria-label', msg); } + + function messageFallback(action) { + var actionKey, actionCommand; + + 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 :('; + } + else if (/Mac/i.test(navigator.userAgent)) { + actionCommand = 'Press ⌘-' + actionKey + ' to ' + action; + } + else { + actionCommand = 'Press Ctrl-' + actionKey + ' to ' + action; + } + + return actionCommand; + } }); diff --git a/index.html b/index.html index 4e44711..018207b 100644 --- a/index.html +++ b/index.html @@ -65,8 +65,6 @@ allowtransparency="true" frameborder="0" scrolling="0" width="156" height="30"><
The easiest way to copy some content to the clipboard, is to include a data-text
attribute in your trigger element.