Image insertion alignment fix

This removes the initial alignment (either left or right) from new
inserted images, letting the wiki decide the default positioning.
Also, it makes sure that VisualEditor positions the image properly
(according to wiki defaults tright/tleft for ltr/rtl) when editing.

Bug: 51851
Change-Id: I25b966cf6f2736437509ea7e70bfda1bdbc79021
This commit is contained in:
Moriel Schottlender 2013-07-23 19:13:28 -04:00
parent ce12fdb6eb
commit 96fa010f58
2 changed files with 24 additions and 5 deletions

View file

@ -63,9 +63,6 @@ ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode( model, config ) {
// Type "frame", "thumb" and the default
this.$image.addClass( 'thumbimage' );
this.$thumb
.addClass(
ve.ce.MWBlockImageNode.static.cssClasses[ 'default' ][ this.model.getAttribute( 'align' ) ]
)
.addClass( 'thumb' );
this.$a.appendTo( this.$thumbInner );
this.$thumbInner.appendTo( this.$thumb );
@ -118,7 +115,8 @@ ve.ce.MWBlockImageNode.static.cssClasses = {
'right': 'tright',
'center' : 'tnone',
'none' : 'tnone',
'default': 'tright'
// Default is different between RTL and LTR wikis:
'default': ['tright', 'tleft']
},
'none': {
'left': 'floatleft',
@ -130,6 +128,27 @@ ve.ce.MWBlockImageNode.static.cssClasses = {
/* Methods */
/**
* Override the default onSetup to add direction-dependent
* classes to the image thumbnail.
*
* @method
*/
ve.ce.MWBlockImageNode.prototype.onSetup = function ( ) {
var type = this.model.getAttribute( 'type' ),
isRTL;
if ( type !== 'none' && type !=='frameless' ) {
// get the proper alignment for the image inside the editor
isRTL = ( this.$.css( 'direction' ) === 'rtl' ) ? 1 : 0;
this.$thumb
.addClass(
ve.ce.MWBlockImageNode.static.cssClasses[ 'default' ][ this.model.getAttribute( 'align' ) ][ isRTL ]
);
}
};
ve.ce.MWBlockImageNode.prototype.onAttributeChange = function ( key, from, to ) {
var $element, type;

View file

@ -68,7 +68,7 @@ ve.ui.MWMediaInsertDialog.prototype.onClose = function ( action ) {
'type': 'mwBlockImage',
'attributes': {
'type': 'thumb',
'align': 'right',
'align': 'default',
//'href': info.descriptionurl,
'href': './' + this.item.title,
'src': info.thumburl,