mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
Followup to small SVG default size
Make sure svg drawings on block images have the default size as the wiki default, no matter their original set size. Also took the opportunity to clarify the synchronization method for scalable and image type in ve.dm.MWImageNode and call it when the image model is loaded to make sure the details are always synchronized before edit. Followup to I682d832e456a501836f33ed1dfc7dbd78a4edf53 Bug: 62893 Change-Id: Ic47016d171634c532092067957cc2c3d431e9746
This commit is contained in:
parent
a6014563bc
commit
4355ea4f10
|
@ -95,7 +95,6 @@ ve.dm.MWImageModel.static.newFromImageNode = function ( node ) {
|
|||
|
||||
imgModel.setDir( doc.getDir() );
|
||||
|
||||
imgModel.setMediaType( attrs.mediatype || 'BITMAP' );
|
||||
imgModel.setType( attrs.type );
|
||||
|
||||
// Fix cases where alignment is undefined
|
||||
|
@ -118,6 +117,9 @@ ve.dm.MWImageModel.static.newFromImageNode = function ( node ) {
|
|||
'custom'
|
||||
);
|
||||
|
||||
// Make sure the node type and scalable are synchronized
|
||||
node.syncScalableToType();
|
||||
|
||||
// If this is a block image, get the caption
|
||||
if ( node.getType() === 'mwBlockImage' ) {
|
||||
captionNode = node.getCaptionNode();
|
||||
|
@ -445,10 +447,10 @@ ve.dm.MWImageModel.prototype.getSizeType = function () {
|
|||
*
|
||||
* Example values: "BITMAP" for JPEG or PNG images; "DRAWING" for SVG graphics
|
||||
*
|
||||
* @return {string|null} Symbolic media type name, or null if empty
|
||||
* @return {string|undefined} Symbolic media type name, or undefined if empty
|
||||
*/
|
||||
ve.dm.MWImageModel.prototype.getMediaType = function () {
|
||||
return this.mediaType;
|
||||
return this.getMediaNode().getMediaType();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -609,7 +611,7 @@ ve.dm.MWImageModel.prototype.setType = function ( type ) {
|
|||
|
||||
// Let the image node update scalable considerations
|
||||
// for default and max dimensions as per the new type.
|
||||
this.getMediaNode().updateType( type );
|
||||
this.getMediaNode().syncScalableToType( type );
|
||||
|
||||
this.emit( 'typeChange', type );
|
||||
};
|
||||
|
@ -664,17 +666,6 @@ ve.dm.MWImageModel.prototype.setSizeType = function ( type ) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set symbolic name of media type.
|
||||
*
|
||||
* @see #getMediaType
|
||||
*
|
||||
* @param {string} type Media type
|
||||
*/
|
||||
ve.dm.MWImageModel.prototype.setMediaType = function ( type ) {
|
||||
this.mediaType = type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set image alignment
|
||||
*
|
||||
|
|
|
@ -34,7 +34,7 @@ ve.dm.MWImageNode = function VeDmMWImageNode() {
|
|||
this.defaultThumbSize = mw.config.get( 'wgVisualEditorConfig' ).defaultUserOptions.defaultthumbsize;
|
||||
|
||||
// Initialize
|
||||
this.updateType( this.getAttribute( 'type' ) );
|
||||
this.syncScalableToType( this.getAttribute( 'type' ) );
|
||||
|
||||
// Events
|
||||
this.connect( this, { 'attributeChange': 'onAttributeChange' } );
|
||||
|
@ -49,11 +49,11 @@ OO.mixinClass( ve.dm.MWImageNode, ve.dm.ResizableNode );
|
|||
/* Methods */
|
||||
|
||||
/**
|
||||
* Update image properties according to the image type.
|
||||
* Update image scalable properties according to the image type.
|
||||
*
|
||||
* @param {string} type The new image type
|
||||
*/
|
||||
ve.dm.MWImageNode.prototype.updateType = function ( type ) {
|
||||
ve.dm.MWImageNode.prototype.syncScalableToType = function ( type ) {
|
||||
var originalDimensions, dimensions,
|
||||
scalable = this.getScalable(),
|
||||
width = this.getAttribute( 'width' ),
|
||||
|
@ -66,7 +66,10 @@ ve.dm.MWImageNode.prototype.updateType = function ( type ) {
|
|||
|
||||
// Deal with the different default sizes
|
||||
if ( type === 'thumb' || type === 'frameless' ) {
|
||||
if ( width >= this.defaultThumbSize ) {
|
||||
// Set the default size to that in the wiki configuration if
|
||||
// 1. The image width is not smaller than the default
|
||||
// 2. If the image is an SVG drawing
|
||||
if ( width >= this.defaultThumbSize || this.getMediaType() === 'DRAWING' ) {
|
||||
dimensions = this.scalable.getDimensionsFromValue( {
|
||||
'width': this.defaultThumbSize
|
||||
} );
|
||||
|
@ -83,7 +86,7 @@ ve.dm.MWImageNode.prototype.updateType = function ( type ) {
|
|||
}
|
||||
|
||||
// Deal with maximum dimensions for images and drawings
|
||||
if ( this.mediaType !== 'DRAWING' ) {
|
||||
if ( this.getMediaType() !== 'DRAWING' ) {
|
||||
if ( originalDimensions ) {
|
||||
scalable.setMaxDimensions( originalDimensions );
|
||||
scalable.setEnforcedMax( true );
|
||||
|
@ -117,7 +120,7 @@ ve.dm.MWImageNode.prototype.updateType = function ( type ) {
|
|||
*/
|
||||
ve.dm.MWImageNode.prototype.onAttributeChange = function ( key, from, to ) {
|
||||
if ( key === 'type' ) {
|
||||
this.updateType( to );
|
||||
this.syncScalableToType( to );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -199,7 +202,7 @@ ve.dm.MWImageNode.prototype.getScalablePromise = function () {
|
|||
// Update media type
|
||||
this.mediaType = info.mediatype;
|
||||
// Update according to type
|
||||
this.updateType();
|
||||
this.syncScalableToType();
|
||||
}
|
||||
}, this ) ).promise();
|
||||
}
|
||||
|
@ -221,3 +224,14 @@ ve.dm.MWImageNode.prototype.createScalable = function () {
|
|||
}
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
|
|
@ -526,7 +526,7 @@ ve.ui.MWMediaEditDialog.prototype.getTeardownProcess = function ( data ) {
|
|||
this.captionNode = null;
|
||||
// Reset the considerations for the scalable
|
||||
// in the image node
|
||||
this.mediaNode.updateType();
|
||||
this.mediaNode.syncScalableToType();
|
||||
}, this );
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue