mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Exposes clearSelection and improves tooltips for non-supported browsers
This commit is contained in:
parent
cb08fd826f
commit
ddefd62593
@ -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;
|
||||
}
|
||||
});
|
||||
|
@ -65,8 +65,6 @@ allowtransparency="true" frameborder="0" scrolling="0" width="156" height="30"><
|
||||
<p>The easiest way to copy some content to the clipboard, is to include a <code>data-text</code> attribute in your trigger element.</p>
|
||||
|
||||
<div id="example-1" class="example">
|
||||
<div class="flash flash-error hidden"></div>
|
||||
|
||||
<button class="btn" data-action="copy" data-text="Just because you can doesn't mean you should — clipboard.js">Copy to clipboard</button>
|
||||
</div>
|
||||
|
||||
@ -106,7 +104,7 @@ allowtransparency="true" frameborder="0" scrolling="0" width="156" height="30"><
|
||||
|
||||
<div id="example-3" class="example">
|
||||
<div class="input-group">
|
||||
<textarea id="bar" cols="62" rows="4" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis. Mé faiz elementum girarzis, nisi eros vermeio, in elementis mé pra quem é amistosis quis leo. Manduma pindureta quium dia nois paga.</textarea>
|
||||
<textarea id="bar" cols="62" rows="5" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">Mussum ipsum cacilds, vidis litro abertis. Consetis adipiscings elitis. Pra lá , depois divoltis porris, paradis. Paisis, filhis, espiritis santis. Mé faiz elementum girarzis, nisi eros vermeio, in elementis mé pra quem é amistosis quis leo. Manduma pindureta quium dia nois paga.</textarea>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn" type="button" data-action="cut" data-target="bar">
|
||||
|
Loading…
Reference in New Issue
Block a user