mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Merge "Another default alignment fix to MWImageModel"
This commit is contained in:
commit
c9a56f17a0
|
@ -102,7 +102,7 @@ ve.dm.MWImageModel.static.newFromImageNode = function ( node ) {
|
|||
// Inline images have no 'align' (they have 'valign' instead)
|
||||
// But we do want an alignment case for these in case they
|
||||
// are transformed to block images
|
||||
attrs.align = attrs.align !== undefined ? attrs.align : 'default';
|
||||
attrs.align = attrs.align || 'default';
|
||||
|
||||
imgModel.setAlignment( attrs.align );
|
||||
|
||||
|
@ -132,13 +132,20 @@ ve.dm.MWImageModel.static.newFromImageNode = function ( node ) {
|
|||
|
||||
/**
|
||||
* Get the current image node type according to the attributes.
|
||||
* If either of the parameters are given, the node type is tested
|
||||
* against them, otherwise, it is tested against the current image
|
||||
* parameters.
|
||||
*
|
||||
* @param {string} [imageType] Optional. Image type.
|
||||
* @param {string} [align] Optional. Image alignment.
|
||||
* @return {string} Node type 'mwInlineImage' or 'mwBlockImage'
|
||||
*/
|
||||
ve.dm.MWImageModel.prototype.getImageNodeType = function () {
|
||||
ve.dm.MWImageModel.prototype.getImageNodeType = function ( imageType, align ) {
|
||||
imageType = imageType || this.getType();
|
||||
|
||||
if (
|
||||
( this.getType() === 'frameless' || this.getType() === 'none' ) &&
|
||||
( !this.isAligned() || this.isDefaultAligned() )
|
||||
( !this.isAligned( align ) || this.isDefaultAligned( imageType, align ) )
|
||||
) {
|
||||
return 'mwInlineImage';
|
||||
} else {
|
||||
|
@ -351,23 +358,41 @@ ve.dm.MWImageModel.prototype.hasBorder = function () {
|
|||
|
||||
/**
|
||||
* Check whether the image has floating alignment set
|
||||
* @param {string} [align] Optional. Alignment value to test against.
|
||||
* @return {boolean} hasAlignment flag on or off
|
||||
*/
|
||||
ve.dm.MWImageModel.prototype.isAligned = function () {
|
||||
return this.alignment !== 'none';
|
||||
ve.dm.MWImageModel.prototype.isAligned = function ( align ) {
|
||||
align = align || this.alignment;
|
||||
// The image is aligned if it has alignment (not undefined and not null)
|
||||
// and if its alignment is not 'none'.
|
||||
// Inline images initially have null alignment value (and are not aligned)
|
||||
return align && align !== 'none';
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether the image is set to default alignment
|
||||
* We explicitly repeat tests so to avoid recursively calling
|
||||
* the other methods.
|
||||
* @param {string} [align] Optional alignment value to test against.
|
||||
* Supplying this parameter would test whether this align parameter
|
||||
* would mean the image is aligned to its default position.
|
||||
* @return {boolean} defaultAlignment flag on or off
|
||||
*/
|
||||
ve.dm.MWImageModel.prototype.isDefaultAligned = function () {
|
||||
var imageType = this.getType(),
|
||||
alignment = this.getAlignment(),
|
||||
ve.dm.MWImageModel.prototype.isDefaultAligned = function ( imageType, align ) {
|
||||
var alignment = align || this.getAlignment(),
|
||||
defaultAlignment = ( this.getDir() === 'rtl' ) ? 'left' : 'right';
|
||||
|
||||
imageType = imageType || this.getType();
|
||||
// No alignment specified means defeault alignment always
|
||||
// Inline images have no align attribute; during the initialization
|
||||
// stage of the model we have to account for that option. Later the
|
||||
// model creates a faux alignment for inline images ('none' for default)
|
||||
// but if initially the alignment is null or undefined, it means the image
|
||||
// is inline without explicit alignment (which makes it default aligned)
|
||||
if ( !alignment ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
(
|
||||
( imageType === 'frameless' || imageType === 'none' ) &&
|
||||
|
@ -428,7 +453,8 @@ ve.dm.MWImageModel.prototype.getMediaType = function () {
|
|||
|
||||
/**
|
||||
* Get image alignment 'left', 'right', 'center', 'none' or 'default'
|
||||
* @return {string} Image alignment
|
||||
* @return {string|null} Image alignment. Inline images have initial alignment
|
||||
* value of null.
|
||||
*/
|
||||
ve.dm.MWImageModel.prototype.getAlignment = function () {
|
||||
return this.alignment;
|
||||
|
@ -494,23 +520,6 @@ ve.dm.MWImageModel.prototype.toggleBorderable = function ( borderable ) {
|
|||
this.borderable = borderable;
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle whether the image has an floating alignment set
|
||||
*
|
||||
* @param {boolean} [aligned] Image has alignment
|
||||
* @fires alignmentChange
|
||||
*
|
||||
ve.dm.MWImageModel.prototype.toggleAligned = function ( aligned ) {
|
||||
var currentAlignment;
|
||||
|
||||
aligned = aligned !== undefined ? !!aligned : !this.isAligned();
|
||||
|
||||
if ( !aligned ) {
|
||||
this.setAlignment( 'none' );
|
||||
}
|
||||
|
||||
this.emit( 'alignmentChange', this.getAlignment() );
|
||||
};
|
||||
/**
|
||||
* Toggle the border flag of the image
|
||||
*
|
||||
|
@ -581,6 +590,8 @@ ve.dm.MWImageModel.prototype.setAltText = function ( text ) {
|
|||
* @fires typeChange
|
||||
*/
|
||||
ve.dm.MWImageModel.prototype.setType = function ( type ) {
|
||||
var wasDefaultAligned = this.isDefaultAligned();
|
||||
|
||||
this.type = type;
|
||||
|
||||
if ( type === 'frame' || type === 'thumb' ) {
|
||||
|
@ -591,6 +602,11 @@ ve.dm.MWImageModel.prototype.setType = function ( type ) {
|
|||
this.toggleBorderable( true );
|
||||
}
|
||||
|
||||
if ( wasDefaultAligned ) {
|
||||
// Reset default alignment
|
||||
this.setAlignment( 'default' );
|
||||
}
|
||||
|
||||
// Let the image node update scalable considerations
|
||||
// for default and max dimensions as per the new type.
|
||||
this.getMediaNode().updateType( type );
|
||||
|
|
|
@ -349,8 +349,7 @@ ve.ui.MWMediaEditDialog.prototype.onImageModelAlignmentChange = function ( align
|
|||
*/
|
||||
|
||||
ve.ui.MWMediaEditDialog.prototype.onImageModelTypeChange = function ( type ) {
|
||||
var newImageType,
|
||||
item = type ? this.typeInput.getItemFromData( type ) : null;
|
||||
var item = type ? this.typeInput.getItemFromData( type ) : null;
|
||||
|
||||
this.typeInput.selectItem( item );
|
||||
|
||||
|
@ -361,27 +360,6 @@ ve.ui.MWMediaEditDialog.prototype.onImageModelTypeChange = function ( type ) {
|
|||
this.borderCheckbox.setValue(
|
||||
this.imageModel.isBorderable() && this.imageModel.hasBorder()
|
||||
);
|
||||
|
||||
// If we switched node type (block/inline or vise versa) the 'default' value
|
||||
// should be updated
|
||||
newImageType = this.imageModel.getImageNodeType();
|
||||
if (
|
||||
this.mediaNode.type === 'mwBlockImage' &&
|
||||
newImageType === 'mwInlineImage'
|
||||
) {
|
||||
// Always reset the default alignment value if we're switching from block
|
||||
// to inline
|
||||
this.imageModel.setAlignment( 'default' );
|
||||
} else if (
|
||||
this.mediaNode.type === 'mwInlineImage' &&
|
||||
newImageType === 'mwBlockImage' &&
|
||||
this.imageModel.getAlignment() === 'none'
|
||||
) {
|
||||
// If the alignment is 'none' and we switch from inline to block
|
||||
// switch the alignment to default
|
||||
this.imageModel.setAlignment( 'default' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -496,7 +474,7 @@ ve.ui.MWMediaEditDialog.prototype.setup = function ( data ) {
|
|||
this.positionCheckbox.setValue(
|
||||
this.imageModel.isAligned()
|
||||
);
|
||||
this.positionInput.chooseItem(
|
||||
this.positionInput.selectItem(
|
||||
this.imageModel.isAligned() ?
|
||||
this.positionInput.getItemFromData(
|
||||
this.imageModel.getAlignment()
|
||||
|
@ -513,7 +491,7 @@ ve.ui.MWMediaEditDialog.prototype.setup = function ( data ) {
|
|||
);
|
||||
|
||||
// Type select
|
||||
this.typeInput.chooseItem(
|
||||
this.typeInput.selectItem(
|
||||
this.typeInput.getItemFromData(
|
||||
this.imageModel.getType() || 'none'
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue