jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/331562 )

Change subject: Create ve.isClipboardMimeTypeSupported
......................................................................


Create ve.isClipboardMimeTypeSupported

Centralizes some logic so we can reuse it elsewhere.

Change-Id: I6750cdfef8ece0a9838cb387c4f5886d5c9e9519
---
M src/ce/ve.ce.Surface.js
M src/ve.utils.js
2 files changed, 34 insertions(+), 11 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jforrester: Looks good to me, approved



diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 00d1410..8f2488d 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1600,9 +1600,7 @@
  * @param {jQuery.Event} e Copy event
  */
 ve.ce.Surface.prototype.onCopy = function ( e ) {
-       var originalSelection, clipboardKey, supportsCustomMimeType,
-               scrollTop, unsafeSelector, slice,
-               profile = $.client.profile(),
+       var originalSelection, clipboardKey, scrollTop, unsafeSelector, slice,
                selection = this.getModel().getSelection(),
                view = this,
                htmlDoc = this.getModel().getDocument().getHtmlDocument(),
@@ -1658,13 +1656,7 @@
        // Support: IE, Firefox<48
        // Writing the key to text/xcustom won't work in IE & Firefox<48, so 
write
        // it to the HTML instead
-       supportsCustomMimeType = !!clipboardData && (
-               // Chrome
-               clipboardData.items ||
-               // Firefox >= 48 (but not Firefox Android, which has 
name='android' and doesn't support this feature)
-               ( profile.name === 'firefox' && profile.versionNumber >= 48 )
-       );
-       if ( !supportsCustomMimeType ) {
+       if ( !ve.isClipboardDataFormatsSupported( e ) ) {
                this.$pasteTarget.prepend(
                        $( '<span>' ).attr( 'data-ve-clipboard-key', 
clipboardKey ).html( '&nbsp;' )
                );
@@ -1683,7 +1675,7 @@
 
                // Only write a custom mime type if we think the browser 
supports it, otherwise
                // we will have already written a key to the HTML above.
-               if ( supportsCustomMimeType ) {
+               if ( ve.isClipboardDataFormatsSupported( e, true ) ) {
                        clipboardData.setData( 'text/xcustom', clipboardKey );
                }
                clipboardData.setData( 'text/html', this.$pasteTarget.html() );
diff --git a/src/ve.utils.js b/src/ve.utils.js
index 31ee874..a30b5d3 100644
--- a/src/ve.utils.js
+++ b/src/ve.utils.js
@@ -1776,3 +1776,34 @@
 ve.isUnmodifiedLeftClick = function ( e ) {
        return e && e.which && e.which === OO.ui.MouseButtons.LEFT && !( 
e.shiftKey || e.altKey || e.ctrlKey || e.metaKey );
 };
+
+/**
+ * Are multiple formats for clipboardData items supported?
+ *
+ * If you want to use unknown formats, an additional check for whether we're
+ * on MS Edge needs to be made, as that only supports standard plain text / 
HTML.
+ *
+ * @param {jQuery.Event} e A jQuery event object for a copy/paste event
+ * @param {boolean} [customTypes] Check whether non-standard formats are 
supported
+ * @return {boolean} Whether multiple clipboardData item formats are supported
+ */
+ve.isClipboardDataFormatsSupported = function ( e, customTypes ) {
+       var profile, clipboardData,
+               cacheKey = customTypes ? 'cachedCustom' : 'cached';
+
+       if ( ve.isClipboardDataFormatsSupported[ cacheKey ] === undefined ) {
+               profile = $.client.profile();
+               clipboardData = e.originalEvent.clipboardData;
+               ve.isClipboardDataFormatsSupported[ cacheKey ] = !!(
+                       clipboardData &&
+                       ( !customTypes || profile.name !== 'edge' ) && (
+                               // Chrome
+                               clipboardData.items ||
+                               // Firefox >= 48 (but not Firefox Android, 
which has name='android' and doesn't support this feature)
+                               ( profile.name === 'firefox' && 
profile.versionNumber >= 48 )
+                       )
+               );
+       }
+
+       return ve.isClipboardDataFormatsSupported[ cacheKey ];
+};

-- 
To view, visit https://gerrit.wikimedia.org/r/331562
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6750cdfef8ece0a9838cb387c4f5886d5c9e9519
Gerrit-PatchSet: 5
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <dly...@wikimedia.org>
Gerrit-Reviewer: DLynch <dly...@wikimedia.org>
Gerrit-Reviewer: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to