| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
ve.ui.MWWikitextDataTransferHandlerFactory = function VeUiMwWikitextDataTransferHandlerFactory() { |
| 15 |
|
| 16 |
ve.ui.MWWikitextDataTransferHandlerFactory.super.apply( this, arguments ); |
| 17 |
|
| 18 |
for ( const name in ve.ui.dataTransferHandlerFactory.registry ) { |
| 19 |
this.register( ve.ui.dataTransferHandlerFactory.registry[ name ] ); |
| 20 |
} |
| 21 |
|
| 22 |
ve.ui.dataTransferHandlerFactory.on( 'register', ( n, data ) => { |
| 23 |
this.register( data ); |
| 24 |
} ); |
| 25 |
}; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
OO.inheritClass( ve.ui.MWWikitextDataTransferHandlerFactory, ve.ui.DataTransferHandlerFactory ); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
ve.ui.MWWikitextDataTransferHandlerFactory.prototype.create = function () { |
| 47 |
|
| 48 |
const handler = ve.ui.MWWikitextDataTransferHandlerFactory.super.prototype.create.apply( this, arguments ), |
| 49 |
resolve = handler.resolve.bind( handler ); |
| 50 |
|
| 51 |
function isPlain( data ) { |
| 52 |
return typeof data === 'string' || ve.dm.LinearData.static.getType( data ) === 'paragraph'; |
| 53 |
} |
| 54 |
|
| 55 |
handler.resolve = function ( dataOrDoc ) { |
| 56 |
if ( typeof dataOrDoc === 'string' || ( Array.isArray( dataOrDoc ) && dataOrDoc.every( isPlain ) ) ) { |
| 57 |
resolve( dataOrDoc ); |
| 58 |
} else { |
| 59 |
const doc = dataOrDoc instanceof ve.dm.Document ? |
| 60 |
dataOrDoc : |
| 61 |
|
| 62 |
new ve.dm.Document( new ve.dm.ElementLinearData( handler.surface.getModel().getDocument().getStore(), dataOrDoc ) ); |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
const annotations = doc.data.getAnnotationsFromRange( new ve.Range( 0, doc.data.getLength() ) ); |
| 69 |
if ( annotations.getLength() === 1 ) { |
| 70 |
const text = doc.data.getText(); |
| 71 |
if ( annotations.get( 0 ).getAttribute( 'href' ) === text ) { |
| 72 |
return resolve( text ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
ve.init.target.getWikitextFragment( doc, false ) |
| 77 |
.done( resolve ) |
| 78 |
.fail( () => { |
| 79 |
handler.abort(); |
| 80 |
} ); |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
return handler; |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
ve.ui.wikitextDataTransferHandlerFactory = new ve.ui.MWWikitextDataTransferHandlerFactory(); |
| 90 |
|
| 91 |
ve.ui.wikitextDataTransferHandlerFactory.unregister( ve.ui.MWWikitextStringTransferHandler ); |