DLynch has uploaded a new change for review. ( 
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, 30 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/62/331562/1

diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 00d1410..e62b818 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -1602,7 +1602,6 @@
 ve.ce.Surface.prototype.onCopy = function ( e ) {
        var originalSelection, clipboardKey, supportsCustomMimeType,
                scrollTop, unsafeSelector, slice,
-               profile = $.client.profile(),
                selection = this.getModel().getSelection(),
                view = this,
                htmlDoc = this.getModel().getDocument().getHtmlDocument(),
@@ -1658,13 +1657,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.isClipboardMimeTypeSupported( e ) ) {
                this.$pasteTarget.prepend(
                        $( '<span>' ).attr( 'data-ve-clipboard-key', 
clipboardKey ).html( '&nbsp;' )
                );
@@ -1683,7 +1676,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.isClipboardMimeTypeSupported( 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..16ee1a4 100644
--- a/src/ve.utils.js
+++ b/src/ve.utils.js
@@ -1776,3 +1776,31 @@
 ve.isUnmodifiedLeftClick = function ( e ) {
        return e && e.which && e.which === OO.ui.MouseButtons.LEFT && !( 
e.shiftKey || e.altKey || e.ctrlKey || e.metaKey );
 };
+
+/**
+ * Are custom mime types on clipboardData supported?
+ *
+ * If you want to use unknown mime types, an additional check for whether we're
+ * on MS Edge needs to be made, as that only supports standard mime types.
+ *
+ * @param {jQuery.Event} e A jQuery event object for a copy/paste event
+ * @param {boolean} [customTypes] Whether non-standard types
+ * @return {boolean} Whether custom mime types are supported
+ */
+ve.isClipboardMimeTypeSupported = function ( e, customTypes ) {
+       var profile, clipboardData,
+               cacheKey = customTypes ? 'cachedCustom' : 'cached';
+
+       if ( this[ cacheKey ] === undefined ) {
+               profile = $.client.profile();
+               clipboardData = e.originalEvent.clipboardData;
+               this[ 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 this[ cacheKey ];
+};

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6750cdfef8ece0a9838cb387c4f5886d5c9e9519
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <dly...@wikimedia.org>

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

Reply via email to