Florianschmidtwelzow has uploaded a new change for review. https://gerrit.wikimedia.org/r/288773
Change subject: WIP: Add possibility to paste a file to the document ...................................................................... WIP: Add possibility to paste a file to the document Currently works for Chrome only, no FF and IE supported (and probably Safari isn't supported, too). Based on the clipboard api[1], which is currently a working draft[2]. [1] http://caniuse.com/#feat=clipboard [2] https://www.w3.org/TR/clipboard-apis/ Bug: T39932 Change-Id: Ib415a0e84667b58796bba03c880501cd6b7a2d80 --- M modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js 1 file changed, 42 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/73/288773/1 diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js b/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js index fb998c2..5a2bd15 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js @@ -193,6 +193,48 @@ this.target.surface.getModel().getDocument().connect( this, { transact: 'recordLastTransactionTime' } ); + // event handler for paste on the contenteditable element + this.target.surface.getView().getDocument().getDocumentNode().$element.on( + 'paste', + $.proxy( this, 'onPaste' ) + ); +}; + +/** + * Event handler for the paste event on the contenteditable. Handles a file that + * is pasted on the editable field to open the upload form with the pasted file + * pre-selected. + * + * @param ev The paste event + */ +ve.init.mw.ArticleTargetEvents.prototype.onPaste = function ( ev ) { + var clipboardData = ev.clipboardData || ev.originalEvent.clipboardData, + surface = this.target.surface, + windowManager = surface.getDialogs(), + items; + + if ( clipboardData ) { + items = clipboardData.items || clipboardData.files; + } + if ( !items || !items.length ) { + // File copy paste is not supported by this browser or no file was pasted + return; + } + for ( index in items ) { + var item = items[index]; + // only images are supported for the upload + if ( item.type && item.type.indexOf( 'image/' ) > -1 ) { + var blob = item.getAsFile(); + windowManager.openWindow( 'media', { + fragment: surface.getModel().getFragment( undefined, true ) + } ).done( function () { + windowManager.getWindow( 'media' ).done( function ( window ) { + window.searchTabs.setCard( 'upload' ); + window.mediaUploadBooklet.setFile( blob ); + } ); + } ); + }; + } }; /** -- To view, visit https://gerrit.wikimedia.org/r/288773 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib415a0e84667b58796bba03c880501cd6b7a2d80 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits