Is there a way to trigger the copy, cut, and paste events? I've never heard of any. I know that you can be alerted when the events have occurred. I also had a difficult time finding anything about oncopy. My only readable source indicates that it's not cross-browser in either case.[0] I also tested it.
There is a way to trigger the events from JS via document.execCommand('copy'/'cut'/'paste'), but the default is to deny. However, if you just want to alter the behavior of ^C, you simply need to override the oncopy event--there's no need to trigger the event manually. To actually set clipboard data, IE uses window.clipboardData, while Firefox/Chrome/Safari all use event.clipboardData.
> There is a way to trigger the events from JS via document.execCommand('copy'/'cut'/'paste'), but the default is to deny.
When you say, deny, does that mean the user must go to their browser settings and set it manually? If so, what bearing does that have on what we're discussing?
As for setting the clipboard data, I have seen no way of setting that through the copy, paste or cut events.
> When you say, deny, to me the user must go to their browser settings and set it manually?
AFAIK:
Safari does not expose a setting for this (but I didn't look).
Chrome uses Chrome app/extension permissions to control this setting.
I'm not sure how Firefox does it.
> If so, what bearing does that have on what we're discussing?
You asked "Is there a way to trigger the copy, cut, and paste events?". You don't need to trigger them in this case since the browser automatically fires them when the user invokes the corresponding edit action.
> As for setting the clipboard data, I have seen no way of setting that through the copy, paste or cut events.
> AFAIK: Safari does not expose a setting for this (but I didn't look). Chrome uses Chrome app/extension permissions to control this setting. I'm not sure how Firefox does it.
Okay, so for all intents and purposes it cannot be done programmatically without user assistance.
> You asked "Is there a way to trigger the copy, cut, and paste events?". You don't need to trigger them in this case since the browser automatically fires them when the user invokes the corresponding edit action.
As I mentioned in a previous comment, I've seen nothing that suggest this event allows you to change the contents of what's copied to the clipboard before it happens. From what I can tell this is an notification that it has happened. The link you have provided does not indicate anything to the contrary.
I'm not ruling out that what you're saying, but I still haven't seen something that definitively shows it's possible. Looking at all the hacks and alternatives to make it as close to "click-to-copy" a possible strong suggests it's not.
I stand corrected! Firefox, Chrome and Safari had no issues with this. I could cmd-c without highlighting and it still copied.
I finally found something indicating browser-support for this.[0] I have to think it wasn't supported in earlier versions of certain browsers and that's why Trello decided not to go this route. I'm definitely going to play around with this. This is pretty darn cool, thanks for sticking with me. :)
I haven't worked on clipboard stuff in a web app yet, and am finding this thread confusing. If there are APIs for this, why are Trello resorting to a complex and probably rather brittle hack? What does the hack give them that the APIs don't?
I'm not sure, but several guesses:
1) The clipboard APIs aren't well known.
2) You can't normally set HTML content in the clipboard with IE since it only supports 'Text' and 'URL' types (http://msdn.microsoft.com/en-us/library/ms536744(v=vs.85).as...).
3) The IE interface (via window.clipboardData) might trigger an infobar. I didn't really test this though.
0: http://help.dottoro.com/ljwexqxl.php