Cleanup elements passed to MWImageNode mixin

Change-Id: Idc736bca6ec7f9cae18d065303364ff5b7828a3b
This commit is contained in:
Ed Sanders 2016-11-06 15:08:23 +00:00
parent 6913a736fd
commit 7a0eb09e32
3 changed files with 28 additions and 20 deletions

View file

@ -17,7 +17,7 @@
* @param {Object} [config] Configuration options
*/
ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode() {
var type, isError;
var type, isError, $image;
// Parent constructor
ve.ce.MWBlockImageNode.super.apply( this, arguments );
@ -35,19 +35,20 @@ ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode() {
// <img> this.$image
// <figcaption> this.caption.view.$element
// Build DOM:
this.$image = $( '<img>' )
.attr( 'src', this.getResolvedAttribute( 'src' ) );
// Build DOM:
if ( isError ) {
$image = $( [] );
this.$a = $( '<a>' )
.addClass( 'new' )
.text( this.model.getFilename() );
} else {
$image = $( '<img>' )
.attr( 'src', this.getResolvedAttribute( 'src' ) );
this.$a = $( '<a>' )
.addClass( 'image' )
.attr( 'href', this.getResolvedAttribute( 'href' ) )
.append( this.$image );
.append( $image );
}
this.$element
@ -63,12 +64,12 @@ ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode() {
// type. The model deals with converting it
.attr( 'typeof', this.typeToRdfa[ type ] );
// Mixin constructors
ve.ce.MWImageNode.call( this, this.$element, $image );
this.updateCaption();
this.updateSize();
// Mixin constructors
ve.ce.MWImageNode.call( this, this.$element, this.$image );
};
/* Inheritance */
@ -265,6 +266,9 @@ ve.ce.MWBlockImageNode.prototype.onSetup = function () {
* @inheritdoc
*/
ve.ce.MWBlockImageNode.prototype.onAttributeChange = function ( key, from, to ) {
// Mixin method
ve.ce.MWImageNode.prototype.onAttributeChange.apply( this, arguments );
if ( key === 'height' || key === 'width' ) {
to = parseInt( to, 10 );
}

View file

@ -15,18 +15,17 @@
* @mixins ve.ce.MWResizableNode
*
* @constructor
* @param {jQuery} $figure Figure element
* @param {jQuery} $image Image element
* @param {jQuery} $focusable Focusable part of the node
* @param {jQuery} $image Image part of the node
* @param {Object} [config] Configuration options
*/
ve.ce.MWImageNode = function VeCeMWImageNode( $figure, $image, config ) {
ve.ce.MWImageNode = function VeCeMWImageNode( $focusable, $image, config ) {
config = ve.extendObject( {
enforceMax: false,
minDimensions: { width: 1, height: 1 }
}, config );
// Properties
this.$figure = $figure;
this.$image = $image;
// Parent constructor triggers render so this must precede it
this.renderedDimensions = null;
@ -35,8 +34,10 @@ ve.ce.MWImageNode = function VeCeMWImageNode( $figure, $image, config ) {
ve.ce.GeneratedContentNode.call( this );
// Mixin constructors
ve.ce.FocusableNode.call( this, this.$figure, config );
ve.ce.MWResizableNode.call( this, this.$image, config );
ve.ce.FocusableNode.call( this, $focusable, config );
if ( this.$image.length ) {
ve.ce.MWResizableNode.call( this, this.$image, config );
}
// Events
this.model.connect( this, { attributeChange: 'onAttributeChange' } );

View file

@ -17,7 +17,7 @@
* @param {Object} [config] Configuration options
*/
ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode() {
var isError;
var isError, $image;
// Parent constructor
ve.ce.MWInlineImageNode.super.apply( this, arguments );
@ -27,20 +27,20 @@ ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode() {
this.$element = $( '<a>' )
.addClass( 'new' )
.text( this.model.getFilename() );
this.$image = $( '<img>' );
$image = $( [] );
} else {
if ( this.model.getAttribute( 'isLinked' ) ) {
this.$element = $( '<a>' ).addClass( 'image' );
this.$image = $( '<img>' ).appendTo( this.$element );
$image = $( '<img>' ).appendTo( this.$element );
} else {
this.$element = this.$image = $( '<img>' ).appendTo( this.$element );
this.$element = $image = $( '<img>' ).appendTo( this.$element );
}
}
// Mixin constructors
ve.ce.MWImageNode.call( this, this.$element, this.$image );
ve.ce.MWImageNode.call( this, this.$element, $image );
this.$image
$image
.attr( 'src', this.getResolvedAttribute( 'src' ) )
.attr( 'width', this.model.getAttribute( 'width' ) )
.attr( 'height', this.model.getAttribute( 'height' ) );
@ -95,6 +95,9 @@ ve.ce.MWInlineImageNode.prototype.updateClasses = function () {
* @inheritdoc
*/
ve.ce.MWInlineImageNode.prototype.onAttributeChange = function ( key, from, to ) {
// Mixin method
ve.ce.MWImageNode.prototype.onAttributeChange.apply( this, arguments );
if ( key === 'height' || key === 'width' ) {
to = parseInt( to, 10 );
}