Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var copied = 'تم النسخ';
- var clipboardDemos = new ClipboardJS('[data-clipboard]');
- clipboardDemos.on('success', function(e) {
- e.clearSelection();
- showTooltip(e.trigger, copied);
- });
- clipboardDemos.on('error', function(e) {
- showTooltip(e.trigger, fallbackMessage(e.action));
- });
- // Tooltip code
- var btns = document.querySelectorAll('.copy-btn');
- for (var i = 0; i < btns.length; i++) {
- btns[i].addEventListener('mouseleave', clearTooltip);
- btns[i].addEventListener('blur', clearTooltip);
- }
- function clearTooltip(e) {
- e.currentTarget.removeAttribute('aria-label');
- }
- function showTooltip(elem, msg) {
- $('.copy-btn').addClass('tooltipped');
- $('.copy-btn').addClass('tooltipped-s');
- elem.setAttribute('aria-label', msg);
- }
- function fallbackMessage(action) {
- var actionMsg = '';
- var actionKey = (action === 'cut' ? 'X' : 'C');
- if (/iPhone|iPad/i.test(navigator.userAgent)) {
- actionMsg = 'No support :(';
- } else if (/Mac/i.test(navigator.userAgent)) {
- actionMsg = 'Press ⌘-' + actionKey + ' to ' + action;
- } else {
- actionMsg = 'Press Ctrl-' + actionKey + ' to ' + action;
- }
- return actionMsg;
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment