Created
July 21, 2015 07:51
-
-
Save kkleidal/440d854235b88b9ba588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use-strict'; | |
| (function() { | |
| function copyTextArea($selTextArea) { | |
| $selTextArea.select(); | |
| var successful = false; | |
| try { | |
| successful = document.execCommand('copy'); | |
| } catch (err) { | |
| successful = false; | |
| } | |
| if (! successful) { | |
| if (BootstrapDialog) { | |
| BootstrapDialog.show({ | |
| title: "Copy", | |
| message: "Copy to clipboard: Ctrl+C (Cmd+C Mac), Enter.<br/><input type='text'/>", | |
| onshown: function(dialog) { | |
| dialog.getModalBody().find('input').val($selTextArea.val()).select(); | |
| }, | |
| buttons: [ | |
| { | |
| label: 'Close', | |
| hotkey: 13, | |
| action: function(dialog) { | |
| dialog.close(); | |
| } | |
| } | |
| ] | |
| }); | |
| } else { | |
| window.prompt("Copy to clipboard: Ctrl+C (Cmd+C Mac), Enter", $selTextArea.val()); | |
| } | |
| } | |
| } | |
| function clickCopyBtn() { | |
| copyTextArea($($(this).attr("x-target"))); | |
| } | |
| $(function() { | |
| $("button.copy").click(clickCopyBtn); | |
| }); | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage in HTML: