2016-05-26 12:08:26 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWWikitextDataTransferHandlerFactory class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see http://ve.mit-license.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drop handler Factory.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.DataTransferHandlerFactory
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextDataTransferHandlerFactory = function VeUiMwWikitextDataTransferHandlerFactory() {
|
|
|
|
var name,
|
|
|
|
factory = this;
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWWikitextDataTransferHandlerFactory.super.apply( this, arguments );
|
|
|
|
|
|
|
|
for ( name in ve.ui.dataTransferHandlerFactory.registry ) {
|
|
|
|
this.register( ve.ui.dataTransferHandlerFactory.registry[ name ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
ve.ui.dataTransferHandlerFactory.on( 'register', function ( name, data ) {
|
|
|
|
factory.register( data );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWWikitextDataTransferHandlerFactory, ve.ui.DataTransferHandlerFactory );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextDataTransferHandlerFactory.prototype.create = function () {
|
|
|
|
// Parent method
|
|
|
|
var doc,
|
|
|
|
handler = ve.ui.MWWikitextDataTransferHandlerFactory.super.prototype.create.apply( this, arguments ),
|
|
|
|
resolve = handler.resolve.bind( handler );
|
|
|
|
|
|
|
|
function isPlain( data ) {
|
|
|
|
return typeof data === 'string' || ve.dm.LinearData.static.getType( data ) === 'paragraph';
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.resolve = function ( dataOrDoc ) {
|
|
|
|
if ( typeof dataOrDoc === 'string' || ( Array.isArray( dataOrDoc ) && dataOrDoc.every( isPlain ) ) ) {
|
|
|
|
resolve( dataOrDoc );
|
|
|
|
} else {
|
2016-12-14 22:54:07 +00:00
|
|
|
doc = dataOrDoc instanceof ve.dm.Document ?
|
|
|
|
dataOrDoc :
|
|
|
|
// The handler may have also written items to the store
|
|
|
|
new ve.dm.Document( new ve.dm.ElementLinearData( handler.surface.getModel().getDocument().getStore(), dataOrDoc ) );
|
|
|
|
|
2016-12-14 22:47:12 +00:00
|
|
|
ve.init.target.getWikitextFragment( doc, false )
|
2016-05-26 12:08:26 +00:00
|
|
|
.done( resolve )
|
|
|
|
.fail( function () {
|
|
|
|
handler.abort();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return handler;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
ve.ui.wikitextDataTransferHandlerFactory = new ve.ui.MWWikitextDataTransferHandlerFactory();
|
2016-09-21 20:08:10 +00:00
|
|
|
|
|
|
|
ve.ui.wikitextDataTransferHandlerFactory.unregister( ve.ui.MWWikitextStringTransferHandler );
|