2013-10-15 12:18:11 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWImageNode class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-10-15 12:18:11 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-08-19 12:25:40 +00:00
|
|
|
* DataModel MediaWiki image node.
|
2013-10-15 12:18:11 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
* @extends ve.dm.GeneratedContentNode
|
2014-09-17 00:33:39 +00:00
|
|
|
* @mixins ve.dm.FocusableNode
|
2014-04-10 00:26:48 +00:00
|
|
|
* @mixins ve.dm.ResizableNode
|
|
|
|
*
|
2013-10-15 12:18:11 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode = function VeDmMWImageNode() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.dm.GeneratedContentNode.call( this );
|
2014-09-17 00:33:39 +00:00
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
ve.dm.FocusableNode.call( this );
|
2017-04-13 10:32:30 +00:00
|
|
|
// ve.dm.MWResizableNode doesn't exist
|
|
|
|
ve.dm.ResizableNode.call( this );
|
2014-04-10 00:26:48 +00:00
|
|
|
|
|
|
|
this.scalablePromise = null;
|
|
|
|
|
|
|
|
// Use 'bitmap' as default media type until we can
|
|
|
|
// fetch the actual media type from the API
|
|
|
|
this.mediaType = 'BITMAP';
|
|
|
|
|
|
|
|
// Initialize
|
2014-07-15 18:43:54 +00:00
|
|
|
this.constructor.static.syncScalableToType(
|
|
|
|
this.getAttribute( 'type' ),
|
|
|
|
this.mediaType,
|
|
|
|
this.getScalable()
|
|
|
|
);
|
2014-04-10 00:26:48 +00:00
|
|
|
|
|
|
|
// Events
|
2014-08-22 20:50:48 +00:00
|
|
|
this.connect( this, { attributeChange: 'onAttributeChange' } );
|
2013-10-15 12:18:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.MWImageNode, ve.dm.GeneratedContentNode );
|
2013-10-15 12:18:11 +00:00
|
|
|
|
2014-09-17 00:33:39 +00:00
|
|
|
OO.mixinClass( ve.dm.MWImageNode, ve.dm.FocusableNode );
|
|
|
|
|
2014-04-10 00:26:48 +00:00
|
|
|
OO.mixinClass( ve.dm.MWImageNode, ve.dm.ResizableNode );
|
|
|
|
|
2014-08-19 12:25:40 +00:00
|
|
|
/* Static methods */
|
|
|
|
|
2017-04-27 18:08:35 +00:00
|
|
|
ve.dm.MWImageNode.static.rdfaToTypes = ( function () {
|
|
|
|
var rdfaToType = {};
|
|
|
|
|
2022-05-30 23:17:46 +00:00
|
|
|
[ 'File', 'Image', 'Video', 'Audio' ].forEach( function ( mediaClass ) {
|
2017-04-27 18:08:35 +00:00
|
|
|
rdfaToType[ 'mw:' + mediaClass ] = { mediaClass: mediaClass, frameType: 'none' };
|
|
|
|
rdfaToType[ 'mw:' + mediaClass + '/Frameless' ] = { mediaClass: mediaClass, frameType: 'frameless' };
|
|
|
|
// Block image only:
|
|
|
|
rdfaToType[ 'mw:' + mediaClass + '/Thumb' ] = { mediaClass: mediaClass, frameType: 'thumb' };
|
|
|
|
rdfaToType[ 'mw:' + mediaClass + '/Frame' ] = { mediaClass: mediaClass, frameType: 'frame' };
|
|
|
|
} );
|
|
|
|
|
|
|
|
return rdfaToType;
|
|
|
|
}() );
|
|
|
|
|
2018-03-20 12:48:27 +00:00
|
|
|
/**
|
|
|
|
* Get RDFa type
|
|
|
|
*
|
|
|
|
* @static
|
2022-05-30 23:17:46 +00:00
|
|
|
* @param {string} mediaClass Media class, one of 'File', 'Image', 'Video' or 'Audio'
|
2018-03-20 12:48:27 +00:00
|
|
|
* @param {string} frameType Frame type, one of 'none', 'frameless', 'thumb' or 'frame'
|
2021-01-27 09:03:38 +00:00
|
|
|
* @param {boolean} isError Whether the included media file is missing
|
2018-03-20 12:48:27 +00:00
|
|
|
* @return {string} RDFa type
|
|
|
|
*/
|
2021-01-27 09:03:38 +00:00
|
|
|
ve.dm.MWImageNode.static.getRdfa = function ( mediaClass, frameType, isError ) {
|
|
|
|
return ( isError ? 'mw:Error ' : '' ) + 'mw:' + mediaClass + {
|
2017-04-27 18:08:35 +00:00
|
|
|
none: '',
|
|
|
|
frameless: '/Frameless',
|
|
|
|
// Block image only:
|
|
|
|
thumb: '/Thumb',
|
|
|
|
frame: '/Frame'
|
|
|
|
}[ frameType ];
|
|
|
|
};
|
|
|
|
|
2018-08-02 19:25:08 +00:00
|
|
|
/**
|
2022-05-30 23:17:46 +00:00
|
|
|
* Map media tags to source attributes
|
2020-06-02 20:30:00 +00:00
|
|
|
*
|
2018-08-02 19:25:08 +00:00
|
|
|
* @type {Object}
|
|
|
|
*/
|
2022-05-30 23:17:46 +00:00
|
|
|
ve.dm.MWImageNode.static.tagsToSrcAttrs = {
|
|
|
|
img: 'src',
|
|
|
|
audio: null,
|
|
|
|
video: 'poster',
|
|
|
|
span: null
|
2018-08-02 19:25:08 +00:00
|
|
|
};
|
|
|
|
|
2018-02-24 12:15:55 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc ve.dm.GeneratedContentNode
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.static.getHashObjectForRendering = function ( dataElement ) {
|
|
|
|
// "Rendering" is just the URL of the thumbnail, so we only
|
|
|
|
// care about src & dimensions
|
2014-08-19 12:25:40 +00:00
|
|
|
return {
|
2018-02-24 12:15:55 +00:00
|
|
|
type: 'mwImage',
|
2014-08-22 20:50:48 +00:00
|
|
|
resource: dataElement.attributes.resource,
|
|
|
|
width: dataElement.attributes.width,
|
|
|
|
height: dataElement.attributes.height
|
2014-08-19 12:25:40 +00:00
|
|
|
};
|
|
|
|
};
|
2014-01-26 15:02:07 +00:00
|
|
|
|
2017-04-27 18:08:35 +00:00
|
|
|
ve.dm.MWImageNode.static.getMatchRdfaTypes = function () {
|
|
|
|
return Object.keys( this.rdfaToTypes );
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWImageNode.static.allowedRdfaTypes = [ 'mw:Error' ];
|
|
|
|
|
2018-06-04 17:14:45 +00:00
|
|
|
ve.dm.MWImageNode.static.isDiffComparable = function ( element, other ) {
|
|
|
|
// Images with different src's shouldn't be diffed
|
|
|
|
return element.type === other.type && element.attributes.resource === other.attributes.resource;
|
|
|
|
};
|
|
|
|
|
2017-03-16 15:32:59 +00:00
|
|
|
ve.dm.MWImageNode.static.describeChanges = function ( attributeChanges, attributes ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var customKeys = [ 'width', 'height', 'defaultSize', 'src', 'href' ],
|
2017-03-16 15:32:59 +00:00
|
|
|
descriptions = [];
|
|
|
|
|
|
|
|
function describeSize( width, height ) {
|
|
|
|
return width + ve.msg( 'visualeditor-dimensionswidget-times' ) + height + ve.msg( 'visualeditor-dimensionswidget-px' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'width' in attributeChanges || 'height' in attributeChanges ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var sizeFrom, sizeTo;
|
2017-03-16 15:32:59 +00:00
|
|
|
if ( attributeChanges.defaultSize && attributeChanges.defaultSize.from === true ) {
|
|
|
|
sizeFrom = ve.msg( 'visualeditor-mediasizewidget-sizeoptions-default' );
|
|
|
|
} else {
|
|
|
|
sizeFrom = describeSize(
|
|
|
|
'width' in attributeChanges ? attributeChanges.width.from : attributes.width,
|
|
|
|
'height' in attributeChanges ? attributeChanges.height.from : attributes.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( attributeChanges.defaultSize && attributeChanges.defaultSize.to === true ) {
|
|
|
|
sizeTo = ve.msg( 'visualeditor-mediasizewidget-sizeoptions-default' );
|
|
|
|
} else {
|
|
|
|
sizeTo = describeSize(
|
|
|
|
'width' in attributeChanges ? attributeChanges.width.to : attributes.width,
|
|
|
|
'height' in attributeChanges ? attributeChanges.height.to : attributes.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-19 12:30:21 +00:00
|
|
|
descriptions.push(
|
2018-09-27 19:26:47 +00:00
|
|
|
ve.htmlMsg( 'visualeditor-changedesc-image-size', this.wrapText( 'del', sizeFrom ), this.wrapText( 'ins', sizeTo ) )
|
2018-06-19 12:30:21 +00:00
|
|
|
);
|
2017-03-16 15:32:59 +00:00
|
|
|
}
|
2021-10-13 12:57:45 +00:00
|
|
|
for ( var key in attributeChanges ) {
|
2017-03-16 15:32:59 +00:00
|
|
|
if ( customKeys.indexOf( key ) === -1 ) {
|
2017-03-23 00:28:41 +00:00
|
|
|
if ( key === 'borderImage' && !attributeChanges.borderImage.from && !attributeChanges.borderImage.to ) {
|
|
|
|
// Skip noise from the data model
|
|
|
|
continue;
|
|
|
|
}
|
2021-10-13 12:57:45 +00:00
|
|
|
var change = this.describeChange( key, attributeChanges[ key ] );
|
2022-05-19 17:00:13 +00:00
|
|
|
if ( change ) {
|
|
|
|
descriptions.push( change );
|
|
|
|
}
|
2017-03-16 15:32:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return descriptions;
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWImageNode.static.describeChange = function ( key, change ) {
|
2018-05-14 11:55:31 +00:00
|
|
|
switch ( key ) {
|
|
|
|
case 'align':
|
2018-06-19 12:30:21 +00:00
|
|
|
return ve.htmlMsg( 'visualeditor-changedesc-align',
|
2019-08-28 15:41:19 +00:00
|
|
|
// The following messages are used here:
|
|
|
|
// * visualeditor-align-desc-left
|
|
|
|
// * visualeditor-align-desc-right
|
|
|
|
// * visualeditor-align-desc-center
|
|
|
|
// * visualeditor-align-desc-default
|
|
|
|
// * visualeditor-align-desc-none
|
2018-09-27 19:26:47 +00:00
|
|
|
this.wrapText( 'del', ve.msg( 'visualeditor-align-desc-' + change.from ) ),
|
|
|
|
this.wrapText( 'ins', ve.msg( 'visualeditor-align-desc-' + change.to ) )
|
2018-05-14 11:55:31 +00:00
|
|
|
);
|
2022-01-26 14:51:52 +00:00
|
|
|
case 'originalWidth':
|
|
|
|
case 'originalHeight':
|
2018-05-14 11:55:31 +00:00
|
|
|
case 'originalClasses':
|
|
|
|
case 'unrecognizedClasses':
|
|
|
|
return;
|
|
|
|
// TODO: Handle valign
|
2017-03-16 15:32:59 +00:00
|
|
|
}
|
|
|
|
// Parent method
|
|
|
|
return ve.dm.Node.static.describeChange.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
2014-07-25 02:28:07 +00:00
|
|
|
/**
|
|
|
|
* Take the given dimensions and scale them to thumbnail size.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-07-25 02:28:07 +00:00
|
|
|
* @param {Object} dimensions Width and height of the image
|
|
|
|
* @param {string} [mediaType] Media type 'DRAWING' or 'BITMAP'
|
|
|
|
* @return {Object} The new width and height of the scaled image
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.static.scaleToThumbnailSize = function ( dimensions, mediaType ) {
|
2019-03-26 21:15:26 +00:00
|
|
|
var defaultThumbSize = mw.config.get( 'wgVisualEditorConfig' )
|
|
|
|
.thumbLimits[ mw.user.options.get( 'thumbsize' ) ];
|
2014-07-25 02:28:07 +00:00
|
|
|
|
|
|
|
mediaType = mediaType || 'BITMAP';
|
|
|
|
|
|
|
|
if ( dimensions.width && dimensions.height ) {
|
|
|
|
// Use dimensions
|
|
|
|
// Resize to default thumbnail size, but only if the image itself
|
|
|
|
// isn't smaller than the default size
|
|
|
|
// For svg/drawings, the default wiki size is always applied
|
|
|
|
if ( dimensions.width > defaultThumbSize || mediaType === 'DRAWING' ) {
|
|
|
|
return ve.dm.Scalable.static.getDimensionsFromValue( {
|
|
|
|
width: defaultThumbSize
|
|
|
|
}, dimensions.width / dimensions.height );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dimensions;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate the image dimensions into new ones according to the bounding box.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2015-08-19 18:33:59 +00:00
|
|
|
* @param {Object} imageDimensions Width and height of the image
|
2014-07-25 02:28:07 +00:00
|
|
|
* @param {Object} boundingBox The limit of the bounding box
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {Object} The new width and height of the scaled image.
|
2014-07-25 02:28:07 +00:00
|
|
|
*/
|
2015-01-15 18:50:30 +00:00
|
|
|
ve.dm.MWImageNode.static.resizeToBoundingBox = function ( imageDimensions, boundingBox ) {
|
|
|
|
var newDimensions = ve.copy( imageDimensions ),
|
|
|
|
scale = Math.min(
|
|
|
|
boundingBox.height / imageDimensions.height,
|
|
|
|
boundingBox.width / imageDimensions.width
|
2014-07-25 02:28:07 +00:00
|
|
|
);
|
2015-01-15 18:50:30 +00:00
|
|
|
|
|
|
|
if ( scale < 1 ) {
|
|
|
|
// Scale down
|
|
|
|
newDimensions = {
|
2015-02-12 01:07:44 +00:00
|
|
|
width: Math.floor( newDimensions.width * scale ),
|
|
|
|
height: Math.floor( newDimensions.height * scale )
|
2015-01-15 18:50:30 +00:00
|
|
|
};
|
2014-07-25 02:28:07 +00:00
|
|
|
}
|
2015-01-15 18:50:30 +00:00
|
|
|
return newDimensions;
|
2014-07-25 02:28:07 +00:00
|
|
|
};
|
|
|
|
|
2014-01-26 15:02:07 +00:00
|
|
|
/**
|
2014-06-04 18:20:37 +00:00
|
|
|
* Update image scalable properties according to the image type.
|
2014-01-26 15:02:07 +00:00
|
|
|
*
|
2014-04-10 00:26:48 +00:00
|
|
|
* @param {string} type The new image type
|
2014-07-15 18:43:54 +00:00
|
|
|
* @param {string} mediaType Image media type 'DRAWING' or 'BITMAP'
|
|
|
|
* @param {ve.dm.Scalable} scalable The scalable object to update
|
2014-01-26 15:02:07 +00:00
|
|
|
*/
|
2014-07-15 18:43:54 +00:00
|
|
|
ve.dm.MWImageNode.static.syncScalableToType = function ( type, mediaType, scalable ) {
|
2021-10-13 12:57:45 +00:00
|
|
|
var defaultThumbSize = mw.config.get( 'wgVisualEditorConfig' )
|
|
|
|
.thumbLimits[ mw.user.options.get( 'thumbsize' ) ];
|
2014-03-25 16:01:04 +00:00
|
|
|
|
2021-10-13 12:57:45 +00:00
|
|
|
var originalDimensions = scalable.getOriginalDimensions();
|
2014-04-10 00:26:48 +00:00
|
|
|
|
2014-09-04 15:29:51 +00:00
|
|
|
// We can only set default dimensions if we have the original ones
|
|
|
|
if ( originalDimensions ) {
|
|
|
|
if ( type === 'thumb' || type === 'frameless' ) {
|
|
|
|
// Set the default size to that in the wiki configuration if
|
|
|
|
// 1. The original image width is not smaller than the default
|
|
|
|
// 2. If the image is an SVG drawing
|
2021-10-13 12:57:45 +00:00
|
|
|
var dimensions;
|
2014-09-04 15:29:51 +00:00
|
|
|
if ( originalDimensions.width >= defaultThumbSize || mediaType === 'DRAWING' ) {
|
|
|
|
dimensions = ve.dm.Scalable.static.getDimensionsFromValue( {
|
|
|
|
width: defaultThumbSize
|
|
|
|
}, scalable.getRatio() );
|
|
|
|
} else {
|
|
|
|
dimensions = ve.dm.Scalable.static.getDimensionsFromValue(
|
|
|
|
originalDimensions,
|
|
|
|
scalable.getRatio()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
scalable.setDefaultDimensions( dimensions );
|
2014-04-10 00:26:48 +00:00
|
|
|
} else {
|
|
|
|
scalable.setDefaultDimensions( originalDimensions );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deal with maximum dimensions for images and drawings
|
2020-02-14 01:23:00 +00:00
|
|
|
if ( mediaType === 'DRAWING' ) {
|
|
|
|
// Vector images are scalable past their original dimensions
|
|
|
|
// EnforcedMax may have previously been set to true
|
|
|
|
scalable.setEnforcedMax( false );
|
|
|
|
|
|
|
|
} else if ( mediaType === 'AUDIO' ) {
|
|
|
|
// Audio files are scalable to any width but have fixed height
|
|
|
|
scalable.fixedRatio = false;
|
|
|
|
scalable.setMinDimensions( { width: 1, height: 32 } );
|
|
|
|
// TODO: No way to enforce max height but not max width
|
|
|
|
scalable.setMaxDimensions( { width: 99999, height: 32 } );
|
|
|
|
scalable.setEnforcedMax( true );
|
|
|
|
scalable.setEnforcedMin( true );
|
|
|
|
|
|
|
|
// Default dimensions for audio files are 0x0, which is no good
|
|
|
|
scalable.setDefaultDimensions( { width: defaultThumbSize, height: 32 } );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Raster image files are limited to their original dimensions
|
2014-04-10 00:26:48 +00:00
|
|
|
if ( originalDimensions ) {
|
|
|
|
scalable.setMaxDimensions( originalDimensions );
|
|
|
|
scalable.setEnforcedMax( true );
|
|
|
|
} else {
|
|
|
|
scalable.setEnforcedMax( false );
|
|
|
|
}
|
|
|
|
}
|
2021-09-25 07:39:29 +00:00
|
|
|
// TODO: Some day, when $wgSvgMaxSize works properly in MediaWiki
|
|
|
|
// we can add it back as max dimension consideration.
|
2014-04-10 00:26:48 +00:00
|
|
|
};
|
2014-07-17 19:55:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scalable promise which fetches original dimensions from the API
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-07-17 19:55:24 +00:00
|
|
|
* @param {string} filename The image filename whose details the scalable will represent
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {jQuery.Promise} Promise which resolves after the image size details are fetched from the API
|
2014-07-17 19:55:24 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.static.getScalablePromise = function ( filename ) {
|
|
|
|
// On the first call set off an async call to update the scalable's
|
|
|
|
// original dimensions from the API.
|
2014-12-16 01:06:05 +00:00
|
|
|
if ( ve.init.platform.imageInfoCache ) {
|
|
|
|
return ve.init.platform.imageInfoCache.get( filename ).then( function ( info ) {
|
2017-06-30 12:51:24 +00:00
|
|
|
if ( !info || info.missing ) {
|
2019-11-02 05:06:28 +00:00
|
|
|
return ve.createDeferred().reject().promise();
|
2014-07-17 19:55:24 +00:00
|
|
|
}
|
2014-12-16 01:06:05 +00:00
|
|
|
return info;
|
2014-07-17 19:55:24 +00:00
|
|
|
} );
|
|
|
|
} else {
|
2019-11-02 05:06:28 +00:00
|
|
|
return ve.createDeferred().reject().promise();
|
2014-07-17 19:55:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-19 12:25:40 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-04-10 00:26:48 +00:00
|
|
|
/**
|
|
|
|
* Respond to attribute change.
|
|
|
|
* Update the rendering of the 'align', src', 'width' and 'height' attributes
|
|
|
|
* when they change in the model.
|
|
|
|
*
|
|
|
|
* @param {string} key Attribute key
|
|
|
|
* @param {string} from Old value
|
|
|
|
* @param {string} to New value
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.prototype.onAttributeChange = function ( key, from, to ) {
|
|
|
|
if ( key === 'type' ) {
|
2014-07-15 18:43:54 +00:00
|
|
|
this.constructor.static.syncScalableToType( to, this.mediaType, this.getScalable() );
|
2014-01-26 15:02:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the normalised filename of the image
|
|
|
|
*
|
2018-02-28 02:01:05 +00:00
|
|
|
* @return {string} Filename (including namespace)
|
2014-01-26 15:02:07 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.prototype.getFilename = function () {
|
2020-03-20 17:08:24 +00:00
|
|
|
return mw.libs.ve.normalizeParsoidResourceName( this.getAttribute( 'resource' ) || '' );
|
2014-01-26 15:02:07 +00:00
|
|
|
};
|
|
|
|
|
2014-04-10 00:26:48 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.prototype.getScalable = function () {
|
2021-10-13 12:57:45 +00:00
|
|
|
var imageNode = this;
|
2014-07-17 19:55:24 +00:00
|
|
|
if ( !this.scalablePromise ) {
|
2014-12-16 01:06:05 +00:00
|
|
|
this.scalablePromise = ve.dm.MWImageNode.static.getScalablePromise( this.getFilename() );
|
|
|
|
// If the promise was already resolved before getScalablePromise returned, then jQuery will execute the done straight away.
|
|
|
|
// So don't just do getScalablePromise( ... ).done because we need to make sure that this.scalablePromise gets set first.
|
|
|
|
this.scalablePromise.done( function ( info ) {
|
2015-02-17 12:30:27 +00:00
|
|
|
if ( info ) {
|
|
|
|
imageNode.getScalable().setOriginalDimensions( {
|
|
|
|
width: info.width,
|
|
|
|
height: info.height
|
|
|
|
} );
|
2021-10-13 12:57:45 +00:00
|
|
|
var oldMediaType = imageNode.mediaType;
|
2015-02-17 12:30:27 +00:00
|
|
|
// Update media type
|
|
|
|
imageNode.mediaType = info.mediatype;
|
|
|
|
// Update according to type
|
|
|
|
imageNode.constructor.static.syncScalableToType(
|
|
|
|
imageNode.getAttribute( 'type' ),
|
|
|
|
imageNode.mediaType,
|
|
|
|
imageNode.getScalable()
|
|
|
|
);
|
2019-04-28 20:56:13 +00:00
|
|
|
imageNode.emit( 'attributeChange', 'mediaType', oldMediaType, imageNode.mediaType );
|
2015-02-17 12:30:27 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-07-17 19:55:24 +00:00
|
|
|
}
|
2016-08-22 21:44:59 +00:00
|
|
|
// Mixin method
|
2014-04-10 00:26:48 +00:00
|
|
|
return ve.dm.ResizableNode.prototype.getScalable.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.prototype.createScalable = function () {
|
|
|
|
return new ve.dm.Scalable( {
|
2014-08-22 20:50:48 +00:00
|
|
|
currentDimensions: {
|
|
|
|
width: this.getAttribute( 'width' ),
|
|
|
|
height: this.getAttribute( 'height' )
|
2014-04-10 00:26:48 +00:00
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
minDimensions: {
|
|
|
|
width: 1,
|
|
|
|
height: 1
|
2014-04-10 00:26:48 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|
2014-06-04 18:20:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get symbolic name of media type.
|
|
|
|
*
|
|
|
|
* Example values: "BITMAP" for JPEG or PNG images; "DRAWING" for SVG graphics
|
|
|
|
*
|
|
|
|
* @return {string|undefined} Symbolic media type name, or undefined if empty
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.prototype.getMediaType = function () {
|
|
|
|
return this.mediaType;
|
|
|
|
};
|
2017-04-27 18:08:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get RDFa type
|
|
|
|
*
|
|
|
|
* @return {string} RDFa type
|
|
|
|
*/
|
|
|
|
ve.dm.MWImageNode.prototype.getRdfa = function () {
|
2021-01-27 09:03:38 +00:00
|
|
|
return this.constructor.static.getRdfa(
|
|
|
|
this.getAttribute( 'mediaClass' ),
|
|
|
|
this.getAttribute( 'type' ),
|
|
|
|
this.getAttribute( 'isError' )
|
|
|
|
);
|
2017-04-27 18:08:35 +00:00
|
|
|
};
|