Last active
May 20, 2016 10:32
-
-
Save olemak/8ed80c649ba81afa91aa516e5692c6cb to your computer and use it in GitHub Desktop.
Adds a copy button after the tags you define (like code or pre). Clicking the button copies the preceeding element/tag text content to the OS clipboard.
Updated:
The first version was in EcmaScript 2015, so I figured it was a good idea to transpile it before sharing :)
Also added arguments, so rather than changing settings inside the function, it now accepts arguments.
And now that it accepts arguments, it needed to vet those arguments, so there are now tests for each of the arguments!
The two arguments are:
1: container - A DOM element. Limits the part of the document that the function affects. Default is the body node.
2: tags - An array of tag names that determines what element types (inside "container") that will receive copy buttons. Default is ['pre','code','blockquote'].
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works in everything except IE<9, which is pretty good, and Safari.
If it does not work, no copy button(s) are displayed, so no loss.
IE and Edge has a "skipping bug"; it scrolls to the bottom of the page when a copy button is clicked. This is related to the position of hiddenCopyContainer (IE scrolls to the position of the selected input element, and in this case it's positioned at the bottom of the page (and off to the left a good ways).
Buttons are unstyled, but can be access bu the CSS class
.reactionary-copy-button