Re: [clipboard] Feature detect Clipboard API support?

On Wed, Feb 11, 2015 at 7:21 PM, James M. Greene <james.m.greene@gmail.com>
wrote:

> The current spec still leaves me a bit unclear about if implementors must
> include the ability to feature detect Clipboard API support, which I think
> is a critical requirement.
>

I agree it's a very important requirement. And it sucks that we're still
struggling to find a good story..
Here's one (semi-random) idea: the interaction with APIs like
queryCommandEnabled() isn't really fleshed out yet. What if we mandate in
the spec that calling queryCommandEnabled must fire the corresponding
onbefore* event synchronously, and also recommend that this is only
implemented when the support for the other parts is ready to go?

The feature detection might then look a bit like this:

var modernClipboardImplementation = false;
document.onbeforecut = function(e){
    e.preventDefault();
}
try{
    if(document.queryCommandEnabled('cut')){
        modernClipboardImplementation = true;
    }
}catch(e){
        modernClipboardImplementation = false; // yeah, likely not
necessary..
}

In other words: if the onbeforecut fires and you can prevent the default
action to tell the script using queryCommandEnabled() that cut is enabled,
we assume the implementation is top-notch. It probably includes
click-to-copy too.. ;)

Maybe not super-elegant, but not too convoluted either - and no
implementation I've tested so far does it.
-Hallvord

Received on Monday, 20 April 2015 22:09:57 UTC