Match MediaWiki's rendering of non-thumb/-frame block images

Change-Id: I43ad72ef2d6b650692e1a0fd4460e4dec70fde7f
This commit is contained in:
Inez Korczyński 2013-06-19 15:58:13 -07:00 committed by Timo Tijhof
parent 38d6c6ba73
commit bed2c1d00d

View file

@ -17,7 +17,7 @@
* @param {Object} [config] Config options * @param {Object} [config] Config options
*/ */
ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode( model, config ) { ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode( model, config ) {
var captionModel, captionView; var captionModel, captionView, type;
// Parent constructor // Parent constructor
ve.ce.BranchNode.call( this, model, config ); ve.ce.BranchNode.call( this, model, config );
@ -27,6 +27,8 @@ ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode( model, config ) {
ve.ce.FocusableNode.call( this ); ve.ce.FocusableNode.call( this );
ve.ce.ResizableNode.call( this ); ve.ce.ResizableNode.call( this );
type = this.model.getAttribute( 'type' );
if ( this.model.getAttribute( 'align' ) === 'center' ) { if ( this.model.getAttribute( 'align' ) === 'center' ) {
this.$.addClass( 'center' ); this.$.addClass( 'center' );
this.$thumb = this.$$( '<div>' ).appendTo( this.$ ); this.$thumb = this.$$( '<div>' ).appendTo( this.$ );
@ -34,29 +36,36 @@ ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode( model, config ) {
this.$thumb = this.$; this.$thumb = this.$;
} }
this.$thumb
.addClass( 'thumb' )
.addClass(
ve.ce.MWBlockImageNode.static.alignToCssClass[ this.model.getAttribute( 'align' ) ]
);
this.$thumbInner = this.$$( '<div>' ) this.$thumbInner = this.$$( '<div>' )
.addClass( 'thumbinner' ) .addClass( 'thumbinner' )
.css( 'width', parseInt( this.model.getAttribute( 'width' ), 10 ) + 2 ) .css( 'width', parseInt( this.model.getAttribute( 'width' ), 10 ) + 2 );
.appendTo( this.$thumb );
this.$a = this.$$( '<a>' ) this.$a = this.$$( '<a>' )
.addClass( 'image' ) .addClass( 'image' )
.attr( 'src', this.model.getAttribute( 'href' ) ) .attr( 'src', this.model.getAttribute( 'href' ) );
.appendTo( this.$thumbInner );
this.$image = this.$$( '<img>' ) this.$image = this.$$( '<img>' )
.addClass( 'thumbimage' )
.attr( 'src', this.model.getAttribute( 'src' ) ) .attr( 'src', this.model.getAttribute( 'src' ) )
.attr( 'width', this.model.getAttribute( 'width' ) ) .attr( 'width', this.model.getAttribute( 'width' ) )
.attr( 'height', this.model.getAttribute( 'height' ) ) .attr( 'height', this.model.getAttribute( 'height' ) )
.appendTo( this.$a ); .appendTo( this.$a );
if ( type === 'none' ) {
this.$thumb.addClass(
ve.ce.MWBlockImageNode.static.cssClasses.none[ this.model.getAttribute( 'align' ) ]
);
this.$a.appendTo( this.$thumb );
} else {
// 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.$resizable = this.$image; this.$resizable = this.$image;
// I smell a caption! // I smell a caption!
@ -93,12 +102,20 @@ ve.ce.MWBlockImageNode.static.renderHtmlAttributes = false;
ve.ce.MWBlockImageNode.static.transition = false; ve.ce.MWBlockImageNode.static.transition = false;
ve.ce.MWBlockImageNode.static.alignToCssClass = { ve.ce.MWBlockImageNode.static.cssClasses = {
'default': {
'left': 'tleft', 'left': 'tleft',
'right': 'tright', 'right': 'tright',
'center' : 'tnone', 'center' : 'tnone',
'none' : 'tnone', 'none' : 'tnone',
'default': 'tright' 'default': 'tright'
},
'none': {
'left': 'floatleft',
'right': 'floatright',
'center' : 'floatnone',
'none' : 'floatnone'
}
}; };
/* Methods */ /* Methods */
@ -122,8 +139,13 @@ ve.ce.MWBlockImageNode.prototype.onAttributeChange = function ( key, from, to )
} }
this.emit( 'setup' ); this.emit( 'setup' );
} }
this.$thumb.removeClass( ve.ce.MWBlockImageNode.static.alignToCssClass[ from ] ); if ( this.model.getAttribute( 'type' ) === 'none' ) {
this.$thumb.addClass( ve.ce.MWBlockImageNode.static.alignToCssClass[ to ] ); this.$thumb.removeClass( ve.ce.MWBlockImageNode.static.cssClasses.none[ from ] );
this.$thumb.addClass( ve.ce.MWBlockImageNode.static.cssClasses.none[ to ] );
} else {
this.$thumb.removeClass( ve.ce.MWBlockImageNode.static.cssClasses[ 'default' ][ from ] );
this.$thumb.addClass( ve.ce.MWBlockImageNode.static.cssClasses[ 'default' ][ to ] );
}
break; break;
case 'src': case 'src':
this.$image.attr( 'src', to ); this.$image.attr( 'src', to );