New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragmentioner default action should copy link instead of nav #1

Open
tantek opened this Issue Jun 27, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@tantek

tantek commented Jun 27, 2018

Instead of "Link to Text", I want "Copy link to text" that copies the fragmention to the clipboard rather than navigates to it. Copying the link is a better default desired action than navigation. Why would you want to navigate to the thing you just selected? It's more likely you want to copy a link to what you just selected so you can post a highlight of, or comment on the selected text.

(Originally published at: http://tantek.com/2018/178/b1/fragmentioner-copy-instead-of-nav)

@kartikprabhu

This comment has been minimized.

Owner

kartikprabhu commented Jun 27, 2018

@tantek I have not found a good way of copying text to clipboard using vanilla JS. If you know a good documented way I would update the code.

Note: the execCommand("copy") is deprecated https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand#Browser_compatibility

@tantek

This comment has been minimized.

tantek commented Jun 27, 2018

<https://github.com/kartikprabhu> according to the linked examples on:

<https://indieweb.org/citation#append_to_text_selection_copy>

It looks like you can intercept document.oncopy and change the selection (using selection.selectAllChildren) to then cause the copy command itself to copy whatever text you want, rather than having to use execCommand("copy").

(Originally published at: http://tantek.com/2018/178/t1/interecept-document-oncopy-change-selection)

@tantek

This comment has been minimized.

tantek commented Jun 27, 2018

<https://github.com/kartikprabhu> Looks like you can also use the Clipboard API (<https://caniuse.com/clipboard>) to write directly to the clipboard (using navigator.clipboard.writeText) in response to e.g. a click on a link (or button), see and try the code in Example 10 here:

<https://w3c.github.io/clipboard-apis/#clipboard-writetext-data>

(Originally published at: http://tantek.com/2018/178/t2/clipboard-api-write-clipboard)

@kartikprabhu

This comment has been minimized.

Owner

kartikprabhu commented Jun 28, 2018

@tantek thanks for the links. I will look into it. My current thoughts are:

  • if the Clipboard API is supported then the button should copy the link to clipboard
  • else either
    • do the current navigation UI, or
    • display the link in a text box to copy manually

cc: @chrisaldrich @kaushalmodi since you also use fragmentioner

@kaushalmodi

This comment has been minimized.

kaushalmodi commented Jun 29, 2018

I agree that if it's possible to copy the fragmention link to the clipboard, that would be a better default. Thanks for copying me here.

@kartikprabhu

This comment has been minimized.

Owner

kartikprabhu commented Jun 29, 2018

Looks like the Clipboard API has not been implemented yet in FF. Also: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText#Browser_compatibility

Will look into hacking around with execCommand("copy") for now and then switch over later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment