mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
56c56e81fe
By not matching, we allow other types of paste to happen, e.g. HTML/plain text. Bug: T142622 Change-Id: I3a2224ab23b5073eb7b031134ecc3170ccc782c0
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
/*!
|
|
* VisualEditor MediaWiki UserInterface media transfer handler class.
|
|
*
|
|
* @copyright 2011-2016 VisualEditor Team and others; see http://ve.mit-license.org
|
|
*/
|
|
|
|
/* global File */
|
|
|
|
/**
|
|
* Media transfer handler.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.DataTransferHandler
|
|
*
|
|
* @constructor
|
|
* @param {ve.ui.Surface} surface
|
|
* @param {ve.ui.DataTransferItem} item
|
|
*/
|
|
ve.ui.MWMediaTransferHandler = function VeUiMWMediaTransferHandler() {
|
|
// Parent constructor
|
|
ve.ui.MWMediaTransferHandler.super.apply( this, arguments );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWMediaTransferHandler, ve.ui.DataTransferHandler );
|
|
|
|
/* Static properties */
|
|
|
|
ve.ui.MWMediaTransferHandler.static.name = 'media';
|
|
|
|
ve.ui.MWMediaTransferHandler.static.kinds = [ 'file' ];
|
|
|
|
// TODO: Pull available types and extensions from MW config
|
|
ve.ui.MWMediaTransferHandler.static.types = [ 'image/jpeg', 'image/png', 'image/gif', 'image/svg+xml' ];
|
|
|
|
ve.ui.MWMediaTransferHandler.static.extensions = [ 'jpg', 'jpeg', 'png', 'gif', 'svg' ];
|
|
|
|
ve.ui.MWMediaTransferHandler.static.matchFunction = function ( item ) {
|
|
var file = item.getAsFile();
|
|
// If file is null, return true as the data is not available yet from the browser.
|
|
// If file is a non-File (pasted Blob), return false as this is not yet supported.
|
|
return !file || file instanceof File;
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.MWMediaTransferHandler.prototype.process = function () {
|
|
var action,
|
|
file = this.item.getAsFile();
|
|
|
|
action = ve.ui.actionFactory.create( 'window', this.surface );
|
|
action.open( 'media', { file: file } );
|
|
|
|
this.insertableDataDeferred.reject();
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.dataTransferHandlerFactory.register( ve.ui.MWMediaTransferHandler );
|