From a2b667c8f7fc1c2197d25d2ca1d0830f602020f4 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 10 Oct 2013 13:35:59 +0100 Subject: [PATCH] Make MWInlineImages resizable Because they are. Change-Id: Ib2ff3ac6e9c5ed896486c93c48697d232b892493 --- .../ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js index 28d39d8af4..f7ed04d2c9 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWInlineImageNode.js @@ -13,6 +13,7 @@ * @mixins ve.ce.ProtectedNode * @mixins ve.ce.FocusableNode * @mixins ve.ce.RelocatableNode + * @mixins ve.ce.MWResizableNode * * @constructor * @param {ve.dm.MWInlineImageNode} model Model to observe @@ -39,6 +40,7 @@ ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode( model, config ) { ve.ce.ProtectedNode.call( this ); ve.ce.FocusableNode.call( this ); ve.ce.RelocatableNode.call( this ); + ve.ce.MWResizableNode.call( this ); this.$image .attr( 'src', this.model.getAttribute( 'src' ) ) @@ -68,12 +70,38 @@ ve.mixinClass( ve.ce.MWInlineImageNode, ve.ce.FocusableNode ); ve.mixinClass( ve.ce.MWInlineImageNode, ve.ce.RelocatableNode ); +// Need to mixin base class as well +ve.mixinClass( ve.ce.MWInlineImageNode, ve.ce.ResizableNode ); + +ve.mixinClass( ve.ce.MWInlineImageNode, ve.ce.MWResizableNode ); + /* Static Properties */ ve.ce.MWInlineImageNode.static.name = 'mwInlineImage'; ve.ce.MWInlineImageNode.static.tagName = 'img'; +/* Methods */ + +/** */ +ve.ce.MWInlineImageNode.prototype.onAttributeChange = function ( key, from, to ) { + if ( key === 'height' || key === 'width' ) { + to = parseInt( to, 10 ); + } + + if ( from !== to ) { + switch ( key ) { + // TODO: 'align', 'src', 'valign', 'border' + case 'width': + this.$image.css( 'width', to ); + break; + case 'height': + this.$image.css( 'height', to ); + break; + } + } +}; + /* Registration */ ve.ce.nodeFactory.register( ve.ce.MWInlineImageNode );