Skip to content

Commit

Permalink
Merge pull request #350 from cksource/t/16982
Browse files Browse the repository at this point in the history
Enable clipboard API for Safari.
  • Loading branch information
mlewand committed Apr 25, 2017
2 parents 2062bfc + 8fbc222 commit 87ff1a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -53,6 +53,7 @@ Other Changes:
* Fixed: The DOM Exception after click "Remove Language" on a selected word with enabled Language plugin in SCAYT.
* [#16958](http://dev.ckeditor.com/ticket/16958): Switched default MathJax CDN provider from `cdn.mathjax.org` to [cdnjs](https://cdnjs.com/), due to closing of `cdn.mathjax.org` scheduled on April 30, 2017.
* [#16954](http://dev.ckeditor.com/ticket/16954): Remove paste dialog.
* [#16982](http://dev.ckeditor.com/ticket/16982): Latest Safari now supports enhanced clipboard API introduced in CKEditor 4.5.0.

## CKEditor 4.6.2

Expand Down
7 changes: 6 additions & 1 deletion plugins/clipboard/plugin.js
Expand Up @@ -1577,7 +1577,12 @@
return true;
}

// In Safari and IE HTML data is not available though the Clipboard API.
// Safari fixed clipboard in 10.1 (https://bugs.webkit.org/show_bug.cgi?id=19893) (#16982).
if ( CKEDITOR.env.safari && CKEDITOR.env.version >= 603 ) {
return true;
}

// In older Safari and IE HTML data is not available though the Clipboard API.
// In Edge things are a bit messy at the moment -
// https://connect.microsoft.com/IE/feedback/details/1572456/edge-clipboard-api-text-html-content-messed-up-in-event-clipboarddata
// It is safer to use the paste bin in unknown cases.
Expand Down
20 changes: 19 additions & 1 deletion tests/plugins/clipboard/paste.js
Expand Up @@ -49,6 +49,8 @@
} );
}

var trustySafari = CKEDITOR.env.safari && CKEDITOR.env.version >= 603;

bender.test( {
setUp: function() {
// Force result data un-formatted.
Expand Down Expand Up @@ -1335,6 +1337,22 @@
assert.isTrue( canClipboardApiBeTrusted( dataTransfer ), 'Clipboard API should be used in Chrome.' );
},

'test canClipboardApiBeTrusted in Safari': function() {
if ( !trustySafari ) {
assert.ignore();
}

var canClipboardApiBeTrusted = CKEDITOR.plugins.clipboard.canClipboardApiBeTrusted,
nativeData = bender.tools.mockNativeDataTransfer();

nativeData.setData( 'text/html', '<b>foo</b>' );

var evt = { data: { $: { clipboardData: nativeData } } },
dataTransfer = CKEDITOR.plugins.clipboard.initPasteDataTransfer( evt );

assert.isTrue( canClipboardApiBeTrusted( dataTransfer ), 'Clipboard API should be marked as trusted.' );
},

'test canClipboardApiBeTrusted in Android Chrome (no dataTransfer support)': function() {
if ( !CKEDITOR.env.chrome ) {
assert.ignore();
Expand Down Expand Up @@ -1398,7 +1416,7 @@
},

'test canClipboardApiBeTrusted on other browser': function() {
if ( CKEDITOR.env.chrome || CKEDITOR.env.gecko ) {
if ( CKEDITOR.env.chrome || CKEDITOR.env.gecko || trustySafari ) {
assert.ignore();
}

Expand Down

0 comments on commit 87ff1a5

Please sign in to comment.