Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | 1x 126x 126x 126x 126x 126x 126x 1x 1x 2x 1x 1x 1x 1x 122x 1x 1x 1x 4x 1x 3x 1x 1x 1x 1x 26x 1x 3x 1x 113x 1x 52x | /**
* Data transfer item wrapper
*
* @class
* @constructor
* @param {string} kind Item kind, e.g. 'string' or 'file'
* @param {string} type MIME type
* @param {Object} [data] Data object to wrap or convert
* @param {string} [data.dataUri] Data URI to convert to a blob
* @param {Blob} [data.blob] File blob
* @param {string} [data.stringData] String data
* @param {string} [data.htmlStringData] HTML string data
* @param {DataTransferItem} [data.item] Native data transfer item
* @param {string} [name] Item's name, for types which support it, e.g. File
*/
ve.ui.DataTransferItem = function VeUiDataTransferItem( kind, type, data, name ) {
this.kind = kind;
this.type = type;
this.data = data || {};
this.blob = this.data.blob || null;
this.stringData = this.data.stringData || ve.getProp( this.blob, 'name' ) || '';
this.name = name;
};
/* Inheritance */
OO.initClass( ve.ui.DataTransferItem );
/* Static methods */
/**
* Create a data transfer item from a file blob.
*
* @param {Blob} blob File blob
* @param {string} [htmlStringData] HTML string representation of data transfer
* @return {ve.ui.DataTransferItem} New data transfer item
*/
ve.ui.DataTransferItem.static.newFromBlob = function ( blob, htmlStringData ) {
return new ve.ui.DataTransferItem( 'file', blob.type, { blob: blob, htmlStringData: htmlStringData }, blob.name );
};
/**
* Create a data transfer item from a data URI.
*
* @param {string} dataUri Data URI
* @param {string} [htmlStringData] HTML string representation of data transfer
* @return {ve.ui.DataTransferItem} New data transfer item
*/
ve.ui.DataTransferItem.static.newFromDataUri = function ( dataUri, htmlStringData ) {
const parts = dataUri.split( ',' );
return new ve.ui.DataTransferItem( 'file', parts[ 0 ].match( /^data:([^;]+)/ )[ 1 ], { dataUri: parts[ 1 ], htmlStringData: htmlStringData } );
};
/**
* Create a data transfer item from string data.
*
* @param {string} stringData Native string data
* @param {string} [type] Native MIME type
* @param {string} [htmlStringData] HTML string representation of data transfer
* @return {ve.ui.DataTransferItem} New data transfer item
*/
ve.ui.DataTransferItem.static.newFromString = function ( stringData, type, htmlStringData ) {
return new ve.ui.DataTransferItem( 'string', type || 'text/plain', { stringData: stringData, htmlStringData: htmlStringData } );
};
/**
* Create a data transfer item from a native data transfer item.
*
* @param {DataTransferItem} item Native data transfer item
* @param {string} [htmlStringData] HTML string representation of data transfer
* @return {ve.ui.DataTransferItem} New data transfer item
*/
ve.ui.DataTransferItem.static.newFromItem = function ( item, htmlStringData ) {
return new ve.ui.DataTransferItem( item.kind, item.type, { item: item, htmlStringData: htmlStringData }, item.getAsFile().name );
};
/**
* Get file blob
*
* Generically getAsFile returns a Blob, which could be a File.
*
* @return {Blob} File blob
*/
ve.ui.DataTransferItem.prototype.getAsFile = function () {
if ( this.data.item ) {
return this.data.item.getAsFile();
}
if ( !this.blob && this.data.dataUri ) {
const binary = atob( this.data.dataUri );
delete this.data.dataUri;
const array = [];
for ( let i = 0; i < binary.length; i++ ) {
array.push( binary.charCodeAt( i ) );
}
this.blob = new Blob(
[ new Uint8Array( array ) ],
{ type: this.type }
);
}
return this.blob;
};
/**
* Get the extension of the item's name
*
* @return {string|null} The extension of the item's name, or null if not present
*/
ve.ui.DataTransferItem.prototype.getExtension = function () {
return this.name ? this.name.split( '.' ).pop() : null;
};
/**
* Get string data
*
* Differs from native DataTransferItem#getAsString by being synchronous
*
* @return {string} String data
*/
ve.ui.DataTransferItem.prototype.getAsString = function () {
return this.stringData;
};
|